pax_global_header00006660000000000000000000000064137740213720014520gustar00rootroot0000000000000052 comment=af043e60da92ce1ca76af0898075fb94b7357f27 beeper-2.1.0/000077500000000000000000000000001377402137200127625ustar00rootroot00000000000000beeper-2.1.0/.editorconfig000066400000000000000000000002571377402137200154430ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 beeper-2.1.0/.gitattributes000066400000000000000000000000231377402137200156500ustar00rootroot00000000000000* text=auto eol=lf beeper-2.1.0/.github/000077500000000000000000000000001377402137200143225ustar00rootroot00000000000000beeper-2.1.0/.github/workflows/000077500000000000000000000000001377402137200163575ustar00rootroot00000000000000beeper-2.1.0/.github/workflows/main.yml000066400000000000000000000007021377402137200200250ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 14 - 12 - 10 - 8 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test beeper-2.1.0/.gitignore000066400000000000000000000000271377402137200147510ustar00rootroot00000000000000node_modules yarn.lock beeper-2.1.0/.npmrc000066400000000000000000000000231377402137200140750ustar00rootroot00000000000000package-lock=false beeper-2.1.0/index.d.ts000066400000000000000000000011511377402137200146610ustar00rootroot00000000000000/** Make your terminal beep. @param count - How many times you want it to beep. Default: `1`. @param melody - Construct your own melody by supplying a string of `*` for beep `-` for pause. @returns A `Promise` that is resolved after the melody has ended. @example ``` import beeper = require('beeper'); (async => { await beeper(); // beep one time await beeper(3); // beep three times await beeper('****-*-*'); // beep, beep, beep, beep, pause, beep, pause, beep })(); ``` */ declare function beeper(count?: number): Promise; declare function beeper(melody: string): Promise; export = beeper; beeper-2.1.0/index.js000066400000000000000000000017731377402137200144370ustar00rootroot00000000000000'use strict'; const delay = require('yoctodelay'); const BEEP_DELAY = 500; function beep() { process.stdout.write('\u0007'); } async function melodicalBeep(melody) { if (melody.length === 0) { return; } await delay(BEEP_DELAY); if (melody.shift() === '*') { beep(); } return melodicalBeep(melody); } module.exports = async countOrMelody => { if ( !process.stdout.isTTY || process.argv.includes('--no-beep') || process.argv.includes('--beep=false') ) { return; } if (countOrMelody === Number.parseInt(countOrMelody, 10)) { if (countOrMelody < 0) { throw new TypeError('Negative numbers are not accepted'); } if (countOrMelody === 0) { return; } for (let i = 0; i < countOrMelody; i++) { await delay(BEEP_DELAY); // eslint-disable-line no-await-in-loop beep(); } } else if (!countOrMelody) { beep(); } else if (typeof countOrMelody === 'string') { await melodicalBeep(countOrMelody.split('')); } else { throw new TypeError('Not an accepted type'); } }; beeper-2.1.0/index.test-d.ts000066400000000000000000000002711377402137200156400ustar00rootroot00000000000000import {expectType} from 'tsd'; import beeper = require('.'); expectType>(beeper()); expectType>(beeper(3)); expectType>(beeper('****-*-*')); beeper-2.1.0/license000066400000000000000000000021251377402137200143270ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. beeper-2.1.0/package.json000066400000000000000000000012531377402137200152510ustar00rootroot00000000000000{ "name": "beeper", "version": "2.1.0", "description": "Make your terminal beep", "license": "MIT", "repository": "sindresorhus/beeper", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "beep", "beeper", "boop", "terminal", "term", "cli", "console", "ding", "ping", "alert", "gulpfriendly" ], "dependencies": { "yoctodelay": "^1.1.0" }, "devDependencies": { "ava": "^1.4.1", "hooker": "^0.2.3", "tsd": "^0.7.2", "xo": "^0.24.0" } } beeper-2.1.0/readme.md000066400000000000000000000015531377402137200145450ustar00rootroot00000000000000# beeper > Make your terminal beep ![](https://cloud.githubusercontent.com/assets/170270/5261236/f8471100-7a49-11e4-81af-96cd09a522d9.gif) Useful as an attention grabber. For example, when an error happens. ## Install ``` $ npm install beeper ``` ## Usage ```js const beeper = require('beeper'); (async => { await beeper(); // beep one time await beeper(3); // beep three times await beeper('****-*-*'); // beep, beep, beep, beep, pause, beep, pause, beep })(); ``` ## API It will not beep if stdout is not TTY or if the user supplies the `--no-beep` flag. ### beeper(count?) ### beeper(melody?) Returns a `Promise` that is resolved after the melody has ended. #### count Type: `number`\ Default: `1` How many times you want it to beep. #### melody Type: `string` Construct your own melody by supplying a string of `*` for beep `-` for pause. beeper-2.1.0/test.js000066400000000000000000000022411377402137200142760ustar00rootroot00000000000000import {serial as test} from 'ava'; import hooker from 'hooker'; import beeper from '.'; const BEEP_CHARACTER = '\u0007'; test('beep', async t => { let i = 0; hooker.hook(process.stdout, 'write', string => { if (string === BEEP_CHARACTER) { i++; } }); await beeper(1); hooker.unhook(process.stdout, 'write'); t.is(i, 1); }); function testBeepCount(count) { test('count ' + count, async t => { let i = 0; hooker.hook(process.stdout, 'write', string => { if (string === BEEP_CHARACTER) { i++; } }); await beeper(count); hooker.unhook(process.stdout, 'write'); t.is(i, count); }); } testBeepCount(0); testBeepCount(1); testBeepCount(3); test('non-integer count should throw exception', async t => { try { await beeper(1.5); t.fail(); } catch (error) { t.pass(); } }); test('negative count should throw exception', async t => { try { await beeper(-1); t.fail(); } catch (error) { t.pass(); } }); test('melody', async t => { let i = 0; hooker.hook(process.stdout, 'write', string => { if (string === BEEP_CHARACTER) { i++; } }); await beeper('*-*'); hooker.unhook(process.stdout, 'write'); t.is(i, 2); });