Skip to content

Commit

Permalink
Convert to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Apr 21, 2021
1 parent 73955be commit 7503eca
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/package-lock.json
/node_modules/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ color.

**Supported browsers:** Chrome, Firefox, Edge, Safari.

Works in the browser with [browserify](http://browserify.org/)!
Works in the browser as an ES module!

## install

Expand All @@ -34,7 +34,7 @@ npm install clipboard-copy
## usage

```js
const copy = require('clipboard-copy')
import copy from 'clipboard-copy';

button.addEventListener('click', function () {
copy('This is some cool text')
Expand All @@ -58,7 +58,7 @@ triggered in direct response to a user gesture like a `'click'` or a `'keypress'

## testing

Testing this module is currently a manual process. Open `test.html` in your web browser and follow the short instructions. The web page will always load the latest version of the module, no bundling is necessary.
Testing this module is currently a manual process. Run `npx http-server`, open `test.html` in your web browser, and follow the short instructions. The web page will always load the latest version of the module, no bundling is necessary.

## license

Expand Down
2 changes: 1 addition & 1 deletion example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const copy = require('./')
import copy from './';

document.body.style.backgroundColor = 'red'

Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*! clipboard-copy. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
/* global DOMException */

module.exports = clipboardCopy

function makeError () {
return new DOMException('The request is not allowed', 'NotAllowedError')
}
Expand Down Expand Up @@ -49,7 +47,7 @@ async function copyExecCommand (text) {
if (!success) throw makeError()
}

async function clipboardCopy (text) {
export default async function clipboardCopy (text) {
try {
await copyClipboardApi(text)
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"simple"
],
"license": "MIT",
"main": "index.js",
"type": "module",
"module": "index.js",
"repository": {
"type": "git",
"url": "git://github.com/feross/clipboard-copy.git"
Expand Down
10 changes: 4 additions & 6 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
3. Test status: <strong>pending</strong>
</p>

<script type="text/javascript">
window.module = {}
</script>
<script src="index.js"></script>
<script type="text/javascript">
<script type="module">
import copy from './index.js';

var secret = Math.random().toFixed(10).slice(2)

function setStatus (success) {
Expand All @@ -30,7 +28,7 @@
}

document.querySelector('button').addEventListener('click', function () {
if (!window.module.exports(secret)) setStatus(false)
if (!copy(secret)) setStatus(false)
})

document.querySelector('input').addEventListener('input', function (ev) {
Expand Down

0 comments on commit 7503eca

Please sign in to comment.