[Pkg-javascript-commits] [node-time-out] 01/04: Import Upstream version 0.0.3

Shirish Togarla shirish12-guest at moszumanska.debian.org
Tue Feb 7 18:17:00 UTC 2017


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

shirish12-guest pushed a commit to branch master
in repository node-time-out.

commit c828f784ea053f1014d77c38f63b1ca63069b54a
Author: Shirish Togarla <shirishtogarla533 at gmail.com>
Date:   Sat Feb 4 18:28:18 2017 +0000

    Import Upstream version 0.0.3
---
 .babelrc     |  3 +++
 .npmignore   |  1 +
 README.md    | 10 ++++++++++
 index.js     | 17 +++++++++++++++++
 lib/index.js | 19 +++++++++++++++++++
 package.json | 20 ++++++++++++++++++++
 6 files changed, 70 insertions(+)

diff --git a/.babelrc b/.babelrc
new file mode 100644
index 0000000..af0f0c3
--- /dev/null
+++ b/.babelrc
@@ -0,0 +1,3 @@
+{
+  "presets": ["es2015"]
+}
\ No newline at end of file
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..40b878d
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1 @@
+node_modules/
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b0f3321
--- /dev/null
+++ b/README.md
@@ -0,0 +1,10 @@
+# time-out
+
+Timeout is a library that wraps setTimeout to provide an easy way to clear timeouts.
+
+```js
+import timeout from 'time-out';
+
+const cancel = timeout(() => console.log('I shall not be called.'), 4000);
+cancel();
+```
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..6d4163d
--- /dev/null
+++ b/index.js
@@ -0,0 +1,17 @@
+module.exports = function timeout(fn, wait, ...fnArgs) {
+  let timeoutID = setTimeout(
+    (...args) => {
+      timeoutID = null;
+      fn(...args);
+    },
+    wait,
+    ...fnArgs
+  );
+
+  return function cancel() {
+    if (timeoutID) {
+      clearTimeout(timeoutID);
+      timeoutID = null;
+    }
+  }
+}
\ No newline at end of file
diff --git a/lib/index.js b/lib/index.js
new file mode 100644
index 0000000..90b633d
--- /dev/null
+++ b/lib/index.js
@@ -0,0 +1,19 @@
+"use strict";
+
+module.exports = function timeout(fn, wait) {
+  for (var _len = arguments.length, fnArgs = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
+    fnArgs[_key - 2] = arguments[_key];
+  }
+
+  var timeoutID = setTimeout.apply(undefined, [function () {
+    timeoutID = null;
+    fn.apply(undefined, arguments);
+  }, wait].concat(fnArgs));
+
+  return function cancel() {
+    if (timeoutID) {
+      clearTimeout(timeoutID);
+      timeoutID = null;
+    }
+  };
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..28f7a3a
--- /dev/null
+++ b/package.json
@@ -0,0 +1,20 @@
+{
+  "name": "time-out",
+  "version": "0.0.3",
+  "description": "Simple setTimeout cancellation",
+  "main": "lib/index.js",
+  "scripts": {
+  	"build": "babel index.js --out-file lib/index.js",
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "Mark Funk",
+  "license": "MIT",
+  "repository": {
+  	"type": "git",
+  	"url": "https://github.com/mfunkie/time-out.git"
+  },
+  "devDependencies": {
+    "babel-cli": "^6.1.18",
+    "babel-preset-es2015": "^6.1.18"
+  }
+}

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



More information about the Pkg-javascript-commits mailing list