first commit
This commit is contained in:
7
app_vue/node_modules/reusify/.github/dependabot.yml
generated
vendored
Normal file
7
app_vue/node_modules/reusify/.github/dependabot.yml
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
96
app_vue/node_modules/reusify/.github/workflows/ci.yml
generated
vendored
Normal file
96
app_vue/node_modules/reusify/.github/workflows/ci.yml
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
name: ci
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
legacy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: ['0.10', '0.12', 4.x, 6.x, 8.x, 10.x, 12.x, 13.x, 14.x, 15.x, 16.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
npm install --production && npm install tape
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
npm run test
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x, 20.x, 22.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
npm install
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
npm run test:coverage
|
||||
|
||||
types:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
npm install
|
||||
|
||||
- name: Run types tests
|
||||
run: |
|
||||
npm run test:typescript
|
||||
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
npm install
|
||||
|
||||
- name: Lint
|
||||
run: |
|
||||
npm run lint
|
22
app_vue/node_modules/reusify/LICENSE
generated
vendored
Normal file
22
app_vue/node_modules/reusify/LICENSE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2024 Matteo Collina
|
||||
|
||||
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.
|
||||
|
139
app_vue/node_modules/reusify/README.md
generated
vendored
Normal file
139
app_vue/node_modules/reusify/README.md
generated
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
# reusify
|
||||
|
||||
[![npm version][npm-badge]][npm-url]
|
||||
|
||||
Reuse your objects and functions for maximum speed. This technique will
|
||||
make any function run ~10% faster. You call your functions a
|
||||
lot, and it adds up quickly in hot code paths.
|
||||
|
||||
```
|
||||
$ node benchmarks/createNoCodeFunction.js
|
||||
Total time 53133
|
||||
Total iterations 100000000
|
||||
Iteration/s 1882069.5236482036
|
||||
|
||||
$ node benchmarks/reuseNoCodeFunction.js
|
||||
Total time 50617
|
||||
Total iterations 100000000
|
||||
Iteration/s 1975620.838848608
|
||||
```
|
||||
|
||||
The above benchmark uses fibonacci to simulate a real high-cpu load.
|
||||
The actual numbers might differ for your use case, but the difference
|
||||
should not.
|
||||
|
||||
The benchmark was taken using Node v6.10.0.
|
||||
|
||||
This library was extracted from
|
||||
[fastparallel](http://npm.im/fastparallel).
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var reusify = require('reusify')
|
||||
var fib = require('reusify/benchmarks/fib')
|
||||
var instance = reusify(MyObject)
|
||||
|
||||
// get an object from the cache,
|
||||
// or creates a new one when cache is empty
|
||||
var obj = instance.get()
|
||||
|
||||
// set the state
|
||||
obj.num = 100
|
||||
obj.func()
|
||||
|
||||
// reset the state.
|
||||
// if the state contains any external object
|
||||
// do not use delete operator (it is slow)
|
||||
// prefer set them to null
|
||||
obj.num = 0
|
||||
|
||||
// store an object in the cache
|
||||
instance.release(obj)
|
||||
|
||||
function MyObject () {
|
||||
// you need to define this property
|
||||
// so V8 can compile MyObject into an
|
||||
// hidden class
|
||||
this.next = null
|
||||
this.num = 0
|
||||
|
||||
var that = this
|
||||
|
||||
// this function is never reallocated,
|
||||
// so it can be optimized by V8
|
||||
this.func = function () {
|
||||
if (null) {
|
||||
// do nothing
|
||||
} else {
|
||||
// calculates fibonacci
|
||||
fib(that.num)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The above example was intended for synchronous code, let's see async:
|
||||
```js
|
||||
var reusify = require('reusify')
|
||||
var instance = reusify(MyObject)
|
||||
|
||||
for (var i = 0; i < 100; i++) {
|
||||
getData(i, console.log)
|
||||
}
|
||||
|
||||
function getData (value, cb) {
|
||||
var obj = instance.get()
|
||||
|
||||
obj.value = value
|
||||
obj.cb = cb
|
||||
obj.run()
|
||||
}
|
||||
|
||||
function MyObject () {
|
||||
this.next = null
|
||||
this.value = null
|
||||
|
||||
var that = this
|
||||
|
||||
this.run = function () {
|
||||
asyncOperation(that.value, that.handle)
|
||||
}
|
||||
|
||||
this.handle = function (err, result) {
|
||||
that.cb(err, result)
|
||||
that.value = null
|
||||
that.cb = null
|
||||
instance.release(that)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Also note how in the above examples, the code, that consumes an instance of `MyObject`,
|
||||
reset the state to initial condition, just before storing it in the cache.
|
||||
That's needed so that every subsequent request for an instance from the cache,
|
||||
could get a clean instance.
|
||||
|
||||
## Why
|
||||
|
||||
It is faster because V8 doesn't have to collect all the functions you
|
||||
create. On a short-lived benchmark, it is as fast as creating the
|
||||
nested function, but on a longer time frame it creates less
|
||||
pressure on the garbage collector.
|
||||
|
||||
## Other examples
|
||||
If you want to see some complex example, checkout [middie](https://github.com/fastify/middie) and [steed](https://github.com/mcollina/steed).
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
Thanks to [Trevor Norris](https://github.com/trevnorris) for
|
||||
getting me down the rabbit hole of performance, and thanks to [Mathias
|
||||
Buss](http://github.com/mafintosh) for suggesting me to share this
|
||||
trick.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[npm-badge]: https://badge.fury.io/js/reusify.svg
|
||||
[npm-url]: https://badge.fury.io/js/reusify
|
15
app_vue/node_modules/reusify/SECURITY.md
generated
vendored
Normal file
15
app_vue/node_modules/reusify/SECURITY.md
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Use this section to tell people about which versions of your project are
|
||||
currently being supported with security updates.
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| 1.x | :white_check_mark: |
|
||||
| < 1.0 | :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please report all vulnerabilities at [https://github.com/mcollina/fastq/security](https://github.com/mcollina/fastq/security).
|
30
app_vue/node_modules/reusify/benchmarks/createNoCodeFunction.js
generated
vendored
Normal file
30
app_vue/node_modules/reusify/benchmarks/createNoCodeFunction.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
var fib = require('./fib')
|
||||
var max = 100000000
|
||||
var start = Date.now()
|
||||
|
||||
// create a funcion with the typical error
|
||||
// pattern, that delegates the heavy load
|
||||
// to something else
|
||||
function createNoCodeFunction () {
|
||||
/* eslint no-constant-condition: "off" */
|
||||
var num = 100
|
||||
|
||||
;(function () {
|
||||
if (null) {
|
||||
// do nothing
|
||||
} else {
|
||||
fib(num)
|
||||
}
|
||||
})()
|
||||
}
|
||||
|
||||
for (var i = 0; i < max; i++) {
|
||||
createNoCodeFunction()
|
||||
}
|
||||
|
||||
var time = Date.now() - start
|
||||
console.log('Total time', time)
|
||||
console.log('Total iterations', max)
|
||||
console.log('Iteration/s', max / time * 1000)
|
13
app_vue/node_modules/reusify/benchmarks/fib.js
generated
vendored
Normal file
13
app_vue/node_modules/reusify/benchmarks/fib.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
function fib (num) {
|
||||
var fib = []
|
||||
|
||||
fib[0] = 0
|
||||
fib[1] = 1
|
||||
for (var i = 2; i <= num; i++) {
|
||||
fib[i] = fib[i - 2] + fib[i - 1]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = fib
|
38
app_vue/node_modules/reusify/benchmarks/reuseNoCodeFunction.js
generated
vendored
Normal file
38
app_vue/node_modules/reusify/benchmarks/reuseNoCodeFunction.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict'
|
||||
|
||||
var reusify = require('../')
|
||||
var fib = require('./fib')
|
||||
var instance = reusify(MyObject)
|
||||
var max = 100000000
|
||||
var start = Date.now()
|
||||
|
||||
function reuseNoCodeFunction () {
|
||||
var obj = instance.get()
|
||||
obj.num = 100
|
||||
obj.func()
|
||||
obj.num = 0
|
||||
instance.release(obj)
|
||||
}
|
||||
|
||||
function MyObject () {
|
||||
this.next = null
|
||||
var that = this
|
||||
this.num = 0
|
||||
this.func = function () {
|
||||
/* eslint no-constant-condition: "off" */
|
||||
if (null) {
|
||||
// do nothing
|
||||
} else {
|
||||
fib(that.num)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < max; i++) {
|
||||
reuseNoCodeFunction()
|
||||
}
|
||||
|
||||
var time = Date.now() - start
|
||||
console.log('Total time', time)
|
||||
console.log('Total iterations', max)
|
||||
console.log('Iteration/s', max / time * 1000)
|
14
app_vue/node_modules/reusify/eslint.config.js
generated
vendored
Normal file
14
app_vue/node_modules/reusify/eslint.config.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
const base = require('neostandard')({})
|
||||
|
||||
module.exports = [
|
||||
...base,
|
||||
{
|
||||
name: 'old-standard',
|
||||
rules: {
|
||||
'no-var': 'off',
|
||||
'object-shorthand': 'off',
|
||||
}
|
||||
}
|
||||
]
|
50
app_vue/node_modules/reusify/package.json
generated
vendored
Normal file
50
app_vue/node_modules/reusify/package.json
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "reusify",
|
||||
"version": "1.1.0",
|
||||
"description": "Reuse objects and functions with style",
|
||||
"main": "reusify.js",
|
||||
"types": "reusify.d.ts",
|
||||
"scripts": {
|
||||
"lint": "eslint",
|
||||
"test": "tape test.js",
|
||||
"test:coverage": "c8 --100 tape test.js",
|
||||
"test:typescript": "tsc"
|
||||
},
|
||||
"pre-commit": [
|
||||
"lint",
|
||||
"test",
|
||||
"test:typescript"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mcollina/reusify.git"
|
||||
},
|
||||
"keywords": [
|
||||
"reuse",
|
||||
"object",
|
||||
"performance",
|
||||
"function",
|
||||
"fast"
|
||||
],
|
||||
"author": "Matteo Collina <hello@matteocollina.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mcollina/reusify/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mcollina/reusify#readme",
|
||||
"engines": {
|
||||
"node": ">=0.10.0",
|
||||
"iojs": ">=1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.9.0",
|
||||
"eslint": "^9.13.0",
|
||||
"neostandard": "^0.12.0",
|
||||
"pre-commit": "^1.2.2",
|
||||
"tape": "^5.0.0",
|
||||
"c8": "^10.1.2",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
14
app_vue/node_modules/reusify/reusify.d.ts
generated
vendored
Normal file
14
app_vue/node_modules/reusify/reusify.d.ts
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
interface Node {
|
||||
next: Node | null;
|
||||
}
|
||||
|
||||
interface Constructor<T> {
|
||||
new(): T;
|
||||
}
|
||||
|
||||
declare function reusify<T extends Node>(constructor: Constructor<T>): {
|
||||
get(): T;
|
||||
release(node: T): void;
|
||||
};
|
||||
|
||||
export = reusify;
|
33
app_vue/node_modules/reusify/reusify.js
generated
vendored
Normal file
33
app_vue/node_modules/reusify/reusify.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
'use strict'
|
||||
|
||||
function reusify (Constructor) {
|
||||
var head = new Constructor()
|
||||
var tail = head
|
||||
|
||||
function get () {
|
||||
var current = head
|
||||
|
||||
if (current.next) {
|
||||
head = current.next
|
||||
} else {
|
||||
head = new Constructor()
|
||||
tail = head
|
||||
}
|
||||
|
||||
current.next = null
|
||||
|
||||
return current
|
||||
}
|
||||
|
||||
function release (obj) {
|
||||
tail.next = obj
|
||||
tail = obj
|
||||
}
|
||||
|
||||
return {
|
||||
get: get,
|
||||
release: release
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = reusify
|
66
app_vue/node_modules/reusify/test.js
generated
vendored
Normal file
66
app_vue/node_modules/reusify/test.js
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
'use strict'
|
||||
|
||||
var test = require('tape')
|
||||
var reusify = require('./')
|
||||
|
||||
test('reuse objects', function (t) {
|
||||
t.plan(6)
|
||||
|
||||
function MyObject () {
|
||||
t.pass('constructor called')
|
||||
this.next = null
|
||||
}
|
||||
|
||||
var instance = reusify(MyObject)
|
||||
var obj = instance.get()
|
||||
|
||||
t.notEqual(obj, instance.get(), 'two instance created')
|
||||
t.notOk(obj.next, 'next must be null')
|
||||
|
||||
instance.release(obj)
|
||||
|
||||
// the internals keeps a hot copy ready for reuse
|
||||
// putting this one back in the queue
|
||||
instance.release(instance.get())
|
||||
|
||||
// comparing the old one with the one we got
|
||||
// never do this in real code, after release you
|
||||
// should never reuse that instance
|
||||
t.equal(obj, instance.get(), 'instance must be reused')
|
||||
})
|
||||
|
||||
test('reuse more than 2 objects', function (t) {
|
||||
function MyObject () {
|
||||
t.pass('constructor called')
|
||||
this.next = null
|
||||
}
|
||||
|
||||
var instance = reusify(MyObject)
|
||||
var obj = instance.get()
|
||||
var obj2 = instance.get()
|
||||
var obj3 = instance.get()
|
||||
|
||||
t.notOk(obj.next, 'next must be null')
|
||||
t.notOk(obj2.next, 'next must be null')
|
||||
t.notOk(obj3.next, 'next must be null')
|
||||
|
||||
t.notEqual(obj, obj2)
|
||||
t.notEqual(obj, obj3)
|
||||
t.notEqual(obj3, obj2)
|
||||
|
||||
instance.release(obj)
|
||||
instance.release(obj2)
|
||||
instance.release(obj3)
|
||||
|
||||
// skip one
|
||||
instance.get()
|
||||
|
||||
var obj4 = instance.get()
|
||||
var obj5 = instance.get()
|
||||
var obj6 = instance.get()
|
||||
|
||||
t.equal(obj4, obj)
|
||||
t.equal(obj5, obj2)
|
||||
t.equal(obj6, obj3)
|
||||
t.end()
|
||||
})
|
11
app_vue/node_modules/reusify/tsconfig.json
generated
vendored
Normal file
11
app_vue/node_modules/reusify/tsconfig.json
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"noEmit": true,
|
||||
"strict": true
|
||||
},
|
||||
"files": [
|
||||
"./reusify.d.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user