@guanghechen/mini-copy
TypeScript icon, indicating that this package has built-in type declarations

6.0.0-alpha.7 • Public • Published

@guanghechen/mini-copy


mini-copy based on clipboardy, it support sharing the clipboard with windows and wsl. But sometimes there has some messy code problem when using both the terminal in wsl and windows, i.e. copy content from cmd.exe, and run demo3 in windows terminal. To solve this problem, you could try copy the node_modules/clipboardy/fallbacks/windows/clipboard_*.exe (depends on your machine's architecture) to /mnt/<d|e|f|g>/clipboard.exe.

Install

  • npm

    npm install --save @guanghechen/mini-copy
  • yarn

    yarn add @guanghechen/mini-copy

Usage

import { copy, paste } from '@guanghechen/mini-copy'

await copy('waw') // => write something to clipboard.
await paste()     // => read content from clipboard.

Examples

  • Basic.

    import { copy, paste } from '@guanghechen/mini-copy'
    
    async function f(): Promise<void> {
      const string = '中国,here,hello world,好的,哦哦'
      await copy(string)
      const p = await paste()
      console.log(`#${p}#`)
    }
    
    void f().catch(e => console.error(e))
  • Use Fake clipboard as fallback.

    import { ChalkLogger, DEBUG } from '@guanghechen/chalk-logger'
    import { FakeClipboard, copy, paste } from '@guanghechen/mini-copy'
    import path from 'node:path'
    
    const logger = new ChalkLogger({
      name: 'mini-copy',
      colorful: true,
      date: true,
      inline: false,
      level: DEBUG,
    })
    
    const fakeClipboard = new FakeClipboard({
      filepath: path.resolve(__dirname, 'fake-clipboard.txt'),
      encoding: 'utf8',
      logger,
    })
    
    async function f(): Promise<void> {
      const string = '中国,here,hello world,好的,哦哦\n'
      await copy(string, { logger, fakeClipboard })
      const p = await paste({ logger, fakeClipboard })
      console.log(`#${p}#`)
    }
    
    void f().catch(e => console.error(e))
  • Use custom logger.

    import { ChalkLogger, DEBUG } from '@guanghechen/chalk-logger'
    import { copy, paste } from '@guanghechen/mini-copy'
    
    const logger = new ChalkLogger({
      name: 'mini-copy',
      colorful: true,
      date: true,
      inline: false,
      level: DEBUG,
    })
    
    async function f(): Promise<void> {
      const string = '中国,here,hello world,好的,哦哦\n'
      await copy(string, { logger })
      const p = await paste({ logger })
      console.log(`#${p}#`)
    }
    
    void f().catch(e => console.error(e))

Dependencies (5)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @guanghechen/mini-copy

    Weekly Downloads

    1

    Version

    6.0.0-alpha.7

    License

    MIT

    Unpacked Size

    45 kB

    Total Files

    8

    Last publish

    Collaborators

    • lemonclown