Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
21
Frontend-Learner/node_modules/stable-hash-x/LICENSE
generated
vendored
Normal file
21
Frontend-Learner/node_modules/stable-hash-x/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2025-present UnTS
|
||||
|
||||
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.
|
||||
242
Frontend-Learner/node_modules/stable-hash-x/README.md
generated
vendored
Normal file
242
Frontend-Learner/node_modules/stable-hash-x/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
# stable-hash-x
|
||||
|
||||
[](https://github.com/un-ts/stable-hash-x/actions/workflows/ci.yml?query=branch%3Amain)
|
||||
[](https://codecov.io/gh/un-ts/stable-hash-x)
|
||||
[](https://github.com/plantain-00/type-coverage)
|
||||
[](https://coderabbit.ai)
|
||||
[](https://www.npmjs.com/package/stable-hash-x)
|
||||
[](https://github.com/un-ts/stable-hash-x/releases)
|
||||
|
||||
[](https://conventionalcommits.org)
|
||||
[](https://renovatebot.com)
|
||||
[](https://standardjs.com)
|
||||
[](https://github.com/prettier/prettier)
|
||||
[](https://github.com/changesets/changesets)
|
||||
|
||||
A tiny and fast (600B <sup>[unpkg](https://unpkg.com/stable-hash-x@latest/lib/index.js)</sup>) lib for "stably hashing" a JavaScript value, works with cross-realm objects. Originally created for [SWR](https://github.com/vercel/swr) by [Shu Ding][] at [`stable-hash`](https://github.com/shuding/stable-hash), we forked it because the original one is a bit out of maintenance for a long time.
|
||||
|
||||
It's similar to `JSON.stringify(value)`, but:
|
||||
|
||||
1. Supports any JavaScript value (`BigInt`, `NaN`, `Symbol`, `function`, `class`, ...)
|
||||
2. Sorts object keys (stable)
|
||||
3. Supports circular objects
|
||||
|
||||
## TOC <!-- omit in toc -->
|
||||
|
||||
- [Use](#use)
|
||||
- [Examples](#examples)
|
||||
- [Primitive Value](#primitive-value)
|
||||
- [Regex](#regex)
|
||||
- [Date](#date)
|
||||
- [Array](#array)
|
||||
- [Object](#object)
|
||||
- [`Function`, `Class`, `Set`, `Map`, `Buffer`...](#function-class-set-map-buffer)
|
||||
- [Cross-realm](#cross-realm)
|
||||
- [Benchmark](#benchmark)
|
||||
- [Notes](#notes)
|
||||
- [Sponsors and Backers](#sponsors-and-backers)
|
||||
- [Sponsors](#sponsors)
|
||||
- [Backers](#backers)
|
||||
- [Changelog](#changelog)
|
||||
- [License](#license)
|
||||
|
||||
## Use
|
||||
|
||||
```bash
|
||||
yarn add stable-hash-x
|
||||
```
|
||||
|
||||
```js
|
||||
import { hash } from 'stable-hash-x'
|
||||
|
||||
hash(anyJavaScriptValueHere) // returns a string
|
||||
|
||||
hash(anyJavaScriptValueHere, true) // if you're running in cross-realm environment, it's disabled by default for performance
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Primitive Value
|
||||
|
||||
```js
|
||||
hash(1)
|
||||
hash('foo')
|
||||
hash(true)
|
||||
hash(undefined)
|
||||
hash(null)
|
||||
hash(NaN)
|
||||
```
|
||||
|
||||
BigInt:
|
||||
|
||||
```js
|
||||
hash(1) === hash(1n)
|
||||
hash(1) !== hash(2n)
|
||||
```
|
||||
|
||||
Symbol:
|
||||
|
||||
```js
|
||||
hash(Symbol.for('foo')) === hash(Symbol.for('foo'))
|
||||
hash(Symbol.for('foo')) === hash(Symbol('foo'))
|
||||
hash(Symbol('foo')) === hash(Symbol('foo'))
|
||||
hash(Symbol('foo')) !== hash(Symbol('bar'))
|
||||
```
|
||||
|
||||
_Since `Symbol`s cannot be serialized, `stable-hash-x` simply uses its description as the hash._
|
||||
|
||||
### Regex
|
||||
|
||||
```js
|
||||
hash(/foo/) === hash(/foo/)
|
||||
hash(/foo/) !== hash(/bar/)
|
||||
```
|
||||
|
||||
### Date
|
||||
|
||||
```js
|
||||
hash(new Date(1)) === hash(new Date(1))
|
||||
```
|
||||
|
||||
### Array
|
||||
|
||||
```js
|
||||
hash([1, '2', [new Date(3)]]) === hash([1, '2', [new Date(3)]])
|
||||
hash([1, 2]) !== hash([2, 1])
|
||||
```
|
||||
|
||||
Circular:
|
||||
|
||||
```js
|
||||
const foo = []
|
||||
foo.push(foo)
|
||||
hash(foo) === hash(foo)
|
||||
```
|
||||
|
||||
### Object
|
||||
|
||||
```js
|
||||
hash({ foo: 'bar' }) === hash({ foo: 'bar' })
|
||||
hash({ foo: { bar: 1 } }) === hash({ foo: { bar: 1 } })
|
||||
```
|
||||
|
||||
Stable:
|
||||
|
||||
```js
|
||||
hash({ a: 1, b: 2, c: 3 }) === hash({ c: 3, b: 2, a: 1 })
|
||||
```
|
||||
|
||||
Circular:
|
||||
|
||||
```js
|
||||
const foo = {}
|
||||
foo.foo = foo
|
||||
hash(foo) === hash(foo)
|
||||
```
|
||||
|
||||
### `Function`, `Class`, `Set`, `Map`, `Buffer`...
|
||||
|
||||
`stable-hash-x` guarantees reference consistency (`===`) for objects that the constructor isn't `Object`.
|
||||
|
||||
```js
|
||||
const foo = () => {}
|
||||
hash(foo) === hash(foo)
|
||||
hash(foo) !== hash(() => {})
|
||||
```
|
||||
|
||||
```js
|
||||
class Foo {}
|
||||
hash(Foo) === hash(Foo)
|
||||
hash(Foo) !== hash(class {})
|
||||
```
|
||||
|
||||
```js
|
||||
const foo = new Set([1])
|
||||
hash(foo) === hash(foo)
|
||||
hash(foo) !== hash(new Set([1]))
|
||||
```
|
||||
|
||||
### Cross-realm
|
||||
|
||||
```js
|
||||
import { runInNewContext } from 'node:vm'
|
||||
|
||||
const obj1 = {
|
||||
a: 1,
|
||||
b: new Date('2022-06-25T01:55:27.743Z'),
|
||||
c: /test/,
|
||||
f: Symbol('test'),
|
||||
}
|
||||
const obj2 = runInNewContext(`({
|
||||
a: 1,
|
||||
b: new Date('2022-06-25T01:55:27.743Z'),
|
||||
c: /test/,
|
||||
f: Symbol('test'),
|
||||
})`)
|
||||
|
||||
obj1 === obj2 // false
|
||||
hash(obj1) === hash(obj2, true) // true
|
||||
```
|
||||
|
||||
## Benchmark
|
||||
|
||||
```log
|
||||
┌─────────┬────────────────────────────────┬──────────────────┬───────────────────┬────────────────────────┬────────────────────────┬─────────┐
|
||||
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
|
||||
├─────────┼────────────────────────────────┼──────────────────┼───────────────────┼────────────────────────┼────────────────────────┼─────────┤
|
||||
│ 0 │ 'stable-hash-x' │ '7877.4 ± 1.57%' │ '7042.0 ± 167.00' │ '138708 ± 0.05%' │ '142005 ± 3449' │ 126975 │
|
||||
│ 1 │ 'hash-object' │ '17632 ± 0.73%' │ '16708 ± 458.00' │ '58820 ± 0.07%' │ '59852 ± 1600' │ 56716 │
|
||||
│ 2 │ 'json-stringify-deterministic' │ '10901 ± 0.83%' │ '10250 ± 250.00' │ '95860 ± 0.05%' │ '97561 ± 2439' │ 91739 │
|
||||
│ 3 │ 'stable-hash' │ '8318.5 ± 3.27%' │ '7042.0 ± 208.00' │ '138347 ± 0.06%' │ '142005 ± 4074' │ 120214 │
|
||||
└─────────┴────────────────────────────────┴──────────────────┴───────────────────┴────────────────────────┴────────────────────────┴─────────┘
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
This function does something similar to `JSON.stringify`, but more than it. It doesn't generate a secure checksum, which usually has a fixed length and is hard to be reversed. With `stable-hash-x` it's still possible to get the original data. Also, the output might include any charaters, not just alphabets and numbers like other hash algorithms. So:
|
||||
|
||||
- Use another encoding layer on top of it if you want to display the output.
|
||||
- Use another crypto layer on top of it if you want to have a secure and fixed length hash.
|
||||
|
||||
```js
|
||||
import crypto from 'node:crypto'
|
||||
|
||||
import { hash } from 'stable-hash-x'
|
||||
|
||||
const weakHash = hash(anyJavaScriptValueHere)
|
||||
const encodedHash = Buffer.from(weakHash).toString('base64')
|
||||
const safeHash = crypto.createHash('MD5').update(weakHash).digest('hex')
|
||||
```
|
||||
|
||||
Also, the consistency of this lib is sometimes guaranteed by the singularity of the WeakMap instance. So it might not generate the consistent results when running in different runtimes, e.g. server/client or parent/worker scenarios.
|
||||
|
||||
## Sponsors and Backers
|
||||
|
||||
[](https://github.com/sponsors/JounQin)
|
||||
|
||||
### Sponsors
|
||||
|
||||
| 1stG | RxTS | UnRS | UnTS |
|
||||
| ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
||||
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unrs) | [](https://opencollective.com/unts) |
|
||||
|
||||
### Backers
|
||||
|
||||
| 1stG | RxTS | UnRS | UnTS |
|
||||
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
||||
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unrs) | [](https://opencollective.com/unts) |
|
||||
|
||||
## Changelog
|
||||
|
||||
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
|
||||
|
||||
## License
|
||||
|
||||
Originally created by [Shu Ding].
|
||||
|
||||
[MIT][] © [JounQin][]@[1stG.me][]
|
||||
|
||||
[1stG.me]: https://www.1stG.me
|
||||
[MIT]: http://opensource.org/licenses/MIT
|
||||
[JounQin]: https://github.com/JounQin
|
||||
[Shu Ding]: https://github.com/shuding
|
||||
45
Frontend-Learner/node_modules/stable-hash-x/lib/index.cjs
generated
vendored
Normal file
45
Frontend-Learner/node_modules/stable-hash-x/lib/index.cjs
generated
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
//#region src/index.ts
|
||||
const table = /* @__PURE__ */ new WeakMap();
|
||||
let counter = 0;
|
||||
const { toString } = Object.prototype;
|
||||
const isType = (arg, type) => toString.call(arg) === `[object ${type}]`;
|
||||
const isPlainObject = (val) => {
|
||||
const prototype = Object.getPrototypeOf(val);
|
||||
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
||||
};
|
||||
function stableHash(arg, crossRealm) {
|
||||
const type = typeof arg;
|
||||
const constructor = arg === null || arg === void 0 ? void 0 : arg.constructor;
|
||||
const isDate = crossRealm ? isType(arg, "Date") : constructor === Date;
|
||||
if (Object(arg) === arg && !isDate && !(crossRealm ? isType(arg, "RegExp") : constructor === RegExp)) {
|
||||
const arg_ = arg;
|
||||
let result = table.get(arg_);
|
||||
if (result) return result;
|
||||
result = ++counter + "~";
|
||||
table.set(arg_, result);
|
||||
let index;
|
||||
if (crossRealm ? Array.isArray(arg) : constructor === Array) {
|
||||
const arg_$1 = arg;
|
||||
result = "@";
|
||||
for (index = 0; index < arg_$1.length; index++) result += stableHash(arg_$1[index], crossRealm) + ",";
|
||||
table.set(arg_$1, result);
|
||||
} else if (crossRealm ? isPlainObject(arg_) : constructor === null || constructor === Object) {
|
||||
result = "#";
|
||||
const keys = Object.keys(arg_).sort();
|
||||
while ((index = keys.pop()) !== void 0) {
|
||||
const index_ = index;
|
||||
if (arg_[index_] !== void 0) result += index + ":" + stableHash(arg_[index_], crossRealm) + ",";
|
||||
}
|
||||
table.set(arg_, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (isDate) return arg.toJSON();
|
||||
if (type === "symbol") return arg.toString();
|
||||
return type === "string" ? JSON.stringify(arg) : "" + arg;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports.hash = stableHash;
|
||||
exports.stableHash = stableHash;
|
||||
4
Frontend-Learner/node_modules/stable-hash-x/lib/index.d.cts
generated
vendored
Normal file
4
Frontend-Learner/node_modules/stable-hash-x/lib/index.d.cts
generated
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
//#region src/index.d.ts
|
||||
declare function stableHash(arg: unknown, crossRealm?: boolean): string;
|
||||
//#endregion
|
||||
export { stableHash as hash, stableHash };
|
||||
4
Frontend-Learner/node_modules/stable-hash-x/lib/index.d.ts
generated
vendored
Normal file
4
Frontend-Learner/node_modules/stable-hash-x/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
//#region src/index.d.ts
|
||||
declare function stableHash(arg: unknown, crossRealm?: boolean): string;
|
||||
//#endregion
|
||||
export { stableHash as hash, stableHash };
|
||||
43
Frontend-Learner/node_modules/stable-hash-x/lib/index.js
generated
vendored
Normal file
43
Frontend-Learner/node_modules/stable-hash-x/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//#region src/index.ts
|
||||
const table = /* @__PURE__ */ new WeakMap();
|
||||
let counter = 0;
|
||||
const { toString } = Object.prototype;
|
||||
const isType = (arg, type) => toString.call(arg) === `[object ${type}]`;
|
||||
const isPlainObject = (val) => {
|
||||
const prototype = Object.getPrototypeOf(val);
|
||||
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
||||
};
|
||||
function stableHash(arg, crossRealm) {
|
||||
const type = typeof arg;
|
||||
const constructor = arg === null || arg === void 0 ? void 0 : arg.constructor;
|
||||
const isDate = crossRealm ? isType(arg, "Date") : constructor === Date;
|
||||
if (Object(arg) === arg && !isDate && !(crossRealm ? isType(arg, "RegExp") : constructor === RegExp)) {
|
||||
const arg_ = arg;
|
||||
let result = table.get(arg_);
|
||||
if (result) return result;
|
||||
result = ++counter + "~";
|
||||
table.set(arg_, result);
|
||||
let index;
|
||||
if (crossRealm ? Array.isArray(arg) : constructor === Array) {
|
||||
const arg_$1 = arg;
|
||||
result = "@";
|
||||
for (index = 0; index < arg_$1.length; index++) result += stableHash(arg_$1[index], crossRealm) + ",";
|
||||
table.set(arg_$1, result);
|
||||
} else if (crossRealm ? isPlainObject(arg_) : constructor === null || constructor === Object) {
|
||||
result = "#";
|
||||
const keys = Object.keys(arg_).sort();
|
||||
while ((index = keys.pop()) !== void 0) {
|
||||
const index_ = index;
|
||||
if (arg_[index_] !== void 0) result += index + ":" + stableHash(arg_[index_], crossRealm) + ",";
|
||||
}
|
||||
table.set(arg_, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (isDate) return arg.toJSON();
|
||||
if (type === "symbol") return arg.toString();
|
||||
return type === "string" ? JSON.stringify(arg) : "" + arg;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { stableHash as hash, stableHash };
|
||||
35
Frontend-Learner/node_modules/stable-hash-x/package.json
generated
vendored
Normal file
35
Frontend-Learner/node_modules/stable-hash-x/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"name": "stable-hash-x",
|
||||
"version": "0.2.0",
|
||||
"type": "module",
|
||||
"description": "Stable JS value hash.",
|
||||
"repository": "https://github.com/un-ts/stable-hash-x",
|
||||
"homepage": "https://github.com/un-ts/stable-hash-x#readme",
|
||||
"author": "Shu Ding",
|
||||
"maintainers": [
|
||||
"JounQin <admin@1stg.me> (https://www.1stG.me)"
|
||||
],
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"main": "./lib/index.cjs",
|
||||
"types": "./lib/index.d.cts",
|
||||
"module": "./lib/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./lib/index.d.cts",
|
||||
"default": "./lib/index.cjs"
|
||||
}
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue