pythonlib 1.0.1 → 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-H76SKASU.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-HQ42WNKZ.js → chunk-BCMGGBWG.js} +2 -5
- package/dist/chunk-BCVIH2BN.js +175 -0
- package/dist/{chunk-EE7SK2GV.js → chunk-D35YI363.js} +15 -12
- package/dist/{chunk-7TH4FCVQ.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-4KYJT3DR.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-LWO6BIAD.js → chunk-LK2L2TFG.js} +5 -6
- package/dist/chunk-LLZFLQS6.js +280 -0
- package/dist/chunk-LTXTS7RP.js +154 -0
- package/dist/{chunk-4QG3772L.js → chunk-LWYBTWBZ.js} +2 -3
- package/dist/{chunk-6ZAJ37MR.js → chunk-MFKIEN7N.js} +3 -3
- 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-6POEDI34.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-CJur5Wg-.d.ts → collections-BthXtkEp.d.ts} +5 -1
- package/dist/collections.d.ts +1 -1
- 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-Bpce8gG2.d.ts → datetime-BM_IjhTq.d.ts} +3 -1
- package/dist/datetime.d.ts +1 -1
- package/dist/datetime.js +2 -3
- package/dist/{functools-NrsZAqJk.d.ts → functools-uIa5g75p.d.ts} +3 -1
- package/dist/functools.d.ts +1 -1
- 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 +61 -437
- package/dist/index.js +138 -1115
- package/dist/{itertools-Sjl1LB_0.d.ts → itertools-T0rwOk2j.d.ts} +2 -4
- package/dist/itertools.d.ts +1 -1
- package/dist/itertools.js +2 -3
- package/dist/{json-DAlvCadU.d.ts → json-DoWhX04T.d.ts} +1 -0
- package/dist/json.d.ts +1 -1
- 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-DwEGjjQ-.d.ts → math-D2NPMc-x.d.ts} +2 -1
- package/dist/math.d.ts +1 -1
- package/dist/math.js +2 -3
- package/dist/{os-C6Nt7Ijx.d.ts → os.browser-krjSx5kF.d.ts} +32 -54
- 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-BJv_rSpL.d.ts → random-DcS5jtEs.d.ts} +3 -5
- package/dist/random.d.ts +1 -1
- package/dist/random.js +2 -3
- package/dist/{re-B1CHCgyr.d.ts → re-Bo-IOqov.d.ts} +3 -7
- package/dist/re.d.ts +1 -1
- 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.d.ts +3 -1
- 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-4KYJT3DR.js.map +0 -1
- package/dist/chunk-4QG3772L.js.map +0 -1
- package/dist/chunk-6POEDI34.js.map +0 -1
- package/dist/chunk-6ZAJ37MR.js.map +0 -1
- package/dist/chunk-7TH4FCVQ.js.map +0 -1
- package/dist/chunk-CXKGPD5D.js +0 -313
- package/dist/chunk-CXKGPD5D.js.map +0 -1
- package/dist/chunk-EE7SK2GV.js.map +0 -1
- package/dist/chunk-H76SKASU.js.map +0 -1
- package/dist/chunk-HQ42WNKZ.js.map +0 -1
- package/dist/chunk-LWO6BIAD.js.map +0 -1
- package/dist/chunk-PZ5AY32C.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,262 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
|
+
|
|
5
|
+
// src/hashlib.ts
|
|
6
|
+
var hashlib_exports = {};
|
|
7
|
+
__export(hashlib_exports, {
|
|
8
|
+
algorithmsAvailable: () => algorithmsAvailable,
|
|
9
|
+
algorithmsGuaranteed: () => algorithmsGuaranteed,
|
|
10
|
+
blake2b: () => blake2b,
|
|
11
|
+
blake2s: () => blake2s,
|
|
12
|
+
compareDigest: () => compareDigest,
|
|
13
|
+
fileDigest: () => fileDigest,
|
|
14
|
+
md5: () => md5,
|
|
15
|
+
newHash: () => newHash,
|
|
16
|
+
pbkdf2Hmac: () => pbkdf2Hmac,
|
|
17
|
+
scrypt: () => scrypt,
|
|
18
|
+
sha1: () => sha1,
|
|
19
|
+
sha224: () => sha224,
|
|
20
|
+
sha256: () => sha256,
|
|
21
|
+
sha384: () => sha384,
|
|
22
|
+
sha3_256: () => sha3_256,
|
|
23
|
+
sha3_512: () => sha3_512,
|
|
24
|
+
sha512: () => sha512
|
|
25
|
+
});
|
|
26
|
+
var ALGORITHM_INFO = {
|
|
27
|
+
md5: { digestSize: 16, blockSize: 64 },
|
|
28
|
+
// Not in Web Crypto
|
|
29
|
+
sha1: { digestSize: 20, blockSize: 64, webCryptoName: "SHA-1" },
|
|
30
|
+
sha224: { digestSize: 28, blockSize: 64 },
|
|
31
|
+
// Not in Web Crypto
|
|
32
|
+
sha256: { digestSize: 32, blockSize: 64, webCryptoName: "SHA-256" },
|
|
33
|
+
sha384: { digestSize: 48, blockSize: 128, webCryptoName: "SHA-384" },
|
|
34
|
+
sha512: { digestSize: 64, blockSize: 128, webCryptoName: "SHA-512" },
|
|
35
|
+
"sha3-256": { digestSize: 32, blockSize: 136 },
|
|
36
|
+
// Not in Web Crypto
|
|
37
|
+
"sha3-512": { digestSize: 64, blockSize: 72 },
|
|
38
|
+
// Not in Web Crypto
|
|
39
|
+
blake2b512: { digestSize: 64, blockSize: 128 },
|
|
40
|
+
// Not in Web Crypto
|
|
41
|
+
blake2s256: { digestSize: 32, blockSize: 64 }
|
|
42
|
+
// Not in Web Crypto
|
|
43
|
+
};
|
|
44
|
+
var isNode = typeof process !== "undefined" && typeof process.versions?.node === "string";
|
|
45
|
+
var nodeCrypto;
|
|
46
|
+
async function getNodeCrypto() {
|
|
47
|
+
nodeCrypto ??= await import("crypto");
|
|
48
|
+
return nodeCrypto;
|
|
49
|
+
}
|
|
50
|
+
function stringToBytes(str) {
|
|
51
|
+
return new TextEncoder().encode(str);
|
|
52
|
+
}
|
|
53
|
+
function bytesToHex(bytes) {
|
|
54
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
55
|
+
}
|
|
56
|
+
function createHashObject(algorithm, initialData) {
|
|
57
|
+
const normalizedAlgorithm = algorithm.toLowerCase();
|
|
58
|
+
const info = ALGORITHM_INFO[normalizedAlgorithm] ?? { digestSize: 32, blockSize: 64 };
|
|
59
|
+
const dataChunks = [];
|
|
60
|
+
if (initialData) {
|
|
61
|
+
dataChunks.push(initialData);
|
|
62
|
+
}
|
|
63
|
+
const hashObject = {
|
|
64
|
+
name: normalizedAlgorithm,
|
|
65
|
+
digestSize: info.digestSize,
|
|
66
|
+
blockSize: info.blockSize,
|
|
67
|
+
update(data) {
|
|
68
|
+
const bytes = typeof data === "string" ? stringToBytes(data) : data;
|
|
69
|
+
dataChunks.push(bytes);
|
|
70
|
+
},
|
|
71
|
+
async digest() {
|
|
72
|
+
const totalLength = dataChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
73
|
+
const allData = new Uint8Array(totalLength);
|
|
74
|
+
let offset = 0;
|
|
75
|
+
for (const chunk of dataChunks) {
|
|
76
|
+
allData.set(chunk, offset);
|
|
77
|
+
offset += chunk.length;
|
|
78
|
+
}
|
|
79
|
+
if (isNode) {
|
|
80
|
+
const crypto2 = await getNodeCrypto();
|
|
81
|
+
const hash = crypto2.createHash(normalizedAlgorithm);
|
|
82
|
+
hash.update(allData);
|
|
83
|
+
return new Uint8Array(hash.digest());
|
|
84
|
+
} else {
|
|
85
|
+
const webCryptoName = info.webCryptoName;
|
|
86
|
+
if (!webCryptoName) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Algorithm "${normalizedAlgorithm}" is not available in Web Crypto API. Available algorithms: SHA-1, SHA-256, SHA-384, SHA-512`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const hashBuffer = await crypto.subtle.digest(webCryptoName, allData);
|
|
92
|
+
return new Uint8Array(hashBuffer);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async hexdigest() {
|
|
96
|
+
const digestBytes = await this.digest();
|
|
97
|
+
return bytesToHex(digestBytes);
|
|
98
|
+
},
|
|
99
|
+
copy() {
|
|
100
|
+
const totalLength = dataChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
101
|
+
const allData = new Uint8Array(totalLength);
|
|
102
|
+
let offset = 0;
|
|
103
|
+
for (const chunk of dataChunks) {
|
|
104
|
+
allData.set(chunk, offset);
|
|
105
|
+
offset += chunk.length;
|
|
106
|
+
}
|
|
107
|
+
return createHashObject(algorithm, allData);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return hashObject;
|
|
111
|
+
}
|
|
112
|
+
function newHash(name, data) {
|
|
113
|
+
const hash = createHashObject(name);
|
|
114
|
+
if (data !== void 0) {
|
|
115
|
+
hash.update(data);
|
|
116
|
+
}
|
|
117
|
+
return hash;
|
|
118
|
+
}
|
|
119
|
+
function md5(data) {
|
|
120
|
+
return newHash("md5", data);
|
|
121
|
+
}
|
|
122
|
+
function sha1(data) {
|
|
123
|
+
return newHash("sha1", data);
|
|
124
|
+
}
|
|
125
|
+
function sha224(data) {
|
|
126
|
+
return newHash("sha224", data);
|
|
127
|
+
}
|
|
128
|
+
function sha256(data) {
|
|
129
|
+
return newHash("sha256", data);
|
|
130
|
+
}
|
|
131
|
+
function sha384(data) {
|
|
132
|
+
return newHash("sha384", data);
|
|
133
|
+
}
|
|
134
|
+
function sha512(data) {
|
|
135
|
+
return newHash("sha512", data);
|
|
136
|
+
}
|
|
137
|
+
function sha3_256(data) {
|
|
138
|
+
return newHash("sha3-256", data);
|
|
139
|
+
}
|
|
140
|
+
function sha3_512(data) {
|
|
141
|
+
return newHash("sha3-512", data);
|
|
142
|
+
}
|
|
143
|
+
function blake2b(data) {
|
|
144
|
+
return newHash("blake2b512", data);
|
|
145
|
+
}
|
|
146
|
+
function blake2s(data) {
|
|
147
|
+
return newHash("blake2s256", data);
|
|
148
|
+
}
|
|
149
|
+
var algorithmsAvailable = /* @__PURE__ */ new Set([
|
|
150
|
+
"md5",
|
|
151
|
+
"sha1",
|
|
152
|
+
"sha224",
|
|
153
|
+
"sha256",
|
|
154
|
+
"sha384",
|
|
155
|
+
"sha512",
|
|
156
|
+
"sha3-256",
|
|
157
|
+
"sha3-512",
|
|
158
|
+
"blake2b512",
|
|
159
|
+
"blake2s256"
|
|
160
|
+
]);
|
|
161
|
+
var algorithmsGuaranteed = /* @__PURE__ */ new Set(["sha1", "sha256", "sha384", "sha512"]);
|
|
162
|
+
async function pbkdf2Hmac(hashName, password, salt, iterations, dklen) {
|
|
163
|
+
const passwordBytes = typeof password === "string" ? stringToBytes(password) : password;
|
|
164
|
+
const saltBytes = typeof salt === "string" ? stringToBytes(salt) : salt;
|
|
165
|
+
if (isNode) {
|
|
166
|
+
const crypto2 = await getNodeCrypto();
|
|
167
|
+
return new Uint8Array(crypto2.pbkdf2Sync(passwordBytes, saltBytes, iterations, dklen, hashName));
|
|
168
|
+
} else {
|
|
169
|
+
const info = ALGORITHM_INFO[hashName.toLowerCase()];
|
|
170
|
+
const webCryptoName = info?.webCryptoName;
|
|
171
|
+
if (!webCryptoName) {
|
|
172
|
+
throw new Error(`Algorithm "${hashName}" is not available in Web Crypto API`);
|
|
173
|
+
}
|
|
174
|
+
const keyMaterial = await crypto.subtle.importKey("raw", passwordBytes, "PBKDF2", false, [
|
|
175
|
+
"deriveBits"
|
|
176
|
+
]);
|
|
177
|
+
const derivedBits = await crypto.subtle.deriveBits(
|
|
178
|
+
{
|
|
179
|
+
name: "PBKDF2",
|
|
180
|
+
salt: saltBytes,
|
|
181
|
+
iterations,
|
|
182
|
+
hash: webCryptoName
|
|
183
|
+
},
|
|
184
|
+
keyMaterial,
|
|
185
|
+
dklen * 8
|
|
186
|
+
);
|
|
187
|
+
return new Uint8Array(derivedBits);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async function scrypt(password, salt, n, r, p, dklen) {
|
|
191
|
+
if (!isNode) {
|
|
192
|
+
throw new Error("scrypt is only available in Node.js, not in browser environments");
|
|
193
|
+
}
|
|
194
|
+
const crypto2 = await getNodeCrypto();
|
|
195
|
+
const passwordBytes = typeof password === "string" ? stringToBytes(password) : password;
|
|
196
|
+
const saltBytes = typeof salt === "string" ? stringToBytes(salt) : salt;
|
|
197
|
+
return new Uint8Array(
|
|
198
|
+
crypto2.scryptSync(passwordBytes, saltBytes, dklen, {
|
|
199
|
+
N: n,
|
|
200
|
+
r,
|
|
201
|
+
p
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
async function compareDigest(a, b) {
|
|
206
|
+
const aBytes = typeof a === "string" ? stringToBytes(a) : a;
|
|
207
|
+
const bBytes = typeof b === "string" ? stringToBytes(b) : b;
|
|
208
|
+
if (aBytes.length !== bBytes.length) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
if (isNode) {
|
|
212
|
+
const crypto2 = await getNodeCrypto();
|
|
213
|
+
return crypto2.timingSafeEqual(aBytes, bBytes);
|
|
214
|
+
} else {
|
|
215
|
+
let result = 0;
|
|
216
|
+
for (let i = 0; i < aBytes.length; i++) {
|
|
217
|
+
const aByte = aBytes[i] ?? 0;
|
|
218
|
+
const bByte = bBytes[i] ?? 0;
|
|
219
|
+
result |= aByte ^ bByte;
|
|
220
|
+
}
|
|
221
|
+
return result === 0;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async function fileDigest(path, algorithm = "sha256") {
|
|
225
|
+
if (!isNode) {
|
|
226
|
+
throw new Error("fileDigest is only available in Node.js");
|
|
227
|
+
}
|
|
228
|
+
const crypto2 = await getNodeCrypto();
|
|
229
|
+
const fs = await import("fs");
|
|
230
|
+
return new Promise((resolve, reject) => {
|
|
231
|
+
const hash = crypto2.createHash(algorithm);
|
|
232
|
+
const stream = fs.createReadStream(path);
|
|
233
|
+
stream.on("data", (data) => {
|
|
234
|
+
hash.update(data);
|
|
235
|
+
});
|
|
236
|
+
stream.on("end", () => {
|
|
237
|
+
resolve(hash.digest("hex"));
|
|
238
|
+
});
|
|
239
|
+
stream.on("error", reject);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export {
|
|
244
|
+
newHash,
|
|
245
|
+
md5,
|
|
246
|
+
sha1,
|
|
247
|
+
sha224,
|
|
248
|
+
sha256,
|
|
249
|
+
sha384,
|
|
250
|
+
sha512,
|
|
251
|
+
sha3_256,
|
|
252
|
+
sha3_512,
|
|
253
|
+
blake2b,
|
|
254
|
+
blake2s,
|
|
255
|
+
algorithmsAvailable,
|
|
256
|
+
algorithmsGuaranteed,
|
|
257
|
+
pbkdf2Hmac,
|
|
258
|
+
scrypt,
|
|
259
|
+
compareDigest,
|
|
260
|
+
fileDigest,
|
|
261
|
+
hashlib_exports
|
|
262
|
+
};
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
|
+
|
|
5
|
+
// src/time.ts
|
|
6
|
+
var time_exports = {};
|
|
7
|
+
__export(time_exports, {
|
|
8
|
+
altzone: () => altzone,
|
|
9
|
+
asctime: () => asctime,
|
|
10
|
+
ctime: () => ctime,
|
|
11
|
+
daylight: () => daylight,
|
|
12
|
+
gmtime: () => gmtime,
|
|
13
|
+
localtime: () => localtime,
|
|
14
|
+
mktime: () => mktime,
|
|
15
|
+
monotonic: () => monotonic,
|
|
16
|
+
monotonicNs: () => monotonicNs,
|
|
17
|
+
perfCounter: () => perfCounter,
|
|
18
|
+
perfCounterNs: () => perfCounterNs,
|
|
19
|
+
processTime: () => processTime,
|
|
20
|
+
processTimeNs: () => processTimeNs,
|
|
21
|
+
sleep: () => sleep,
|
|
22
|
+
strftime: () => strftime,
|
|
23
|
+
strptime: () => strptime,
|
|
24
|
+
threadTime: () => threadTime,
|
|
25
|
+
threadTimeNs: () => threadTimeNs,
|
|
26
|
+
time: () => time,
|
|
27
|
+
timeNs: () => timeNs,
|
|
28
|
+
timezone: () => timezone,
|
|
29
|
+
tzname: () => tzname
|
|
30
|
+
});
|
|
31
|
+
var startTime = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
32
|
+
function time() {
|
|
33
|
+
return Date.now() / 1e3;
|
|
34
|
+
}
|
|
35
|
+
function timeNs() {
|
|
36
|
+
return BigInt(Date.now()) * 1000000n;
|
|
37
|
+
}
|
|
38
|
+
function sleep(secs) {
|
|
39
|
+
const end = Date.now() + secs * 1e3;
|
|
40
|
+
while (Date.now() < end) {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function perfCounter() {
|
|
44
|
+
if (typeof performance !== "undefined") {
|
|
45
|
+
return performance.now() / 1e3;
|
|
46
|
+
}
|
|
47
|
+
return (Date.now() - startTime) / 1e3;
|
|
48
|
+
}
|
|
49
|
+
function perfCounterNs() {
|
|
50
|
+
if (typeof performance !== "undefined") {
|
|
51
|
+
return BigInt(Math.floor(performance.now() * 1e6));
|
|
52
|
+
}
|
|
53
|
+
return BigInt(Date.now() - startTime) * 1000000n;
|
|
54
|
+
}
|
|
55
|
+
function monotonic() {
|
|
56
|
+
return perfCounter();
|
|
57
|
+
}
|
|
58
|
+
function monotonicNs() {
|
|
59
|
+
return perfCounterNs();
|
|
60
|
+
}
|
|
61
|
+
function localtime(secs) {
|
|
62
|
+
const date = secs === void 0 ? /* @__PURE__ */ new Date() : new Date(secs * 1e3);
|
|
63
|
+
const startOfYear = new Date(date.getFullYear(), 0, 0);
|
|
64
|
+
const diff = date.getTime() - startOfYear.getTime();
|
|
65
|
+
const oneDay = 1e3 * 60 * 60 * 24;
|
|
66
|
+
const tm_yday = Math.floor(diff / oneDay);
|
|
67
|
+
const jsDay = date.getDay();
|
|
68
|
+
const tm_wday = jsDay === 0 ? 6 : jsDay - 1;
|
|
69
|
+
return {
|
|
70
|
+
tm_year: date.getFullYear(),
|
|
71
|
+
tm_mon: date.getMonth() + 1,
|
|
72
|
+
// JavaScript months are 0-indexed
|
|
73
|
+
tm_mday: date.getDate(),
|
|
74
|
+
tm_hour: date.getHours(),
|
|
75
|
+
tm_min: date.getMinutes(),
|
|
76
|
+
tm_sec: date.getSeconds(),
|
|
77
|
+
tm_wday,
|
|
78
|
+
tm_yday,
|
|
79
|
+
tm_isdst: -1
|
|
80
|
+
// Not determinable in JavaScript
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function gmtime(secs) {
|
|
84
|
+
const date = secs === void 0 ? /* @__PURE__ */ new Date() : new Date(secs * 1e3);
|
|
85
|
+
const startOfYear = new Date(Date.UTC(date.getUTCFullYear(), 0, 0));
|
|
86
|
+
const diff = date.getTime() - startOfYear.getTime();
|
|
87
|
+
const oneDay = 1e3 * 60 * 60 * 24;
|
|
88
|
+
const tm_yday = Math.floor(diff / oneDay);
|
|
89
|
+
const jsDay = date.getUTCDay();
|
|
90
|
+
const tm_wday = jsDay === 0 ? 6 : jsDay - 1;
|
|
91
|
+
return {
|
|
92
|
+
tm_year: date.getUTCFullYear(),
|
|
93
|
+
tm_mon: date.getUTCMonth() + 1,
|
|
94
|
+
tm_mday: date.getUTCDate(),
|
|
95
|
+
tm_hour: date.getUTCHours(),
|
|
96
|
+
tm_min: date.getUTCMinutes(),
|
|
97
|
+
tm_sec: date.getUTCSeconds(),
|
|
98
|
+
tm_wday,
|
|
99
|
+
tm_yday,
|
|
100
|
+
tm_isdst: 0
|
|
101
|
+
// UTC never has DST
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function mktime(t) {
|
|
105
|
+
const date = new Date(
|
|
106
|
+
t.tm_year,
|
|
107
|
+
t.tm_mon - 1,
|
|
108
|
+
// Convert to 0-indexed month
|
|
109
|
+
t.tm_mday,
|
|
110
|
+
t.tm_hour,
|
|
111
|
+
t.tm_min,
|
|
112
|
+
t.tm_sec
|
|
113
|
+
);
|
|
114
|
+
return date.getTime() / 1e3;
|
|
115
|
+
}
|
|
116
|
+
function strftime(format, t) {
|
|
117
|
+
const st = t ?? localtime();
|
|
118
|
+
const weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
|
119
|
+
const weekdaysShort = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
120
|
+
const months = [
|
|
121
|
+
"January",
|
|
122
|
+
"February",
|
|
123
|
+
"March",
|
|
124
|
+
"April",
|
|
125
|
+
"May",
|
|
126
|
+
"June",
|
|
127
|
+
"July",
|
|
128
|
+
"August",
|
|
129
|
+
"September",
|
|
130
|
+
"October",
|
|
131
|
+
"November",
|
|
132
|
+
"December"
|
|
133
|
+
];
|
|
134
|
+
const monthsShort = [
|
|
135
|
+
"Jan",
|
|
136
|
+
"Feb",
|
|
137
|
+
"Mar",
|
|
138
|
+
"Apr",
|
|
139
|
+
"May",
|
|
140
|
+
"Jun",
|
|
141
|
+
"Jul",
|
|
142
|
+
"Aug",
|
|
143
|
+
"Sep",
|
|
144
|
+
"Oct",
|
|
145
|
+
"Nov",
|
|
146
|
+
"Dec"
|
|
147
|
+
];
|
|
148
|
+
const pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
149
|
+
const sundayWday = (st.tm_wday + 1) % 7;
|
|
150
|
+
const hour12 = st.tm_hour % 12 || 12;
|
|
151
|
+
const date = new Date(st.tm_year, st.tm_mon - 1, st.tm_mday);
|
|
152
|
+
const startOfYear = new Date(st.tm_year, 0, 1);
|
|
153
|
+
const dayOfYear = Math.floor((date.getTime() - startOfYear.getTime()) / (24 * 60 * 60 * 1e3)) + 1;
|
|
154
|
+
const sundayWeek = Math.floor((dayOfYear + startOfYear.getDay()) / 7);
|
|
155
|
+
const mondayWeek = Math.floor((dayOfYear + (startOfYear.getDay() + 6) % 7) / 7);
|
|
156
|
+
const replacements = {
|
|
157
|
+
"%Y": String(st.tm_year),
|
|
158
|
+
"%y": pad(st.tm_year % 100),
|
|
159
|
+
"%m": pad(st.tm_mon),
|
|
160
|
+
"%d": pad(st.tm_mday),
|
|
161
|
+
"%H": pad(st.tm_hour),
|
|
162
|
+
"%I": pad(hour12),
|
|
163
|
+
"%M": pad(st.tm_min),
|
|
164
|
+
"%S": pad(st.tm_sec),
|
|
165
|
+
"%p": st.tm_hour < 12 ? "AM" : "PM",
|
|
166
|
+
"%A": weekdays[st.tm_wday] ?? "",
|
|
167
|
+
"%a": weekdaysShort[st.tm_wday] ?? "",
|
|
168
|
+
"%B": months[st.tm_mon - 1] ?? "",
|
|
169
|
+
"%b": monthsShort[st.tm_mon - 1] ?? "",
|
|
170
|
+
"%w": String(sundayWday),
|
|
171
|
+
"%j": pad(st.tm_yday, 3),
|
|
172
|
+
"%U": pad(sundayWeek),
|
|
173
|
+
"%W": pad(mondayWeek),
|
|
174
|
+
"%c": `${weekdaysShort[st.tm_wday] ?? ""} ${monthsShort[st.tm_mon - 1] ?? ""} ${pad(st.tm_mday)} ${pad(st.tm_hour)}:${pad(st.tm_min)}:${pad(st.tm_sec)} ${String(st.tm_year)}`,
|
|
175
|
+
"%x": `${pad(st.tm_mon)}/${pad(st.tm_mday)}/${pad(st.tm_year % 100)}`,
|
|
176
|
+
"%X": `${pad(st.tm_hour)}:${pad(st.tm_min)}:${pad(st.tm_sec)}`,
|
|
177
|
+
"%%": "%"
|
|
178
|
+
};
|
|
179
|
+
let result = format;
|
|
180
|
+
for (const [code, value] of Object.entries(replacements)) {
|
|
181
|
+
result = result.split(code).join(value);
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
function strptime(timeString, format) {
|
|
186
|
+
const result = {
|
|
187
|
+
tm_year: 1900,
|
|
188
|
+
tm_mon: 1,
|
|
189
|
+
tm_mday: 1,
|
|
190
|
+
tm_hour: 0,
|
|
191
|
+
tm_min: 0,
|
|
192
|
+
tm_sec: 0,
|
|
193
|
+
tm_wday: 0,
|
|
194
|
+
tm_yday: 1,
|
|
195
|
+
tm_isdst: -1
|
|
196
|
+
};
|
|
197
|
+
const monthsShort = [
|
|
198
|
+
"jan",
|
|
199
|
+
"feb",
|
|
200
|
+
"mar",
|
|
201
|
+
"apr",
|
|
202
|
+
"may",
|
|
203
|
+
"jun",
|
|
204
|
+
"jul",
|
|
205
|
+
"aug",
|
|
206
|
+
"sep",
|
|
207
|
+
"oct",
|
|
208
|
+
"nov",
|
|
209
|
+
"dec"
|
|
210
|
+
];
|
|
211
|
+
const months = [
|
|
212
|
+
"january",
|
|
213
|
+
"february",
|
|
214
|
+
"march",
|
|
215
|
+
"april",
|
|
216
|
+
"may",
|
|
217
|
+
"june",
|
|
218
|
+
"july",
|
|
219
|
+
"august",
|
|
220
|
+
"september",
|
|
221
|
+
"october",
|
|
222
|
+
"november",
|
|
223
|
+
"december"
|
|
224
|
+
];
|
|
225
|
+
let pattern = format;
|
|
226
|
+
pattern = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
227
|
+
const formatMap = [
|
|
228
|
+
{ code: "%Y", regex: "(\\d{4})", handler: (m) => result.tm_year = parseInt(m, 10) },
|
|
229
|
+
{
|
|
230
|
+
code: "%y",
|
|
231
|
+
regex: "(\\d{2})",
|
|
232
|
+
handler: (m) => {
|
|
233
|
+
const yr = parseInt(m, 10);
|
|
234
|
+
result.tm_year = yr >= 69 ? 1900 + yr : 2e3 + yr;
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
{ code: "%m", regex: "(\\d{1,2})", handler: (m) => result.tm_mon = parseInt(m, 10) },
|
|
238
|
+
{ code: "%d", regex: "(\\d{1,2})", handler: (m) => result.tm_mday = parseInt(m, 10) },
|
|
239
|
+
{ code: "%H", regex: "(\\d{1,2})", handler: (m) => result.tm_hour = parseInt(m, 10) },
|
|
240
|
+
{ code: "%I", regex: "(\\d{1,2})", handler: (m) => result.tm_hour = parseInt(m, 10) },
|
|
241
|
+
{ code: "%M", regex: "(\\d{1,2})", handler: (m) => result.tm_min = parseInt(m, 10) },
|
|
242
|
+
{ code: "%S", regex: "(\\d{1,2})", handler: (m) => result.tm_sec = parseInt(m, 10) },
|
|
243
|
+
{
|
|
244
|
+
code: "%p",
|
|
245
|
+
regex: "(AM|PM|am|pm)",
|
|
246
|
+
handler: (m) => {
|
|
247
|
+
if (m.toUpperCase() === "PM" && result.tm_hour !== void 0 && result.tm_hour < 12) {
|
|
248
|
+
result.tm_hour += 12;
|
|
249
|
+
} else if (m.toUpperCase() === "AM" && result.tm_hour === 12) {
|
|
250
|
+
result.tm_hour = 0;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
code: "%b",
|
|
256
|
+
regex: "([A-Za-z]+)",
|
|
257
|
+
handler: (m) => {
|
|
258
|
+
const idx = monthsShort.indexOf(m.toLowerCase());
|
|
259
|
+
if (idx !== -1) result.tm_mon = idx + 1;
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
code: "%B",
|
|
264
|
+
regex: "([A-Za-z]+)",
|
|
265
|
+
handler: (m) => {
|
|
266
|
+
const idx = months.indexOf(m.toLowerCase());
|
|
267
|
+
if (idx !== -1) result.tm_mon = idx + 1;
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
{ code: "%j", regex: "(\\d{1,3})", handler: (m) => result.tm_yday = parseInt(m, 10) },
|
|
271
|
+
{ code: "%w", regex: "(\\d)", handler: (m) => result.tm_wday = (parseInt(m, 10) + 6) % 7 },
|
|
272
|
+
{ code: "%%", regex: "%", handler: () => void 0 }
|
|
273
|
+
];
|
|
274
|
+
const handlers = [];
|
|
275
|
+
for (const { code, regex, handler } of formatMap) {
|
|
276
|
+
const idx = pattern.indexOf(code.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
277
|
+
if (idx !== -1) {
|
|
278
|
+
pattern = pattern.replace(code.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), regex);
|
|
279
|
+
handlers.push(handler);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const match = new RegExp("^" + pattern + "$").exec(timeString);
|
|
283
|
+
if (!match) {
|
|
284
|
+
throw new Error(`time data '${timeString}' does not match format '${format}'`);
|
|
285
|
+
}
|
|
286
|
+
for (let i = 0; i < handlers.length; i++) {
|
|
287
|
+
if (match[i + 1] !== void 0) {
|
|
288
|
+
handlers[i]?.(match[i + 1] ?? "");
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (result.tm_year !== void 0 && result.tm_mon !== void 0 && result.tm_mday !== void 0) {
|
|
292
|
+
const date = new Date(result.tm_year, result.tm_mon - 1, result.tm_mday);
|
|
293
|
+
const jsDay = date.getDay();
|
|
294
|
+
result.tm_wday = jsDay === 0 ? 6 : jsDay - 1;
|
|
295
|
+
}
|
|
296
|
+
if (result.tm_year !== void 0 && result.tm_mon !== void 0 && result.tm_mday !== void 0) {
|
|
297
|
+
const date = new Date(result.tm_year, result.tm_mon - 1, result.tm_mday);
|
|
298
|
+
const startOfYear = new Date(result.tm_year, 0, 0);
|
|
299
|
+
const diff = date.getTime() - startOfYear.getTime();
|
|
300
|
+
const oneDay = 1e3 * 60 * 60 * 24;
|
|
301
|
+
result.tm_yday = Math.floor(diff / oneDay);
|
|
302
|
+
}
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
function asctime(t) {
|
|
306
|
+
return strftime("%a %b %d %H:%M:%S %Y", t);
|
|
307
|
+
}
|
|
308
|
+
function ctime(secs) {
|
|
309
|
+
return asctime(localtime(secs));
|
|
310
|
+
}
|
|
311
|
+
var timezone = (/* @__PURE__ */ new Date()).getTimezoneOffset() * 60;
|
|
312
|
+
var altzone = timezone;
|
|
313
|
+
var tzname = (() => {
|
|
314
|
+
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
315
|
+
return [tz, tz];
|
|
316
|
+
})();
|
|
317
|
+
var daylight = 0;
|
|
318
|
+
function processTime() {
|
|
319
|
+
if (typeof performance !== "undefined") {
|
|
320
|
+
return performance.now() / 1e3;
|
|
321
|
+
}
|
|
322
|
+
return Date.now() / 1e3;
|
|
323
|
+
}
|
|
324
|
+
function processTimeNs() {
|
|
325
|
+
if (typeof performance !== "undefined") {
|
|
326
|
+
return BigInt(Math.floor(performance.now() * 1e6));
|
|
327
|
+
}
|
|
328
|
+
return BigInt(Date.now()) * 1000000n;
|
|
329
|
+
}
|
|
330
|
+
function threadTime() {
|
|
331
|
+
return processTime();
|
|
332
|
+
}
|
|
333
|
+
function threadTimeNs() {
|
|
334
|
+
return processTimeNs();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export {
|
|
338
|
+
time,
|
|
339
|
+
timeNs,
|
|
340
|
+
sleep,
|
|
341
|
+
perfCounter,
|
|
342
|
+
perfCounterNs,
|
|
343
|
+
monotonic,
|
|
344
|
+
monotonicNs,
|
|
345
|
+
localtime,
|
|
346
|
+
gmtime,
|
|
347
|
+
mktime,
|
|
348
|
+
strftime,
|
|
349
|
+
strptime,
|
|
350
|
+
asctime,
|
|
351
|
+
ctime,
|
|
352
|
+
timezone,
|
|
353
|
+
altzone,
|
|
354
|
+
tzname,
|
|
355
|
+
daylight,
|
|
356
|
+
processTime,
|
|
357
|
+
processTimeNs,
|
|
358
|
+
threadTime,
|
|
359
|
+
threadTimeNs,
|
|
360
|
+
time_exports
|
|
361
|
+
};
|