clipboardy 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -7,23 +7,30 @@ import windows from './lib/windows.js';
7
7
 
8
8
  const platformLib = (() => {
9
9
  switch (process.platform) {
10
- case 'darwin':
10
+ case 'darwin': {
11
11
  return macos;
12
- case 'win32':
12
+ }
13
+
14
+ case 'win32': {
13
15
  return windows;
14
- case 'android':
16
+ }
17
+
18
+ case 'android': {
15
19
  if (process.env.PREFIX !== '/data/data/com.termux/files/usr') {
16
20
  throw new Error('You need to install Termux for this module to work on Android: https://termux.com');
17
21
  }
18
22
 
19
23
  return termux;
20
- default:
24
+ }
25
+
26
+ default: {
21
27
  // `process.platform === 'linux'` for WSL.
22
28
  if (isWSL) {
23
29
  return windows;
24
30
  }
25
31
 
26
32
  return linux;
33
+ }
27
34
  }
28
35
  })();
29
36
 
package/lib/linux.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import {fileURLToPath} from 'node:url';
3
- import execa from 'execa';
3
+ import {execa, execaSync} from 'execa';
4
4
 
5
5
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
6
 
@@ -39,10 +39,10 @@ const xselWithFallback = async (argumentList, options) => {
39
39
 
40
40
  const xselWithFallbackSync = (argumentList, options) => {
41
41
  try {
42
- return execa.sync(xsel, argumentList, options).stdout;
42
+ return execaSync(xsel, argumentList, options).stdout;
43
43
  } catch (xselError) {
44
44
  try {
45
- return execa.sync(xselFallback, argumentList, options).stdout;
45
+ return execaSync(xselFallback, argumentList, options).stdout;
46
46
  } catch (fallbackError) {
47
47
  throw makeError(xselError, fallbackError);
48
48
  }
@@ -50,10 +50,10 @@ const xselWithFallbackSync = (argumentList, options) => {
50
50
  };
51
51
 
52
52
  const clipboard = {
53
- copy: async options => {
53
+ async copy(options) {
54
54
  await xselWithFallback(copyArguments, options);
55
55
  },
56
- copySync: options => {
56
+ copySync(options) {
57
57
  xselWithFallbackSync(copyArguments, options);
58
58
  },
59
59
  paste: options => xselWithFallback(pasteArguments, options),
package/lib/macos.js CHANGED
@@ -1,17 +1,17 @@
1
- import execa from 'execa';
1
+ import {execa, execaSync} from 'execa';
2
2
 
3
3
  const env = {
4
- LC_CTYPE: 'UTF-8',
4
+ LC_CTYPE: 'UTF-8', // eslint-disable-line unicorn/text-encoding-identifier-case
5
5
  };
6
6
 
7
7
  const clipboard = {
8
8
  copy: async options => execa('pbcopy', {...options, env}),
9
- paste: async options => {
9
+ async paste(options) {
10
10
  const {stdout} = await execa('pbpaste', {...options, env});
11
11
  return stdout;
12
12
  },
13
- copySync: options => execa.sync('pbcopy', {...options, env}),
14
- pasteSync: options => execa.sync('pbpaste', {...options, env}).stdout,
13
+ copySync: options => execaSync('pbcopy', {...options, env}),
14
+ pasteSync: options => execaSync('pbpaste', {...options, env}).stdout,
15
15
  };
16
16
 
17
17
  export default clipboard;
package/lib/termux.js CHANGED
@@ -1,4 +1,4 @@
1
- import execa from 'execa';
1
+ import {execa, execaSync} from 'execa';
2
2
 
3
3
  const handler = error => {
4
4
  if (error.code === 'ENOENT') {
@@ -9,14 +9,14 @@ const handler = error => {
9
9
  };
10
10
 
11
11
  const clipboard = {
12
- copy: async options => {
12
+ async copy(options) {
13
13
  try {
14
14
  await execa('termux-clipboard-set', options);
15
15
  } catch (error) {
16
16
  handler(error);
17
17
  }
18
18
  },
19
- paste: async options => {
19
+ async paste(options) {
20
20
  try {
21
21
  const {stdout} = await execa('termux-clipboard-get', options);
22
22
  return stdout;
@@ -24,16 +24,16 @@ const clipboard = {
24
24
  handler(error);
25
25
  }
26
26
  },
27
- copySync: options => {
27
+ copySync(options) {
28
28
  try {
29
- execa.sync('termux-clipboard-set', options);
29
+ execaSync('termux-clipboard-set', options);
30
30
  } catch (error) {
31
31
  handler(error);
32
32
  }
33
33
  },
34
- pasteSync: options => {
34
+ pasteSync(options) {
35
35
  try {
36
- return execa.sync('termux-clipboard-get', options).stdout;
36
+ return execaSync('termux-clipboard-get', options).stdout;
37
37
  } catch (error) {
38
38
  handler(error);
39
39
  }
package/lib/windows.js CHANGED
@@ -1,23 +1,23 @@
1
1
  import path from 'node:path';
2
2
  import {fileURLToPath} from 'node:url';
3
- import execa from 'execa';
4
- import arch from 'arch';
3
+ import {execa, execaSync} from 'execa';
4
+ import {is64bitSync} from 'is64bit';
5
5
 
6
6
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
7
 
8
- const binarySuffix = arch() === 'x64' ? 'x86_64' : 'i686';
8
+ const binarySuffix = is64bitSync() ? 'x86_64' : 'i686';
9
9
 
10
10
  // Binaries from: https://github.com/sindresorhus/win-clipboard
11
11
  const windowBinaryPath = path.join(__dirname, `../fallbacks/windows/clipboard_${binarySuffix}.exe`);
12
12
 
13
13
  const clipboard = {
14
14
  copy: async options => execa(windowBinaryPath, ['--copy'], options),
15
- paste: async options => {
15
+ async paste(options) {
16
16
  const {stdout} = await execa(windowBinaryPath, ['--paste'], options);
17
17
  return stdout;
18
18
  },
19
- copySync: options => execa.sync(windowBinaryPath, ['--copy'], options),
20
- pasteSync: options => execa.sync(windowBinaryPath, ['--paste'], options).stdout,
19
+ copySync: options => execaSync(windowBinaryPath, ['--copy'], options),
20
+ pasteSync: options => execaSync(windowBinaryPath, ['--paste'], options).stdout,
21
21
  };
22
22
 
23
23
  export default clipboard;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clipboardy",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "Access the system clipboard (copy/paste)",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/clipboardy",
@@ -12,12 +12,14 @@
12
12
  },
13
13
  "type": "module",
14
14
  "exports": {
15
+ "types": "./index.d.ts",
15
16
  "node": "./index.js",
16
17
  "default": "./browser.js"
17
18
  },
18
19
  "engines": {
19
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
20
+ "node": ">=18"
20
21
  },
22
+ "sideEffects": false,
21
23
  "scripts": {
22
24
  "test": "xo && ava && tsd"
23
25
  },
@@ -42,14 +44,14 @@
42
44
  "xsel"
43
45
  ],
44
46
  "dependencies": {
45
- "arch": "^2.2.0",
46
- "execa": "^5.1.1",
47
- "is-wsl": "^2.2.0"
47
+ "execa": "^8.0.1",
48
+ "is-wsl": "^3.1.0",
49
+ "is64bit": "^2.0.0"
48
50
  },
49
51
  "devDependencies": {
50
- "ava": "^3.15.0",
51
- "tsd": "^0.18.0",
52
- "xo": "^0.45.0"
52
+ "ava": "^5.3.1",
53
+ "tsd": "^0.29.0",
54
+ "xo": "^0.56.0"
53
55
  },
54
56
  "ava": {
55
57
  "serial": true
package/readme.md CHANGED
@@ -23,6 +23,8 @@ clipboard.readSync();
23
23
 
24
24
  ## API
25
25
 
26
+ In the browser, it requires a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts).
27
+
26
28
  ### clipboard
27
29
 
28
30
  #### .write(text)