Initial commit: ERP system with advance verification fixes
This commit is contained in:
+74
@@ -0,0 +1,74 @@
|
||||
declare namespace debounceFn {
|
||||
interface Options {
|
||||
/**
|
||||
Time to wait until the `input` function is called.
|
||||
|
||||
@default 0
|
||||
*/
|
||||
readonly wait?: number;
|
||||
|
||||
/**
|
||||
Trigger the function on the leading edge of the `wait` interval.
|
||||
|
||||
For example, this can be useful for preventing accidental double-clicks on a "submit" button from firing a second time.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly before?: boolean;
|
||||
|
||||
/**
|
||||
Trigger the function on the trailing edge of the `wait` interval.
|
||||
|
||||
@default true
|
||||
*/
|
||||
readonly after?: boolean;
|
||||
}
|
||||
|
||||
interface BeforeOptions extends Options {
|
||||
readonly before: true;
|
||||
}
|
||||
|
||||
interface NoBeforeNoAfterOptions extends Options {
|
||||
readonly after: false;
|
||||
readonly before?: false;
|
||||
}
|
||||
|
||||
interface DebouncedFunction<ArgumentsType extends unknown[], ReturnType> {
|
||||
(...arguments: ArgumentsType): ReturnType;
|
||||
cancel(): void;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[Debounce](https://davidwalsh.name/javascript-debounce-function) a function.
|
||||
|
||||
@param input - Function to debounce.
|
||||
@returns A debounced function that delays calling the `input` function until after `wait` milliseconds have elapsed since the last time the debounced function was called.
|
||||
|
||||
It comes with a `.cancel()` method to cancel any scheduled `input` function calls.
|
||||
|
||||
@example
|
||||
```
|
||||
import debounceFn = require('debounce-fn');
|
||||
|
||||
window.onresize = debounceFn(() => {
|
||||
// Do something on window resize
|
||||
}, {wait: 100});
|
||||
```
|
||||
*/
|
||||
declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
|
||||
input: (...arguments: ArgumentsType) => ReturnType,
|
||||
options: debounceFn.BeforeOptions
|
||||
): debounceFn.DebouncedFunction<ArgumentsType, ReturnType>;
|
||||
|
||||
declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
|
||||
input: (...arguments: ArgumentsType) => ReturnType,
|
||||
options: debounceFn.NoBeforeNoAfterOptions
|
||||
): debounceFn.DebouncedFunction<ArgumentsType, undefined>;
|
||||
|
||||
declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
|
||||
input: (...arguments: ArgumentsType) => ReturnType,
|
||||
options?: debounceFn.Options
|
||||
): debounceFn.DebouncedFunction<ArgumentsType, ReturnType | undefined>;
|
||||
|
||||
export = debounceFn;
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
const mimicFn = require('mimic-fn');
|
||||
|
||||
module.exports = (inputFunction, options = {}) => {
|
||||
if (typeof inputFunction !== 'function') {
|
||||
throw new TypeError(`Expected the first argument to be a function, got \`${typeof inputFunction}\``);
|
||||
}
|
||||
|
||||
const {
|
||||
wait = 0,
|
||||
before = false,
|
||||
after = true
|
||||
} = options;
|
||||
|
||||
if (!before && !after) {
|
||||
throw new Error('Both `before` and `after` are false, function wouldn\'t be called.');
|
||||
}
|
||||
|
||||
let timeout;
|
||||
let result;
|
||||
|
||||
const debouncedFunction = function (...arguments_) {
|
||||
const context = this;
|
||||
|
||||
const later = () => {
|
||||
timeout = undefined;
|
||||
|
||||
if (after) {
|
||||
result = inputFunction.apply(context, arguments_);
|
||||
}
|
||||
};
|
||||
|
||||
const shouldCallNow = before && !timeout;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
|
||||
if (shouldCallNow) {
|
||||
result = inputFunction.apply(context, arguments_);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
mimicFn(debouncedFunction, inputFunction);
|
||||
|
||||
debouncedFunction.cancel = () => {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
timeout = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
return debouncedFunction;
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://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.
|
||||
Generated
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
declare namespace mimicFn {
|
||||
interface Options {
|
||||
/**
|
||||
Skip modifying [non-configurable properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#Description) instead of throwing an error.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly ignoreNonConfigurable?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Modifies the `to` function to mimic the `from` function. Returns the `to` function.
|
||||
|
||||
`name`, `displayName`, and any other properties of `from` are copied. The `length` property is not copied. Prototype, class, and inherited properties are copied.
|
||||
|
||||
`to.toString()` will return the same as `from.toString()` but prepended with a `Wrapped with to()` comment.
|
||||
|
||||
@param to - Mimicking function.
|
||||
@param from - Function to mimic.
|
||||
@returns The modified `to` function.
|
||||
|
||||
@example
|
||||
```
|
||||
import mimicFn = require('mimic-fn');
|
||||
|
||||
function foo() {}
|
||||
foo.unicorn = '🦄';
|
||||
|
||||
function wrapper() {
|
||||
return foo();
|
||||
}
|
||||
|
||||
console.log(wrapper.name);
|
||||
//=> 'wrapper'
|
||||
|
||||
mimicFn(wrapper, foo);
|
||||
|
||||
console.log(wrapper.name);
|
||||
//=> 'foo'
|
||||
|
||||
console.log(wrapper.unicorn);
|
||||
//=> '🦄'
|
||||
```
|
||||
*/
|
||||
declare function mimicFn<
|
||||
ArgumentsType extends unknown[],
|
||||
ReturnType,
|
||||
FunctionType extends (...arguments: ArgumentsType) => ReturnType
|
||||
>(
|
||||
to: (...arguments: ArgumentsType) => ReturnType,
|
||||
from: FunctionType,
|
||||
options?: mimicFn.Options,
|
||||
): FunctionType;
|
||||
|
||||
export = mimicFn;
|
||||
Generated
Vendored
+75
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const copyProperty = (to, from, property, ignoreNonConfigurable) => {
|
||||
// `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
|
||||
// `Function#prototype` is non-writable and non-configurable so can never be modified.
|
||||
if (property === 'length' || property === 'prototype') {
|
||||
return;
|
||||
}
|
||||
|
||||
// `Function#arguments` and `Function#caller` should not be copied. They were reported to be present in `Reflect.ownKeys` for some devices in React Native (#41), so we explicitly ignore them here.
|
||||
if (property === 'arguments' || property === 'caller') {
|
||||
return;
|
||||
}
|
||||
|
||||
const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
|
||||
const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
|
||||
|
||||
if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.defineProperty(to, property, fromDescriptor);
|
||||
};
|
||||
|
||||
// `Object.defineProperty()` throws if the property exists, is not configurable and either:
|
||||
// - one its descriptors is changed
|
||||
// - it is non-writable and its value is changed
|
||||
const canCopyProperty = function (toDescriptor, fromDescriptor) {
|
||||
return toDescriptor === undefined || toDescriptor.configurable || (
|
||||
toDescriptor.writable === fromDescriptor.writable &&
|
||||
toDescriptor.enumerable === fromDescriptor.enumerable &&
|
||||
toDescriptor.configurable === fromDescriptor.configurable &&
|
||||
(toDescriptor.writable || toDescriptor.value === fromDescriptor.value)
|
||||
);
|
||||
};
|
||||
|
||||
const changePrototype = (to, from) => {
|
||||
const fromPrototype = Object.getPrototypeOf(from);
|
||||
if (fromPrototype === Object.getPrototypeOf(to)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(to, fromPrototype);
|
||||
};
|
||||
|
||||
const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`;
|
||||
|
||||
const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString');
|
||||
const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name');
|
||||
|
||||
// We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected.
|
||||
// We use `bind()` instead of a closure for the same reason.
|
||||
// Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times.
|
||||
const changeToString = (to, from, name) => {
|
||||
const withName = name === '' ? '' : `with ${name.trim()}() `;
|
||||
const newToString = wrappedToString.bind(null, withName, from.toString());
|
||||
// Ensure `to.toString.toString` is non-enumerable and has the same `same`
|
||||
Object.defineProperty(newToString, 'name', toStringName);
|
||||
Object.defineProperty(to, 'toString', {...toStringDescriptor, value: newToString});
|
||||
};
|
||||
|
||||
const mimicFn = (to, from, {ignoreNonConfigurable = false} = {}) => {
|
||||
const {name} = to;
|
||||
|
||||
for (const property of Reflect.ownKeys(from)) {
|
||||
copyProperty(to, from, property, ignoreNonConfigurable);
|
||||
}
|
||||
|
||||
changePrototype(to, from);
|
||||
changeToString(to, from, name);
|
||||
|
||||
return to;
|
||||
};
|
||||
|
||||
module.exports = mimicFn;
|
||||
Generated
Vendored
+9
@@ -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.
|
||||
Generated
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "mimic-fn",
|
||||
"version": "3.1.0",
|
||||
"description": "Make a function mimic another one",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/mimic-fn",
|
||||
"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": [
|
||||
"function",
|
||||
"mimic",
|
||||
"imitate",
|
||||
"rename",
|
||||
"copy",
|
||||
"inherit",
|
||||
"properties",
|
||||
"name",
|
||||
"func",
|
||||
"fn",
|
||||
"set",
|
||||
"infer",
|
||||
"change"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^2.1.0",
|
||||
"tsd": "^0.7.1",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+95
@@ -0,0 +1,95 @@
|
||||
<img src="media/logo.svg" alt="mimic-fn" width="400">
|
||||
<br>
|
||||
|
||||
[](https://travis-ci.org/sindresorhus/mimic-fn)
|
||||
|
||||
> Make a function mimic another one
|
||||
|
||||
Useful when you wrap a function in another function and like to preserve the original name and other properties.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install mimic-fn
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const mimicFn = require('mimic-fn');
|
||||
|
||||
function foo() {}
|
||||
foo.unicorn = '🦄';
|
||||
|
||||
function wrapper() {
|
||||
return foo();
|
||||
}
|
||||
|
||||
console.log(wrapper.name);
|
||||
//=> 'wrapper'
|
||||
|
||||
mimicFn(wrapper, foo);
|
||||
|
||||
console.log(wrapper.name);
|
||||
//=> 'foo'
|
||||
|
||||
console.log(wrapper.unicorn);
|
||||
//=> '🦄'
|
||||
|
||||
console.log(String(wrapper));
|
||||
//=> '/* Wrapped with wrapper() */\nfunction foo() {}'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### mimicFn(to, from, options?)
|
||||
|
||||
Modifies the `to` function to mimic the `from` function. Returns the `to` function.
|
||||
|
||||
`name`, `displayName`, and any other properties of `from` are copied. The `length` property is not copied. Prototype, class, and inherited properties are copied.
|
||||
|
||||
`to.toString()` will return the same as `from.toString()` but prepended with a `Wrapped with to()` comment.
|
||||
|
||||
#### to
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Mimicking function.
|
||||
|
||||
#### from
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Function to mimic.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### ignoreNonConfigurable
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Skip modifying [non-configurable properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#Description) instead of throwing an error.
|
||||
|
||||
## Related
|
||||
|
||||
- [rename-fn](https://github.com/sindresorhus/rename-fn) - Rename a function
|
||||
- [keep-func-props](https://github.com/ehmicky/keep-func-props) - Wrap a function without changing its name and other properties
|
||||
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-mimic-fn?utm_source=npm-mimic-fn&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "debounce-fn",
|
||||
"version": "4.0.0",
|
||||
"description": "Debounce a function",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/debounce-fn",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"debounce",
|
||||
"function",
|
||||
"debouncer",
|
||||
"fn",
|
||||
"func",
|
||||
"throttle",
|
||||
"delay",
|
||||
"invoked"
|
||||
],
|
||||
"dependencies": {
|
||||
"mimic-fn": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"delay": "^4.2.0",
|
||||
"tsd": "^0.11.0",
|
||||
"xo": "^0.26.1"
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
# debounce-fn [](https://travis-ci.org/sindresorhus/debounce-fn)
|
||||
|
||||
> [Debounce](https://davidwalsh.name/javascript-debounce-function) a function
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install debounce-fn
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const debounceFn = require('debounce-fn');
|
||||
|
||||
window.onresize = debounceFn(() => {
|
||||
// Do something on window resize
|
||||
}, {wait: 100});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### debounceFn(input, options?)
|
||||
|
||||
Returns a debounced function that delays calling the `input` function until after `wait` milliseconds have elapsed since the last time the debounced function was called.
|
||||
|
||||
It comes with a `.cancel()` method to cancel any scheduled `input` function calls.
|
||||
|
||||
#### input
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Function to debounce.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### wait
|
||||
|
||||
Type: `number`\
|
||||
Default: `0`
|
||||
|
||||
Time to wait until the `input` function is called.
|
||||
|
||||
##### before
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Trigger the function on the leading edge of the `wait` interval.
|
||||
|
||||
For example, can be useful for preventing accidental double-clicks on a "submit" button from firing a second time.
|
||||
|
||||
##### after
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Trigger the function on the trailing edge of the `wait` interval.
|
||||
|
||||
## Related
|
||||
|
||||
- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions
|
||||
Reference in New Issue
Block a user