UNPKG

1.05 kBJavaScriptView Raw
1'use strict';
2const termux = require('./lib/termux.js');
3const linux = require('./lib/linux.js');
4const macos = require('./lib/macos.js');
5const windows = require('./lib/windows.js');
6
7function platform() {
8 switch (process.platform) {
9 case 'darwin':
10 return macos;
11 case 'win32':
12 return windows;
13 case 'android':
14 if (process.env.PREFIX !== '/data/data/com.termux/files/usr') {
15 throw new Error('You need to install Termux for this module to work on Android: https://termux.com');
16 }
17 return termux;
18 default:
19 return linux;
20 }
21}
22
23exports.write = input => {
24 if (typeof input !== 'string') {
25 return Promise.reject(new TypeError(`Expected a string, got ${typeof input}`));
26 }
27
28 return platform().copy({input}).then(() => {});
29};
30
31exports.read = () => platform().paste({stripEof: false});
32
33exports.writeSync = input => {
34 if (typeof input !== 'string') {
35 throw new TypeError(`Expected a string, got ${typeof input}`);
36 }
37
38 platform().copySync({input});
39};
40
41exports.readSync = () => platform().pasteSync({stripEof: false}).stdout;