-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
index.js
59 lines (45 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import process from 'node:process';
import isWSL from 'is-wsl';
import termux from './lib/termux.js';
import linux from './lib/linux.js';
import macos from './lib/macos.js';
import windows from './lib/windows.js';
const platformLib = (() => {
switch (process.platform) {
case 'darwin': {
return macos;
}
case 'win32': {
return windows;
}
case 'android': {
if (process.env.PREFIX !== '/data/data/com.termux/files/usr') {
throw new Error('You need to install Termux for this module to work on Android: https://termux.com');
}
return termux;
}
default: {
// `process.platform === 'linux'` for WSL.
if (isWSL) {
return windows;
}
return linux;
}
}
})();
const clipboard = {};
clipboard.write = async text => {
if (typeof text !== 'string') {
throw new TypeError(`Expected a string, got ${typeof text}`);
}
await platformLib.copy({input: text});
};
clipboard.read = async () => platformLib.paste({stripFinalNewline: false});
clipboard.writeSync = text => {
if (typeof text !== 'string') {
throw new TypeError(`Expected a string, got ${typeof text}`);
}
platformLib.copySync({input: text});
};
clipboard.readSync = () => platformLib.pasteSync({stripFinalNewline: false});
export default clipboard;