1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-06-17 01:16:00 +00:00
This commit is contained in:
MatteZ02
2020-03-03 22:30:50 +02:00
parent edfcc6f474
commit 30022c7634
11800 changed files with 1984416 additions and 1 deletions

49
node_modules/onetime/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,49 @@
declare namespace oneTime {
interface Options {
/**
Throw an error when called more than once.
@default false
*/
throw?: boolean;
}
}
declare const oneTime: {
/**
Ensure a function is only called once. When called multiple times it will return the return value from the first call.
@param fn - Function that should only be called once.
@returns A function that only calls `fn` once.
*/
<ArgumentsType extends unknown[], ReturnType>(
fn: (...arguments: ArgumentsType) => ReturnType,
options?: oneTime.Options
): (...arguments: ArgumentsType) => ReturnType;
/**
Get the number of times `fn` has been called.
@param fn - Function to get call count from.
@returns A number representing how many times `fn` has been called.
@example
```
import onetime = require('onetime');
const foo = onetime(() => {});
foo();
foo();
foo();
console.log(onetime.callCount(foo));
//=> 3
```
*/
callCount(fn: (...arguments: any[]) => unknown): number;
// TODO: Remove this for the next major release
default: typeof oneTime;
};
export = oneTime;

50
node_modules/onetime/index.js generated vendored Normal file
View File

@ -0,0 +1,50 @@
'use strict';
const mimicFn = require('mimic-fn');
const calledFunctions = new WeakMap();
const oneTime = (fn, options = {}) => {
if (typeof fn !== 'function') {
throw new TypeError('Expected a function');
}
let ret;
let isCalled = false;
let callCount = 0;
const functionName = fn.displayName || fn.name || '<anonymous>';
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;
}
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);
};

9
node_modules/onetime/license generated vendored Normal file
View File

@ -0,0 +1,9 @@
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:
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.

78
node_modules/onetime/package.json generated vendored Normal file
View File

@ -0,0 +1,78 @@
{
"_args": [
[
"onetime@5.1.0",
"C:\\Users\\matia\\Musix"
]
],
"_from": "onetime@5.1.0",
"_id": "onetime@5.1.0",
"_inBundle": false,
"_integrity": "sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q==",
"_location": "/onetime",
"_optional": true,
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "onetime@5.1.0",
"name": "onetime",
"escapedName": "onetime",
"rawSpec": "5.1.0",
"saveSpec": null,
"fetchSpec": "5.1.0"
},
"_requiredBy": [
"/@google-cloud/storage"
],
"_resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz",
"_spec": "5.1.0",
"_where": "C:\\Users\\matia\\Musix",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/onetime/issues"
},
"dependencies": {
"mimic-fn": "^2.1.0"
},
"description": "Ensure a function is only called once",
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.1",
"xo": "^0.24.0"
},
"engines": {
"node": ">=6"
},
"files": [
"index.js",
"index.d.ts"
],
"homepage": "https://github.com/sindresorhus/onetime#readme",
"keywords": [
"once",
"function",
"one",
"onetime",
"func",
"fn",
"single",
"call",
"called",
"prevent"
],
"license": "MIT",
"name": "onetime",
"repository": {
"type": "git",
"url": "git+https://github.com/sindresorhus/onetime.git"
},
"scripts": {
"test": "xo && ava && tsd"
},
"version": "5.1.0"
}

94
node_modules/onetime/readme.md generated vendored Normal file
View File

@ -0,0 +1,94 @@
# onetime [![Build Status](https://travis-ci.org/sindresorhus/onetime.svg?branch=master)](https://travis-ci.org/sindresorhus/onetime)
> Ensure a function is only called once
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 and extending `Function.prototype`.*
## Install
```
$ npm install onetime
```
## Usage
```js
const onetime = require('onetime');
let i = 0;
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();
foo();
//=> Error: Function `foo` can only be called once
```
## API
### onetime(fn, [options])
Returns a function that only calls `fn` once.
#### fn
Type: `Function`
Function that should only be called once.
#### options
Type: `Object`
##### throw
Type: `boolean`<br>
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
MIT © [Sindre Sorhus](https://sindresorhus.com)