├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── bin └── cmd.js ├── index.js └── package.json /.npmignore: -------------------------------------------------------------------------------- 1 | .travis.yml 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - lts/* 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Feross Aboukhadijeh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # beepbeep [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] 2 | 3 | [travis-image]: https://img.shields.io/travis/feross/beepbeep/master.svg 4 | [travis-url]: https://travis-ci.org/feross/beepbeep 5 | [npm-image]: https://img.shields.io/npm/v/beepbeep.svg 6 | [npm-url]: https://npmjs.org/package/beepbeep 7 | [downloads-image]: https://img.shields.io/npm/dm/beepbeep.svg 8 | [downloads-url]: https://npmjs.org/package/beepbeep 9 | [standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg 10 | [standard-url]: https://standardjs.com 11 | 12 | Make a console beep sound. *Well-tested, web-scale, cloud-based, restful node.js module.* 13 | 14 | ## Usage 15 | 16 | ```javascript 17 | var beep = require('beepbeep') 18 | 19 | beep() 20 | // Beep! 21 | 22 | beep(2) 23 | // Beep! Beep! 24 | 25 | beep(3, 1000) 26 | // Beep! ... Beep! ... Beep! 27 | 28 | beep([1000, 500, 2000]) 29 | // 1 second delay...Beep! 0.5 second delay...Beep! 2 second delay...Beep! 30 | ``` 31 | 32 | ## Installation 33 | 34 | ``` 35 | npm install beepbeep 36 | ``` 37 | 38 | ## License 39 | 40 | MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org). 41 | -------------------------------------------------------------------------------- /bin/cmd.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict' 3 | 4 | var beep = require('../') 5 | 6 | try { 7 | var args = process.argv.splice(2).map(_ => parseInt(_)) 8 | switch (args.length) { 9 | case 0: 10 | beep() 11 | break 12 | case 1: 13 | beep(args[0]) 14 | break 15 | case 2: 16 | beep(args[0], args[1]) 17 | break 18 | default: 19 | beep(args) 20 | break 21 | } 22 | } catch (error) { 23 | console.log('Wrong parameters', error) 24 | process.exit(-1) 25 | } 26 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | /** 4 | * Make multiple console beep sounds 5 | * @param {number} [i=1] - Number of beeps 6 | * @param {number} [t=500] - Milliseconds between beeps 7 | */ 8 | module.exports = function (i, t) { 9 | if (i instanceof Array) { 10 | return delayedBeeps(i) 11 | } 12 | 13 | i = isNaN(i) ? 1 : i 14 | t = isNaN(t) ? 500 : t 15 | 16 | while (i-- > 0) { 17 | if (t * i === 0) beepNow() 18 | else setTimeout(beepNow, t * i) 19 | } 20 | } 21 | 22 | function delayedBeeps (i) { 23 | if (i.length === 0) { 24 | return 25 | } 26 | 27 | setTimeout(function () { 28 | beepNow() 29 | i.splice(0, 1) 30 | delayedBeeps(i) 31 | }, i[0]) 32 | } 33 | 34 | function beepNow () { 35 | process.stdout.write('\x07') 36 | } 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "beepbeep", 3 | "description": "Make a console beep noise in Node.js", 4 | "version": "1.3.0", 5 | "author": { 6 | "name": "Feross Aboukhadijeh", 7 | "email": "feross@feross.org", 8 | "url": "https://feross.org" 9 | }, 10 | "bin": { 11 | "beepbeep": "./bin/cmd.js" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/feross/beepbeep/issues" 15 | }, 16 | "dependencies": {}, 17 | "devDependencies": { 18 | "standard": "*" 19 | }, 20 | "homepage": "https://github.com/feross/beepbeep#readme", 21 | "keywords": [ 22 | "beep", 23 | "beep beep", 24 | "console beep", 25 | "ding", 26 | "fun", 27 | "ping" 28 | ], 29 | "license": "MIT", 30 | "main": "index.js", 31 | "repository": { 32 | "type": "git", 33 | "url": "git://github.com/feross/beepbeep.git" 34 | }, 35 | "scripts": { 36 | "test": "standard && ./bin/cmd.js" 37 | } 38 | } 39 | --------------------------------------------------------------------------------