summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/onetime
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/onetime')
-rw-r--r--tools/node_modules/eslint/node_modules/onetime/index.js41
-rw-r--r--tools/node_modules/eslint/node_modules/onetime/license20
-rw-r--r--tools/node_modules/eslint/node_modules/onetime/package.json16
-rw-r--r--tools/node_modules/eslint/node_modules/onetime/readme.md35
4 files changed, 71 insertions, 41 deletions
diff --git a/tools/node_modules/eslint/node_modules/onetime/index.js b/tools/node_modules/eslint/node_modules/onetime/index.js
index 0d76476b0b..a3f412af1b 100644
--- a/tools/node_modules/eslint/node_modules/onetime/index.js
+++ b/tools/node_modules/eslint/node_modules/onetime/index.js
@@ -1,39 +1,50 @@
'use strict';
const mimicFn = require('mimic-fn');
-module.exports = (fn, opts) => {
- // TODO: Remove this in v3
- if (opts === true) {
- throw new TypeError('The second argument is now an options object');
- }
+const calledFunctions = new WeakMap();
+const oneTime = (fn, options = {}) => {
if (typeof fn !== 'function') {
throw new TypeError('Expected a function');
}
- opts = opts || {};
-
let ret;
- let called = false;
- const fnName = fn.displayName || fn.name || '<anonymous>';
+ let isCalled = false;
+ let callCount = 0;
+ const functionName = fn.displayName || fn.name || '<anonymous>';
- const onetime = function () {
- if (called) {
- if (opts.throw === true) {
- throw new Error(`Function \`${fnName}\` can only be called once`);
+ const onetime = function (...args) {
+ calledFunctions.set(onetime, ++callCount);
+
+ if (isCalled) {
+ if (options.throw === true) {
+ throw new Error(`Function \`${functionName}\` can only be called once`);
}
return ret;
}
- called = true;
- ret = fn.apply(this, arguments);
+ isCalled = true;
+ ret = fn.apply(this, args);
fn = null;
return ret;
};
mimicFn(onetime, fn);
+ calledFunctions.set(onetime, callCount);
return onetime;
};
+
+module.exports = oneTime;
+// TODO: Remove this for the next major release
+module.exports.default = oneTime;
+
+module.exports.callCount = fn => {
+ if (!calledFunctions.has(fn)) {
+ throw new Error(`The given function \`${fn.name}\` is not wrapped by the \`onetime\` package`);
+ }
+
+ return calledFunctions.get(fn);
+};
diff --git a/tools/node_modules/eslint/node_modules/onetime/license b/tools/node_modules/eslint/node_modules/onetime/license
index 654d0bfe94..e7af2f7710 100644
--- a/tools/node_modules/eslint/node_modules/onetime/license
+++ b/tools/node_modules/eslint/node_modules/onetime/license
@@ -1,21 +1,9 @@
-The MIT License (MIT)
+MIT License
Copyright (c) Sindre Sorhus <sindresorhus@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:
+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 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.
+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/tools/node_modules/eslint/node_modules/onetime/package.json b/tools/node_modules/eslint/node_modules/onetime/package.json
index c448600d33..3b9293f2b5 100644
--- a/tools/node_modules/eslint/node_modules/onetime/package.json
+++ b/tools/node_modules/eslint/node_modules/onetime/package.json
@@ -9,19 +9,21 @@
},
"bundleDependencies": false,
"dependencies": {
- "mimic-fn": "^1.0.0"
+ "mimic-fn": "^2.1.0"
},
"deprecated": false,
"description": "Ensure a function is only called once",
"devDependencies": {
- "ava": "*",
- "xo": "*"
+ "ava": "^1.4.1",
+ "tsd": "^0.7.1",
+ "xo": "^0.24.0"
},
"engines": {
- "node": ">=4"
+ "node": ">=6"
},
"files": [
- "index.js"
+ "index.js",
+ "index.d.ts"
],
"homepage": "https://github.com/sindresorhus/onetime#readme",
"keywords": [
@@ -43,7 +45,7 @@
"url": "git+https://github.com/sindresorhus/onetime.git"
},
"scripts": {
- "test": "xo && ava"
+ "test": "xo && ava && tsd"
},
- "version": "2.0.1"
+ "version": "5.1.0"
} \ No newline at end of file
diff --git a/tools/node_modules/eslint/node_modules/onetime/readme.md b/tools/node_modules/eslint/node_modules/onetime/readme.md
index 95eb3b7c9e..9ecd1b24db 100644
--- a/tools/node_modules/eslint/node_modules/onetime/readme.md
+++ b/tools/node_modules/eslint/node_modules/onetime/readme.md
@@ -4,29 +4,35 @@
When called multiple times it will return the return value from the first call.
-*Unlike the module [once](https://github.com/isaacs/once), this one isn't naughty extending `Function.prototype`.*
+*Unlike the module [once](https://github.com/isaacs/once), this one isn't naughty and extending `Function.prototype`.*
## Install
```
-$ npm install --save onetime
+$ npm install onetime
```
## Usage
```js
+const onetime = require('onetime');
+
let i = 0;
-const foo = onetime(() => i++);
+const foo = onetime(() => ++i);
foo(); //=> 0
foo(); //=> 0
foo(); //=> 0
+
+onetime.callCount(foo); //=> 3
```
```js
+const onetime = require('onetime');
+
const foo = onetime(() => {}, {throw: true});
foo();
@@ -59,6 +65,29 @@ Default: `false`
Throw an error when called more than once.
+### onetime.callCount(fn)
+
+Returns a number representing how many times `fn` has been called.
+
+Note: It throws an error if you pass in a function that is not wrapped by `onetime`.
+
+```js
+const foo = onetime(() => {});
+
+foo();
+foo();
+foo();
+
+console.log(onetime.callCount(foo));
+//=> 3
+```
+
+#### fn
+
+Type: `Function`
+
+Function to get call count from.
+
## License