clean
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
**/.DS_Store
|
**/.DS_Store
|
||||||
node_modules
|
.*.sw*
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../esbuild/bin/esbuild
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../prettier/bin/prettier.cjs
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../typescript/bin/tsc
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../typescript/bin/tsserver
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../uuid/dist/bin/uuid
|
||||||
+153
@@ -0,0 +1,153 @@
|
|||||||
|
{
|
||||||
|
"name": "udn-comms",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"node_modules/@esbuild/linux-arm64": {
|
||||||
|
"version": "0.23.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.23.1.tgz",
|
||||||
|
"integrity": "sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/uuid": {
|
||||||
|
"version": "10.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz",
|
||||||
|
"integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/bloatless-react": {
|
||||||
|
"version": "1.3.14",
|
||||||
|
"resolved": "https://registry.npmjs.org/bloatless-react/-/bloatless-react-1.3.14.tgz",
|
||||||
|
"integrity": "sha512-Y4v8RnZeggUozvqHsG6QkZI6AvwxtumaJ4NLPQRbCB7/MuuxA2cc6U+Cw4SiXPY1y9TAarI75xOWh8CNK6wijA==",
|
||||||
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"uuid": "^13.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/bloatless-react/node_modules/uuid": {
|
||||||
|
"version": "13.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-13.0.0.tgz",
|
||||||
|
"integrity": "sha512-XQegIaBTVUjSHliKqcnFqYypAd4S+WCYt5NIeRs6w/UAry7z8Y9j5ZwRRL4kzq9U3sD6v+85er9FvkEaBpji2w==",
|
||||||
|
"funding": [
|
||||||
|
"https://github.com/sponsors/broofa",
|
||||||
|
"https://github.com/sponsors/ctavan"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"uuid": "dist-node/bin/uuid"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/esbuild": {
|
||||||
|
"version": "0.23.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz",
|
||||||
|
"integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==",
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"esbuild": "bin/esbuild"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@esbuild/aix-ppc64": "0.23.1",
|
||||||
|
"@esbuild/android-arm": "0.23.1",
|
||||||
|
"@esbuild/android-arm64": "0.23.1",
|
||||||
|
"@esbuild/android-x64": "0.23.1",
|
||||||
|
"@esbuild/darwin-arm64": "0.23.1",
|
||||||
|
"@esbuild/darwin-x64": "0.23.1",
|
||||||
|
"@esbuild/freebsd-arm64": "0.23.1",
|
||||||
|
"@esbuild/freebsd-x64": "0.23.1",
|
||||||
|
"@esbuild/linux-arm": "0.23.1",
|
||||||
|
"@esbuild/linux-arm64": "0.23.1",
|
||||||
|
"@esbuild/linux-ia32": "0.23.1",
|
||||||
|
"@esbuild/linux-loong64": "0.23.1",
|
||||||
|
"@esbuild/linux-mips64el": "0.23.1",
|
||||||
|
"@esbuild/linux-ppc64": "0.23.1",
|
||||||
|
"@esbuild/linux-riscv64": "0.23.1",
|
||||||
|
"@esbuild/linux-s390x": "0.23.1",
|
||||||
|
"@esbuild/linux-x64": "0.23.1",
|
||||||
|
"@esbuild/netbsd-x64": "0.23.1",
|
||||||
|
"@esbuild/openbsd-arm64": "0.23.1",
|
||||||
|
"@esbuild/openbsd-x64": "0.23.1",
|
||||||
|
"@esbuild/sunos-x64": "0.23.1",
|
||||||
|
"@esbuild/win32-arm64": "0.23.1",
|
||||||
|
"@esbuild/win32-ia32": "0.23.1",
|
||||||
|
"@esbuild/win32-x64": "0.23.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/prettier": {
|
||||||
|
"version": "3.8.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.3.tgz",
|
||||||
|
"integrity": "sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"prettier": "bin/prettier.cjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/prettier-plugin-sort-imports": {
|
||||||
|
"version": "1.8.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/prettier-plugin-sort-imports/-/prettier-plugin-sort-imports-1.8.11.tgz",
|
||||||
|
"integrity": "sha512-ApmZkEmNh2Fi6TAcYNgUR15rsP1+omX43+8neY+MXfNZ7JQwrqSdjzKhLUYTtaLo52aaC9gCs+lJaYSU8oSJJA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"prettier": "^3.1.1"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"typescript": ">4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/typescript": {
|
||||||
|
"version": "6.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz",
|
||||||
|
"integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"peer": true,
|
||||||
|
"bin": {
|
||||||
|
"tsc": "bin/tsc",
|
||||||
|
"tsserver": "bin/tsserver"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.17"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/udn-frontend": {
|
||||||
|
"version": "1.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/udn-frontend/-/udn-frontend-1.0.9.tgz",
|
||||||
|
"integrity": "sha512-6wDnGEFQ0Jan33+3yxIEq2ukeuuZjtmvQylHpAL/VDa2ioCEkzTPMvskGdClXBpEh0scPUQwU5QWL6q33U4rsA==",
|
||||||
|
"license": "SEE LICENSE IN LICENSE"
|
||||||
|
},
|
||||||
|
"node_modules/uuid": {
|
||||||
|
"version": "10.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz",
|
||||||
|
"integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==",
|
||||||
|
"funding": [
|
||||||
|
"https://github.com/sponsors/broofa",
|
||||||
|
"https://github.com/sponsors/ctavan"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"uuid": "dist/bin/uuid"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
# esbuild
|
||||||
|
|
||||||
|
This is the Linux ARM 64-bit binary for esbuild, a JavaScript bundler and minifier. See https://github.com/evanw/esbuild for details.
|
||||||
BIN
Binary file not shown.
+20
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "@esbuild/linux-arm64",
|
||||||
|
"version": "0.23.1",
|
||||||
|
"description": "The Linux ARM 64-bit binary for esbuild, a JavaScript bundler.",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/evanw/esbuild.git"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"preferUnplugged": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
]
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Microsoft Corporation.
|
||||||
|
|
||||||
|
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
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
# Installation
|
||||||
|
> `npm install --save @types/uuid`
|
||||||
|
|
||||||
|
# Summary
|
||||||
|
This package contains type definitions for uuid (https://github.com/uuidjs/uuid).
|
||||||
|
|
||||||
|
# Details
|
||||||
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/uuid.
|
||||||
|
|
||||||
|
### Additional Details
|
||||||
|
* Last updated: Thu, 20 Jun 2024 21:07:25 GMT
|
||||||
|
* Dependencies: none
|
||||||
|
|
||||||
|
# Credits
|
||||||
|
These definitions were written by [Oliver Hoffmann](https://github.com/iamolivinius), [Felipe Ochoa](https://github.com/felipeochoa), [Chris Barth](https://github.com/cjbarth), [Linus Unnebäck](https://github.com/LinusU), and [Christoph Tavan](https://github.com/ctavan).
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
import uuid from "./index.js";
|
||||||
|
export import v1 = uuid.v1;
|
||||||
|
export import v1ToV6 = uuid.v1ToV6;
|
||||||
|
export import v3 = uuid.v3;
|
||||||
|
export import v4 = uuid.v4;
|
||||||
|
export import v5 = uuid.v5;
|
||||||
|
export import v6 = uuid.v6;
|
||||||
|
export import v6ToV1 = uuid.v6ToV1;
|
||||||
|
export import v7 = uuid.v7;
|
||||||
|
export import NIL = uuid.NIL;
|
||||||
|
export import MAX = uuid.MAX;
|
||||||
|
export import version = uuid.version;
|
||||||
|
export import validate = uuid.validate;
|
||||||
|
export import stringify = uuid.stringify;
|
||||||
|
export import parse = uuid.parse;
|
||||||
|
export import V1Options = uuid.V1Options;
|
||||||
|
export import V4Options = uuid.V4Options;
|
||||||
|
export import V6Options = uuid.V6Options;
|
||||||
|
export import V7Options = uuid.V7Options;
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
// disable automatic export
|
||||||
|
export {};
|
||||||
|
|
||||||
|
// Uses ArrayLike to admit Uint8 and co.
|
||||||
|
type OutputBuffer = ArrayLike<number>;
|
||||||
|
type InputBuffer = ArrayLike<number>;
|
||||||
|
|
||||||
|
interface RandomOptions {
|
||||||
|
/** `Array` of 16 random bytes (0-255) */
|
||||||
|
random?: InputBuffer | undefined;
|
||||||
|
}
|
||||||
|
interface RngOptions {
|
||||||
|
/** Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) */
|
||||||
|
rng?: (() => InputBuffer) | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface V1BaseOptions {
|
||||||
|
/** RFC "node" field as an `Array[6]` of byte values (per 4.1.6) */
|
||||||
|
node?: InputBuffer | undefined;
|
||||||
|
/** RFC "clock sequence" as a `Number` between 0 - 0x3fff */
|
||||||
|
clockseq?: number | undefined;
|
||||||
|
/** RFC "timestamp" field (`Number` of milliseconds, unix epoch) */
|
||||||
|
msecs?: number | Date | undefined;
|
||||||
|
/** RFC "timestamp" field (`Number` of nanoseconds to add to msecs, should be 0-10,000) */
|
||||||
|
nsecs?: number | undefined;
|
||||||
|
}
|
||||||
|
interface V1RandomOptions extends V1BaseOptions, RandomOptions {}
|
||||||
|
interface V1RngOptions extends V1BaseOptions, RngOptions {}
|
||||||
|
|
||||||
|
export type V1Options = V1RandomOptions | V1RngOptions;
|
||||||
|
export type V4Options = RandomOptions | RngOptions;
|
||||||
|
export type V6Options = V1Options;
|
||||||
|
|
||||||
|
interface V7BaseOptions {
|
||||||
|
msecs?: number | Date | undefined;
|
||||||
|
seq?: number;
|
||||||
|
}
|
||||||
|
export type V7Options = (RandomOptions | RngOptions) & V7BaseOptions;
|
||||||
|
|
||||||
|
type VToV = ((uuid: string) => string) & ((uuid: OutputBuffer) => Uint8Array);
|
||||||
|
|
||||||
|
type v1String = (options?: V1Options) => string;
|
||||||
|
type v1Buffer = <T extends OutputBuffer>(options: V1Options | null | undefined, buffer: T, offset?: number) => T;
|
||||||
|
type v1 = v1Buffer & v1String;
|
||||||
|
|
||||||
|
type v1ToV6 = VToV;
|
||||||
|
|
||||||
|
type v4String = (options?: V4Options) => string;
|
||||||
|
type v4Buffer = <T extends OutputBuffer>(options: V4Options | null | undefined, buffer: T, offset?: number) => T;
|
||||||
|
type v4 = v4Buffer & v4String;
|
||||||
|
|
||||||
|
type v3String = (name: string | InputBuffer, namespace: string | InputBuffer) => string;
|
||||||
|
type v3Buffer = <T extends OutputBuffer>(
|
||||||
|
name: string | InputBuffer,
|
||||||
|
namespace: string | InputBuffer,
|
||||||
|
buffer: T,
|
||||||
|
offset?: number,
|
||||||
|
) => T;
|
||||||
|
interface v3Static {
|
||||||
|
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L16
|
||||||
|
DNS: string;
|
||||||
|
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L17
|
||||||
|
URL: string;
|
||||||
|
}
|
||||||
|
type v3 = v3Buffer & v3String & v3Static;
|
||||||
|
|
||||||
|
type v5String = (name: string | InputBuffer, namespace: string | InputBuffer) => string;
|
||||||
|
type v5Buffer = <T extends OutputBuffer>(
|
||||||
|
name: string | InputBuffer,
|
||||||
|
namespace: string | InputBuffer,
|
||||||
|
buffer: T,
|
||||||
|
offset?: number,
|
||||||
|
) => T;
|
||||||
|
interface v5Static {
|
||||||
|
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L16
|
||||||
|
DNS: string;
|
||||||
|
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L17
|
||||||
|
URL: string;
|
||||||
|
}
|
||||||
|
type v5 = v5Buffer & v5String & v5Static;
|
||||||
|
|
||||||
|
type v6String = (options?: V6Options) => string;
|
||||||
|
type v6Buffer = <T extends OutputBuffer>(options: V6Options | null | undefined, buffer: T, offset?: number) => T;
|
||||||
|
type v6 = v6Buffer & v6String;
|
||||||
|
|
||||||
|
type v6ToV1 = VToV;
|
||||||
|
|
||||||
|
type v7String = (options?: V7Options) => string;
|
||||||
|
type v7Buffer = <T extends OutputBuffer>(options: V7Options | null | undefined, buffer: T, offset?: number) => T;
|
||||||
|
type v7 = v7Buffer & v7String;
|
||||||
|
|
||||||
|
type NIL = string;
|
||||||
|
type MAX = string;
|
||||||
|
|
||||||
|
type parse = (uuid: string) => Uint8Array;
|
||||||
|
type stringify = (buffer: InputBuffer, offset?: number) => string;
|
||||||
|
type validate = (uuid: string) => boolean;
|
||||||
|
type version = (uuid: string) => number;
|
||||||
|
|
||||||
|
export const NIL: NIL;
|
||||||
|
export const MAX: MAX;
|
||||||
|
export const parse: parse;
|
||||||
|
export const stringify: stringify;
|
||||||
|
export const v1: v1;
|
||||||
|
export const v1ToV6: v1ToV6;
|
||||||
|
export const v3: v3;
|
||||||
|
export const v4: v4;
|
||||||
|
export const v5: v5;
|
||||||
|
export const v6: v6;
|
||||||
|
export const v6ToV1: v6ToV1;
|
||||||
|
export const v7: v7;
|
||||||
|
export const validate: validate;
|
||||||
|
export const version: version;
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
"name": "@types/uuid",
|
||||||
|
"version": "10.0.0",
|
||||||
|
"description": "TypeScript definitions for uuid",
|
||||||
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/uuid",
|
||||||
|
"license": "MIT",
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "Oliver Hoffmann",
|
||||||
|
"githubUsername": "iamolivinius",
|
||||||
|
"url": "https://github.com/iamolivinius"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Felipe Ochoa",
|
||||||
|
"githubUsername": "felipeochoa",
|
||||||
|
"url": "https://github.com/felipeochoa"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Chris Barth",
|
||||||
|
"githubUsername": "cjbarth",
|
||||||
|
"url": "https://github.com/cjbarth"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Linus Unnebäck",
|
||||||
|
"githubUsername": "LinusU",
|
||||||
|
"url": "https://github.com/LinusU"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Christoph Tavan",
|
||||||
|
"githubUsername": "ctavan",
|
||||||
|
"url": "https://github.com/ctavan"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"main": "",
|
||||||
|
"types": "index.d.ts",
|
||||||
|
"exports": {
|
||||||
|
"./package.json": "./package.json",
|
||||||
|
".": {
|
||||||
|
"types": {
|
||||||
|
"import": "./index.d.mts",
|
||||||
|
"default": "./index.d.ts"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
||||||
|
"directory": "types/uuid"
|
||||||
|
},
|
||||||
|
"scripts": {},
|
||||||
|
"dependencies": {},
|
||||||
|
"typesPublisherContentHash": "08fbc5ff7d23aaac1e81b5acf98181d2544ce6ffd5578e9879e2a75f0c087d54",
|
||||||
|
"typeScriptVersion": "4.7"
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
tabWidth: 4
|
||||||
+674
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
+426
@@ -0,0 +1,426 @@
|
|||||||
|
# bloatless-react
|
||||||
|
|
||||||
|
Bloatless-React is a very minimal and flexible alternative to React.
|
||||||
|
|
||||||
|
# Features
|
||||||
|
|
||||||
|
- Supports reactivity through States
|
||||||
|
- Supports JSX for components
|
||||||
|
- Written in TypeScript
|
||||||
|
- Really minimal (under 300 lines)
|
||||||
|
- No bloated server or compiler required - just bundle the JavaScript into a static .html file
|
||||||
|
|
||||||
|
# Setup
|
||||||
|
|
||||||
|
You can use any bundler you want, but esbuild is the fastest and smallest out there:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
npm install esbuild bloatless-react
|
||||||
|
mkdir src dist
|
||||||
|
touch src/index.tsx dist/index.html
|
||||||
|
```
|
||||||
|
|
||||||
|
The following build script will be enough:
|
||||||
|
|
||||||
|
```JSON
|
||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"build": "esbuild src/index.tsx --bundle --outdir=dist"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
# States
|
||||||
|
|
||||||
|
In Bloatless-React, States are the foundation of how reactivity is implemented. Similar to many frameworks, a State can hold a value and triggers the UI to update when it changes. However, **subscriptions have to be made manually** due to the minimal nature of this project.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
// Import
|
||||||
|
import * as React from 'bloatless-react';
|
||||||
|
|
||||||
|
// Create States
|
||||||
|
const name = new React.State("John Doe"); // will be State<string>
|
||||||
|
const age = new React.State(69); //will be State<number>
|
||||||
|
|
||||||
|
// Get value
|
||||||
|
console.log(name.value);
|
||||||
|
// John Doe
|
||||||
|
|
||||||
|
// Subscribe
|
||||||
|
age.subscribe(newAge => console.log(`Age changed to ${newAge}`));
|
||||||
|
// Age changed to 69
|
||||||
|
|
||||||
|
React.bulkSubscribe([name, age], () => console.log(`${name.value} is ${age.value} years old`))
|
||||||
|
|
||||||
|
// Set value
|
||||||
|
age.value = 70;
|
||||||
|
// Age changed to 70
|
||||||
|
// John Doe is 70 years old
|
||||||
|
|
||||||
|
name.value = "Josh"
|
||||||
|
// Josh is 70 years old
|
||||||
|
```
|
||||||
|
|
||||||
|
## Proxy States
|
||||||
|
|
||||||
|
A Proxy State is a State based on multiple other States. This reduces code and can increase performance.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
// Import
|
||||||
|
import * as React from 'bloatless-react';
|
||||||
|
|
||||||
|
// Create States
|
||||||
|
const name = new React.State("John Doe");
|
||||||
|
const age = new React.State(69);
|
||||||
|
|
||||||
|
// Proxy State
|
||||||
|
const summary = React.createProxyState([name, age], () => `${name.value} is ${age.value} years old.`)
|
||||||
|
summary.subscribe(console.log);
|
||||||
|
//John Doe is 69 years old.
|
||||||
|
```
|
||||||
|
|
||||||
|
## ListStates
|
||||||
|
|
||||||
|
A `ListState<T>` is a State whose value is a `Set<T>`. A ListState allows specific subscriptions to detect when items get added and removed.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
import * as React from "bloatless-react";
|
||||||
|
|
||||||
|
const listState = new React.ListState([1, 2]);
|
||||||
|
|
||||||
|
console.log(listState.value);
|
||||||
|
// Set [ 1, 2 ]
|
||||||
|
|
||||||
|
listState.handleAddition((newItem: number) => {
|
||||||
|
console.log("+", newItem);
|
||||||
|
|
||||||
|
listState.handleRemoval(newItem, () => {
|
||||||
|
console.log("-", newItem);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// + 1
|
||||||
|
// + 2
|
||||||
|
|
||||||
|
listState.add(3);
|
||||||
|
// + 3
|
||||||
|
|
||||||
|
listState.remove(1);
|
||||||
|
// - 1
|
||||||
|
|
||||||
|
listState.clear();
|
||||||
|
// - 2
|
||||||
|
// - 3
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## MapStates
|
||||||
|
|
||||||
|
A `MapState<T>` is a State whose value is a `Map<string, T>`. A ListState allows specific subscriptions to detect when items get added and removed.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
import * as React from "bloatless-react";
|
||||||
|
|
||||||
|
const mapState = new React.MapState<number>([
|
||||||
|
["a", 1],
|
||||||
|
["b", 2],
|
||||||
|
])
|
||||||
|
|
||||||
|
console.log(mapState.value);
|
||||||
|
// Map { a → 1, b → 2 }
|
||||||
|
|
||||||
|
mapState.handleAddition((newItem: number) => {
|
||||||
|
console.log("+", newItem)
|
||||||
|
|
||||||
|
mapState.handleRemoval(newItem, () => {
|
||||||
|
console.log("-", newItem)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
// + 1
|
||||||
|
// + 2
|
||||||
|
|
||||||
|
mapState.set("c", 3);
|
||||||
|
// + 3
|
||||||
|
|
||||||
|
mapState.remove("a");
|
||||||
|
// - 1
|
||||||
|
|
||||||
|
mapState.clear();
|
||||||
|
// - 2
|
||||||
|
// - 3
|
||||||
|
```
|
||||||
|
|
||||||
|
## Persistence
|
||||||
|
|
||||||
|
States can persist through reloads via LocalStorage. To implement this, modify your code like this:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
normal State
|
||||||
|
-const myState = new React.State("hello");
|
||||||
|
+const myState = React.restoreState("my-state", "hello");
|
||||||
|
|
||||||
|
MapState
|
||||||
|
-const myMapState = new React.MapState<T>();
|
||||||
|
+const myMapState = React.restoreMapState<T>("my-map-state");
|
||||||
|
OR
|
||||||
|
-const myMapState = new React.MapState<number>([["a", 1], ["b", 2]]);
|
||||||
|
+const myMapState = React.restoreMapState<number>("my-map-state", [["a", 1], ["b", 2]]);
|
||||||
|
|
||||||
|
ListState
|
||||||
|
-const myListState = new React.ListState<T>();
|
||||||
|
+const myListState = React.restoreListState<T>("my-list-state");
|
||||||
|
OR
|
||||||
|
-const myListState = new React.ListState<number>([1, 2]);
|
||||||
|
+const myListState = React.restoreListState<number>("my-list-state", [1, 2]);
|
||||||
|
```
|
||||||
|
|
||||||
|
# UI
|
||||||
|
|
||||||
|
For a minimalist stylesheet, I'd recommend checking out my project called [carbon-mini](https://github.com/marlon-erler/carbon-mini/).
|
||||||
|
|
||||||
|
Bloatless React provides a modified polyfill for the React API. This means that **you can use JSX** almost like you would in a React project. Additional functionailiy is implemented through directives, similar to Svelte:
|
||||||
|
|
||||||
|
## Handling Events
|
||||||
|
|
||||||
|
The `on:<event>` directive adds an EventListener. This directive also supports the `on:enter` event.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
<input on:enter={someFunction}></input>
|
||||||
|
<button on:click={someFunction}>Click me</button>
|
||||||
|
<div metakey:s={someFunction}>...</div> // triggers when pressing Command/Ctrl+s
|
||||||
|
```
|
||||||
|
|
||||||
|
## Changing Properties
|
||||||
|
|
||||||
|
The `subscribe:<property>` directive subscribes to a State and changes a property of the element. Use this for properties available via the DOM model (ie. innerText, innerHTML).
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
const name = new React.State("John Doe");
|
||||||
|
<span subscribe:innerText={name}></span>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Setting Attributes
|
||||||
|
|
||||||
|
The `set:<attribute>` directive subscribes to a State and changes an attribute of the element.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
<span set:someAttribute={attributeValue}></span>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Toggling Attributes
|
||||||
|
|
||||||
|
The `toggle:<attribute>` directive toggles attributes on the HTML element without assigning a value. This is useful for the `disabled` attribute. You can use states or normal variables.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
const isDisabled = new React.State(false);
|
||||||
|
<button toggle:disabled={isDisabled}>Some button</button>
|
||||||
|
<button toggle:disabled={false}>Some button</button>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Binding Input Values
|
||||||
|
|
||||||
|
The `bind:<property>` directive acts like a combination of `subscribe:<property>` and `on:input`. It binds the element's property to the state bi-directinally.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
const name = new React.State("John Doe");
|
||||||
|
// Both inputs will be in sync
|
||||||
|
<input bind:value={name}></input>
|
||||||
|
<input bind:value={name}></input>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Dynamically Creating and Removing Child Elements
|
||||||
|
|
||||||
|
The **children:set** subscribes to a `State<HTMLElement>` or `State<HTMLElement[]>` and replaces the element's contents with the State's value.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
let count = 0;
|
||||||
|
const childElement = new React.State(<div>0</div>);
|
||||||
|
|
||||||
|
function change() {
|
||||||
|
count++;
|
||||||
|
childElement.value = <div>{count}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.append(
|
||||||
|
<div>
|
||||||
|
<button on:click={change}>+</button>
|
||||||
|
<div children:set={childElement}></div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
The **children:append** and **children:prepend** directives subscribe to a `ListState` or `MapState` and sync the element's contents accordingly.
|
||||||
|
|
||||||
|
The StateItemConverter turns an item of the State into an HTMLElement.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
import * as React from "bloatless-react";
|
||||||
|
|
||||||
|
// Model
|
||||||
|
class MyDataModel {
|
||||||
|
items = new React.ListState<string>();
|
||||||
|
newItemName = new React.State("");
|
||||||
|
|
||||||
|
addItem = () => {
|
||||||
|
console.log(this);
|
||||||
|
this.items.add(this.newItemName.value);
|
||||||
|
};
|
||||||
|
removeItem = (item: string) => {
|
||||||
|
this.items.remove(item);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const model = new MyDataModel();
|
||||||
|
|
||||||
|
// Item -> Element
|
||||||
|
const convertItem: React.StateItemConverter<string> = (item: string) => {
|
||||||
|
function remove() {
|
||||||
|
model.removeItem(item);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<span>
|
||||||
|
{item}
|
||||||
|
<button on:click={remove}>Remove</button>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Build UI
|
||||||
|
document.body.append(
|
||||||
|
<div>
|
||||||
|
<input bind:value={model.newItemName}></input>
|
||||||
|
<button on:click={model.addItem}>Add</button>
|
||||||
|
<div
|
||||||
|
class="flex-column"
|
||||||
|
children:append={[model.items, convertItem]}
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 1.1.0
|
||||||
|
|
||||||
|
- Improve code
|
||||||
|
- Add missing `break` statements for directives
|
||||||
|
- Add `toggle` directive
|
||||||
|
- Improve documentation
|
||||||
|
|
||||||
|
## 1.1.1
|
||||||
|
|
||||||
|
- Improve documentation
|
||||||
|
|
||||||
|
## 1.1.2
|
||||||
|
|
||||||
|
- Remove `console.log()` calls
|
||||||
|
- Improve documentation
|
||||||
|
|
||||||
|
## 1.1.3
|
||||||
|
|
||||||
|
- Add `on:enter` directive
|
||||||
|
|
||||||
|
## 1.2.0
|
||||||
|
|
||||||
|
**BREAKING CHANGES**
|
||||||
|
|
||||||
|
- Replace UUID class with function;
|
||||||
|
- `new UUID()` => `UUID() returns string`
|
||||||
|
- Replace definition of `Identifiable`
|
||||||
|
- now has `id: string` instead of `uuid: UUID()`
|
||||||
|
|
||||||
|
Other changes:
|
||||||
|
|
||||||
|
- Add State persistence
|
||||||
|
- Add error description when utilizing `subscribe:children` incorrectly
|
||||||
|
- Fix bug where ListState subscriptions were not called
|
||||||
|
- Improve documentation
|
||||||
|
|
||||||
|
## 1.2.1
|
||||||
|
|
||||||
|
- Add `set:<attribute>` directive
|
||||||
|
|
||||||
|
## 1.2.2
|
||||||
|
|
||||||
|
- Remove list parameter from `ListItemConverter`
|
||||||
|
- Add `clear()` method to `ListState`
|
||||||
|
|
||||||
|
## 1.2.3
|
||||||
|
|
||||||
|
- Allow `toggle:<attribute>` to be used without a state
|
||||||
|
|
||||||
|
## 1.2.4
|
||||||
|
|
||||||
|
- On `subscribe:children`, scroll new elements into view
|
||||||
|
|
||||||
|
## 1.2.5
|
||||||
|
|
||||||
|
- Instead of using `scrollIntoView()`, `subscribe:children` now scrolls to the bottom
|
||||||
|
|
||||||
|
## 1.3.0
|
||||||
|
|
||||||
|
**BREAKING CHANGES**
|
||||||
|
|
||||||
|
- Replace `set:children` with `children:append`
|
||||||
|
|
||||||
|
Other changes
|
||||||
|
|
||||||
|
- Add `children:<action>` directive
|
||||||
|
- Improve documentation
|
||||||
|
|
||||||
|
## 1.3.1
|
||||||
|
|
||||||
|
- Allow arrays to be passed to `children:set`
|
||||||
|
|
||||||
|
## 1.3.2
|
||||||
|
|
||||||
|
- Allow initial value on `restoreListState()`
|
||||||
|
- Add `MapState` and `restoreMapState()`
|
||||||
|
|
||||||
|
## 1.3.3
|
||||||
|
|
||||||
|
- Rename `ListItemConverter` to `StateItemConverter`
|
||||||
|
- Improve documentation
|
||||||
|
|
||||||
|
## 1.3.4
|
||||||
|
|
||||||
|
- Remove old item from `MapState` when calling `MapState.set()` for an existing key
|
||||||
|
|
||||||
|
## 1.3.5
|
||||||
|
|
||||||
|
- Fix bug where `MapState.clear()` would not trigger removal handlers
|
||||||
|
|
||||||
|
## 1.3.6
|
||||||
|
|
||||||
|
- Add `State.subscribeSilent()`
|
||||||
|
- Add `bulkSubscribe()`
|
||||||
|
|
||||||
|
## 1.3.7
|
||||||
|
|
||||||
|
- `bulkSubscribe()` does not fire the callback when set up
|
||||||
|
|
||||||
|
## 1.3.8
|
||||||
|
|
||||||
|
- Allow multiple handlers for `MapState` and `ListState`
|
||||||
|
|
||||||
|
## 1.3.9
|
||||||
|
|
||||||
|
- Improve error handling
|
||||||
|
- Fix error where the `children:` directive would attempt to set attributes
|
||||||
|
|
||||||
|
## 1.3.10
|
||||||
|
|
||||||
|
- Improve error handling
|
||||||
|
|
||||||
|
## 1.3.11
|
||||||
|
|
||||||
|
- Add `metakey:` directive
|
||||||
|
- Pass event to `on:enter` call
|
||||||
|
|
||||||
|
## 1.3.12
|
||||||
|
- Replace `metakey:` with `keystroke:` directive to support control key additionally
|
||||||
|
|
||||||
|
## 1.3.13
|
||||||
|
- trigger state subscriptions even when value is unchanged
|
||||||
|
|
||||||
|
## 1.3.14
|
||||||
|
- fix bug where proxy states would trigger subscriptions upon creation
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"configVersion": 0,
|
||||||
|
"workspaces": {
|
||||||
|
"": {
|
||||||
|
"name": "bloatless-react",
|
||||||
|
"dependencies": {
|
||||||
|
"uuid": "^13.0.0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"packages": {
|
||||||
|
"uuid": ["uuid@13.0.0", "", { "bin": { "uuid": "dist-node/bin/uuid" } }, "sha512-XQegIaBTVUjSHliKqcnFqYypAd4S+WCYt5NIeRs6w/UAry7z8Y9j5ZwRRL4kzq9U3sD6v+85er9FvkEaBpji2w=="],
|
||||||
|
}
|
||||||
|
}
|
||||||
+372
@@ -0,0 +1,372 @@
|
|||||||
|
import { v4 } from "uuid";
|
||||||
|
|
||||||
|
/*
|
||||||
|
DATA MODEL
|
||||||
|
*/
|
||||||
|
/* Types */
|
||||||
|
export interface Identifiable {
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Stringifiable {
|
||||||
|
toString: () => string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Utility */
|
||||||
|
export function UUID(): string {
|
||||||
|
return v4();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* State */
|
||||||
|
export type StateSubscription<T> = (newValue: T) => void;
|
||||||
|
export type AdditionSubscription<T> = (newItem: T) => void;
|
||||||
|
export type RemovalSubscription<T> = (removedItem: T) => void;
|
||||||
|
|
||||||
|
export class State<T> {
|
||||||
|
private _value: T;
|
||||||
|
private _bindings = new Set<StateSubscription<T>>();
|
||||||
|
|
||||||
|
// init
|
||||||
|
constructor(initialValue: T) {
|
||||||
|
this._value = initialValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// value
|
||||||
|
get value(): T {
|
||||||
|
return this._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set value(newValue: T) {
|
||||||
|
this._value = newValue;
|
||||||
|
this.callSubscriptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
// subscriptions
|
||||||
|
callSubscriptions(): void {
|
||||||
|
this._bindings.forEach((fn) => fn(this._value));
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribe(fn: (newValue: T) => void): void {
|
||||||
|
this._bindings.add(fn);
|
||||||
|
fn(this._value);
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribeSilent(fn: (newValue: T) => void): void {
|
||||||
|
this._bindings.add(fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// stringify
|
||||||
|
toString(): string {
|
||||||
|
return JSON.stringify(this._value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ListState<T> extends State<Set<T>> {
|
||||||
|
private additionHandlers = new Set<AdditionSubscription<T>>();
|
||||||
|
private removalHandlers = new Map<T, Set<RemovalSubscription<T>>>();
|
||||||
|
|
||||||
|
// init
|
||||||
|
constructor(initialItems?: T[]) {
|
||||||
|
super(new Set<T>(initialItems));
|
||||||
|
}
|
||||||
|
|
||||||
|
// list
|
||||||
|
add(...items: T[]): void {
|
||||||
|
items.forEach((item) => {
|
||||||
|
this.value.add(item);
|
||||||
|
this.additionHandlers.forEach((handler) => handler(item));
|
||||||
|
});
|
||||||
|
this.callSubscriptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(...items: T[]): void {
|
||||||
|
items.forEach((item) => {
|
||||||
|
this.value.delete(item);
|
||||||
|
|
||||||
|
if (!this.removalHandlers.has(item)) return;
|
||||||
|
this.removalHandlers.get(item)!.forEach((handler) => handler(item));
|
||||||
|
this.removalHandlers.delete(item);
|
||||||
|
});
|
||||||
|
this.callSubscriptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
this.remove(...this.value.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
// handlers
|
||||||
|
handleAddition(handler: AdditionSubscription<T>): void {
|
||||||
|
this.additionHandlers.add(handler);
|
||||||
|
[...this.value.values()].forEach(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleRemoval(item: T, handler: RemovalSubscription<T>): void {
|
||||||
|
if (!this.removalHandlers.has(item))
|
||||||
|
this.removalHandlers.set(item, new Set());
|
||||||
|
this.removalHandlers.get(item)!.add(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
// stringification
|
||||||
|
toString(): string {
|
||||||
|
const array = [...this.value.values()];
|
||||||
|
const json = JSON.stringify(array);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MapState<T> extends State<Map<string, T>> {
|
||||||
|
private additionHandlers = new Set<AdditionSubscription<T>>();
|
||||||
|
private removalHandlers = new Map<T, Set<RemovalSubscription<T>>>();
|
||||||
|
|
||||||
|
// init
|
||||||
|
constructor(initialItems?: [string, T][]) {
|
||||||
|
super(new Map<string, T>(initialItems));
|
||||||
|
}
|
||||||
|
|
||||||
|
// list
|
||||||
|
set(key: string, item: T): void {
|
||||||
|
this.remove(key);
|
||||||
|
this.value.set(key, item);
|
||||||
|
this.additionHandlers.forEach((handler) => handler(item));
|
||||||
|
this.callSubscriptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(key: string): void {
|
||||||
|
const item = this.value.get(key);
|
||||||
|
if (!item) return;
|
||||||
|
|
||||||
|
this.value.delete(key);
|
||||||
|
this.callSubscriptions();
|
||||||
|
|
||||||
|
if (!this.removalHandlers.has(item)) return;
|
||||||
|
this.removalHandlers.get(item)!.forEach((handler) => handler(item));
|
||||||
|
this.removalHandlers.delete(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
[...this.value.keys()].forEach((key) => this.remove(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
// handlers
|
||||||
|
handleAddition(handler: AdditionSubscription<T>): void {
|
||||||
|
this.additionHandlers.add(handler);
|
||||||
|
[...this.value.values()].forEach(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleRemoval(item: T, handler: RemovalSubscription<T>): void {
|
||||||
|
if (!this.removalHandlers.has(item))
|
||||||
|
this.removalHandlers.set(item, new Set());
|
||||||
|
this.removalHandlers.get(item)!.add(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
// stringification
|
||||||
|
toString(): string {
|
||||||
|
const array = [...this.value.entries()];
|
||||||
|
const json = JSON.stringify(array);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UTILITY
|
||||||
|
export function createProxyState<T>(
|
||||||
|
statesToSubscibe: State<any>[],
|
||||||
|
fn: () => T
|
||||||
|
): State<T> {
|
||||||
|
const proxyState = new State<T>(fn());
|
||||||
|
statesToSubscibe.forEach((state) =>
|
||||||
|
state.subscribeSilent(() => (proxyState.value = fn()))
|
||||||
|
);
|
||||||
|
return proxyState;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function bulkSubscribe(
|
||||||
|
statesToSubscibe: State<any>[],
|
||||||
|
fn: () => void
|
||||||
|
): void {
|
||||||
|
statesToSubscibe.forEach((state) => state.subscribeSilent(fn));
|
||||||
|
}
|
||||||
|
|
||||||
|
function persistState(localStorageKey: string, state: State<any>) {
|
||||||
|
state.subscribe(() => {
|
||||||
|
const stringifiedValue = state.toString();
|
||||||
|
localStorage.setItem(localStorageKey, stringifiedValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function restoreState<T>(
|
||||||
|
localStorageKey: string,
|
||||||
|
initialStateValue: T
|
||||||
|
): State<T> {
|
||||||
|
const storedString =
|
||||||
|
localStorage.getItem(localStorageKey) ??
|
||||||
|
JSON.stringify(initialStateValue);
|
||||||
|
const convertedValue = JSON.parse(storedString);
|
||||||
|
|
||||||
|
const state = new State(convertedValue);
|
||||||
|
persistState(localStorageKey, state);
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function restoreListState<T>(
|
||||||
|
localStorageKey: string,
|
||||||
|
initialItems: any[] = []
|
||||||
|
): ListState<T> {
|
||||||
|
const storedString = localStorage.getItem(localStorageKey) ?? "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const array = JSON.parse(storedString);
|
||||||
|
if (!Array.isArray(array)) throw "";
|
||||||
|
initialItems = array;
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
const state = new ListState<T>(initialItems);
|
||||||
|
persistState(localStorageKey, state);
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function restoreMapState<T>(
|
||||||
|
localStorageKey: string,
|
||||||
|
initialItems: [string, any][] = []
|
||||||
|
): MapState<T> {
|
||||||
|
const storedString = localStorage.getItem(localStorageKey) ?? "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const array = JSON.parse(storedString);
|
||||||
|
if (!Array.isArray(array)) throw "";
|
||||||
|
initialItems = array;
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
const state = new MapState<T>(initialItems);
|
||||||
|
persistState(localStorageKey, state);
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type StateItemConverter<T> = (item: T) => HTMLElement;
|
||||||
|
|
||||||
|
/*
|
||||||
|
JSX
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function createElement(
|
||||||
|
tagName: keyof HTMLElementTagNameMap,
|
||||||
|
attributes: { [key: string]: any } | null = {},
|
||||||
|
...children: (HTMLElement | string)[]
|
||||||
|
) {
|
||||||
|
const element = document.createElement(tagName);
|
||||||
|
|
||||||
|
if (attributes != null)
|
||||||
|
Object.entries(attributes).forEach((entry) => {
|
||||||
|
const [attributename, value] = entry;
|
||||||
|
const [directiveKey, directiveValue] = attributename.split(":");
|
||||||
|
|
||||||
|
switch (directiveKey) {
|
||||||
|
case "on": {
|
||||||
|
switch (directiveValue) {
|
||||||
|
case "enter": {
|
||||||
|
element.addEventListener("keydown", (e: KeyboardEvent) => {
|
||||||
|
if (e.key != "Enter") return;
|
||||||
|
value(e);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
element.addEventListener(directiveValue, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "keystroke": {
|
||||||
|
element.addEventListener("keydown", (e: KeyboardEvent) => {
|
||||||
|
if (e.metaKey == false && e.ctrlKey == false) return;
|
||||||
|
if (e.key != directiveValue) return;
|
||||||
|
value(e);
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "subscribe": {
|
||||||
|
const state = value as State<any>;
|
||||||
|
state.subscribe(
|
||||||
|
(newValue) => (element[directiveValue] = newValue)
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "bind": {
|
||||||
|
const state = value as State<any>;
|
||||||
|
state.subscribe(
|
||||||
|
(newValue) => (element[directiveValue] = newValue)
|
||||||
|
);
|
||||||
|
element.addEventListener(
|
||||||
|
"input",
|
||||||
|
() => (state.value = (element as any)[directiveValue])
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "toggle": {
|
||||||
|
if (value.subscribe) {
|
||||||
|
const state = value as State<any>;
|
||||||
|
state.subscribe((newValue) =>
|
||||||
|
element.toggleAttribute(directiveValue, newValue)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
element.toggleAttribute(directiveValue, value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "set": {
|
||||||
|
const state = value as State<any>;
|
||||||
|
state.subscribe((newValue) =>
|
||||||
|
element.setAttribute(directiveValue, newValue)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "children": {
|
||||||
|
switch (directiveValue) {
|
||||||
|
case "set": {
|
||||||
|
const state = value as State<Node | Node[]>;
|
||||||
|
state.subscribe((newValue) => {
|
||||||
|
element.innerHTML = "";
|
||||||
|
element.append(...[newValue].flat());
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "append":
|
||||||
|
case "prepend": {
|
||||||
|
try {
|
||||||
|
const [listState, toElement] = value as [
|
||||||
|
listState: ListState<any>,
|
||||||
|
StateItemConverter<any>
|
||||||
|
];
|
||||||
|
|
||||||
|
listState.handleAddition((newItem) => {
|
||||||
|
const child = toElement(newItem);
|
||||||
|
listState.handleRemoval(newItem, () =>
|
||||||
|
child.remove()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (directiveValue == "append") {
|
||||||
|
element.append(child);
|
||||||
|
} else if (directiveValue == "prepend") {
|
||||||
|
element.prepend(child);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
throw `error: cannot process subscribe:children directive. \n Usage: "children:append={[list, converter]}"; you can find a more detailed example in the documentation.`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
element.setAttribute(attributename, value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
children.filter((x) => x).forEach((child) => element.append(child));
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../uuid/dist-node/bin/uuid
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
||||||
|
|
||||||
|
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.
|
||||||
+499
@@ -0,0 +1,499 @@
|
|||||||
|
<!--
|
||||||
|
-- This file is auto-generated from README_js.md. Changes should be made there.
|
||||||
|
-->
|
||||||
|
|
||||||
|
# uuid [](https://github.com/uuidjs/uuid/actions?query=workflow%3ACI) [](https://github.com/uuidjs/uuid/actions/workflows/browser.yml)
|
||||||
|
|
||||||
|
For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (formerly [RFC4122](https://www.rfc-editor.org/rfc/rfc4122.html)) UUIDs
|
||||||
|
|
||||||
|
- **Complete** - Support for all RFC9562 UUID versions
|
||||||
|
- **Cross-platform** - Support for...
|
||||||
|
- [Typescript](#support)
|
||||||
|
- [Chrome, Safari, Firefox, and Edge](#support)
|
||||||
|
- [NodeJS](#support)
|
||||||
|
- [React Native / Expo](#react-native--expo)
|
||||||
|
- **Secure** - Uses modern `crypto` API for random values
|
||||||
|
- **Compact** - Zero-dependency, [tree-shakable](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking)
|
||||||
|
- **CLI** - [`uuid` command line](#command-line) utility
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
> [!NOTE]
|
||||||
|
>
|
||||||
|
> Starting with `uuid@12` CommonJS is no longer supported. See [implications](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) and [motivation](https://github.com/uuidjs/uuid/issues/881) for details.
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
|
||||||
|
**1. Install**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
npm install uuid
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. Create a UUID**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
|
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
|
||||||
|
```
|
||||||
|
|
||||||
|
For timestamp UUIDs, namespace UUIDs, and other options read on ...
|
||||||
|
|
||||||
|
## API Summary
|
||||||
|
|
||||||
|
| | | |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [`uuid.NIL`](#uuidnil) | The nil UUID string (all zeros) | New in `uuid@8.3` |
|
||||||
|
| [`uuid.MAX`](#uuidmax) | The max UUID string (all ones) | New in `uuid@9.1` |
|
||||||
|
| [`uuid.parse()`](#uuidparsestr) | Convert UUID string to array of bytes | New in `uuid@8.3` |
|
||||||
|
| [`uuid.stringify()`](#uuidstringifyarr-offset) | Convert array of bytes to UUID string | New in `uuid@8.3` |
|
||||||
|
| [`uuid.v1()`](#uuidv1options-buffer-offset) | Create a version 1 (timestamp) UUID | |
|
||||||
|
| [`uuid.v1ToV6()`](#uuidv1tov6uuid) | Create a version 6 UUID from a version 1 UUID | New in `uuid@10` |
|
||||||
|
| [`uuid.v3()`](#uuidv3name-namespace-buffer-offset) | Create a version 3 (namespace w/ MD5) UUID | |
|
||||||
|
| [`uuid.v4()`](#uuidv4options-buffer-offset) | Create a version 4 (random) UUID | |
|
||||||
|
| [`uuid.v5()`](#uuidv5name-namespace-buffer-offset) | Create a version 5 (namespace w/ SHA-1) UUID | |
|
||||||
|
| [`uuid.v6()`](#uuidv6options-buffer-offset) | Create a version 6 (timestamp, reordered) UUID | New in `uuid@10` |
|
||||||
|
| [`uuid.v6ToV1()`](#uuidv6tov1uuid) | Create a version 1 UUID from a version 6 UUID | New in `uuid@10` |
|
||||||
|
| [`uuid.v7()`](#uuidv7options-buffer-offset) | Create a version 7 (Unix Epoch time-based) UUID | New in `uuid@10` |
|
||||||
|
| ~~[`uuid.v8()`](#uuidv8)~~ | "Intentionally left blank" | |
|
||||||
|
| [`uuid.validate()`](#uuidvalidatestr) | Test a string to see if it is a valid UUID | New in `uuid@8.3` |
|
||||||
|
| [`uuid.version()`](#uuidversionstr) | Detect RFC version of a UUID | New in `uuid@8.3` |
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### uuid.NIL
|
||||||
|
|
||||||
|
The nil UUID string (all zeros).
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { NIL as NIL_UUID } from 'uuid';
|
||||||
|
|
||||||
|
NIL_UUID; // ⇨ '00000000-0000-0000-0000-000000000000'
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.MAX
|
||||||
|
|
||||||
|
The max UUID string (all ones).
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { MAX as MAX_UUID } from 'uuid';
|
||||||
|
|
||||||
|
MAX_UUID; // ⇨ 'ffffffff-ffff-ffff-ffff-ffffffffffff'
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.parse(str)
|
||||||
|
|
||||||
|
Convert UUID string to array of bytes
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --------- | ---------------------------------------- |
|
||||||
|
| `str` | A valid UUID `String` |
|
||||||
|
| _returns_ | `Uint8Array[16]` |
|
||||||
|
| _throws_ | `TypeError` if `str` is not a valid UUID |
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
> [!NOTE]
|
||||||
|
> Ordering of values in the byte arrays used by `parse()` and `stringify()` follows the left ↠ right order of hex-pairs in UUID strings. As shown in the example below.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { parse as uuidParse } from 'uuid';
|
||||||
|
|
||||||
|
// Parse a UUID
|
||||||
|
uuidParse('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨
|
||||||
|
// Uint8Array(16) [
|
||||||
|
// 110, 192, 189, 127, 17,
|
||||||
|
// 192, 67, 218, 151, 94,
|
||||||
|
// 42, 138, 217, 235, 174,
|
||||||
|
// 11
|
||||||
|
// ]
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.stringify(arr[, offset])
|
||||||
|
|
||||||
|
Convert array of bytes to UUID string
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| -------------- | ---------------------------------------------------------------------------- |
|
||||||
|
| `arr` | `Array`-like collection of 16 values (starting from `offset`) between 0-255. |
|
||||||
|
| [`offset` = 0] | `Number` Starting index in the Array |
|
||||||
|
| _returns_ | `String` |
|
||||||
|
| _throws_ | `TypeError` if a valid UUID string cannot be generated |
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
> [!NOTE]
|
||||||
|
> Ordering of values in the byte arrays used by `parse()` and `stringify()` follows the left ↠ right order of hex-pairs in UUID strings. As shown in the example below.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { stringify as uuidStringify } from 'uuid';
|
||||||
|
|
||||||
|
const uuidBytes = Uint8Array.of(
|
||||||
|
0x6e,
|
||||||
|
0xc0,
|
||||||
|
0xbd,
|
||||||
|
0x7f,
|
||||||
|
0x11,
|
||||||
|
0xc0,
|
||||||
|
0x43,
|
||||||
|
0xda,
|
||||||
|
0x97,
|
||||||
|
0x5e,
|
||||||
|
0x2a,
|
||||||
|
0x8a,
|
||||||
|
0xd9,
|
||||||
|
0xeb,
|
||||||
|
0xae,
|
||||||
|
0x0b
|
||||||
|
);
|
||||||
|
|
||||||
|
uuidStringify(uuidBytes); // ⇨ '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.v1([options[, buffer[, offset]]])
|
||||||
|
|
||||||
|
Create an RFC version 1 (timestamp) UUID
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --- | --- |
|
||||||
|
| [`options`] | `Object` with one or more of the following properties: |
|
||||||
|
| [`options.node = (random)` ] | RFC "node" field as an `Array[6]` of byte values (per 4.1.6) |
|
||||||
|
| [`options.clockseq = (random)`] | RFC "clock sequence" as a `Number` between 0 - 0x3fff |
|
||||||
|
| [`options.msecs = (current time)`] | RFC "timestamp" field (`Number` of milliseconds, unix epoch) |
|
||||||
|
| [`options.nsecs = 0`] | RFC "timestamp" field (`Number` of nanoseconds to add to `msecs`, should be 0-10,000) |
|
||||||
|
| [`options.random = (random)`] | `Array` of 16 random bytes (0-255) used to generate other fields, above |
|
||||||
|
| [`options.rng`] | Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) |
|
||||||
|
| [`buffer`] | `Uint8Array` or `Uint8Array` subtype (e.g. Node.js `Buffer`). If provided, binary UUID is written into the array, starting at `offset` |
|
||||||
|
| [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
|
||||||
|
| _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
|
||||||
|
| _throws_ | `Error` if more than 10M UUIDs/sec are requested |
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
> [!NOTE]
|
||||||
|
> The default [node id](https://datatracker.ietf.org/doc/html/rfc9562#section-5.1) (the last 12 digits in the UUID) is generated once, randomly, on process startup, and then remains unchanged for the duration of the process.
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
> [!NOTE]
|
||||||
|
> `options.random` and `options.rng` are only meaningful on the very first call to `v1()`, where they may be passed to initialize the internal `node` and `clockseq` fields.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v1 as uuidv1 } from 'uuid';
|
||||||
|
|
||||||
|
uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-9b5d-ab8dfbbd4bed'
|
||||||
|
```
|
||||||
|
|
||||||
|
Example using `options`:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v1 as uuidv1 } from 'uuid';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
node: Uint8Array.of(0x01, 0x23, 0x45, 0x67, 0x89, 0xab),
|
||||||
|
clockseq: 0x1234,
|
||||||
|
msecs: new Date('2011-11-01').getTime(),
|
||||||
|
nsecs: 5678,
|
||||||
|
};
|
||||||
|
uuidv1(options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.v1ToV6(uuid)
|
||||||
|
|
||||||
|
Convert a UUID from version 1 to version 6
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v1ToV6 } from 'uuid';
|
||||||
|
|
||||||
|
v1ToV6('92f62d9e-22c4-11ef-97e9-325096b39f47'); // ⇨ '1ef22c49-2f62-6d9e-97e9-325096b39f47'
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.v3(name, namespace[, buffer[, offset]])
|
||||||
|
|
||||||
|
Create an RFC version 3 (namespace w/ MD5) UUID
|
||||||
|
|
||||||
|
API is identical to `v5()`, but uses "v3" instead.
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> Per the RFC, "_If backward compatibility is not an issue, SHA-1 [Version 5] is preferred_."
|
||||||
|
|
||||||
|
### uuid.v4([options[, buffer[, offset]]])
|
||||||
|
|
||||||
|
Create an RFC version 4 (random) UUID
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --- | --- |
|
||||||
|
| [`options`] | `Object` with one or more of the following properties: |
|
||||||
|
| [`options.random`] | `Array` of 16 random bytes (0-255) |
|
||||||
|
| [`options.rng`] | Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) |
|
||||||
|
| [`buffer`] | `Uint8Array` or `Uint8Array` subtype (e.g. Node.js `Buffer`). If provided, binary UUID is written into the array, starting at `offset` |
|
||||||
|
| [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
|
||||||
|
| _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
|
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
|
||||||
|
```
|
||||||
|
|
||||||
|
Example using predefined `random` values:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
|
const v4options = {
|
||||||
|
random: Uint8Array.of(
|
||||||
|
0x10,
|
||||||
|
0x91,
|
||||||
|
0x56,
|
||||||
|
0xbe,
|
||||||
|
0xc4,
|
||||||
|
0xfb,
|
||||||
|
0xc1,
|
||||||
|
0xea,
|
||||||
|
0x71,
|
||||||
|
0xb4,
|
||||||
|
0xef,
|
||||||
|
0xe1,
|
||||||
|
0x67,
|
||||||
|
0x1c,
|
||||||
|
0x58,
|
||||||
|
0x36
|
||||||
|
),
|
||||||
|
};
|
||||||
|
uuidv4(v4options); // ⇨ '109156be-c4fb-41ea-b1b4-efe1671c5836'
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.v5(name, namespace[, buffer[, offset]])
|
||||||
|
|
||||||
|
Create an RFC version 5 (namespace w/ SHA-1) UUID
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --- | --- |
|
||||||
|
| `name` | `String \| Array` |
|
||||||
|
| `namespace` | `String \| Array[16]` Namespace UUID |
|
||||||
|
| [`buffer`] | `Uint8Array` or `Uint8Array` subtype (e.g. Node.js `Buffer`). If provided, binary UUID is written into the array, starting at `offset` |
|
||||||
|
| [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
|
||||||
|
| _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
> [!NOTE]
|
||||||
|
> The RFC `DNS` and `URL` namespaces are available as `v5.DNS` and `v5.URL`.
|
||||||
|
|
||||||
|
Example with custom namespace:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v5 as uuidv5 } from 'uuid';
|
||||||
|
|
||||||
|
// Define a custom namespace. Readers, create your own using something like
|
||||||
|
// https://www.uuidgenerator.net/
|
||||||
|
const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
|
||||||
|
|
||||||
|
uuidv5('Hello, World!', MY_NAMESPACE); // ⇨ '630eb68f-e0fa-5ecc-887a-7c7a62614681'
|
||||||
|
```
|
||||||
|
|
||||||
|
Example with RFC `URL` namespace:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v5 as uuidv5 } from 'uuid';
|
||||||
|
|
||||||
|
uuidv5('https://www.w3.org/', uuidv5.URL); // ⇨ 'c106a26a-21bb-5538-8bf2-57095d1976c1'
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.v6([options[, buffer[, offset]]])
|
||||||
|
|
||||||
|
Create an RFC version 6 (timestamp, reordered) UUID
|
||||||
|
|
||||||
|
This method takes the same arguments as uuid.v1().
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v6 as uuidv6 } from 'uuid';
|
||||||
|
|
||||||
|
uuidv6(); // ⇨ '1e940672-c5ea-64c1-9bdd-2b0d7b3dcb6d'
|
||||||
|
```
|
||||||
|
|
||||||
|
Example using `options`:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v6 as uuidv6 } from 'uuid';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
|
||||||
|
clockseq: 0x1234,
|
||||||
|
msecs: new Date('2011-11-01').getTime(),
|
||||||
|
nsecs: 5678,
|
||||||
|
};
|
||||||
|
uuidv6(options); // ⇨ '1e1041c7-10b9-662e-9234-0123456789ab'
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.v6ToV1(uuid)
|
||||||
|
|
||||||
|
Convert a UUID from version 6 to version 1
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v6ToV1 } from 'uuid';
|
||||||
|
|
||||||
|
v6ToV1('1ef22c49-2f62-6d9e-97e9-325096b39f47'); // ⇨ '92f62d9e-22c4-11ef-97e9-325096b39f47'
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.v7([options[, buffer[, offset]]])
|
||||||
|
|
||||||
|
Create an RFC version 7 (random) UUID
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --- | --- |
|
||||||
|
| [`options`] | `Object` with one or more of the following properties: |
|
||||||
|
| [`options.msecs = (current time)`] | RFC "timestamp" field (`Number` of milliseconds, unix epoch) |
|
||||||
|
| [`options.random = (random)`] | `Array` of 16 random bytes (0-255) used to generate other fields, above |
|
||||||
|
| [`options.rng`] | Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) |
|
||||||
|
| [`options.seq = (random)`] | 32-bit sequence `Number` between 0 - 0xffffffff. This may be provided to help ensure uniqueness for UUIDs generated within the same millisecond time interval. Default = random value. |
|
||||||
|
| [`buffer`] | `Uint8Array` or `Uint8Array` subtype (e.g. Node.js `Buffer`). If provided, binary UUID is written into the array, starting at `offset` |
|
||||||
|
| [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
|
||||||
|
| _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { v7 as uuidv7 } from 'uuid';
|
||||||
|
|
||||||
|
uuidv7(); // ⇨ '01695553-c90c-745a-b76f-770d7b3dcb6d'
|
||||||
|
```
|
||||||
|
|
||||||
|
### ~~uuid.v8()~~
|
||||||
|
|
||||||
|
**_"Intentionally left blank"_**
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
> [!NOTE]
|
||||||
|
> Version 8 (experimental) UUIDs are "[for experimental or vendor-specific use cases](https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-8)". The RFC does not define a creation algorithm for them, which is why this package does not offer a `v8()` method. The `validate()` and `version()` methods do work with such UUIDs, however.
|
||||||
|
|
||||||
|
### uuid.validate(str)
|
||||||
|
|
||||||
|
Test a string to see if it is a valid UUID
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --------- | --------------------------------------------------- |
|
||||||
|
| `str` | `String` to validate |
|
||||||
|
| _returns_ | `true` if string is a valid UUID, `false` otherwise |
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { validate as uuidValidate } from 'uuid';
|
||||||
|
|
||||||
|
uuidValidate('not a UUID'); // ⇨ false
|
||||||
|
uuidValidate('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨ true
|
||||||
|
```
|
||||||
|
|
||||||
|
Using `validate` and `version` together it is possible to do per-version validation, e.g. validate for only v4 UUIds.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { version as uuidVersion } from 'uuid';
|
||||||
|
import { validate as uuidValidate } from 'uuid';
|
||||||
|
|
||||||
|
function uuidValidateV4(uuid) {
|
||||||
|
return uuidValidate(uuid) && uuidVersion(uuid) === 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
const v1Uuid = 'd9428888-122b-11e1-b85c-61cd3cbb3210';
|
||||||
|
const v4Uuid = '109156be-c4fb-41ea-b1b4-efe1671c5836';
|
||||||
|
|
||||||
|
uuidValidateV4(v4Uuid); // ⇨ true
|
||||||
|
uuidValidateV4(v1Uuid); // ⇨ false
|
||||||
|
```
|
||||||
|
|
||||||
|
### uuid.version(str)
|
||||||
|
|
||||||
|
Detect RFC version of a UUID
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --------- | ---------------------------------------- |
|
||||||
|
| `str` | A valid UUID `String` |
|
||||||
|
| _returns_ | `Number` The RFC version of the UUID |
|
||||||
|
| _throws_ | `TypeError` if `str` is not a valid UUID |
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { version as uuidVersion } from 'uuid';
|
||||||
|
|
||||||
|
uuidVersion('45637ec4-c85f-11ea-87d0-0242ac130003'); // ⇨ 1
|
||||||
|
uuidVersion('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨ 4
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
> [!NOTE]
|
||||||
|
> This method returns `0` for the `NIL` UUID, and `15` for the `MAX` UUID.
|
||||||
|
|
||||||
|
## Command Line
|
||||||
|
|
||||||
|
UUIDs can be generated from the command line using `uuid`.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ npx uuid
|
||||||
|
ddeb27fb-d9a0-4624-be4d-4615062daed4
|
||||||
|
```
|
||||||
|
|
||||||
|
The default is to generate version 4 UUIDS, however the other versions are supported. Type `uuid --help` for details:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ npx uuid --help
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
uuid
|
||||||
|
uuid v1
|
||||||
|
uuid v3 <name> <namespace uuid>
|
||||||
|
uuid v4
|
||||||
|
uuid v5 <name> <namespace uuid>
|
||||||
|
uuid v7
|
||||||
|
uuid --help
|
||||||
|
|
||||||
|
Note: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs
|
||||||
|
defined by RFC9562
|
||||||
|
```
|
||||||
|
|
||||||
|
## `options` Handling for Timestamp UUIDs
|
||||||
|
|
||||||
|
Prior to `uuid@11`, it was possible for `options` state to interfere with the internal state used to ensure uniqueness of timestamp-based UUIDs (the `v1()`, `v6()`, and `v7()` methods). Starting with `uuid@11`, this issue has been addressed by using the presence of the `options` argument as a flag to select between two possible behaviors:
|
||||||
|
|
||||||
|
- Without `options`: Internal state is utilized to improve UUID uniqueness.
|
||||||
|
- With `options`: Internal state is **NOT** used and, instead, appropriate defaults are applied as needed.
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
**Browsers**: `uuid` [builds are tested](/uuidjs/uuid/blob/main/wdio.conf.js) against the latest version of desktop Chrome, Safari, Firefox, and Edge. Mobile versions of these same browsers are expected to work but aren't currently tested.
|
||||||
|
|
||||||
|
**Node**: `uuid` [builds are tested](https://github.com/uuidjs/uuid/blob/main/.github/workflows/ci.yml#L26-L27) against node ([LTS releases](https://github.com/nodejs/Release)), plus one prior. E.g. At the time of this writing `node@20` is the "maintenance" release and `node@24` is the "current" release, so `uuid` supports `node@18`-`node@24`.
|
||||||
|
|
||||||
|
**Typescript**: TS versions released within the past two years are supported. [source](https://github.com/microsoft/TypeScript/issues/49088#issuecomment-2468723715)
|
||||||
|
|
||||||
|
## Known issues
|
||||||
|
|
||||||
|
<!-- This header is referenced as an anchor in src/rng-browser.ts -->
|
||||||
|
|
||||||
|
### "getRandomValues() not supported"
|
||||||
|
|
||||||
|
This error occurs in environments where the standard [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) API is not supported. This issue can be resolved by adding an appropriate polyfill:
|
||||||
|
|
||||||
|
#### React Native / Expo
|
||||||
|
|
||||||
|
1. Install [`react-native-get-random-values`](https://github.com/LinusU/react-native-get-random-values#readme)
|
||||||
|
1. Import it _before_ `uuid`. Since `uuid` might also appear as a transitive dependency of some other imports it's safest to just import `react-native-get-random-values` as the very first thing in your entry point:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import 'react-native-get-random-values';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Markdown generated from [README_js.md](README_js.md) by <a href="https://github.com/broofa/runmd"><image height="13" src="https://camo.githubusercontent.com/5c7c603cd1e6a43370b0a5063d457e0dabb74cf317adc7baba183acb686ee8d0/687474703a2f2f692e696d6775722e636f6d2f634a4b6f3662552e706e67" /></a>
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
import '../uuid-bin.js';
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
export { default as MAX } from './max.js';
|
||||||
|
export { default as NIL } from './nil.js';
|
||||||
|
export { default as parse } from './parse.js';
|
||||||
|
export { default as stringify } from './stringify.js';
|
||||||
|
export { default as v1 } from './v1.js';
|
||||||
|
export { default as v1ToV6 } from './v1ToV6.js';
|
||||||
|
export { default as v3 } from './v3.js';
|
||||||
|
export { default as v4 } from './v4.js';
|
||||||
|
export { default as v5 } from './v5.js';
|
||||||
|
export { default as v6 } from './v6.js';
|
||||||
|
export { default as v6ToV1 } from './v6ToV1.js';
|
||||||
|
export { default as v7 } from './v7.js';
|
||||||
|
export { default as validate } from './validate.js';
|
||||||
|
export { default as version } from './version.js';
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export default 'ffffffff-ffff-ffff-ffff-ffffffffffff';
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
import { createHash } from 'node:crypto';
|
||||||
|
function md5(bytes) {
|
||||||
|
if (Array.isArray(bytes)) {
|
||||||
|
bytes = Buffer.from(bytes);
|
||||||
|
}
|
||||||
|
else if (typeof bytes === 'string') {
|
||||||
|
bytes = Buffer.from(bytes, 'utf8');
|
||||||
|
}
|
||||||
|
return createHash('md5').update(bytes).digest();
|
||||||
|
}
|
||||||
|
export default md5;
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
import { randomUUID } from 'node:crypto';
|
||||||
|
export default { randomUUID };
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export default '00000000-0000-0000-0000-000000000000';
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import validate from './validate.js';
|
||||||
|
function parse(uuid) {
|
||||||
|
if (!validate(uuid)) {
|
||||||
|
throw TypeError('Invalid UUID');
|
||||||
|
}
|
||||||
|
let v;
|
||||||
|
return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, (v >>> 16) & 0xff, (v >>> 8) & 0xff, v & 0xff, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 0xff, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 0xff, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 0xff, ((v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000) & 0xff, (v / 0x100000000) & 0xff, (v >>> 24) & 0xff, (v >>> 16) & 0xff, (v >>> 8) & 0xff, v & 0xff);
|
||||||
|
}
|
||||||
|
export default parse;
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
import { randomFillSync } from 'node:crypto';
|
||||||
|
const rnds8Pool = new Uint8Array(256);
|
||||||
|
let poolPtr = rnds8Pool.length;
|
||||||
|
export default function rng() {
|
||||||
|
if (poolPtr > rnds8Pool.length - 16) {
|
||||||
|
randomFillSync(rnds8Pool);
|
||||||
|
poolPtr = 0;
|
||||||
|
}
|
||||||
|
return rnds8Pool.slice(poolPtr, (poolPtr += 16));
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
import { createHash } from 'node:crypto';
|
||||||
|
function sha1(bytes) {
|
||||||
|
if (Array.isArray(bytes)) {
|
||||||
|
bytes = Buffer.from(bytes);
|
||||||
|
}
|
||||||
|
else if (typeof bytes === 'string') {
|
||||||
|
bytes = Buffer.from(bytes, 'utf8');
|
||||||
|
}
|
||||||
|
return createHash('sha1').update(bytes).digest();
|
||||||
|
}
|
||||||
|
export default sha1;
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
import validate from './validate.js';
|
||||||
|
const byteToHex = [];
|
||||||
|
for (let i = 0; i < 256; ++i) {
|
||||||
|
byteToHex.push((i + 0x100).toString(16).slice(1));
|
||||||
|
}
|
||||||
|
export function unsafeStringify(arr, offset = 0) {
|
||||||
|
return (byteToHex[arr[offset + 0]] +
|
||||||
|
byteToHex[arr[offset + 1]] +
|
||||||
|
byteToHex[arr[offset + 2]] +
|
||||||
|
byteToHex[arr[offset + 3]] +
|
||||||
|
'-' +
|
||||||
|
byteToHex[arr[offset + 4]] +
|
||||||
|
byteToHex[arr[offset + 5]] +
|
||||||
|
'-' +
|
||||||
|
byteToHex[arr[offset + 6]] +
|
||||||
|
byteToHex[arr[offset + 7]] +
|
||||||
|
'-' +
|
||||||
|
byteToHex[arr[offset + 8]] +
|
||||||
|
byteToHex[arr[offset + 9]] +
|
||||||
|
'-' +
|
||||||
|
byteToHex[arr[offset + 10]] +
|
||||||
|
byteToHex[arr[offset + 11]] +
|
||||||
|
byteToHex[arr[offset + 12]] +
|
||||||
|
byteToHex[arr[offset + 13]] +
|
||||||
|
byteToHex[arr[offset + 14]] +
|
||||||
|
byteToHex[arr[offset + 15]]).toLowerCase();
|
||||||
|
}
|
||||||
|
function stringify(arr, offset = 0) {
|
||||||
|
const uuid = unsafeStringify(arr, offset);
|
||||||
|
if (!validate(uuid)) {
|
||||||
|
throw TypeError('Stringified UUID is invalid');
|
||||||
|
}
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
export default stringify;
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export {};
|
||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
import * as assert from 'node:assert/strict';
|
||||||
|
import v1 from './v1.js';
|
||||||
|
import v3 from './v3.js';
|
||||||
|
import v4 from './v4.js';
|
||||||
|
import v5 from './v5.js';
|
||||||
|
import v6 from './v6.js';
|
||||||
|
import v7 from './v7.js';
|
||||||
|
function usage() {
|
||||||
|
console.log('Usage:');
|
||||||
|
console.log(' uuid');
|
||||||
|
console.log(' uuid v1');
|
||||||
|
console.log(' uuid v3 <name> <namespace uuid>');
|
||||||
|
console.log(' uuid v4');
|
||||||
|
console.log(' uuid v5 <name> <namespace uuid>');
|
||||||
|
console.log(' uuid v6');
|
||||||
|
console.log(' uuid v7');
|
||||||
|
console.log(' uuid --help');
|
||||||
|
console.log('\nNote: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs defined by RFC9562');
|
||||||
|
}
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
if (args.indexOf('--help') >= 0) {
|
||||||
|
usage();
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
const version = args.shift() || 'v4';
|
||||||
|
switch (version) {
|
||||||
|
case 'v1':
|
||||||
|
console.log(v1());
|
||||||
|
break;
|
||||||
|
case 'v3': {
|
||||||
|
const name = args.shift();
|
||||||
|
let namespace = args.shift();
|
||||||
|
assert.ok(name != null, 'v3 name not specified');
|
||||||
|
assert.ok(namespace != null, 'v3 namespace not specified');
|
||||||
|
if (namespace === 'URL') {
|
||||||
|
namespace = v3.URL;
|
||||||
|
}
|
||||||
|
if (namespace === 'DNS') {
|
||||||
|
namespace = v3.DNS;
|
||||||
|
}
|
||||||
|
console.log(v3(name, namespace));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'v4':
|
||||||
|
console.log(v4());
|
||||||
|
break;
|
||||||
|
case 'v5': {
|
||||||
|
const name = args.shift();
|
||||||
|
let namespace = args.shift();
|
||||||
|
assert.ok(name != null, 'v5 name not specified');
|
||||||
|
assert.ok(namespace != null, 'v5 namespace not specified');
|
||||||
|
if (namespace === 'URL') {
|
||||||
|
namespace = v5.URL;
|
||||||
|
}
|
||||||
|
if (namespace === 'DNS') {
|
||||||
|
namespace = v5.DNS;
|
||||||
|
}
|
||||||
|
console.log(v5(name, namespace));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'v6':
|
||||||
|
console.log(v6());
|
||||||
|
break;
|
||||||
|
case 'v7':
|
||||||
|
console.log(v7());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
import rng from './rng.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
const _state = {};
|
||||||
|
function v1(options, buf, offset) {
|
||||||
|
let bytes;
|
||||||
|
const isV6 = options?._v6 ?? false;
|
||||||
|
if (options) {
|
||||||
|
const optionsKeys = Object.keys(options);
|
||||||
|
if (optionsKeys.length === 1 && optionsKeys[0] === '_v6') {
|
||||||
|
options = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (options) {
|
||||||
|
bytes = v1Bytes(options.random ?? options.rng?.() ?? rng(), options.msecs, options.nsecs, options.clockseq, options.node, buf, offset);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const now = Date.now();
|
||||||
|
const rnds = rng();
|
||||||
|
updateV1State(_state, now, rnds);
|
||||||
|
bytes = v1Bytes(rnds, _state.msecs, _state.nsecs, isV6 ? undefined : _state.clockseq, isV6 ? undefined : _state.node, buf, offset);
|
||||||
|
}
|
||||||
|
return buf ?? unsafeStringify(bytes);
|
||||||
|
}
|
||||||
|
export function updateV1State(state, now, rnds) {
|
||||||
|
state.msecs ??= -Infinity;
|
||||||
|
state.nsecs ??= 0;
|
||||||
|
if (now === state.msecs) {
|
||||||
|
state.nsecs++;
|
||||||
|
if (state.nsecs >= 10000) {
|
||||||
|
state.node = undefined;
|
||||||
|
state.nsecs = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (now > state.msecs) {
|
||||||
|
state.nsecs = 0;
|
||||||
|
}
|
||||||
|
else if (now < state.msecs) {
|
||||||
|
state.node = undefined;
|
||||||
|
}
|
||||||
|
if (!state.node) {
|
||||||
|
state.node = rnds.slice(10, 16);
|
||||||
|
state.node[0] |= 0x01;
|
||||||
|
state.clockseq = ((rnds[8] << 8) | rnds[9]) & 0x3fff;
|
||||||
|
}
|
||||||
|
state.msecs = now;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
|
||||||
|
if (rnds.length < 16) {
|
||||||
|
throw new Error('Random bytes length must be >= 16');
|
||||||
|
}
|
||||||
|
if (!buf) {
|
||||||
|
buf = new Uint8Array(16);
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (offset < 0 || offset + 16 > buf.length) {
|
||||||
|
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msecs ??= Date.now();
|
||||||
|
nsecs ??= 0;
|
||||||
|
clockseq ??= ((rnds[8] << 8) | rnds[9]) & 0x3fff;
|
||||||
|
node ??= rnds.slice(10, 16);
|
||||||
|
msecs += 12219292800000;
|
||||||
|
const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
||||||
|
buf[offset++] = (tl >>> 24) & 0xff;
|
||||||
|
buf[offset++] = (tl >>> 16) & 0xff;
|
||||||
|
buf[offset++] = (tl >>> 8) & 0xff;
|
||||||
|
buf[offset++] = tl & 0xff;
|
||||||
|
const tmh = ((msecs / 0x100000000) * 10000) & 0xfffffff;
|
||||||
|
buf[offset++] = (tmh >>> 8) & 0xff;
|
||||||
|
buf[offset++] = tmh & 0xff;
|
||||||
|
buf[offset++] = ((tmh >>> 24) & 0xf) | 0x10;
|
||||||
|
buf[offset++] = (tmh >>> 16) & 0xff;
|
||||||
|
buf[offset++] = (clockseq >>> 8) | 0x80;
|
||||||
|
buf[offset++] = clockseq & 0xff;
|
||||||
|
for (let n = 0; n < 6; ++n) {
|
||||||
|
buf[offset++] = node[n];
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
export default v1;
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
import parse from './parse.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
export default function v1ToV6(uuid) {
|
||||||
|
const v1Bytes = typeof uuid === 'string' ? parse(uuid) : uuid;
|
||||||
|
const v6Bytes = _v1ToV6(v1Bytes);
|
||||||
|
return typeof uuid === 'string' ? unsafeStringify(v6Bytes) : v6Bytes;
|
||||||
|
}
|
||||||
|
function _v1ToV6(v1Bytes) {
|
||||||
|
return Uint8Array.of(((v1Bytes[6] & 0x0f) << 4) | ((v1Bytes[7] >> 4) & 0x0f), ((v1Bytes[7] & 0x0f) << 4) | ((v1Bytes[4] & 0xf0) >> 4), ((v1Bytes[4] & 0x0f) << 4) | ((v1Bytes[5] & 0xf0) >> 4), ((v1Bytes[5] & 0x0f) << 4) | ((v1Bytes[0] & 0xf0) >> 4), ((v1Bytes[0] & 0x0f) << 4) | ((v1Bytes[1] & 0xf0) >> 4), ((v1Bytes[1] & 0x0f) << 4) | ((v1Bytes[2] & 0xf0) >> 4), 0x60 | (v1Bytes[2] & 0x0f), v1Bytes[3], v1Bytes[8], v1Bytes[9], v1Bytes[10], v1Bytes[11], v1Bytes[12], v1Bytes[13], v1Bytes[14], v1Bytes[15]);
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import md5 from './md5.js';
|
||||||
|
import v35, { DNS, URL } from './v35.js';
|
||||||
|
export { DNS, URL } from './v35.js';
|
||||||
|
function v3(value, namespace, buf, offset) {
|
||||||
|
return v35(0x30, md5, value, namespace, buf, offset);
|
||||||
|
}
|
||||||
|
v3.DNS = DNS;
|
||||||
|
v3.URL = URL;
|
||||||
|
export default v3;
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
import parse from './parse.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
export function stringToBytes(str) {
|
||||||
|
str = unescape(encodeURIComponent(str));
|
||||||
|
const bytes = new Uint8Array(str.length);
|
||||||
|
for (let i = 0; i < str.length; ++i) {
|
||||||
|
bytes[i] = str.charCodeAt(i);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
export const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
||||||
|
export const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
|
||||||
|
export default function v35(version, hash, value, namespace, buf, offset) {
|
||||||
|
const valueBytes = typeof value === 'string' ? stringToBytes(value) : value;
|
||||||
|
const namespaceBytes = typeof namespace === 'string' ? parse(namespace) : namespace;
|
||||||
|
if (typeof namespace === 'string') {
|
||||||
|
namespace = parse(namespace);
|
||||||
|
}
|
||||||
|
if (namespace?.length !== 16) {
|
||||||
|
throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
|
||||||
|
}
|
||||||
|
let bytes = new Uint8Array(16 + valueBytes.length);
|
||||||
|
bytes.set(namespaceBytes);
|
||||||
|
bytes.set(valueBytes, namespaceBytes.length);
|
||||||
|
bytes = hash(bytes);
|
||||||
|
bytes[6] = (bytes[6] & 0x0f) | version;
|
||||||
|
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
||||||
|
if (buf) {
|
||||||
|
offset = offset || 0;
|
||||||
|
for (let i = 0; i < 16; ++i) {
|
||||||
|
buf[offset + i] = bytes[i];
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
return unsafeStringify(bytes);
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
import native from './native.js';
|
||||||
|
import rng from './rng.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
function _v4(options, buf, offset) {
|
||||||
|
options = options || {};
|
||||||
|
const rnds = options.random ?? options.rng?.() ?? rng();
|
||||||
|
if (rnds.length < 16) {
|
||||||
|
throw new Error('Random bytes length must be >= 16');
|
||||||
|
}
|
||||||
|
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
||||||
|
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
||||||
|
if (buf) {
|
||||||
|
offset = offset || 0;
|
||||||
|
if (offset < 0 || offset + 16 > buf.length) {
|
||||||
|
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
||||||
|
}
|
||||||
|
for (let i = 0; i < 16; ++i) {
|
||||||
|
buf[offset + i] = rnds[i];
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
return unsafeStringify(rnds);
|
||||||
|
}
|
||||||
|
function v4(options, buf, offset) {
|
||||||
|
if (native.randomUUID && !buf && !options) {
|
||||||
|
return native.randomUUID();
|
||||||
|
}
|
||||||
|
return _v4(options, buf, offset);
|
||||||
|
}
|
||||||
|
export default v4;
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import sha1 from './sha1.js';
|
||||||
|
import v35, { DNS, URL } from './v35.js';
|
||||||
|
export { DNS, URL } from './v35.js';
|
||||||
|
function v5(value, namespace, buf, offset) {
|
||||||
|
return v35(0x50, sha1, value, namespace, buf, offset);
|
||||||
|
}
|
||||||
|
v5.DNS = DNS;
|
||||||
|
v5.URL = URL;
|
||||||
|
export default v5;
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
import v1 from './v1.js';
|
||||||
|
import v1ToV6 from './v1ToV6.js';
|
||||||
|
function v6(options, buf, offset) {
|
||||||
|
options ??= {};
|
||||||
|
offset ??= 0;
|
||||||
|
let bytes = v1({ ...options, _v6: true }, new Uint8Array(16));
|
||||||
|
bytes = v1ToV6(bytes);
|
||||||
|
if (buf) {
|
||||||
|
for (let i = 0; i < 16; i++) {
|
||||||
|
buf[offset + i] = bytes[i];
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
return unsafeStringify(bytes);
|
||||||
|
}
|
||||||
|
export default v6;
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
import parse from './parse.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
export default function v6ToV1(uuid) {
|
||||||
|
const v6Bytes = typeof uuid === 'string' ? parse(uuid) : uuid;
|
||||||
|
const v1Bytes = _v6ToV1(v6Bytes);
|
||||||
|
return typeof uuid === 'string' ? unsafeStringify(v1Bytes) : v1Bytes;
|
||||||
|
}
|
||||||
|
function _v6ToV1(v6Bytes) {
|
||||||
|
return Uint8Array.of(((v6Bytes[3] & 0x0f) << 4) | ((v6Bytes[4] >> 4) & 0x0f), ((v6Bytes[4] & 0x0f) << 4) | ((v6Bytes[5] & 0xf0) >> 4), ((v6Bytes[5] & 0x0f) << 4) | (v6Bytes[6] & 0x0f), v6Bytes[7], ((v6Bytes[1] & 0x0f) << 4) | ((v6Bytes[2] & 0xf0) >> 4), ((v6Bytes[2] & 0x0f) << 4) | ((v6Bytes[3] & 0xf0) >> 4), 0x10 | ((v6Bytes[0] & 0xf0) >> 4), ((v6Bytes[0] & 0x0f) << 4) | ((v6Bytes[1] & 0xf0) >> 4), v6Bytes[8], v6Bytes[9], v6Bytes[10], v6Bytes[11], v6Bytes[12], v6Bytes[13], v6Bytes[14], v6Bytes[15]);
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
import rng from './rng.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
const _state = {};
|
||||||
|
function v7(options, buf, offset) {
|
||||||
|
let bytes;
|
||||||
|
if (options) {
|
||||||
|
bytes = v7Bytes(options.random ?? options.rng?.() ?? rng(), options.msecs, options.seq, buf, offset);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const now = Date.now();
|
||||||
|
const rnds = rng();
|
||||||
|
updateV7State(_state, now, rnds);
|
||||||
|
bytes = v7Bytes(rnds, _state.msecs, _state.seq, buf, offset);
|
||||||
|
}
|
||||||
|
return buf ?? unsafeStringify(bytes);
|
||||||
|
}
|
||||||
|
export function updateV7State(state, now, rnds) {
|
||||||
|
state.msecs ??= -Infinity;
|
||||||
|
state.seq ??= 0;
|
||||||
|
if (now > state.msecs) {
|
||||||
|
state.seq = (rnds[6] << 23) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
|
||||||
|
state.msecs = now;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
state.seq = (state.seq + 1) | 0;
|
||||||
|
if (state.seq === 0) {
|
||||||
|
state.msecs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
|
||||||
|
if (rnds.length < 16) {
|
||||||
|
throw new Error('Random bytes length must be >= 16');
|
||||||
|
}
|
||||||
|
if (!buf) {
|
||||||
|
buf = new Uint8Array(16);
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (offset < 0 || offset + 16 > buf.length) {
|
||||||
|
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msecs ??= Date.now();
|
||||||
|
seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
|
||||||
|
buf[offset++] = (msecs / 0x10000000000) & 0xff;
|
||||||
|
buf[offset++] = (msecs / 0x100000000) & 0xff;
|
||||||
|
buf[offset++] = (msecs / 0x1000000) & 0xff;
|
||||||
|
buf[offset++] = (msecs / 0x10000) & 0xff;
|
||||||
|
buf[offset++] = (msecs / 0x100) & 0xff;
|
||||||
|
buf[offset++] = msecs & 0xff;
|
||||||
|
buf[offset++] = 0x70 | ((seq >>> 28) & 0x0f);
|
||||||
|
buf[offset++] = (seq >>> 20) & 0xff;
|
||||||
|
buf[offset++] = 0x80 | ((seq >>> 14) & 0x3f);
|
||||||
|
buf[offset++] = (seq >>> 6) & 0xff;
|
||||||
|
buf[offset++] = ((seq << 2) & 0xff) | (rnds[10] & 0x03);
|
||||||
|
buf[offset++] = rnds[11];
|
||||||
|
buf[offset++] = rnds[12];
|
||||||
|
buf[offset++] = rnds[13];
|
||||||
|
buf[offset++] = rnds[14];
|
||||||
|
buf[offset++] = rnds[15];
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
export default v7;
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
import REGEX from './regex.js';
|
||||||
|
function validate(uuid) {
|
||||||
|
return typeof uuid === 'string' && REGEX.test(uuid);
|
||||||
|
}
|
||||||
|
export default validate;
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
import validate from './validate.js';
|
||||||
|
function version(uuid) {
|
||||||
|
if (!validate(uuid)) {
|
||||||
|
throw TypeError('Invalid UUID');
|
||||||
|
}
|
||||||
|
return parseInt(uuid.slice(14, 15), 16);
|
||||||
|
}
|
||||||
|
export default version;
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
export type * from './types.js';
|
||||||
|
export { default as MAX } from './max.js';
|
||||||
|
export { default as NIL } from './nil.js';
|
||||||
|
export { default as parse } from './parse.js';
|
||||||
|
export { default as stringify } from './stringify.js';
|
||||||
|
export { default as v1 } from './v1.js';
|
||||||
|
export { default as v1ToV6 } from './v1ToV6.js';
|
||||||
|
export { default as v3 } from './v3.js';
|
||||||
|
export { default as v4 } from './v4.js';
|
||||||
|
export { default as v5 } from './v5.js';
|
||||||
|
export { default as v6 } from './v6.js';
|
||||||
|
export { default as v6ToV1 } from './v6ToV1.js';
|
||||||
|
export { default as v7 } from './v7.js';
|
||||||
|
export { default as validate } from './validate.js';
|
||||||
|
export { default as version } from './version.js';
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
export { default as MAX } from './max.js';
|
||||||
|
export { default as NIL } from './nil.js';
|
||||||
|
export { default as parse } from './parse.js';
|
||||||
|
export { default as stringify } from './stringify.js';
|
||||||
|
export { default as v1 } from './v1.js';
|
||||||
|
export { default as v1ToV6 } from './v1ToV6.js';
|
||||||
|
export { default as v3 } from './v3.js';
|
||||||
|
export { default as v4 } from './v4.js';
|
||||||
|
export { default as v5 } from './v5.js';
|
||||||
|
export { default as v6 } from './v6.js';
|
||||||
|
export { default as v6ToV1 } from './v6ToV1.js';
|
||||||
|
export { default as v7 } from './v7.js';
|
||||||
|
export { default as validate } from './validate.js';
|
||||||
|
export { default as version } from './version.js';
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
declare const _default: "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
||||||
|
export default _default;
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export default 'ffffffff-ffff-ffff-ffff-ffffffffffff';
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
declare function md5(bytes: Uint8Array): Uint8Array;
|
||||||
|
export default md5;
|
||||||
+135
@@ -0,0 +1,135 @@
|
|||||||
|
function md5(bytes) {
|
||||||
|
const words = uint8ToUint32(bytes);
|
||||||
|
const md5Bytes = wordsToMd5(words, bytes.length * 8);
|
||||||
|
return uint32ToUint8(md5Bytes);
|
||||||
|
}
|
||||||
|
function uint32ToUint8(input) {
|
||||||
|
const bytes = new Uint8Array(input.length * 4);
|
||||||
|
for (let i = 0; i < input.length * 4; i++) {
|
||||||
|
bytes[i] = (input[i >> 2] >>> ((i % 4) * 8)) & 0xff;
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
function getOutputLength(inputLength8) {
|
||||||
|
return (((inputLength8 + 64) >>> 9) << 4) + 14 + 1;
|
||||||
|
}
|
||||||
|
function wordsToMd5(x, len) {
|
||||||
|
const xpad = new Uint32Array(getOutputLength(len)).fill(0);
|
||||||
|
xpad.set(x);
|
||||||
|
xpad[len >> 5] |= 0x80 << len % 32;
|
||||||
|
xpad[xpad.length - 1] = len;
|
||||||
|
x = xpad;
|
||||||
|
let a = 1732584193;
|
||||||
|
let b = -271733879;
|
||||||
|
let c = -1732584194;
|
||||||
|
let d = 271733878;
|
||||||
|
for (let i = 0; i < x.length; i += 16) {
|
||||||
|
const olda = a;
|
||||||
|
const oldb = b;
|
||||||
|
const oldc = c;
|
||||||
|
const oldd = d;
|
||||||
|
a = md5ff(a, b, c, d, x[i], 7, -680876936);
|
||||||
|
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
|
||||||
|
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
|
||||||
|
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
||||||
|
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
|
||||||
|
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
||||||
|
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
||||||
|
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
|
||||||
|
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
||||||
|
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
||||||
|
c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
|
||||||
|
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
||||||
|
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
||||||
|
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
|
||||||
|
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
||||||
|
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
||||||
|
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
|
||||||
|
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
||||||
|
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
|
||||||
|
b = md5gg(b, c, d, a, x[i], 20, -373897302);
|
||||||
|
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
|
||||||
|
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
|
||||||
|
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
|
||||||
|
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
|
||||||
|
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
|
||||||
|
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
||||||
|
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
|
||||||
|
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
||||||
|
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
||||||
|
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
|
||||||
|
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
||||||
|
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
||||||
|
a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
|
||||||
|
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
||||||
|
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
||||||
|
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
|
||||||
|
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
||||||
|
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
||||||
|
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
|
||||||
|
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
||||||
|
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
|
||||||
|
d = md5hh(d, a, b, c, x[i], 11, -358537222);
|
||||||
|
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
|
||||||
|
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
|
||||||
|
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
|
||||||
|
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
|
||||||
|
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
|
||||||
|
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
|
||||||
|
a = md5ii(a, b, c, d, x[i], 6, -198630844);
|
||||||
|
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
||||||
|
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
||||||
|
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
|
||||||
|
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
||||||
|
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
||||||
|
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
|
||||||
|
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
||||||
|
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
||||||
|
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
|
||||||
|
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
||||||
|
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
||||||
|
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
|
||||||
|
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
||||||
|
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
|
||||||
|
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
|
||||||
|
a = safeAdd(a, olda);
|
||||||
|
b = safeAdd(b, oldb);
|
||||||
|
c = safeAdd(c, oldc);
|
||||||
|
d = safeAdd(d, oldd);
|
||||||
|
}
|
||||||
|
return Uint32Array.of(a, b, c, d);
|
||||||
|
}
|
||||||
|
function uint8ToUint32(input) {
|
||||||
|
if (input.length === 0) {
|
||||||
|
return new Uint32Array();
|
||||||
|
}
|
||||||
|
const output = new Uint32Array(getOutputLength(input.length * 8)).fill(0);
|
||||||
|
for (let i = 0; i < input.length; i++) {
|
||||||
|
output[i >> 2] |= (input[i] & 0xff) << ((i % 4) * 8);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
function safeAdd(x, y) {
|
||||||
|
const lsw = (x & 0xffff) + (y & 0xffff);
|
||||||
|
const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||||
|
return (msw << 16) | (lsw & 0xffff);
|
||||||
|
}
|
||||||
|
function bitRotateLeft(num, cnt) {
|
||||||
|
return (num << cnt) | (num >>> (32 - cnt));
|
||||||
|
}
|
||||||
|
function md5cmn(q, a, b, x, s, t) {
|
||||||
|
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
|
||||||
|
}
|
||||||
|
function md5ff(a, b, c, d, x, s, t) {
|
||||||
|
return md5cmn((b & c) | (~b & d), a, b, x, s, t);
|
||||||
|
}
|
||||||
|
function md5gg(a, b, c, d, x, s, t) {
|
||||||
|
return md5cmn((b & d) | (c & ~d), a, b, x, s, t);
|
||||||
|
}
|
||||||
|
function md5hh(a, b, c, d, x, s, t) {
|
||||||
|
return md5cmn(b ^ c ^ d, a, b, x, s, t);
|
||||||
|
}
|
||||||
|
function md5ii(a, b, c, d, x, s, t) {
|
||||||
|
return md5cmn(c ^ (b | ~d), a, b, x, s, t);
|
||||||
|
}
|
||||||
|
export default md5;
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
declare const _default: {
|
||||||
|
randomUUID: false | (() => `${string}-${string}-${string}-${string}-${string}`);
|
||||||
|
};
|
||||||
|
export default _default;
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
||||||
|
export default { randomUUID };
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
declare const _default: "00000000-0000-0000-0000-000000000000";
|
||||||
|
export default _default;
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export default '00000000-0000-0000-0000-000000000000';
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
declare function parse(uuid: string): Uint8Array;
|
||||||
|
export default parse;
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import validate from './validate.js';
|
||||||
|
function parse(uuid) {
|
||||||
|
if (!validate(uuid)) {
|
||||||
|
throw TypeError('Invalid UUID');
|
||||||
|
}
|
||||||
|
let v;
|
||||||
|
return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, (v >>> 16) & 0xff, (v >>> 8) & 0xff, v & 0xff, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 0xff, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 0xff, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 0xff, ((v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000) & 0xff, (v / 0x100000000) & 0xff, (v >>> 24) & 0xff, (v >>> 16) & 0xff, (v >>> 8) & 0xff, v & 0xff);
|
||||||
|
}
|
||||||
|
export default parse;
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
declare const _default: RegExp;
|
||||||
|
export default _default;
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export default function rng(): Uint8Array;
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
let getRandomValues;
|
||||||
|
const rnds8 = new Uint8Array(16);
|
||||||
|
export default function rng() {
|
||||||
|
if (!getRandomValues) {
|
||||||
|
if (typeof crypto === 'undefined' || !crypto.getRandomValues) {
|
||||||
|
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
||||||
|
}
|
||||||
|
getRandomValues = crypto.getRandomValues.bind(crypto);
|
||||||
|
}
|
||||||
|
return getRandomValues(rnds8);
|
||||||
|
}
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
declare function sha1(bytes: Uint8Array): Uint8Array;
|
||||||
|
export default sha1;
|
||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
function f(s, x, y, z) {
|
||||||
|
switch (s) {
|
||||||
|
case 0:
|
||||||
|
return (x & y) ^ (~x & z);
|
||||||
|
case 1:
|
||||||
|
return x ^ y ^ z;
|
||||||
|
case 2:
|
||||||
|
return (x & y) ^ (x & z) ^ (y & z);
|
||||||
|
case 3:
|
||||||
|
return x ^ y ^ z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function ROTL(x, n) {
|
||||||
|
return (x << n) | (x >>> (32 - n));
|
||||||
|
}
|
||||||
|
function sha1(bytes) {
|
||||||
|
const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
|
||||||
|
const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
|
||||||
|
const newBytes = new Uint8Array(bytes.length + 1);
|
||||||
|
newBytes.set(bytes);
|
||||||
|
newBytes[bytes.length] = 0x80;
|
||||||
|
bytes = newBytes;
|
||||||
|
const l = bytes.length / 4 + 2;
|
||||||
|
const N = Math.ceil(l / 16);
|
||||||
|
const M = new Array(N);
|
||||||
|
for (let i = 0; i < N; ++i) {
|
||||||
|
const arr = new Uint32Array(16);
|
||||||
|
for (let j = 0; j < 16; ++j) {
|
||||||
|
arr[j] =
|
||||||
|
(bytes[i * 64 + j * 4] << 24) |
|
||||||
|
(bytes[i * 64 + j * 4 + 1] << 16) |
|
||||||
|
(bytes[i * 64 + j * 4 + 2] << 8) |
|
||||||
|
bytes[i * 64 + j * 4 + 3];
|
||||||
|
}
|
||||||
|
M[i] = arr;
|
||||||
|
}
|
||||||
|
M[N - 1][14] = ((bytes.length - 1) * 8) / Math.pow(2, 32);
|
||||||
|
M[N - 1][14] = Math.floor(M[N - 1][14]);
|
||||||
|
M[N - 1][15] = ((bytes.length - 1) * 8) & 0xffffffff;
|
||||||
|
for (let i = 0; i < N; ++i) {
|
||||||
|
const W = new Uint32Array(80);
|
||||||
|
for (let t = 0; t < 16; ++t) {
|
||||||
|
W[t] = M[i][t];
|
||||||
|
}
|
||||||
|
for (let t = 16; t < 80; ++t) {
|
||||||
|
W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
|
||||||
|
}
|
||||||
|
let a = H[0];
|
||||||
|
let b = H[1];
|
||||||
|
let c = H[2];
|
||||||
|
let d = H[3];
|
||||||
|
let e = H[4];
|
||||||
|
for (let t = 0; t < 80; ++t) {
|
||||||
|
const s = Math.floor(t / 20);
|
||||||
|
const T = (ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t]) >>> 0;
|
||||||
|
e = d;
|
||||||
|
d = c;
|
||||||
|
c = ROTL(b, 30) >>> 0;
|
||||||
|
b = a;
|
||||||
|
a = T;
|
||||||
|
}
|
||||||
|
H[0] = (H[0] + a) >>> 0;
|
||||||
|
H[1] = (H[1] + b) >>> 0;
|
||||||
|
H[2] = (H[2] + c) >>> 0;
|
||||||
|
H[3] = (H[3] + d) >>> 0;
|
||||||
|
H[4] = (H[4] + e) >>> 0;
|
||||||
|
}
|
||||||
|
return Uint8Array.of(H[0] >> 24, H[0] >> 16, H[0] >> 8, H[0], H[1] >> 24, H[1] >> 16, H[1] >> 8, H[1], H[2] >> 24, H[2] >> 16, H[2] >> 8, H[2], H[3] >> 24, H[3] >> 16, H[3] >> 8, H[3], H[4] >> 24, H[4] >> 16, H[4] >> 8, H[4]);
|
||||||
|
}
|
||||||
|
export default sha1;
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
export declare function unsafeStringify(arr: Uint8Array, offset?: number): string;
|
||||||
|
declare function stringify(arr: Uint8Array, offset?: number): string;
|
||||||
|
export default stringify;
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
import validate from './validate.js';
|
||||||
|
const byteToHex = [];
|
||||||
|
for (let i = 0; i < 256; ++i) {
|
||||||
|
byteToHex.push((i + 0x100).toString(16).slice(1));
|
||||||
|
}
|
||||||
|
export function unsafeStringify(arr, offset = 0) {
|
||||||
|
return (byteToHex[arr[offset + 0]] +
|
||||||
|
byteToHex[arr[offset + 1]] +
|
||||||
|
byteToHex[arr[offset + 2]] +
|
||||||
|
byteToHex[arr[offset + 3]] +
|
||||||
|
'-' +
|
||||||
|
byteToHex[arr[offset + 4]] +
|
||||||
|
byteToHex[arr[offset + 5]] +
|
||||||
|
'-' +
|
||||||
|
byteToHex[arr[offset + 6]] +
|
||||||
|
byteToHex[arr[offset + 7]] +
|
||||||
|
'-' +
|
||||||
|
byteToHex[arr[offset + 8]] +
|
||||||
|
byteToHex[arr[offset + 9]] +
|
||||||
|
'-' +
|
||||||
|
byteToHex[arr[offset + 10]] +
|
||||||
|
byteToHex[arr[offset + 11]] +
|
||||||
|
byteToHex[arr[offset + 12]] +
|
||||||
|
byteToHex[arr[offset + 13]] +
|
||||||
|
byteToHex[arr[offset + 14]] +
|
||||||
|
byteToHex[arr[offset + 15]]).toLowerCase();
|
||||||
|
}
|
||||||
|
function stringify(arr, offset = 0) {
|
||||||
|
const uuid = unsafeStringify(arr, offset);
|
||||||
|
if (!validate(uuid)) {
|
||||||
|
throw TypeError('Stringified UUID is invalid');
|
||||||
|
}
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
export default stringify;
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
export type UUIDTypes<TBuf extends Uint8Array = Uint8Array> = string | TBuf;
|
||||||
|
export type Version1Options = {
|
||||||
|
node?: Uint8Array;
|
||||||
|
clockseq?: number;
|
||||||
|
random?: Uint8Array;
|
||||||
|
rng?: () => Uint8Array;
|
||||||
|
msecs?: number;
|
||||||
|
nsecs?: number;
|
||||||
|
_v6?: boolean;
|
||||||
|
};
|
||||||
|
export type Version4Options = {
|
||||||
|
random?: Uint8Array;
|
||||||
|
rng?: () => Uint8Array;
|
||||||
|
};
|
||||||
|
export type Version6Options = Version1Options;
|
||||||
|
export type Version7Options = {
|
||||||
|
random?: Uint8Array;
|
||||||
|
msecs?: number;
|
||||||
|
seq?: number;
|
||||||
|
rng?: () => Uint8Array;
|
||||||
|
};
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export {};
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export {};
|
||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
import * as assert from 'node:assert/strict';
|
||||||
|
import v1 from './v1.js';
|
||||||
|
import v3 from './v3.js';
|
||||||
|
import v4 from './v4.js';
|
||||||
|
import v5 from './v5.js';
|
||||||
|
import v6 from './v6.js';
|
||||||
|
import v7 from './v7.js';
|
||||||
|
function usage() {
|
||||||
|
console.log('Usage:');
|
||||||
|
console.log(' uuid');
|
||||||
|
console.log(' uuid v1');
|
||||||
|
console.log(' uuid v3 <name> <namespace uuid>');
|
||||||
|
console.log(' uuid v4');
|
||||||
|
console.log(' uuid v5 <name> <namespace uuid>');
|
||||||
|
console.log(' uuid v6');
|
||||||
|
console.log(' uuid v7');
|
||||||
|
console.log(' uuid --help');
|
||||||
|
console.log('\nNote: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs defined by RFC9562');
|
||||||
|
}
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
if (args.indexOf('--help') >= 0) {
|
||||||
|
usage();
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
const version = args.shift() || 'v4';
|
||||||
|
switch (version) {
|
||||||
|
case 'v1':
|
||||||
|
console.log(v1());
|
||||||
|
break;
|
||||||
|
case 'v3': {
|
||||||
|
const name = args.shift();
|
||||||
|
let namespace = args.shift();
|
||||||
|
assert.ok(name != null, 'v3 name not specified');
|
||||||
|
assert.ok(namespace != null, 'v3 namespace not specified');
|
||||||
|
if (namespace === 'URL') {
|
||||||
|
namespace = v3.URL;
|
||||||
|
}
|
||||||
|
if (namespace === 'DNS') {
|
||||||
|
namespace = v3.DNS;
|
||||||
|
}
|
||||||
|
console.log(v3(name, namespace));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'v4':
|
||||||
|
console.log(v4());
|
||||||
|
break;
|
||||||
|
case 'v5': {
|
||||||
|
const name = args.shift();
|
||||||
|
let namespace = args.shift();
|
||||||
|
assert.ok(name != null, 'v5 name not specified');
|
||||||
|
assert.ok(namespace != null, 'v5 namespace not specified');
|
||||||
|
if (namespace === 'URL') {
|
||||||
|
namespace = v5.URL;
|
||||||
|
}
|
||||||
|
if (namespace === 'DNS') {
|
||||||
|
namespace = v5.DNS;
|
||||||
|
}
|
||||||
|
console.log(v5(name, namespace));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'v6':
|
||||||
|
console.log(v6());
|
||||||
|
break;
|
||||||
|
case 'v7':
|
||||||
|
console.log(v7());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
import { Version1Options } from './types.js';
|
||||||
|
type V1State = {
|
||||||
|
node?: Uint8Array;
|
||||||
|
clockseq?: number;
|
||||||
|
msecs?: number;
|
||||||
|
nsecs?: number;
|
||||||
|
};
|
||||||
|
declare function v1(options?: Version1Options, buf?: undefined, offset?: number): string;
|
||||||
|
declare function v1<Buf extends Uint8Array = Uint8Array>(options: Version1Options | undefined, buf: Buf, offset?: number): Buf;
|
||||||
|
export declare function updateV1State(state: V1State, now: number, rnds: Uint8Array): V1State;
|
||||||
|
export default v1;
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
import rng from './rng.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
const _state = {};
|
||||||
|
function v1(options, buf, offset) {
|
||||||
|
let bytes;
|
||||||
|
const isV6 = options?._v6 ?? false;
|
||||||
|
if (options) {
|
||||||
|
const optionsKeys = Object.keys(options);
|
||||||
|
if (optionsKeys.length === 1 && optionsKeys[0] === '_v6') {
|
||||||
|
options = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (options) {
|
||||||
|
bytes = v1Bytes(options.random ?? options.rng?.() ?? rng(), options.msecs, options.nsecs, options.clockseq, options.node, buf, offset);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const now = Date.now();
|
||||||
|
const rnds = rng();
|
||||||
|
updateV1State(_state, now, rnds);
|
||||||
|
bytes = v1Bytes(rnds, _state.msecs, _state.nsecs, isV6 ? undefined : _state.clockseq, isV6 ? undefined : _state.node, buf, offset);
|
||||||
|
}
|
||||||
|
return buf ?? unsafeStringify(bytes);
|
||||||
|
}
|
||||||
|
export function updateV1State(state, now, rnds) {
|
||||||
|
state.msecs ??= -Infinity;
|
||||||
|
state.nsecs ??= 0;
|
||||||
|
if (now === state.msecs) {
|
||||||
|
state.nsecs++;
|
||||||
|
if (state.nsecs >= 10000) {
|
||||||
|
state.node = undefined;
|
||||||
|
state.nsecs = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (now > state.msecs) {
|
||||||
|
state.nsecs = 0;
|
||||||
|
}
|
||||||
|
else if (now < state.msecs) {
|
||||||
|
state.node = undefined;
|
||||||
|
}
|
||||||
|
if (!state.node) {
|
||||||
|
state.node = rnds.slice(10, 16);
|
||||||
|
state.node[0] |= 0x01;
|
||||||
|
state.clockseq = ((rnds[8] << 8) | rnds[9]) & 0x3fff;
|
||||||
|
}
|
||||||
|
state.msecs = now;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
|
||||||
|
if (rnds.length < 16) {
|
||||||
|
throw new Error('Random bytes length must be >= 16');
|
||||||
|
}
|
||||||
|
if (!buf) {
|
||||||
|
buf = new Uint8Array(16);
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (offset < 0 || offset + 16 > buf.length) {
|
||||||
|
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msecs ??= Date.now();
|
||||||
|
nsecs ??= 0;
|
||||||
|
clockseq ??= ((rnds[8] << 8) | rnds[9]) & 0x3fff;
|
||||||
|
node ??= rnds.slice(10, 16);
|
||||||
|
msecs += 12219292800000;
|
||||||
|
const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
||||||
|
buf[offset++] = (tl >>> 24) & 0xff;
|
||||||
|
buf[offset++] = (tl >>> 16) & 0xff;
|
||||||
|
buf[offset++] = (tl >>> 8) & 0xff;
|
||||||
|
buf[offset++] = tl & 0xff;
|
||||||
|
const tmh = ((msecs / 0x100000000) * 10000) & 0xfffffff;
|
||||||
|
buf[offset++] = (tmh >>> 8) & 0xff;
|
||||||
|
buf[offset++] = tmh & 0xff;
|
||||||
|
buf[offset++] = ((tmh >>> 24) & 0xf) | 0x10;
|
||||||
|
buf[offset++] = (tmh >>> 16) & 0xff;
|
||||||
|
buf[offset++] = (clockseq >>> 8) | 0x80;
|
||||||
|
buf[offset++] = clockseq & 0xff;
|
||||||
|
for (let n = 0; n < 6; ++n) {
|
||||||
|
buf[offset++] = node[n];
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
export default v1;
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
export default function v1ToV6(uuid: string): string;
|
||||||
|
export default function v1ToV6(uuid: Uint8Array): Uint8Array;
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
import parse from './parse.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
export default function v1ToV6(uuid) {
|
||||||
|
const v1Bytes = typeof uuid === 'string' ? parse(uuid) : uuid;
|
||||||
|
const v6Bytes = _v1ToV6(v1Bytes);
|
||||||
|
return typeof uuid === 'string' ? unsafeStringify(v6Bytes) : v6Bytes;
|
||||||
|
}
|
||||||
|
function _v1ToV6(v1Bytes) {
|
||||||
|
return Uint8Array.of(((v1Bytes[6] & 0x0f) << 4) | ((v1Bytes[7] >> 4) & 0x0f), ((v1Bytes[7] & 0x0f) << 4) | ((v1Bytes[4] & 0xf0) >> 4), ((v1Bytes[4] & 0x0f) << 4) | ((v1Bytes[5] & 0xf0) >> 4), ((v1Bytes[5] & 0x0f) << 4) | ((v1Bytes[0] & 0xf0) >> 4), ((v1Bytes[0] & 0x0f) << 4) | ((v1Bytes[1] & 0xf0) >> 4), ((v1Bytes[1] & 0x0f) << 4) | ((v1Bytes[2] & 0xf0) >> 4), 0x60 | (v1Bytes[2] & 0x0f), v1Bytes[3], v1Bytes[8], v1Bytes[9], v1Bytes[10], v1Bytes[11], v1Bytes[12], v1Bytes[13], v1Bytes[14], v1Bytes[15]);
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import { UUIDTypes } from './types.js';
|
||||||
|
export { DNS, URL } from './v35.js';
|
||||||
|
declare function v3(value: string | Uint8Array, namespace: UUIDTypes, buf?: undefined, offset?: number): string;
|
||||||
|
declare function v3<TBuf extends Uint8Array = Uint8Array>(value: string | Uint8Array, namespace: UUIDTypes, buf: TBuf, offset?: number): TBuf;
|
||||||
|
declare namespace v3 {
|
||||||
|
var DNS: string;
|
||||||
|
var URL: string;
|
||||||
|
}
|
||||||
|
export default v3;
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import md5 from './md5.js';
|
||||||
|
import v35, { DNS, URL } from './v35.js';
|
||||||
|
export { DNS, URL } from './v35.js';
|
||||||
|
function v3(value, namespace, buf, offset) {
|
||||||
|
return v35(0x30, md5, value, namespace, buf, offset);
|
||||||
|
}
|
||||||
|
v3.DNS = DNS;
|
||||||
|
v3.URL = URL;
|
||||||
|
export default v3;
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
import { UUIDTypes } from './types.js';
|
||||||
|
export declare function stringToBytes(str: string): Uint8Array;
|
||||||
|
export declare const DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
|
||||||
|
export declare const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
|
||||||
|
type HashFunction = (bytes: Uint8Array) => Uint8Array;
|
||||||
|
export default function v35<TBuf extends Uint8Array = Uint8Array>(version: 0x30 | 0x50, hash: HashFunction, value: string | Uint8Array, namespace: UUIDTypes, buf?: TBuf, offset?: number): UUIDTypes<TBuf>;
|
||||||
|
export {};
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
import parse from './parse.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
export function stringToBytes(str) {
|
||||||
|
str = unescape(encodeURIComponent(str));
|
||||||
|
const bytes = new Uint8Array(str.length);
|
||||||
|
for (let i = 0; i < str.length; ++i) {
|
||||||
|
bytes[i] = str.charCodeAt(i);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
export const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
||||||
|
export const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
|
||||||
|
export default function v35(version, hash, value, namespace, buf, offset) {
|
||||||
|
const valueBytes = typeof value === 'string' ? stringToBytes(value) : value;
|
||||||
|
const namespaceBytes = typeof namespace === 'string' ? parse(namespace) : namespace;
|
||||||
|
if (typeof namespace === 'string') {
|
||||||
|
namespace = parse(namespace);
|
||||||
|
}
|
||||||
|
if (namespace?.length !== 16) {
|
||||||
|
throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
|
||||||
|
}
|
||||||
|
let bytes = new Uint8Array(16 + valueBytes.length);
|
||||||
|
bytes.set(namespaceBytes);
|
||||||
|
bytes.set(valueBytes, namespaceBytes.length);
|
||||||
|
bytes = hash(bytes);
|
||||||
|
bytes[6] = (bytes[6] & 0x0f) | version;
|
||||||
|
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
||||||
|
if (buf) {
|
||||||
|
offset = offset || 0;
|
||||||
|
for (let i = 0; i < 16; ++i) {
|
||||||
|
buf[offset + i] = bytes[i];
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
return unsafeStringify(bytes);
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
import { Version4Options } from './types.js';
|
||||||
|
declare function v4(options?: Version4Options, buf?: undefined, offset?: number): string;
|
||||||
|
declare function v4<TBuf extends Uint8Array = Uint8Array>(options: Version4Options | undefined, buf: TBuf, offset?: number): TBuf;
|
||||||
|
export default v4;
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
import native from './native.js';
|
||||||
|
import rng from './rng.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
function _v4(options, buf, offset) {
|
||||||
|
options = options || {};
|
||||||
|
const rnds = options.random ?? options.rng?.() ?? rng();
|
||||||
|
if (rnds.length < 16) {
|
||||||
|
throw new Error('Random bytes length must be >= 16');
|
||||||
|
}
|
||||||
|
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
||||||
|
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
||||||
|
if (buf) {
|
||||||
|
offset = offset || 0;
|
||||||
|
if (offset < 0 || offset + 16 > buf.length) {
|
||||||
|
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
||||||
|
}
|
||||||
|
for (let i = 0; i < 16; ++i) {
|
||||||
|
buf[offset + i] = rnds[i];
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
return unsafeStringify(rnds);
|
||||||
|
}
|
||||||
|
function v4(options, buf, offset) {
|
||||||
|
if (native.randomUUID && !buf && !options) {
|
||||||
|
return native.randomUUID();
|
||||||
|
}
|
||||||
|
return _v4(options, buf, offset);
|
||||||
|
}
|
||||||
|
export default v4;
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import { UUIDTypes } from './types.js';
|
||||||
|
export { DNS, URL } from './v35.js';
|
||||||
|
declare function v5(value: string | Uint8Array, namespace: UUIDTypes, buf?: undefined, offset?: number): string;
|
||||||
|
declare function v5<TBuf extends Uint8Array = Uint8Array>(value: string | Uint8Array, namespace: UUIDTypes, buf: TBuf, offset?: number): TBuf;
|
||||||
|
declare namespace v5 {
|
||||||
|
var DNS: string;
|
||||||
|
var URL: string;
|
||||||
|
}
|
||||||
|
export default v5;
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import sha1 from './sha1.js';
|
||||||
|
import v35, { DNS, URL } from './v35.js';
|
||||||
|
export { DNS, URL } from './v35.js';
|
||||||
|
function v5(value, namespace, buf, offset) {
|
||||||
|
return v35(0x50, sha1, value, namespace, buf, offset);
|
||||||
|
}
|
||||||
|
v5.DNS = DNS;
|
||||||
|
v5.URL = URL;
|
||||||
|
export default v5;
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
import { Version6Options } from './types.js';
|
||||||
|
declare function v6(options?: Version6Options, buf?: undefined, offset?: number): string;
|
||||||
|
declare function v6<TBuf extends Uint8Array = Uint8Array>(options: Version6Options | undefined, buf: TBuf, offset?: number): TBuf;
|
||||||
|
export default v6;
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
import v1 from './v1.js';
|
||||||
|
import v1ToV6 from './v1ToV6.js';
|
||||||
|
function v6(options, buf, offset) {
|
||||||
|
options ??= {};
|
||||||
|
offset ??= 0;
|
||||||
|
let bytes = v1({ ...options, _v6: true }, new Uint8Array(16));
|
||||||
|
bytes = v1ToV6(bytes);
|
||||||
|
if (buf) {
|
||||||
|
for (let i = 0; i < 16; i++) {
|
||||||
|
buf[offset + i] = bytes[i];
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
return unsafeStringify(bytes);
|
||||||
|
}
|
||||||
|
export default v6;
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
export default function v6ToV1(uuid: string): string;
|
||||||
|
export default function v6ToV1(uuid: Uint8Array): Uint8Array;
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
import parse from './parse.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
export default function v6ToV1(uuid) {
|
||||||
|
const v6Bytes = typeof uuid === 'string' ? parse(uuid) : uuid;
|
||||||
|
const v1Bytes = _v6ToV1(v6Bytes);
|
||||||
|
return typeof uuid === 'string' ? unsafeStringify(v1Bytes) : v1Bytes;
|
||||||
|
}
|
||||||
|
function _v6ToV1(v6Bytes) {
|
||||||
|
return Uint8Array.of(((v6Bytes[3] & 0x0f) << 4) | ((v6Bytes[4] >> 4) & 0x0f), ((v6Bytes[4] & 0x0f) << 4) | ((v6Bytes[5] & 0xf0) >> 4), ((v6Bytes[5] & 0x0f) << 4) | (v6Bytes[6] & 0x0f), v6Bytes[7], ((v6Bytes[1] & 0x0f) << 4) | ((v6Bytes[2] & 0xf0) >> 4), ((v6Bytes[2] & 0x0f) << 4) | ((v6Bytes[3] & 0xf0) >> 4), 0x10 | ((v6Bytes[0] & 0xf0) >> 4), ((v6Bytes[0] & 0x0f) << 4) | ((v6Bytes[1] & 0xf0) >> 4), v6Bytes[8], v6Bytes[9], v6Bytes[10], v6Bytes[11], v6Bytes[12], v6Bytes[13], v6Bytes[14], v6Bytes[15]);
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import { Version7Options } from './types.js';
|
||||||
|
type V7State = {
|
||||||
|
msecs?: number;
|
||||||
|
seq?: number;
|
||||||
|
};
|
||||||
|
declare function v7(options?: Version7Options, buf?: undefined, offset?: number): string;
|
||||||
|
declare function v7<TBuf extends Uint8Array = Uint8Array>(options: Version7Options | undefined, buf: TBuf, offset?: number): TBuf;
|
||||||
|
export declare function updateV7State(state: V7State, now: number, rnds: Uint8Array): V7State;
|
||||||
|
export default v7;
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
import rng from './rng.js';
|
||||||
|
import { unsafeStringify } from './stringify.js';
|
||||||
|
const _state = {};
|
||||||
|
function v7(options, buf, offset) {
|
||||||
|
let bytes;
|
||||||
|
if (options) {
|
||||||
|
bytes = v7Bytes(options.random ?? options.rng?.() ?? rng(), options.msecs, options.seq, buf, offset);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const now = Date.now();
|
||||||
|
const rnds = rng();
|
||||||
|
updateV7State(_state, now, rnds);
|
||||||
|
bytes = v7Bytes(rnds, _state.msecs, _state.seq, buf, offset);
|
||||||
|
}
|
||||||
|
return buf ?? unsafeStringify(bytes);
|
||||||
|
}
|
||||||
|
export function updateV7State(state, now, rnds) {
|
||||||
|
state.msecs ??= -Infinity;
|
||||||
|
state.seq ??= 0;
|
||||||
|
if (now > state.msecs) {
|
||||||
|
state.seq = (rnds[6] << 23) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
|
||||||
|
state.msecs = now;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
state.seq = (state.seq + 1) | 0;
|
||||||
|
if (state.seq === 0) {
|
||||||
|
state.msecs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
|
||||||
|
if (rnds.length < 16) {
|
||||||
|
throw new Error('Random bytes length must be >= 16');
|
||||||
|
}
|
||||||
|
if (!buf) {
|
||||||
|
buf = new Uint8Array(16);
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (offset < 0 || offset + 16 > buf.length) {
|
||||||
|
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msecs ??= Date.now();
|
||||||
|
seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
|
||||||
|
buf[offset++] = (msecs / 0x10000000000) & 0xff;
|
||||||
|
buf[offset++] = (msecs / 0x100000000) & 0xff;
|
||||||
|
buf[offset++] = (msecs / 0x1000000) & 0xff;
|
||||||
|
buf[offset++] = (msecs / 0x10000) & 0xff;
|
||||||
|
buf[offset++] = (msecs / 0x100) & 0xff;
|
||||||
|
buf[offset++] = msecs & 0xff;
|
||||||
|
buf[offset++] = 0x70 | ((seq >>> 28) & 0x0f);
|
||||||
|
buf[offset++] = (seq >>> 20) & 0xff;
|
||||||
|
buf[offset++] = 0x80 | ((seq >>> 14) & 0x3f);
|
||||||
|
buf[offset++] = (seq >>> 6) & 0xff;
|
||||||
|
buf[offset++] = ((seq << 2) & 0xff) | (rnds[10] & 0x03);
|
||||||
|
buf[offset++] = rnds[11];
|
||||||
|
buf[offset++] = rnds[12];
|
||||||
|
buf[offset++] = rnds[13];
|
||||||
|
buf[offset++] = rnds[14];
|
||||||
|
buf[offset++] = rnds[15];
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
export default v7;
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
declare function validate(uuid: unknown): boolean;
|
||||||
|
export default validate;
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
import REGEX from './regex.js';
|
||||||
|
function validate(uuid) {
|
||||||
|
return typeof uuid === 'string' && REGEX.test(uuid);
|
||||||
|
}
|
||||||
|
export default validate;
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
declare function version(uuid: string): number;
|
||||||
|
export default version;
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
import validate from './validate.js';
|
||||||
|
function version(uuid) {
|
||||||
|
if (!validate(uuid)) {
|
||||||
|
throw TypeError('Invalid UUID');
|
||||||
|
}
|
||||||
|
return parseInt(uuid.slice(14, 15), 16);
|
||||||
|
}
|
||||||
|
export default version;
|
||||||
+119
@@ -0,0 +1,119 @@
|
|||||||
|
{
|
||||||
|
"name": "uuid",
|
||||||
|
"version": "13.0.0",
|
||||||
|
"description": "RFC9562 UUIDs",
|
||||||
|
"type": "module",
|
||||||
|
"funding": [
|
||||||
|
"https://github.com/sponsors/broofa",
|
||||||
|
"https://github.com/sponsors/ctavan"
|
||||||
|
],
|
||||||
|
"commitlint": {
|
||||||
|
"extends": [
|
||||||
|
"@commitlint/config-conventional"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"uuid",
|
||||||
|
"guid",
|
||||||
|
"rfc4122",
|
||||||
|
"rfc9562"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"uuid": "./dist-node/bin/uuid"
|
||||||
|
},
|
||||||
|
"sideEffects": false,
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"node": "./dist-node/index.js",
|
||||||
|
"default": "./dist/index.js"
|
||||||
|
},
|
||||||
|
"./package.json": "./package.json"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"dist-node",
|
||||||
|
"!**/test"
|
||||||
|
],
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/eslint-parser": "7.27.1",
|
||||||
|
"@commitlint/cli": "19.8.0",
|
||||||
|
"@commitlint/config-conventional": "19.8.0",
|
||||||
|
"@eslint/js": "9.26.0",
|
||||||
|
"bundlewatch": "0.4.1",
|
||||||
|
"commander": "13.1.0",
|
||||||
|
"eslint": "9.26.0",
|
||||||
|
"eslint-config-prettier": "10.1.2",
|
||||||
|
"eslint-plugin-prettier": "5.4.0",
|
||||||
|
"globals": "16.0.0",
|
||||||
|
"husky": "9.1.7",
|
||||||
|
"jest": "29.7.0",
|
||||||
|
"lint-staged": "15.5.2",
|
||||||
|
"neostandard": "0.12.1",
|
||||||
|
"npm-run-all": "4.1.5",
|
||||||
|
"prettier": "3.5.3",
|
||||||
|
"release-please": "17.0.0",
|
||||||
|
"runmd": "1.4.1",
|
||||||
|
"standard-version": "9.5.0",
|
||||||
|
"typescript": "5.2.2",
|
||||||
|
"typescript-eslint": "8.32.0"
|
||||||
|
},
|
||||||
|
"optionalDevDependencies": {
|
||||||
|
"@wdio/browserstack-service": "9.2.1",
|
||||||
|
"@wdio/cli": "9.2.1",
|
||||||
|
"@wdio/jasmine-framework": "9.2.1",
|
||||||
|
"@wdio/local-runner": "9.2.1",
|
||||||
|
"@wdio/spec-reporter": "9.1.3",
|
||||||
|
"@wdio/static-server-service": "9.1.3"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "./scripts/build.sh",
|
||||||
|
"build:watch": "tsc --watch -p tsconfig.json",
|
||||||
|
"bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json",
|
||||||
|
"docs:diff": "npm run docs && git diff --quiet -I \"[0-9a-f-]{36}\" README.md",
|
||||||
|
"docs": "npm run build && npx runmd --output=README.md README_js.md",
|
||||||
|
"eslint:check": "eslint src/ test/ examples/ *.[jt]s",
|
||||||
|
"eslint:fix": "eslint --fix src/ test/ examples/ *.[jt]s",
|
||||||
|
"examples:browser:rollup:build": "cd examples/browser-rollup && npm run build",
|
||||||
|
"examples:browser:webpack:build": "cd examples/browser-webpack && npm run build",
|
||||||
|
"examples:node:esmodules:test": "cd examples/node-esmodules && npm test",
|
||||||
|
"examples:node:jest:test": "cd examples/node-jest && npm test",
|
||||||
|
"examples:node:typescript:test": "cd examples/typescript && npm test",
|
||||||
|
"lint": "npm run eslint:check && npm run prettier:check",
|
||||||
|
"md": "runmd --watch --output=README.md README_js.md",
|
||||||
|
"prepack": "npm run build -- --no-pack",
|
||||||
|
"prepare": "husky",
|
||||||
|
"prepublishOnly": "npm run build",
|
||||||
|
"pretest:benchmark": "npm run build",
|
||||||
|
"pretest:browser": "./scripts/iodd && npm run build && npm-run-all --parallel examples:browser:**",
|
||||||
|
"pretest:node": "npm run build",
|
||||||
|
"pretest": "npm run build",
|
||||||
|
"prettier:check": "prettier --check .",
|
||||||
|
"prettier:fix": "prettier --write .",
|
||||||
|
"release": "standard-version --no-verify",
|
||||||
|
"test:benchmark": "cd examples/benchmark && npm test",
|
||||||
|
"test:browser": "wdio run ./wdio.conf.js",
|
||||||
|
"test:node": "npm-run-all --parallel examples:node:**",
|
||||||
|
"test:watch": "node --test --enable-source-maps --watch dist-node/test/*.js",
|
||||||
|
"test": "node --test --enable-source-maps dist-node/test/*.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/uuidjs/uuid.git"
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*": [
|
||||||
|
"prettier --no-error-on-unmatched-pattern --write"
|
||||||
|
],
|
||||||
|
"*.{js,jsx}": [
|
||||||
|
"eslint --no-error-on-unmatched-pattern --fix"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"standard-version": {
|
||||||
|
"scripts": {
|
||||||
|
"postchangelog": "prettier --write CHANGELOG.md"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"packageManager": "npm@11.3.0"
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "bloatless-react",
|
||||||
|
"version": "1.3.14",
|
||||||
|
"description": "very minimal and flexible react alternative",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/marlon-erler/bloatless-react"
|
||||||
|
},
|
||||||
|
"author": "marlon-erler",
|
||||||
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"uuid": "^13.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"noImplicitAny": false,
|
||||||
|
"jsx": "react",
|
||||||
|
"jsxFactory": "FWI.createElement",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"target": "es2020"
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 Evan Wallace
|
||||||
|
|
||||||
|
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.
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
# esbuild
|
||||||
|
|
||||||
|
This is a JavaScript bundler and minifier. See https://github.com/evanw/esbuild and the [JavaScript API documentation](https://esbuild.github.io/api/) for details.
|
||||||
+221
@@ -0,0 +1,221 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
"use strict";
|
||||||
|
var __create = Object.create;
|
||||||
|
var __defProp = Object.defineProperty;
|
||||||
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||||
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||||
|
var __getProtoOf = Object.getPrototypeOf;
|
||||||
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||||
|
var __copyProps = (to, from, except, desc) => {
|
||||||
|
if (from && typeof from === "object" || typeof from === "function") {
|
||||||
|
for (let key of __getOwnPropNames(from))
|
||||||
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||||
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||||
|
}
|
||||||
|
return to;
|
||||||
|
};
|
||||||
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||||
|
// If the importer is in node compatibility mode or this is not an ESM
|
||||||
|
// file that has been converted to a CommonJS file using a Babel-
|
||||||
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||||
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||||
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||||
|
mod
|
||||||
|
));
|
||||||
|
|
||||||
|
// lib/npm/node-platform.ts
|
||||||
|
var fs = require("fs");
|
||||||
|
var os = require("os");
|
||||||
|
var path = require("path");
|
||||||
|
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
||||||
|
var isValidBinaryPath = (x) => !!x && x !== "/usr/bin/esbuild";
|
||||||
|
var packageDarwin_arm64 = "@esbuild/darwin-arm64";
|
||||||
|
var packageDarwin_x64 = "@esbuild/darwin-x64";
|
||||||
|
var knownWindowsPackages = {
|
||||||
|
"win32 arm64 LE": "@esbuild/win32-arm64",
|
||||||
|
"win32 ia32 LE": "@esbuild/win32-ia32",
|
||||||
|
"win32 x64 LE": "@esbuild/win32-x64"
|
||||||
|
};
|
||||||
|
var knownUnixlikePackages = {
|
||||||
|
"aix ppc64 BE": "@esbuild/aix-ppc64",
|
||||||
|
"android arm64 LE": "@esbuild/android-arm64",
|
||||||
|
"darwin arm64 LE": "@esbuild/darwin-arm64",
|
||||||
|
"darwin x64 LE": "@esbuild/darwin-x64",
|
||||||
|
"freebsd arm64 LE": "@esbuild/freebsd-arm64",
|
||||||
|
"freebsd x64 LE": "@esbuild/freebsd-x64",
|
||||||
|
"linux arm LE": "@esbuild/linux-arm",
|
||||||
|
"linux arm64 LE": "@esbuild/linux-arm64",
|
||||||
|
"linux ia32 LE": "@esbuild/linux-ia32",
|
||||||
|
"linux mips64el LE": "@esbuild/linux-mips64el",
|
||||||
|
"linux ppc64 LE": "@esbuild/linux-ppc64",
|
||||||
|
"linux riscv64 LE": "@esbuild/linux-riscv64",
|
||||||
|
"linux s390x BE": "@esbuild/linux-s390x",
|
||||||
|
"linux x64 LE": "@esbuild/linux-x64",
|
||||||
|
"linux loong64 LE": "@esbuild/linux-loong64",
|
||||||
|
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
||||||
|
"openbsd arm64 LE": "@esbuild/openbsd-arm64",
|
||||||
|
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
||||||
|
"sunos x64 LE": "@esbuild/sunos-x64"
|
||||||
|
};
|
||||||
|
var knownWebAssemblyFallbackPackages = {
|
||||||
|
"android arm LE": "@esbuild/android-arm",
|
||||||
|
"android x64 LE": "@esbuild/android-x64"
|
||||||
|
};
|
||||||
|
function pkgAndSubpathForCurrentPlatform() {
|
||||||
|
let pkg;
|
||||||
|
let subpath;
|
||||||
|
let isWASM2 = false;
|
||||||
|
let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
||||||
|
if (platformKey in knownWindowsPackages) {
|
||||||
|
pkg = knownWindowsPackages[platformKey];
|
||||||
|
subpath = "esbuild.exe";
|
||||||
|
} else if (platformKey in knownUnixlikePackages) {
|
||||||
|
pkg = knownUnixlikePackages[platformKey];
|
||||||
|
subpath = "bin/esbuild";
|
||||||
|
} else if (platformKey in knownWebAssemblyFallbackPackages) {
|
||||||
|
pkg = knownWebAssemblyFallbackPackages[platformKey];
|
||||||
|
subpath = "bin/esbuild";
|
||||||
|
isWASM2 = true;
|
||||||
|
} else {
|
||||||
|
throw new Error(`Unsupported platform: ${platformKey}`);
|
||||||
|
}
|
||||||
|
return { pkg, subpath, isWASM: isWASM2 };
|
||||||
|
}
|
||||||
|
function pkgForSomeOtherPlatform() {
|
||||||
|
const libMainJS = require.resolve("esbuild");
|
||||||
|
const nodeModulesDirectory = path.dirname(path.dirname(path.dirname(libMainJS)));
|
||||||
|
if (path.basename(nodeModulesDirectory) === "node_modules") {
|
||||||
|
for (const unixKey in knownUnixlikePackages) {
|
||||||
|
try {
|
||||||
|
const pkg = knownUnixlikePackages[unixKey];
|
||||||
|
if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const windowsKey in knownWindowsPackages) {
|
||||||
|
try {
|
||||||
|
const pkg = knownWindowsPackages[windowsKey];
|
||||||
|
if (fs.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
function downloadedBinPath(pkg, subpath) {
|
||||||
|
const esbuildLibDir = path.dirname(require.resolve("esbuild"));
|
||||||
|
return path.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
||||||
|
}
|
||||||
|
function generateBinPath() {
|
||||||
|
if (isValidBinaryPath(ESBUILD_BINARY_PATH)) {
|
||||||
|
if (!fs.existsSync(ESBUILD_BINARY_PATH)) {
|
||||||
|
console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
|
||||||
|
} else {
|
||||||
|
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const { pkg, subpath, isWASM: isWASM2 } = pkgAndSubpathForCurrentPlatform();
|
||||||
|
let binPath2;
|
||||||
|
try {
|
||||||
|
binPath2 = require.resolve(`${pkg}/${subpath}`);
|
||||||
|
} catch (e) {
|
||||||
|
binPath2 = downloadedBinPath(pkg, subpath);
|
||||||
|
if (!fs.existsSync(binPath2)) {
|
||||||
|
try {
|
||||||
|
require.resolve(pkg);
|
||||||
|
} catch {
|
||||||
|
const otherPkg = pkgForSomeOtherPlatform();
|
||||||
|
if (otherPkg) {
|
||||||
|
let suggestions = `
|
||||||
|
Specifically the "${otherPkg}" package is present but this platform
|
||||||
|
needs the "${pkg}" package instead. People often get into this
|
||||||
|
situation by installing esbuild on Windows or macOS and copying "node_modules"
|
||||||
|
into a Docker image that runs Linux, or by copying "node_modules" between
|
||||||
|
Windows and WSL environments.
|
||||||
|
|
||||||
|
If you are installing with npm, you can try not copying the "node_modules"
|
||||||
|
directory when you copy the files over, and running "npm ci" or "npm install"
|
||||||
|
on the destination platform after the copy. Or you could consider using yarn
|
||||||
|
instead of npm which has built-in support for installing a package on multiple
|
||||||
|
platforms simultaneously.
|
||||||
|
|
||||||
|
If you are installing with yarn, you can try listing both this platform and the
|
||||||
|
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
||||||
|
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
||||||
|
Keep in mind that this means multiple copies of esbuild will be present.
|
||||||
|
`;
|
||||||
|
if (pkg === packageDarwin_x64 && otherPkg === packageDarwin_arm64 || pkg === packageDarwin_arm64 && otherPkg === packageDarwin_x64) {
|
||||||
|
suggestions = `
|
||||||
|
Specifically the "${otherPkg}" package is present but this platform
|
||||||
|
needs the "${pkg}" package instead. People often get into this
|
||||||
|
situation by installing esbuild with npm running inside of Rosetta 2 and then
|
||||||
|
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
|
||||||
|
2 is Apple's on-the-fly x86_64-to-arm64 translation service).
|
||||||
|
|
||||||
|
If you are installing with npm, you can try ensuring that both npm and node are
|
||||||
|
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
|
||||||
|
changing how you installed npm and/or node. For example, installing node with
|
||||||
|
the universal installer here should work: https://nodejs.org/en/download/. Or
|
||||||
|
you could consider using yarn instead of npm which has built-in support for
|
||||||
|
installing a package on multiple platforms simultaneously.
|
||||||
|
|
||||||
|
If you are installing with yarn, you can try listing both "arm64" and "x64"
|
||||||
|
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
|
||||||
|
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
||||||
|
Keep in mind that this means multiple copies of esbuild will be present.
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
throw new Error(`
|
||||||
|
You installed esbuild for another platform than the one you're currently using.
|
||||||
|
This won't work because esbuild is written with native code and needs to
|
||||||
|
install a platform-specific binary executable.
|
||||||
|
${suggestions}
|
||||||
|
Another alternative is to use the "esbuild-wasm" package instead, which works
|
||||||
|
the same way on all platforms. But it comes with a heavy performance cost and
|
||||||
|
can sometimes be 10x slower than the "esbuild" package, so you may also not
|
||||||
|
want to do that.
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
|
||||||
|
|
||||||
|
If you are installing esbuild with npm, make sure that you don't specify the
|
||||||
|
"--no-optional" or "--omit=optional" flags. The "optionalDependencies" feature
|
||||||
|
of "package.json" is used by esbuild to install the correct binary executable
|
||||||
|
for your current platform.`);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (/\.zip\//.test(binPath2)) {
|
||||||
|
let pnpapi;
|
||||||
|
try {
|
||||||
|
pnpapi = require("pnpapi");
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
if (pnpapi) {
|
||||||
|
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
|
||||||
|
const binTargetPath = path.join(
|
||||||
|
root,
|
||||||
|
"node_modules",
|
||||||
|
".cache",
|
||||||
|
"esbuild",
|
||||||
|
`pnpapi-${pkg.replace("/", "-")}-${"0.23.1"}-${path.basename(subpath)}`
|
||||||
|
);
|
||||||
|
if (!fs.existsSync(binTargetPath)) {
|
||||||
|
fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
|
||||||
|
fs.copyFileSync(binPath2, binTargetPath);
|
||||||
|
fs.chmodSync(binTargetPath, 493);
|
||||||
|
}
|
||||||
|
return { binPath: binTargetPath, isWASM: isWASM2 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { binPath: binPath2, isWASM: isWASM2 };
|
||||||
|
}
|
||||||
|
|
||||||
|
// lib/npm/node-shim.ts
|
||||||
|
var { binPath, isWASM } = generateBinPath();
|
||||||
|
if (isWASM) {
|
||||||
|
require("child_process").execFileSync("node", [binPath].concat(process.argv.slice(2)), { stdio: "inherit" });
|
||||||
|
} else {
|
||||||
|
require("child_process").execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
||||||
|
}
|
||||||
+286
@@ -0,0 +1,286 @@
|
|||||||
|
"use strict";
|
||||||
|
var __create = Object.create;
|
||||||
|
var __defProp = Object.defineProperty;
|
||||||
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||||
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||||
|
var __getProtoOf = Object.getPrototypeOf;
|
||||||
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||||
|
var __copyProps = (to, from, except, desc) => {
|
||||||
|
if (from && typeof from === "object" || typeof from === "function") {
|
||||||
|
for (let key of __getOwnPropNames(from))
|
||||||
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||||
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||||
|
}
|
||||||
|
return to;
|
||||||
|
};
|
||||||
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||||
|
// If the importer is in node compatibility mode or this is not an ESM
|
||||||
|
// file that has been converted to a CommonJS file using a Babel-
|
||||||
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||||
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||||
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||||
|
mod
|
||||||
|
));
|
||||||
|
|
||||||
|
// lib/npm/node-platform.ts
|
||||||
|
var fs = require("fs");
|
||||||
|
var os = require("os");
|
||||||
|
var path = require("path");
|
||||||
|
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
||||||
|
var isValidBinaryPath = (x) => !!x && x !== "/usr/bin/esbuild";
|
||||||
|
var knownWindowsPackages = {
|
||||||
|
"win32 arm64 LE": "@esbuild/win32-arm64",
|
||||||
|
"win32 ia32 LE": "@esbuild/win32-ia32",
|
||||||
|
"win32 x64 LE": "@esbuild/win32-x64"
|
||||||
|
};
|
||||||
|
var knownUnixlikePackages = {
|
||||||
|
"aix ppc64 BE": "@esbuild/aix-ppc64",
|
||||||
|
"android arm64 LE": "@esbuild/android-arm64",
|
||||||
|
"darwin arm64 LE": "@esbuild/darwin-arm64",
|
||||||
|
"darwin x64 LE": "@esbuild/darwin-x64",
|
||||||
|
"freebsd arm64 LE": "@esbuild/freebsd-arm64",
|
||||||
|
"freebsd x64 LE": "@esbuild/freebsd-x64",
|
||||||
|
"linux arm LE": "@esbuild/linux-arm",
|
||||||
|
"linux arm64 LE": "@esbuild/linux-arm64",
|
||||||
|
"linux ia32 LE": "@esbuild/linux-ia32",
|
||||||
|
"linux mips64el LE": "@esbuild/linux-mips64el",
|
||||||
|
"linux ppc64 LE": "@esbuild/linux-ppc64",
|
||||||
|
"linux riscv64 LE": "@esbuild/linux-riscv64",
|
||||||
|
"linux s390x BE": "@esbuild/linux-s390x",
|
||||||
|
"linux x64 LE": "@esbuild/linux-x64",
|
||||||
|
"linux loong64 LE": "@esbuild/linux-loong64",
|
||||||
|
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
||||||
|
"openbsd arm64 LE": "@esbuild/openbsd-arm64",
|
||||||
|
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
||||||
|
"sunos x64 LE": "@esbuild/sunos-x64"
|
||||||
|
};
|
||||||
|
var knownWebAssemblyFallbackPackages = {
|
||||||
|
"android arm LE": "@esbuild/android-arm",
|
||||||
|
"android x64 LE": "@esbuild/android-x64"
|
||||||
|
};
|
||||||
|
function pkgAndSubpathForCurrentPlatform() {
|
||||||
|
let pkg;
|
||||||
|
let subpath;
|
||||||
|
let isWASM = false;
|
||||||
|
let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
||||||
|
if (platformKey in knownWindowsPackages) {
|
||||||
|
pkg = knownWindowsPackages[platformKey];
|
||||||
|
subpath = "esbuild.exe";
|
||||||
|
} else if (platformKey in knownUnixlikePackages) {
|
||||||
|
pkg = knownUnixlikePackages[platformKey];
|
||||||
|
subpath = "bin/esbuild";
|
||||||
|
} else if (platformKey in knownWebAssemblyFallbackPackages) {
|
||||||
|
pkg = knownWebAssemblyFallbackPackages[platformKey];
|
||||||
|
subpath = "bin/esbuild";
|
||||||
|
isWASM = true;
|
||||||
|
} else {
|
||||||
|
throw new Error(`Unsupported platform: ${platformKey}`);
|
||||||
|
}
|
||||||
|
return { pkg, subpath, isWASM };
|
||||||
|
}
|
||||||
|
function downloadedBinPath(pkg, subpath) {
|
||||||
|
const esbuildLibDir = path.dirname(require.resolve("esbuild"));
|
||||||
|
return path.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lib/npm/node-install.ts
|
||||||
|
var fs2 = require("fs");
|
||||||
|
var os2 = require("os");
|
||||||
|
var path2 = require("path");
|
||||||
|
var zlib = require("zlib");
|
||||||
|
var https = require("https");
|
||||||
|
var child_process = require("child_process");
|
||||||
|
var versionFromPackageJSON = require(path2.join(__dirname, "package.json")).version;
|
||||||
|
var toPath = path2.join(__dirname, "bin", "esbuild");
|
||||||
|
var isToPathJS = true;
|
||||||
|
function validateBinaryVersion(...command) {
|
||||||
|
command.push("--version");
|
||||||
|
let stdout;
|
||||||
|
try {
|
||||||
|
stdout = child_process.execFileSync(command.shift(), command, {
|
||||||
|
// Without this, this install script strangely crashes with the error
|
||||||
|
// "EACCES: permission denied, write" but only on Ubuntu Linux when node is
|
||||||
|
// installed from the Snap Store. This is not a problem when you download
|
||||||
|
// the official version of node. The problem appears to be that stderr
|
||||||
|
// (i.e. file descriptor 2) isn't writable?
|
||||||
|
//
|
||||||
|
// More info:
|
||||||
|
// - https://snapcraft.io/ (what the Snap Store is)
|
||||||
|
// - https://nodejs.org/dist/ (download the official version of node)
|
||||||
|
// - https://github.com/evanw/esbuild/issues/1711#issuecomment-1027554035
|
||||||
|
//
|
||||||
|
stdio: "pipe"
|
||||||
|
}).toString().trim();
|
||||||
|
} catch (err) {
|
||||||
|
if (os2.platform() === "darwin" && /_SecTrustEvaluateWithError/.test(err + "")) {
|
||||||
|
let os3 = "this version of macOS";
|
||||||
|
try {
|
||||||
|
os3 = "macOS " + child_process.execFileSync("sw_vers", ["-productVersion"]).toString().trim();
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
throw new Error(`The "esbuild" package cannot be installed because ${os3} is too outdated.
|
||||||
|
|
||||||
|
The Go compiler (which esbuild relies on) no longer supports ${os3},
|
||||||
|
which means the "esbuild" binary executable can't be run. You can either:
|
||||||
|
|
||||||
|
* Update your version of macOS to one that the Go compiler supports
|
||||||
|
* Use the "esbuild-wasm" package instead of the "esbuild" package
|
||||||
|
* Build esbuild yourself using an older version of the Go compiler
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
if (stdout !== versionFromPackageJSON) {
|
||||||
|
throw new Error(`Expected ${JSON.stringify(versionFromPackageJSON)} but got ${JSON.stringify(stdout)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function isYarn() {
|
||||||
|
const { npm_config_user_agent } = process.env;
|
||||||
|
if (npm_config_user_agent) {
|
||||||
|
return /\byarn\//.test(npm_config_user_agent);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
function fetch(url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
https.get(url, (res) => {
|
||||||
|
if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location)
|
||||||
|
return fetch(res.headers.location).then(resolve, reject);
|
||||||
|
if (res.statusCode !== 200)
|
||||||
|
return reject(new Error(`Server responded with ${res.statusCode}`));
|
||||||
|
let chunks = [];
|
||||||
|
res.on("data", (chunk) => chunks.push(chunk));
|
||||||
|
res.on("end", () => resolve(Buffer.concat(chunks)));
|
||||||
|
}).on("error", reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function extractFileFromTarGzip(buffer, subpath) {
|
||||||
|
try {
|
||||||
|
buffer = zlib.unzipSync(buffer);
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Invalid gzip data in archive: ${err && err.message || err}`);
|
||||||
|
}
|
||||||
|
let str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
|
||||||
|
let offset = 0;
|
||||||
|
subpath = `package/${subpath}`;
|
||||||
|
while (offset < buffer.length) {
|
||||||
|
let name = str(offset, 100);
|
||||||
|
let size = parseInt(str(offset + 124, 12), 8);
|
||||||
|
offset += 512;
|
||||||
|
if (!isNaN(size)) {
|
||||||
|
if (name === subpath) return buffer.subarray(offset, offset + size);
|
||||||
|
offset += size + 511 & ~511;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error(`Could not find ${JSON.stringify(subpath)} in archive`);
|
||||||
|
}
|
||||||
|
function installUsingNPM(pkg, subpath, binPath) {
|
||||||
|
const env = { ...process.env, npm_config_global: void 0 };
|
||||||
|
const esbuildLibDir = path2.dirname(require.resolve("esbuild"));
|
||||||
|
const installDir = path2.join(esbuildLibDir, "npm-install");
|
||||||
|
fs2.mkdirSync(installDir);
|
||||||
|
try {
|
||||||
|
fs2.writeFileSync(path2.join(installDir, "package.json"), "{}");
|
||||||
|
child_process.execSync(
|
||||||
|
`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${pkg}@${versionFromPackageJSON}`,
|
||||||
|
{ cwd: installDir, stdio: "pipe", env }
|
||||||
|
);
|
||||||
|
const installedBinPath = path2.join(installDir, "node_modules", pkg, subpath);
|
||||||
|
fs2.renameSync(installedBinPath, binPath);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
removeRecursive(installDir);
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function removeRecursive(dir) {
|
||||||
|
for (const entry of fs2.readdirSync(dir)) {
|
||||||
|
const entryPath = path2.join(dir, entry);
|
||||||
|
let stats;
|
||||||
|
try {
|
||||||
|
stats = fs2.lstatSync(entryPath);
|
||||||
|
} catch {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (stats.isDirectory()) removeRecursive(entryPath);
|
||||||
|
else fs2.unlinkSync(entryPath);
|
||||||
|
}
|
||||||
|
fs2.rmdirSync(dir);
|
||||||
|
}
|
||||||
|
function applyManualBinaryPathOverride(overridePath) {
|
||||||
|
const pathString = JSON.stringify(overridePath);
|
||||||
|
fs2.writeFileSync(toPath, `#!/usr/bin/env node
|
||||||
|
require('child_process').execFileSync(${pathString}, process.argv.slice(2), { stdio: 'inherit' });
|
||||||
|
`);
|
||||||
|
const libMain = path2.join(__dirname, "lib", "main.js");
|
||||||
|
const code = fs2.readFileSync(libMain, "utf8");
|
||||||
|
fs2.writeFileSync(libMain, `var ESBUILD_BINARY_PATH = ${pathString};
|
||||||
|
${code}`);
|
||||||
|
}
|
||||||
|
function maybeOptimizePackage(binPath) {
|
||||||
|
if (os2.platform() !== "win32" && !isYarn()) {
|
||||||
|
const tempPath = path2.join(__dirname, "bin-esbuild");
|
||||||
|
try {
|
||||||
|
fs2.linkSync(binPath, tempPath);
|
||||||
|
fs2.renameSync(tempPath, toPath);
|
||||||
|
isToPathJS = false;
|
||||||
|
fs2.unlinkSync(tempPath);
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function downloadDirectlyFromNPM(pkg, subpath, binPath) {
|
||||||
|
const url = `https://registry.npmjs.org/${pkg}/-/${pkg.replace("@esbuild/", "")}-${versionFromPackageJSON}.tgz`;
|
||||||
|
console.error(`[esbuild] Trying to download ${JSON.stringify(url)}`);
|
||||||
|
try {
|
||||||
|
fs2.writeFileSync(binPath, extractFileFromTarGzip(await fetch(url), subpath));
|
||||||
|
fs2.chmodSync(binPath, 493);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`[esbuild] Failed to download ${JSON.stringify(url)}: ${e && e.message || e}`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function checkAndPreparePackage() {
|
||||||
|
if (isValidBinaryPath(ESBUILD_BINARY_PATH)) {
|
||||||
|
if (!fs2.existsSync(ESBUILD_BINARY_PATH)) {
|
||||||
|
console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
|
||||||
|
} else {
|
||||||
|
applyManualBinaryPathOverride(ESBUILD_BINARY_PATH);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
|
||||||
|
let binPath;
|
||||||
|
try {
|
||||||
|
binPath = require.resolve(`${pkg}/${subpath}`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`[esbuild] Failed to find package "${pkg}" on the file system
|
||||||
|
|
||||||
|
This can happen if you use the "--no-optional" flag. The "optionalDependencies"
|
||||||
|
package.json feature is used by esbuild to install the correct binary executable
|
||||||
|
for your current platform. This install script will now attempt to work around
|
||||||
|
this. If that fails, you need to remove the "--no-optional" flag to use esbuild.
|
||||||
|
`);
|
||||||
|
binPath = downloadedBinPath(pkg, subpath);
|
||||||
|
try {
|
||||||
|
console.error(`[esbuild] Trying to install package "${pkg}" using npm`);
|
||||||
|
installUsingNPM(pkg, subpath, binPath);
|
||||||
|
} catch (e2) {
|
||||||
|
console.error(`[esbuild] Failed to install package "${pkg}" using npm: ${e2 && e2.message || e2}`);
|
||||||
|
try {
|
||||||
|
await downloadDirectlyFromNPM(pkg, subpath, binPath);
|
||||||
|
} catch (e3) {
|
||||||
|
throw new Error(`Failed to install package "${pkg}"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maybeOptimizePackage(binPath);
|
||||||
|
}
|
||||||
|
checkAndPreparePackage().then(() => {
|
||||||
|
if (isToPathJS) {
|
||||||
|
validateBinaryVersion(process.execPath, toPath);
|
||||||
|
} else {
|
||||||
|
validateBinaryVersion(toPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user