Skip to content

Commit 7503eca

Browse files
committed
Convert to ESM
1 parent 73955be commit 7503eca

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/package-lock.json
2+
/node_modules/

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ color.
2323

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

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

2828
## install
2929

@@ -34,7 +34,7 @@ npm install clipboard-copy
3434
## usage
3535

3636
```js
37-
const copy = require('clipboard-copy')
37+
import copy from 'clipboard-copy';
3838

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

5959
## testing
6060

61-
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.
61+
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.
6262

6363
## license
6464

example.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const copy = require('./')
1+
import copy from './';
22

33
document.body.style.backgroundColor = 'red'
44

index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/*! clipboard-copy. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
22
/* global DOMException */
33

4-
module.exports = clipboardCopy
5-
64
function makeError () {
75
return new DOMException('The request is not allowed', 'NotAllowedError')
86
}
@@ -49,7 +47,7 @@ async function copyExecCommand (text) {
4947
if (!success) throw makeError()
5048
}
5149

52-
async function clipboardCopy (text) {
50+
export default async function clipboardCopy (text) {
5351
try {
5452
await copyClipboardApi(text)
5553
} catch (err) {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"simple"
2727
],
2828
"license": "MIT",
29-
"main": "index.js",
29+
"type": "module",
30+
"module": "index.js",
3031
"repository": {
3132
"type": "git",
3233
"url": "git://github.com/feross/clipboard-copy.git"

test.html

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
3. Test status: <strong>pending</strong>
1818
</p>
1919

20-
<script type="text/javascript">
21-
window.module = {}
22-
</script>
23-
<script src="index.js"></script>
24-
<script type="text/javascript">
20+
<script type="module">
21+
import copy from './index.js';
22+
2523
var secret = Math.random().toFixed(10).slice(2)
2624

2725
function setStatus (success) {
@@ -30,7 +28,7 @@
3028
}
3129

3230
document.querySelector('button').addEventListener('click', function () {
33-
if (!window.module.exports(secret)) setStatus(false)
31+
if (!copy(secret)) setStatus(false)
3432
})
3533

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

0 commit comments

Comments
 (0)