1 | 'use strict';
|
2 | const termux = require('./lib/termux.js');
|
3 | const linux = require('./lib/linux.js');
|
4 | const macos = require('./lib/macos.js');
|
5 | const windows = require('./lib/windows.js');
|
6 |
|
7 | function 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 |
|
23 | exports.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 |
|
31 | exports.read = () => platform().paste({stripEof: false});
|
32 |
|
33 | exports.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 |
|
41 | exports.readSync = () => platform().pasteSync({stripEof: false}).stdout;
|