1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/clipboardy/index.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
'use strict';
2024-01-16 21:26:16 +08:00
const isWSL = require('is-wsl');
2023-12-18 13:12:25 +08:00
const termux = require('./lib/termux.js');
const linux = require('./lib/linux.js');
const macos = require('./lib/macos.js');
const windows = require('./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:
2024-01-16 21:26:16 +08:00
// `process.platform === 'linux'` for WSL.
if (isWSL) {
return windows;
}
2023-12-18 13:12:25 +08:00
return linux;
}
})();
exports.write = async text => {
if (typeof text !== 'string') {
throw new TypeError(`Expected a string, got ${typeof text}`);
}
await platformLib.copy({input: text});
};
exports.read = async () => platformLib.paste({stripEof: false});
exports.writeSync = text => {
if (typeof text !== 'string') {
throw new TypeError(`Expected a string, got ${typeof text}`);
}
platformLib.copySync({input: text});
};
exports.readSync = () => platformLib.pasteSync({stripEof: false}).stdout;