-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 12.20 and move to ESM
- Loading branch information
1 parent
c59f194
commit 661d9da
Showing
15 changed files
with
184 additions
and
120 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
/* eslint-env browser */ | ||
'use strict'; | ||
|
||
export const write = async text => { | ||
const clipboard = {}; | ||
|
||
clipboard.write = async text => { | ||
await navigator.clipboard.writeText(text); | ||
}; | ||
|
||
export const read = async () => navigator.clipboard.readText(); | ||
clipboard.read = async () => navigator.clipboard.readText(); | ||
|
||
export const readSync = () => { | ||
clipboard.readSync = () => { | ||
throw new Error('`.readSync()` is not supported in browsers!'); | ||
}; | ||
|
||
export const writeSync = () => { | ||
clipboard.writeSync = () => { | ||
throw new Error('`.writeSync()` is not supported in browsers!'); | ||
}; | ||
|
||
export default clipboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
'use strict'; | ||
const clipboardy = require('.'); | ||
import clipboard from './index.js'; | ||
|
||
clipboardy.write('你好🦄'); | ||
clipboardy.read().then(console.log); | ||
(async () => { | ||
clipboard.write('你好🦄'); | ||
console.log(await clipboard.read()); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,71 @@ | ||
/** | ||
Write (copy) to the clipboard asynchronously. | ||
declare const clipboard: { | ||
/** | ||
Write (copy) to the clipboard asynchronously. | ||
@param text - The text to write to the clipboard. | ||
*/ | ||
export function write(text: string): Promise<void>; | ||
@param text - The text to write to the clipboard. | ||
/** | ||
Write (copy) to the clipboard synchronously. | ||
@example | ||
``` | ||
import clipboard from 'clipboardy'; | ||
Doesn't work in browsers. | ||
await clipboard.write('🦄'); | ||
@param text - The text to write to the clipboard. | ||
await clipboard.read(); | ||
//=> '🦄' | ||
``` | ||
*/ | ||
write(text: string): Promise<void>; | ||
|
||
@example | ||
``` | ||
import * as clipboardy from 'clipboardy'; | ||
/** | ||
Read (paste) from the clipboard asynchronously. | ||
clipboardy.writeSync('🦄'); | ||
@example | ||
``` | ||
import clipboard from 'clipboardy'; | ||
clipboardy.readSync(); | ||
//=> '🦄' | ||
``` | ||
*/ | ||
export function writeSync(text: string): void; | ||
await clipboard.write('🦄'); | ||
/** | ||
Read (paste) from the clipboard asynchronously. | ||
*/ | ||
export function read(): Promise<string>; | ||
await clipboard.read(); | ||
//=> '🦄' | ||
``` | ||
*/ | ||
read(): Promise<string>; | ||
|
||
/** | ||
Read (paste) from the clipboard synchronously. | ||
/** | ||
Write (copy) to the clipboard synchronously. | ||
Doesn't work in browsers. | ||
*/ | ||
export function readSync(): string; | ||
__Doesn't work in browsers.__ | ||
@param text - The text to write to the clipboard. | ||
@example | ||
``` | ||
import clipboard from 'clipboardy'; | ||
clipboard.writeSync('🦄'); | ||
clipboard.readSync(); | ||
//=> '🦄' | ||
``` | ||
*/ | ||
writeSync(text: string): void; | ||
|
||
/** | ||
Read (paste) from the clipboard synchronously. | ||
__Doesn't work in browsers.__ | ||
@example | ||
``` | ||
import clipboard from 'clipboardy'; | ||
clipboard.writeSync('🦄'); | ||
clipboard.readSync(); | ||
//=> '🦄' | ||
``` | ||
*/ | ||
readSync(): string; | ||
}; | ||
|
||
export default clipboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import {expectType} from 'tsd'; | ||
import * as clipboardy from '.'; | ||
import clipboard from './index.js'; | ||
|
||
clipboardy.writeSync('🦄'); | ||
expectType<Promise<void>>(clipboardy.write('🦄')); | ||
expectType<string>(clipboardy.readSync()); | ||
expectType<Promise<string>>(clipboardy.read()); | ||
clipboard.writeSync('🦄'); | ||
expectType<Promise<void>>(clipboard.write('🦄')); | ||
expectType<string>(clipboard.readSync()); | ||
expectType<Promise<string>>(clipboard.read()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
'use strict'; | ||
const execa = require('execa'); | ||
import execa from 'execa'; | ||
|
||
const env = { | ||
...process.env, | ||
LC_CTYPE: 'UTF-8' | ||
LC_CTYPE: 'UTF-8', | ||
}; | ||
|
||
module.exports = { | ||
const clipboard = { | ||
copy: async options => execa('pbcopy', {...options, env}), | ||
paste: async options => execa.stdout('pbpaste', {...options, env}), | ||
paste: async options => { | ||
const {stdout} = await execa('pbpaste', {...options, env}); | ||
return stdout; | ||
}, | ||
copySync: options => execa.sync('pbcopy', {...options, env}), | ||
pasteSync: options => execa.sync('pbpaste', {...options, env}) | ||
pasteSync: options => execa.sync('pbpaste', {...options, env}).stdout, | ||
}; | ||
|
||
export default clipboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const execa = require('execa'); | ||
const arch = require('arch'); | ||
import path from 'node:path'; | ||
import {fileURLToPath} from 'node:url'; | ||
import execa from 'execa'; | ||
import arch from 'arch'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
const binarySuffix = arch() === 'x64' ? 'x86_64' : 'i686'; | ||
|
||
// Binaries from: https://github.com/sindresorhus/win-clipboard | ||
const windowBinaryPath = arch() === 'x64' ? | ||
path.join(__dirname, '../fallbacks/windows/clipboard_x86_64.exe') : | ||
path.join(__dirname, '../fallbacks/windows/clipboard_i686.exe'); | ||
const windowBinaryPath = path.join(__dirname, `../fallbacks/windows/clipboard_${binarySuffix}.exe`); | ||
|
||
module.exports = { | ||
const clipboard = { | ||
copy: async options => execa(windowBinaryPath, ['--copy'], options), | ||
paste: async options => execa.stdout(windowBinaryPath, ['--paste'], options), | ||
paste: async options => { | ||
const {stdout} = await execa(windowBinaryPath, ['--paste'], options); | ||
return stdout; | ||
}, | ||
copySync: options => execa.sync(windowBinaryPath, ['--copy'], options), | ||
pasteSync: options => execa.sync(windowBinaryPath, ['--paste'], options) | ||
pasteSync: options => execa.sync(windowBinaryPath, ['--paste'], options).stdout, | ||
}; | ||
|
||
export default clipboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
MIT License | ||
|
||
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com) | ||
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
|
Oops, something went wrong.