Comparing version 1.1.1 to 2.0.0
56
index.js
'use strict'; | ||
const delay = require('delay'); | ||
var BEEP_DELAY = 500; | ||
const BEEP_DELAY = 500; | ||
@@ -9,50 +10,43 @@ function beep() { | ||
function melodicalBeep(val, cb) { | ||
if (val.length === 0) { | ||
cb(); | ||
async function melodicalBeep(melody) { | ||
if (melody.length === 0) { | ||
return; | ||
} | ||
setTimeout(function () { | ||
if (val.shift() === '*') { | ||
beep(); | ||
} | ||
await delay(BEEP_DELAY); | ||
melodicalBeep(val, cb); | ||
}, BEEP_DELAY); | ||
if (melody.shift() === '*') { | ||
beep(); | ||
} | ||
return melodicalBeep(melody); | ||
} | ||
module.exports = function (val, cb) { | ||
if (!process.stdout.isTTY || | ||
process.argv.indexOf('--no-beep') !== -1 || | ||
process.argv.indexOf('--beep=false') !== -1) { | ||
module.exports = async countOrMelody => { | ||
if ( | ||
!process.stdout.isTTY || | ||
process.argv.includes('--no-beep') || | ||
process.argv.includes('--beep=false') | ||
) { | ||
return; | ||
} | ||
cb = cb || function () {}; | ||
if (val === parseInt(val)) { | ||
if (val < 0) { | ||
if (countOrMelody === Number.parseInt(countOrMelody, 10)) { | ||
if (countOrMelody < 0) { | ||
throw new TypeError('Negative numbers are not accepted'); | ||
} | ||
if (val === 0) { | ||
cb(); | ||
if (countOrMelody === 0) { | ||
return; | ||
} | ||
for (var i = 0; i < val; i++) { | ||
setTimeout(function (i) { | ||
beep(); | ||
for (let i = 0; i < countOrMelody; i++) { | ||
await delay(BEEP_DELAY); // eslint-disable-line no-await-in-loop | ||
if (i === val - 1) { | ||
cb(); | ||
} | ||
}, BEEP_DELAY * i, i); | ||
beep(); | ||
} | ||
} else if (!val) { | ||
} else if (!countOrMelody) { | ||
beep(); | ||
cb(); | ||
} else if (typeof val === 'string') { | ||
melodicalBeep(val.split(''), cb); | ||
} else if (typeof countOrMelody === 'string') { | ||
await melodicalBeep(countOrMelody.split('')); | ||
} else { | ||
@@ -59,0 +53,0 @@ throw new TypeError('Not an accepted type'); |
{ | ||
"name": "beeper", | ||
"version": "1.1.1", | ||
"description": "Make your terminal beep", | ||
"license": "MIT", | ||
"repository": "sindresorhus/beeper", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "node test.js" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"beep", | ||
"beeper", | ||
"boop", | ||
"terminal", | ||
"term", | ||
"cli", | ||
"console", | ||
"ding", | ||
"ping", | ||
"alert", | ||
"gulpfriendly" | ||
], | ||
"devDependencies": { | ||
"hooker": "^0.2.3", | ||
"tape": "^4.0.0" | ||
} | ||
"name": "beeper", | ||
"version": "2.0.0", | ||
"description": "Make your terminal beep", | ||
"license": "MIT", | ||
"repository": "sindresorhus/beeper", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "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": { | ||
"delay": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"hooker": "^0.2.3", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -7,3 +7,3 @@ # beeper [![Build Status](https://travis-ci.org/sindresorhus/beeper.svg?branch=master)](https://travis-ci.org/sindresorhus/beeper) | ||
Useful as an attention grabber e.g. when an error happens. | ||
Useful as an attention grabber. For example, when an error happens. | ||
@@ -14,3 +14,3 @@ | ||
``` | ||
$ npm install --save beeper | ||
$ npm install beeper | ||
``` | ||
@@ -22,12 +22,14 @@ | ||
```js | ||
var beeper = require('beeper'); | ||
const beeper = require('beeper'); | ||
beeper(); | ||
// beep one time | ||
(async => { | ||
await beeper(); | ||
// beep one time | ||
beeper(3); | ||
// beep three times | ||
await beeper(3); | ||
// beep three times | ||
beeper('****-*-*'); | ||
// beep, beep, beep, beep, pause, beep, pause, beep | ||
await beeper('****-*-*'); | ||
// beep, beep, beep, beep, pause, beep, pause, beep | ||
})(); | ||
``` | ||
@@ -40,7 +42,9 @@ | ||
### beeper([count|melody], [callback]) | ||
### beeper([count|melody]) | ||
Returns a `Promise<void>` that is resolved after the melody has ended. | ||
#### count | ||
Type: `number` | ||
Type: `number` | ||
Default: `1` | ||
@@ -59,2 +63,2 @@ | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4460
5
64
60
1
4
+ Addeddelay@^4.1.0
+ Addeddelay@4.4.1(transitive)