[Pkg-javascript-commits] [node-beeper] 01/06: Import Upstream version 1.1.0

Sagar Ippalpalli isaagar-guest at moszumanska.debian.org
Mon Oct 17 05:26:49 UTC 2016


This is an automated email from the git hooks/post-receive script.

isaagar-guest pushed a commit to branch master
in repository node-beeper.

commit 43c535d74bb2166458c65983699b2d022fd4109a
Author: Sagar Ippalpalli <i.vikram15 at gmail.com>
Date:   Sun Oct 16 15:57:00 2016 +0530

    Import Upstream version 1.1.0
---
 .editorconfig  | 15 +++++++++++
 .gitattributes |  1 +
 .gitignore     |  1 +
 .jshintrc      | 12 +++++++++
 .travis.yml    |  5 ++++
 index.js       | 61 ++++++++++++++++++++++++++++++++++++++++++
 license        | 21 +++++++++++++++
 package.json   | 38 +++++++++++++++++++++++++++
 readme.md      | 55 ++++++++++++++++++++++++++++++++++++++
 test.js        | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 292 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..8f9d77e
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{package.json,*.yml}]
+indent_style = space
+indent_size = 2
+
+[*.md]
+trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..9fe1be2
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,12 @@
+{
+	"node": true,
+	"esnext": true,
+	"bitwise": true,
+	"curly": true,
+	"immed": true,
+	"newcap": true,
+	"noarg": true,
+	"undef": true,
+	"unused": "vars",
+	"strict": true
+}
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..1d94c4b
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+sudo: false
+language: node_js
+node_js:
+  - '0.12'
+  - '0.10'
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..21e0aa9
--- /dev/null
+++ b/index.js
@@ -0,0 +1,61 @@
+'use strict';
+
+var BEEP_DELAY = 500;
+
+if (!process.stdout.isTTY ||
+	process.argv.indexOf('--no-beep') !== -1 ||
+	process.argv.indexOf('--beep=false') !== -1) {
+	module.exports = function () {};
+	return;
+}
+
+function beep() {
+	process.stdout.write('\u0007');
+}
+
+function melodicalBeep(val, cb) {
+	if (val.length === 0) {
+		cb();
+		return;
+	}
+
+	setTimeout(function () {
+		if (val.shift() === '*') {
+			beep();
+		}
+
+		melodicalBeep(val, cb);
+	}, BEEP_DELAY);
+}
+
+module.exports = function (val, cb) {
+	cb = cb || function () {};
+
+	if (val === parseInt(val)) {
+		if (val < 0) {
+			throw new TypeError('Negative numbers are not accepted');
+		}
+
+		if (val === 0) {
+			cb();
+			return;
+		}
+
+		for (var i = 0; i < val; i++) {
+			setTimeout(function (i) {
+				beep();
+
+				if (i === val - 1) {
+					cb();
+				}
+			}, BEEP_DELAY * i, i);
+		}
+	} else if (!val) {
+		beep();
+		cb();
+	} else if (typeof val === 'string') {
+		melodicalBeep(val.split(''), cb);
+	} else {
+		throw new TypeError('Not an accepted type');
+	}
+};
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (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.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..6377310
--- /dev/null
+++ b/package.json
@@ -0,0 +1,38 @@
+{
+  "name": "beeper",
+  "version": "1.1.0",
+  "description": "Make your terminal beep",
+  "license": "MIT",
+  "repository": "sindresorhus/beeper",
+  "author": {
+    "name": "Sindre Sorhus",
+    "email": "sindresorhus at 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"
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..55bdd52
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,55 @@
+# beeper [![Build Status](https://travis-ci.org/sindresorhus/beeper.svg?branch=master)](https://travis-ci.org/sindresorhus/beeper)
+
+> Make your terminal beep
+
+![](https://cloud.githubusercontent.com/assets/170270/5261236/f8471100-7a49-11e4-81af-96cd09a522d9.gif)
+
+Useful as an attention grabber e.g. when an error happens.
+
+
+## Install
+
+```
+$ npm install --save beeper
+```
+
+
+## Usage
+
+```js
+var beeper = require('beeper');
+
+beeper();
+// beep one time
+
+beeper(3);
+// beep three times
+
+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|melody], [callback])
+
+#### 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.
+
+
+## License
+
+MIT © [Sindre Sorhus](http://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..29b5071
--- /dev/null
+++ b/test.js
@@ -0,0 +1,83 @@
+'use strict';
+var test = require('tape');
+var hooker = require('hooker');
+var beeper = require('./');
+var BEEP_CHAR = '\u0007';
+
+test('beep', function (t) {
+	var i = 0;
+
+	hooker.hook(process.stdout, 'write', function (str) {
+		if (str === BEEP_CHAR) {
+			i++;
+		}
+	});
+
+	beeper(1, function () {
+		hooker.unhook(process.stdout, 'write');
+		t.assert(i === 1, i);
+		t.end();
+	});
+});
+
+function testBeepCount(count) {
+	test('count ' + count, function (t) {
+		var i = 0;
+
+		hooker.hook(process.stdout, 'write', function (str) {
+			if (str === BEEP_CHAR) {
+				i++;
+			}
+		});
+
+		beeper(count, function () {
+			hooker.unhook(process.stdout, 'write');
+			t.assert(i === count, i);
+			t.end();
+		});
+	});
+}
+
+testBeepCount(0);
+testBeepCount(1);
+testBeepCount(3);
+
+test('non-integer count should throw exception', function (t) {
+	try {
+		beeper(1.5, function () {
+			t.assert(false);
+			t.end();
+		});
+	} catch (e) {
+		t.assert(true);
+		t.end();
+	}
+});
+
+test('negative count should throw exception', function (t) {
+	try {
+		beeper(-1, function () {
+			t.assert(false);
+			t.end();
+		});
+	} catch (e) {
+		t.assert(true);
+		t.end();
+	}
+});
+
+test('melody', function (t) {
+	var i = 0;
+
+	hooker.hook(process.stdout, 'write', function (str) {
+		if (str === BEEP_CHAR) {
+			i++;
+		}
+	});
+
+	beeper('*-*', function () {
+		hooker.unhook(process.stdout, 'write');
+		t.assert(i === 2, i);
+		t.end();
+	});
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-beeper.git



More information about the Pkg-javascript-commits mailing list