pythonlib 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/base64-C_am75Sv.d.ts +165 -0
- package/dist/base64.d.ts +1 -0
- package/dist/base64.js +37 -0
- package/dist/chunk-2YTO24B5.js +78 -0
- package/dist/chunk-3CLXPGAB.js +237 -0
- package/dist/{chunk-7BZB2TQF.js → chunk-3M3PB4RO.js} +4 -6
- package/dist/chunk-5OKGPZBQ.js +1106 -0
- package/dist/chunk-5VAHUJNC.js +348 -0
- package/dist/chunk-B5AUEOAH.js +193 -0
- package/dist/chunk-B5LQJODJ.js +37 -0
- package/dist/{chunk-CUP6EPDB.js → chunk-BCMGGBWG.js} +2 -5
- package/dist/chunk-BCVIH2BN.js +175 -0
- package/dist/{chunk-QURVRHY2.js → chunk-D35YI363.js} +15 -12
- package/dist/{chunk-RSBRI27Z.js → chunk-ETBW6XNR.js} +3 -4
- package/dist/chunk-FCJ7E4OE.js +250 -0
- package/dist/chunk-HSTC277I.js +255 -0
- package/dist/chunk-IANXD4D4.js +250 -0
- package/dist/{chunk-G6PUQTVZ.js → chunk-JAUU3HMH.js} +1 -2
- package/dist/chunk-JJKTRIVO.js +262 -0
- package/dist/chunk-KKHKTQNN.js +361 -0
- package/dist/chunk-KKJHGY4C.js +551 -0
- package/dist/chunk-LHPQS75Z.js +192 -0
- package/dist/{chunk-OSX7QZAW.js → chunk-LK2L2TFG.js} +5 -6
- package/dist/chunk-LLZFLQS6.js +280 -0
- package/dist/chunk-LTXTS7RP.js +154 -0
- package/dist/{chunk-CEZSBJJV.js → chunk-LWYBTWBZ.js} +2 -3
- package/dist/{chunk-TAYRRHJ3.js → chunk-MFKIEN7N.js} +1 -2
- package/dist/{chunk-PZ5AY32C.js → chunk-MLKGABMK.js} +0 -1
- package/dist/chunk-OZRS5PC4.js +312 -0
- package/dist/chunk-PWA3YQZU.js +346 -0
- package/dist/{chunk-56DGFWIJ.js → chunk-QKJBQKPY.js} +1 -2
- package/dist/chunk-RB6BYCIQ.js +141 -0
- package/dist/chunk-U4X5DEIP.js +188 -0
- package/dist/chunk-UGZ5OY5Z.js +165 -0
- package/dist/chunk-WTZSAITC.js +82 -0
- package/dist/collections.js +2 -3
- package/dist/copy-6ZaZ__ge.d.ts +59 -0
- package/dist/copy.d.ts +1 -0
- package/dist/copy.js +9 -0
- package/dist/datetime.js +2 -3
- package/dist/functools.js +2 -3
- package/dist/glob.browser-B6d_YdV5.d.ts +50 -0
- package/dist/glob.browser.d.ts +1 -0
- package/dist/glob.browser.js +15 -0
- package/dist/glob.node-wn5ehtyM.d.ts +80 -0
- package/dist/glob.node.d.ts +1 -0
- package/dist/glob.node.js +15 -0
- package/dist/hashlib-vKP511NY.d.ts +205 -0
- package/dist/hashlib.d.ts +1 -0
- package/dist/hashlib.js +39 -0
- package/dist/index.browser.d.ts +172 -0
- package/dist/index.browser.js +304 -0
- package/dist/index.d.ts +36 -602
- package/dist/index.js +138 -1073
- package/dist/itertools.js +2 -3
- package/dist/json.js +2 -3
- package/dist/logging.browser-Dux4L5kz.d.ts +185 -0
- package/dist/logging.browser.d.ts +1 -0
- package/dist/logging.browser.js +63 -0
- package/dist/logging.node-CH75bVdE.d.ts +185 -0
- package/dist/logging.node.d.ts +1 -0
- package/dist/logging.node.js +61 -0
- package/dist/math.js +2 -3
- package/dist/{os-CqGKe872.d.ts → os.browser-krjSx5kF.d.ts} +32 -55
- package/dist/os.browser.d.ts +2 -0
- package/dist/{os.js → os.browser.js} +41 -16
- package/dist/os.node-CQjch8Ht.d.ts +124 -0
- package/dist/os.node.d.ts +2 -0
- package/dist/os.node.js +83 -0
- package/dist/os.shared-C3x70nhO.d.ts +59 -0
- package/dist/pathlib.browser-NC7kKQYe.d.ts +91 -0
- package/dist/pathlib.browser.d.ts +1 -0
- package/dist/pathlib.browser.js +17 -0
- package/dist/pathlib.node-CY3yUFdT.d.ts +331 -0
- package/dist/pathlib.node.d.ts +2 -0
- package/dist/pathlib.node.js +17 -0
- package/dist/random.js +2 -3
- package/dist/re.js +2 -3
- package/dist/set-JQbLAq8B.d.ts +592 -0
- package/dist/shutil.browser-Ck5oWhnP.d.ts +113 -0
- package/dist/shutil.browser.d.ts +1 -0
- package/dist/shutil.browser.js +33 -0
- package/dist/shutil.node-C9kwvhAf.d.ts +160 -0
- package/dist/shutil.node.d.ts +2 -0
- package/dist/shutil.node.js +33 -0
- package/dist/string.js +2 -3
- package/dist/subprocess-CZVYzQ3V.d.ts +214 -0
- package/dist/subprocess.d.ts +1 -0
- package/dist/subprocess.js +29 -0
- package/dist/sys-IL8LgI_W.d.ts +212 -0
- package/dist/sys.d.ts +1 -0
- package/dist/sys.js +51 -0
- package/dist/tempfile.browser-DciOKfNm.d.ts +78 -0
- package/dist/tempfile.browser.d.ts +1 -0
- package/dist/tempfile.browser.js +19 -0
- package/dist/tempfile.node-bVMY60Cu.d.ts +195 -0
- package/dist/tempfile.node.d.ts +2 -0
- package/dist/tempfile.node.js +23 -0
- package/dist/time-CcYhdiSu.d.ts +245 -0
- package/dist/time.d.ts +1 -0
- package/dist/time.js +49 -0
- package/dist/urllib-DJtkj-0f.d.ts +198 -0
- package/dist/urllib.d.ts +1 -0
- package/dist/urllib.js +37 -0
- package/dist/uuid-C0ypmn56.d.ts +160 -0
- package/dist/uuid.d.ts +1 -0
- package/dist/uuid.js +23 -0
- package/package.json +127 -5
- package/dist/chunk-56DGFWIJ.js.map +0 -1
- package/dist/chunk-5AOJFFYN.js +0 -313
- package/dist/chunk-5AOJFFYN.js.map +0 -1
- package/dist/chunk-7BZB2TQF.js.map +0 -1
- package/dist/chunk-CEZSBJJV.js.map +0 -1
- package/dist/chunk-CUP6EPDB.js.map +0 -1
- package/dist/chunk-G6PUQTVZ.js.map +0 -1
- package/dist/chunk-OSX7QZAW.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-QURVRHY2.js.map +0 -1
- package/dist/chunk-RSBRI27Z.js.map +0 -1
- package/dist/chunk-TAYRRHJ3.js.map +0 -1
- package/dist/collections.js.map +0 -1
- package/dist/datetime.js.map +0 -1
- package/dist/functools.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/itertools.js.map +0 -1
- package/dist/json.js.map +0 -1
- package/dist/math.js.map +0 -1
- package/dist/os.d.ts +0 -1
- package/dist/os.js.map +0 -1
- package/dist/random.js.map +0 -1
- package/dist/re.js.map +0 -1
- package/dist/string.js.map +0 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
altSep,
|
|
3
|
+
chdir,
|
|
4
|
+
curDir,
|
|
5
|
+
environ,
|
|
6
|
+
extSep,
|
|
7
|
+
getCwd,
|
|
8
|
+
getCwdb,
|
|
9
|
+
getenv,
|
|
10
|
+
lineSep,
|
|
11
|
+
name,
|
|
12
|
+
parDir,
|
|
13
|
+
pathBasename,
|
|
14
|
+
pathCommonPath,
|
|
15
|
+
pathDirname,
|
|
16
|
+
pathExpandUser,
|
|
17
|
+
pathExpandVars,
|
|
18
|
+
pathExtName,
|
|
19
|
+
pathIsAbs,
|
|
20
|
+
pathJoin,
|
|
21
|
+
pathNormPath,
|
|
22
|
+
pathRelPath,
|
|
23
|
+
pathSep,
|
|
24
|
+
pathSplitExt,
|
|
25
|
+
pathSplitFn,
|
|
26
|
+
sep
|
|
27
|
+
} from "./chunk-LHPQS75Z.js";
|
|
28
|
+
import {
|
|
29
|
+
__export
|
|
30
|
+
} from "./chunk-MLKGABMK.js";
|
|
31
|
+
|
|
32
|
+
// src/os.browser.ts
|
|
33
|
+
var os_browser_exports = {};
|
|
34
|
+
__export(os_browser_exports, {
|
|
35
|
+
altSep: () => altSep,
|
|
36
|
+
chdir: () => chdir,
|
|
37
|
+
curDir: () => curDir,
|
|
38
|
+
environ: () => environ,
|
|
39
|
+
extSep: () => extSep,
|
|
40
|
+
getCwd: () => getCwd,
|
|
41
|
+
getCwdb: () => getCwdb,
|
|
42
|
+
getenv: () => getenv,
|
|
43
|
+
lineSep: () => lineSep,
|
|
44
|
+
listDir: () => listDir,
|
|
45
|
+
makeDirs: () => makeDirs,
|
|
46
|
+
mkdir: () => mkdir,
|
|
47
|
+
name: () => name,
|
|
48
|
+
parDir: () => parDir,
|
|
49
|
+
path: () => path,
|
|
50
|
+
pathBasename: () => pathBasename,
|
|
51
|
+
pathCommonPath: () => pathCommonPath,
|
|
52
|
+
pathDirname: () => pathDirname,
|
|
53
|
+
pathExpandUser: () => pathExpandUser,
|
|
54
|
+
pathExpandVars: () => pathExpandVars,
|
|
55
|
+
pathExtName: () => pathExtName,
|
|
56
|
+
pathIsAbs: () => pathIsAbs,
|
|
57
|
+
pathJoin: () => pathJoin,
|
|
58
|
+
pathNormPath: () => pathNormPath,
|
|
59
|
+
pathRelPath: () => pathRelPath,
|
|
60
|
+
pathSep: () => pathSep,
|
|
61
|
+
pathSplitExt: () => pathSplitExt,
|
|
62
|
+
pathSplitFn: () => pathSplitFn,
|
|
63
|
+
remove: () => remove,
|
|
64
|
+
removeDirs: () => removeDirs,
|
|
65
|
+
rename: () => rename,
|
|
66
|
+
renames: () => renames,
|
|
67
|
+
replace: () => replace,
|
|
68
|
+
rmdir: () => rmdir,
|
|
69
|
+
sep: () => sep,
|
|
70
|
+
stat: () => stat,
|
|
71
|
+
unlink: () => unlink,
|
|
72
|
+
walk: () => walk
|
|
73
|
+
});
|
|
74
|
+
var path = {
|
|
75
|
+
join: pathJoin,
|
|
76
|
+
basename: pathBasename,
|
|
77
|
+
dirname: pathDirname,
|
|
78
|
+
split: pathSplitFn,
|
|
79
|
+
splitExt: pathSplitExt,
|
|
80
|
+
extName: pathExtName,
|
|
81
|
+
isAbs: pathIsAbs,
|
|
82
|
+
normPath: pathNormPath,
|
|
83
|
+
relPath: pathRelPath,
|
|
84
|
+
commonPath: pathCommonPath,
|
|
85
|
+
expandUser: pathExpandUser,
|
|
86
|
+
expandVars: pathExpandVars,
|
|
87
|
+
/** Return normalized absolutized version of pathname */
|
|
88
|
+
absPath(p) {
|
|
89
|
+
if (pathIsAbs(p)) {
|
|
90
|
+
return pathNormPath(p);
|
|
91
|
+
}
|
|
92
|
+
return pathNormPath(p);
|
|
93
|
+
},
|
|
94
|
+
/** Return canonical path, eliminating symlinks (stub - just normalizes) */
|
|
95
|
+
realPath(p) {
|
|
96
|
+
return path.absPath(p);
|
|
97
|
+
},
|
|
98
|
+
/* v8 ignore start -- browser stubs @preserve */
|
|
99
|
+
/** Test if path exists (stub - always returns false in browser) */
|
|
100
|
+
exists(_p) {
|
|
101
|
+
return false;
|
|
102
|
+
},
|
|
103
|
+
/** Test if path is a file (stub - always returns false in browser) */
|
|
104
|
+
isFile(_p) {
|
|
105
|
+
return false;
|
|
106
|
+
},
|
|
107
|
+
/** Test if path is a directory (stub - always returns false in browser) */
|
|
108
|
+
isDir(_p) {
|
|
109
|
+
return false;
|
|
110
|
+
},
|
|
111
|
+
/** Test if path is a symbolic link (stub - always returns false in browser) */
|
|
112
|
+
isLink(_p) {
|
|
113
|
+
return false;
|
|
114
|
+
},
|
|
115
|
+
/** Return size of file (stub - returns 0 in browser) */
|
|
116
|
+
getSize(_p) {
|
|
117
|
+
return 0;
|
|
118
|
+
},
|
|
119
|
+
/** Return modification time (stub - returns 0 in browser) */
|
|
120
|
+
getMtime(_p) {
|
|
121
|
+
return 0;
|
|
122
|
+
},
|
|
123
|
+
/** Return access time (stub - returns 0 in browser) */
|
|
124
|
+
getAtime(_p) {
|
|
125
|
+
return 0;
|
|
126
|
+
},
|
|
127
|
+
/** Return creation time (stub - returns 0 in browser) */
|
|
128
|
+
getCtime(_p) {
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
/* v8 ignore stop */
|
|
132
|
+
};
|
|
133
|
+
function listDir(_p = ".") {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
function mkdir(_p, _mode = 511) {
|
|
137
|
+
}
|
|
138
|
+
function makeDirs(_p, _mode = 511, _existOk = false) {
|
|
139
|
+
}
|
|
140
|
+
function remove(_p) {
|
|
141
|
+
}
|
|
142
|
+
var unlink = remove;
|
|
143
|
+
function rmdir(_p) {
|
|
144
|
+
}
|
|
145
|
+
function removeDirs(_p) {
|
|
146
|
+
}
|
|
147
|
+
function rename(_src, _dst) {
|
|
148
|
+
}
|
|
149
|
+
function renames(_src, _dst) {
|
|
150
|
+
}
|
|
151
|
+
function replace(_src, _dst) {
|
|
152
|
+
}
|
|
153
|
+
function* walk(_top, _options) {
|
|
154
|
+
}
|
|
155
|
+
function stat(_p) {
|
|
156
|
+
return { st_mode: 0, st_size: 0, st_mtime: 0, st_atime: 0, st_ctime: 0 };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export {
|
|
160
|
+
path,
|
|
161
|
+
listDir,
|
|
162
|
+
mkdir,
|
|
163
|
+
makeDirs,
|
|
164
|
+
remove,
|
|
165
|
+
unlink,
|
|
166
|
+
rmdir,
|
|
167
|
+
removeDirs,
|
|
168
|
+
rename,
|
|
169
|
+
renames,
|
|
170
|
+
replace,
|
|
171
|
+
walk,
|
|
172
|
+
stat,
|
|
173
|
+
os_browser_exports
|
|
174
|
+
};
|
|
175
|
+
/* v8 ignore start -- browser stubs for filesystem operations @preserve */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__export
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
4
|
|
|
5
5
|
// src/functools.ts
|
|
6
6
|
var functools_exports = {};
|
|
@@ -54,14 +54,15 @@ function lruCache(func, maxsize = 128) {
|
|
|
54
54
|
let misses = 0;
|
|
55
55
|
const cached = ((...args) => {
|
|
56
56
|
const key = JSON.stringify(args);
|
|
57
|
-
|
|
57
|
+
const entry = cache2.get(key);
|
|
58
|
+
if (entry !== void 0) {
|
|
58
59
|
hits++;
|
|
59
60
|
const idx = order.indexOf(key);
|
|
60
61
|
if (idx > -1) {
|
|
61
62
|
order.splice(idx, 1);
|
|
62
63
|
order.push(key);
|
|
63
64
|
}
|
|
64
|
-
return
|
|
65
|
+
return entry.value;
|
|
65
66
|
}
|
|
66
67
|
misses++;
|
|
67
68
|
const result = func(...args);
|
|
@@ -71,7 +72,7 @@ function lruCache(func, maxsize = 128) {
|
|
|
71
72
|
cache2.delete(oldest);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
|
-
cache2.set(key, result);
|
|
75
|
+
cache2.set(key, { value: result });
|
|
75
76
|
order.push(key);
|
|
76
77
|
return result;
|
|
77
78
|
});
|
|
@@ -93,11 +94,12 @@ function cache(func) {
|
|
|
93
94
|
const cacheMap = /* @__PURE__ */ new Map();
|
|
94
95
|
return ((...args) => {
|
|
95
96
|
const key = JSON.stringify(args);
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
const entry = cacheMap.get(key);
|
|
98
|
+
if (entry !== void 0) {
|
|
99
|
+
return entry.value;
|
|
98
100
|
}
|
|
99
101
|
const result = func(...args);
|
|
100
|
-
cacheMap.set(key, result);
|
|
102
|
+
cacheMap.set(key, { value: result });
|
|
101
103
|
return result;
|
|
102
104
|
});
|
|
103
105
|
}
|
|
@@ -135,8 +137,9 @@ function wraps(wrapped) {
|
|
|
135
137
|
};
|
|
136
138
|
}
|
|
137
139
|
function attrGetter(...attrs) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
const [firstAttr] = attrs;
|
|
141
|
+
if (attrs.length === 1 && firstAttr !== void 0) {
|
|
142
|
+
const attr = firstAttr;
|
|
140
143
|
const parts = attr.split(".");
|
|
141
144
|
return (obj) => {
|
|
142
145
|
let result = obj;
|
|
@@ -158,8 +161,9 @@ function attrGetter(...attrs) {
|
|
|
158
161
|
};
|
|
159
162
|
}
|
|
160
163
|
function itemGetter(...items) {
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
const [firstItem] = items;
|
|
165
|
+
if (items.length === 1 && firstItem !== void 0) {
|
|
166
|
+
const item = firstItem;
|
|
163
167
|
return (obj) => {
|
|
164
168
|
if (Array.isArray(obj) && typeof item === "number") {
|
|
165
169
|
return obj[item];
|
|
@@ -248,4 +252,3 @@ export {
|
|
|
248
252
|
functools_exports
|
|
249
253
|
};
|
|
250
254
|
/* v8 ignore start -- complex utility rarely used directly @preserve */
|
|
251
|
-
//# sourceMappingURL=chunk-QURVRHY2.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__export
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
4
|
|
|
5
5
|
// src/re.ts
|
|
6
6
|
var re_exports = {};
|
|
@@ -144,8 +144,8 @@ var Match = class {
|
|
|
144
144
|
}
|
|
145
145
|
/** Return iterator of all groups */
|
|
146
146
|
*[Symbol.iterator]() {
|
|
147
|
-
for (
|
|
148
|
-
yield
|
|
147
|
+
for (const match2 of this._match) {
|
|
148
|
+
yield match2;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
toString() {
|
|
@@ -420,4 +420,3 @@ export {
|
|
|
420
420
|
purge,
|
|
421
421
|
re_exports
|
|
422
422
|
};
|
|
423
|
-
//# sourceMappingURL=chunk-RSBRI27Z.js.map
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
|
+
|
|
5
|
+
// src/uuid.ts
|
|
6
|
+
var uuid_exports = {};
|
|
7
|
+
__export(uuid_exports, {
|
|
8
|
+
NAMESPACE_DNS: () => NAMESPACE_DNS,
|
|
9
|
+
NAMESPACE_OID: () => NAMESPACE_OID,
|
|
10
|
+
NAMESPACE_URL: () => NAMESPACE_URL,
|
|
11
|
+
NAMESPACE_X500: () => NAMESPACE_X500,
|
|
12
|
+
UUID: () => UUID,
|
|
13
|
+
uuid1: () => uuid1,
|
|
14
|
+
uuid3: () => uuid3,
|
|
15
|
+
uuid4: () => uuid4,
|
|
16
|
+
uuid5: () => uuid5
|
|
17
|
+
});
|
|
18
|
+
var UUID = class _UUID {
|
|
19
|
+
_bytes;
|
|
20
|
+
/** Helper to safely get byte at index */
|
|
21
|
+
getByte(index) {
|
|
22
|
+
return this._bytes[index] ?? 0;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a UUID from various input formats.
|
|
26
|
+
*
|
|
27
|
+
* @param hex - Hexadecimal string (with or without hyphens)
|
|
28
|
+
* @param bytes - 16 bytes as Uint8Array
|
|
29
|
+
* @param int - Integer value
|
|
30
|
+
*/
|
|
31
|
+
constructor(options) {
|
|
32
|
+
if (typeof options === "string") {
|
|
33
|
+
options = { hex: options };
|
|
34
|
+
}
|
|
35
|
+
if ("hex" in options) {
|
|
36
|
+
const hex = options.hex.replace(/-/g, "").replace(/[{}]/g, "");
|
|
37
|
+
if (hex.length !== 32) {
|
|
38
|
+
throw new Error("badly formed hexadecimal UUID string");
|
|
39
|
+
}
|
|
40
|
+
this._bytes = new Uint8Array(16);
|
|
41
|
+
for (let i = 0; i < 16; i++) {
|
|
42
|
+
this._bytes[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
43
|
+
}
|
|
44
|
+
} else if ("bytes" in options) {
|
|
45
|
+
if (options.bytes.length !== 16) {
|
|
46
|
+
throw new Error("bytes must be a 16-byte array");
|
|
47
|
+
}
|
|
48
|
+
this._bytes = new Uint8Array(options.bytes);
|
|
49
|
+
} else if ("int" in options) {
|
|
50
|
+
this._bytes = new Uint8Array(16);
|
|
51
|
+
let value = options.int;
|
|
52
|
+
for (let i = 15; i >= 0; i--) {
|
|
53
|
+
this._bytes[i] = Number(value & 0xffn);
|
|
54
|
+
value = value >> 8n;
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
throw new Error("one of hex, bytes, or int is required");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The UUID as a 32-character lowercase hexadecimal string.
|
|
62
|
+
*/
|
|
63
|
+
get hex() {
|
|
64
|
+
let result = "";
|
|
65
|
+
for (const byte of this._bytes) {
|
|
66
|
+
result += byte.toString(16).padStart(2, "0");
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The UUID as a 16-byte Uint8Array.
|
|
72
|
+
*/
|
|
73
|
+
get bytes() {
|
|
74
|
+
return new Uint8Array(this._bytes);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The UUID as a 128-bit integer.
|
|
78
|
+
*/
|
|
79
|
+
get int() {
|
|
80
|
+
let value = 0n;
|
|
81
|
+
for (const byte of this._bytes) {
|
|
82
|
+
value = value << 8n | BigInt(byte);
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The version number (1 through 5, as an integer).
|
|
88
|
+
*/
|
|
89
|
+
get version() {
|
|
90
|
+
return this.getByte(6) >> 4 & 15;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The variant (reserved bits).
|
|
94
|
+
*/
|
|
95
|
+
get variant() {
|
|
96
|
+
const byte = this.getByte(8);
|
|
97
|
+
if ((byte & 128) === 0) {
|
|
98
|
+
return "reserved for NCS compatibility";
|
|
99
|
+
} else if ((byte & 192) === 128) {
|
|
100
|
+
return "specified in RFC 4122";
|
|
101
|
+
} else if ((byte & 224) === 192) {
|
|
102
|
+
return "reserved for Microsoft compatibility";
|
|
103
|
+
} else {
|
|
104
|
+
return "reserved for future definition";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The UUID as a hyphenated string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
|
|
109
|
+
*/
|
|
110
|
+
toString() {
|
|
111
|
+
const h = this.hex;
|
|
112
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The UUID as a URN (urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
|
|
116
|
+
*/
|
|
117
|
+
get urn() {
|
|
118
|
+
return `urn:uuid:${this.toString()}`;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Compare UUIDs for equality.
|
|
122
|
+
*/
|
|
123
|
+
equals(other) {
|
|
124
|
+
if (!(other instanceof _UUID)) return false;
|
|
125
|
+
for (let i = 0; i < 16; i++) {
|
|
126
|
+
if (this._bytes[i] !== other._bytes[i]) return false;
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get the time_low field (first 32 bits).
|
|
132
|
+
*/
|
|
133
|
+
get timeLow() {
|
|
134
|
+
return (this.getByte(0) << 24 | this.getByte(1) << 16 | this.getByte(2) << 8 | this.getByte(3)) >>> 0;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get the time_mid field (next 16 bits).
|
|
138
|
+
*/
|
|
139
|
+
get timeMid() {
|
|
140
|
+
return this.getByte(4) << 8 | this.getByte(5);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get the time_hi_version field (next 16 bits).
|
|
144
|
+
*/
|
|
145
|
+
get timeHiVersion() {
|
|
146
|
+
return this.getByte(6) << 8 | this.getByte(7);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get the clock_seq_hi_variant field.
|
|
150
|
+
*/
|
|
151
|
+
get clockSeqHiVariant() {
|
|
152
|
+
return this.getByte(8);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get the clock_seq_low field.
|
|
156
|
+
*/
|
|
157
|
+
get clockSeqLow() {
|
|
158
|
+
return this.getByte(9);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get the node field (last 48 bits).
|
|
162
|
+
*/
|
|
163
|
+
get node() {
|
|
164
|
+
let value = 0n;
|
|
165
|
+
for (let i = 10; i < 16; i++) {
|
|
166
|
+
value = value << 8n | BigInt(this.getByte(i));
|
|
167
|
+
}
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
function uuid4() {
|
|
172
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
173
|
+
return new UUID({ hex: crypto.randomUUID() });
|
|
174
|
+
}
|
|
175
|
+
const bytes = new Uint8Array(16);
|
|
176
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
177
|
+
crypto.getRandomValues(bytes);
|
|
178
|
+
} else {
|
|
179
|
+
for (let i = 0; i < 16; i++) {
|
|
180
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
bytes[6] = (bytes[6] ?? 0) & 15 | 64;
|
|
184
|
+
bytes[8] = (bytes[8] ?? 0) & 63 | 128;
|
|
185
|
+
return new UUID({ bytes });
|
|
186
|
+
}
|
|
187
|
+
function uuid1(node, clockSeq) {
|
|
188
|
+
const bytes = new Uint8Array(16);
|
|
189
|
+
const now = Date.now();
|
|
190
|
+
const UUID_EPOCH_OFFSET = 122192928000000000n;
|
|
191
|
+
const timestamp = BigInt(now) * 10000n + UUID_EPOCH_OFFSET;
|
|
192
|
+
const timeLow = Number(timestamp & 0xffffffffn);
|
|
193
|
+
bytes[0] = timeLow >> 24 & 255;
|
|
194
|
+
bytes[1] = timeLow >> 16 & 255;
|
|
195
|
+
bytes[2] = timeLow >> 8 & 255;
|
|
196
|
+
bytes[3] = timeLow & 255;
|
|
197
|
+
const timeMid = Number(timestamp >> 32n & 0xffffn);
|
|
198
|
+
bytes[4] = timeMid >> 8 & 255;
|
|
199
|
+
bytes[5] = timeMid & 255;
|
|
200
|
+
const timeHi = Number(timestamp >> 48n & 0x0fffn);
|
|
201
|
+
bytes[6] = timeHi >> 8 & 15 | 16;
|
|
202
|
+
bytes[7] = timeHi & 255;
|
|
203
|
+
const seq = clockSeq ?? Math.floor(Math.random() * 16384);
|
|
204
|
+
bytes[8] = seq >> 8 & 63 | 128;
|
|
205
|
+
bytes[9] = seq & 255;
|
|
206
|
+
let nodeId = node;
|
|
207
|
+
if (nodeId === void 0) {
|
|
208
|
+
const randomNode = new Uint8Array(6);
|
|
209
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
210
|
+
crypto.getRandomValues(randomNode);
|
|
211
|
+
} else {
|
|
212
|
+
for (let i = 0; i < 6; i++) {
|
|
213
|
+
randomNode[i] = Math.floor(Math.random() * 256);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
randomNode[0] = (randomNode[0] ?? 0) | 1;
|
|
217
|
+
nodeId = 0n;
|
|
218
|
+
for (const byte of randomNode) {
|
|
219
|
+
nodeId = nodeId << 8n | BigInt(byte);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (let i = 15; i >= 10; i--) {
|
|
223
|
+
bytes[i] = Number(nodeId & 0xffn);
|
|
224
|
+
nodeId = nodeId >> 8n;
|
|
225
|
+
}
|
|
226
|
+
return new UUID({ bytes });
|
|
227
|
+
}
|
|
228
|
+
function uuid3(_namespace, _name) {
|
|
229
|
+
throw new Error("uuid3 requires hashlib.md5 - import from 'pythonlib/hashlib'");
|
|
230
|
+
}
|
|
231
|
+
function uuid5(_namespace, _name) {
|
|
232
|
+
throw new Error("uuid5 requires hashlib.sha1 - import from 'pythonlib/hashlib'");
|
|
233
|
+
}
|
|
234
|
+
var NAMESPACE_DNS = new UUID({ hex: "6ba7b810-9dad-11d1-80b4-00c04fd430c8" });
|
|
235
|
+
var NAMESPACE_URL = new UUID({ hex: "6ba7b811-9dad-11d1-80b4-00c04fd430c8" });
|
|
236
|
+
var NAMESPACE_OID = new UUID({ hex: "6ba7b812-9dad-11d1-80b4-00c04fd430c8" });
|
|
237
|
+
var NAMESPACE_X500 = new UUID({ hex: "6ba7b814-9dad-11d1-80b4-00c04fd430c8" });
|
|
238
|
+
|
|
239
|
+
export {
|
|
240
|
+
UUID,
|
|
241
|
+
uuid4,
|
|
242
|
+
uuid1,
|
|
243
|
+
uuid3,
|
|
244
|
+
uuid5,
|
|
245
|
+
NAMESPACE_DNS,
|
|
246
|
+
NAMESPACE_URL,
|
|
247
|
+
NAMESPACE_OID,
|
|
248
|
+
NAMESPACE_X500,
|
|
249
|
+
uuid_exports
|
|
250
|
+
};
|