@wener/utils 1.1.21 → 1.1.23
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/dist/LICENSE.txt +135 -1
- package/dist/cjs/index-69020bc5.js +13 -0
- package/dist/cjs/index-69020bc5.js.map +1 -0
- package/dist/cjs/index.cjs +9 -9
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/server.cjs +1 -1
- package/dist/cjs/server.cjs.map +1 -1
- package/dist/cjs/servers/jsdom.cjs +2 -0
- package/dist/cjs/servers/jsdom.cjs.map +1 -0
- package/dist/cjs/servers/node-fetch.cjs +2 -0
- package/dist/cjs/servers/node-fetch.cjs.map +1 -0
- package/dist/cjs/servers/ws.cjs +2 -0
- package/dist/cjs/servers/ws.cjs.map +1 -0
- package/dist/esm/index-f9528fde.js +13 -0
- package/dist/esm/index-f9528fde.js.map +1 -0
- package/dist/esm/index.js +9 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/servers/jsdom.js +2 -0
- package/dist/esm/servers/jsdom.js.map +1 -0
- package/dist/esm/servers/node-fetch.js +2 -0
- package/dist/esm/servers/node-fetch.js.map +1 -0
- package/dist/esm/servers/ws.js +2 -0
- package/dist/esm/servers/ws.js.map +1 -0
- package/dist/system/index-a2917815.js +13 -0
- package/dist/system/index-a2917815.js.map +1 -0
- package/dist/system/index.js +9 -9
- package/dist/system/index.js.map +1 -1
- package/dist/system/server.js +1 -1
- package/dist/system/server.js.map +1 -1
- package/dist/system/servers/jsdom.js +2 -0
- package/dist/system/servers/jsdom.js.map +1 -0
- package/dist/system/servers/node-fetch.js +2 -0
- package/dist/system/servers/node-fetch.js.map +1 -0
- package/dist/system/servers/ws.js +2 -0
- package/dist/system/servers/ws.js.map +1 -0
- package/lib/crypto/md5.js +123 -0
- package/lib/crypto/md5.js.map +1 -0
- package/lib/errors/Errors.js +1 -1
- package/lib/errors/Errors.js.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/logging/createLogger.js.map +1 -1
- package/lib/server.js +0 -3
- package/lib/server.js.map +1 -1
- package/lib/servers/fetch/createFetchWithProxyByNodeFetch.js +38 -0
- package/lib/servers/fetch/createFetchWithProxyByNodeFetch.js.map +1 -0
- package/lib/servers/jsdom.js +2 -0
- package/lib/servers/jsdom.js.map +1 -0
- package/lib/servers/node-fetch.js +3 -0
- package/lib/servers/node-fetch.js.map +1 -0
- package/lib/servers/ws.js +2 -0
- package/lib/servers/ws.js.map +1 -0
- package/package.json +22 -6
- package/server/jsdom.ts +1 -0
- package/server/node-fetch.ts +1 -0
- package/server/ws.ts +1 -0
- package/src/crypto/md5.bench.ts +31 -0
- package/src/crypto/md5.test.ts +8 -0
- package/src/errors/Errors.ts +1 -1
- package/src/index.ts +2 -1
- package/src/logging/createLogger.ts +9 -0
- package/src/server.ts +0 -3
- package/src/servers/jsdom.ts +1 -0
- package/src/servers/node-fetch.ts +2 -0
- package/src/servers/ws.ts +1 -0
- package/lib/servers/polyfill/polyfillBrowser.js +0 -12
- package/lib/servers/polyfill/polyfillBrowser.js.map +0 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { bench, describe } from 'vitest';
|
|
3
|
+
import { md5 } from './md5';
|
|
4
|
+
|
|
5
|
+
describe('md5', () => {
|
|
6
|
+
const dataset = new Array(10000).fill(0).map((_, i) => String(Math.random() * i));
|
|
7
|
+
let iterations = 0;
|
|
8
|
+
bench(
|
|
9
|
+
'js',
|
|
10
|
+
function () {
|
|
11
|
+
iterations++;
|
|
12
|
+
md5(dataset[iterations % dataset.length]);
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
iterations: 10000,
|
|
16
|
+
},
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
bench(
|
|
20
|
+
'native',
|
|
21
|
+
function () {
|
|
22
|
+
iterations++;
|
|
23
|
+
createHash('md5')
|
|
24
|
+
.update(dataset[iterations % dataset.length])
|
|
25
|
+
.digest('hex');
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
iterations: 10000,
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
});
|
package/src/errors/Errors.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -86,6 +86,7 @@ export { structuredClone } from './isomorphics/structuredClone';
|
|
|
86
86
|
export { randomUUID } from './crypto/randomUUID';
|
|
87
87
|
export { getRandomValues } from './crypto/getRandomValues';
|
|
88
88
|
export { sha1, sha256, sha384, sha512 } from './crypto/hashing';
|
|
89
|
+
export { md5 } from './crypto/md5';
|
|
89
90
|
export { hex } from './crypto/base';
|
|
90
91
|
export { isULID, createULID, ulid, parseULID } from './crypto/ulid';
|
|
91
92
|
export { PEM } from './crypto/pem/pem';
|
|
@@ -100,7 +101,7 @@ export { type FetchLike, createFetchWith, createFetchWithLogging, dumpResponse,
|
|
|
100
101
|
export { default as ms } from './libs/ms';
|
|
101
102
|
|
|
102
103
|
// error
|
|
103
|
-
export { Errors, type ErrorDetail, type ErrorDetailInit } from './errors/Errors';
|
|
104
|
+
export { Errors, DetailError, type ErrorDetail, type ErrorDetailInit } from './errors/Errors';
|
|
104
105
|
// http
|
|
105
106
|
export { getHttpStatusText, isRetryableHttpStatus } from './http/HttpStatus';
|
|
106
107
|
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { LoggerWithChild, LogLevel } from './Logger';
|
|
2
2
|
|
|
3
|
+
export interface CreateLoggerOptions {
|
|
4
|
+
name?: string;
|
|
5
|
+
handler?: (o: { level: LogLevel; values: any[] } & Record<string | symbol, any>) => void;
|
|
6
|
+
context?: Record<string, any>;
|
|
7
|
+
levels?: LogLevel[];
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
export function createLogger(
|
|
4
11
|
write: (o: { level: LogLevel; values: any[] } & Record<string | symbol, any>) => void = ({
|
|
5
12
|
level,
|
|
@@ -39,3 +46,5 @@ function merge(ctx: any, values: any[]) {
|
|
|
39
46
|
}
|
|
40
47
|
return { ...ctx, values };
|
|
41
48
|
}
|
|
49
|
+
|
|
50
|
+
// https://github.com/nestjs/nest/blob/master/packages/common/services/console-logger.service.ts
|
package/src/server.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export { polyfillCrypto } from './servers/polyfill/polyfillCrypto';
|
|
2
|
-
export { polyfillJsDom } from './servers/polyfill/polyfillJsDom';
|
|
3
|
-
export { polyfillBrowser } from './servers/polyfill/polyfillBrowser';
|
|
4
|
-
export { polyfillWebSocket } from './servers/polyfill/polyfillWebSocket';
|
|
5
2
|
export { createFetchWithProxyByUndici } from './servers/fetch/createFetchWithProxyByUndici';
|
|
6
3
|
export { createFetchWithProxy } from './servers/fetch/createFetchWithProxy';
|
|
7
4
|
export { createFetchWithRetry, type FetchWithRetryOptions } from './servers/fetch/createFetchWithRetry';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './polyfill/polyfillJsDom';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './polyfill/polyfillWebSocket';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { polyfillCrypto } from './polyfillCrypto.js';
|
|
2
|
-
import { polyfillFetch } from './polyfillFetch.js';
|
|
3
|
-
import { polyfillJsDom } from './polyfillJsDom.js';
|
|
4
|
-
|
|
5
|
-
async function polyfillBrowser() {
|
|
6
|
-
await polyfillCrypto();
|
|
7
|
-
await polyfillFetch();
|
|
8
|
-
await polyfillJsDom();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { polyfillBrowser };
|
|
12
|
-
//# sourceMappingURL=polyfillBrowser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"polyfillBrowser.js","sources":["../../../src/servers/polyfill/polyfillBrowser.ts"],"sourcesContent":["import { polyfillCrypto } from './polyfillCrypto';\nimport { polyfillFetch } from './polyfillFetch';\nimport { polyfillJsDom } from './polyfillJsDom';\n\n/**\n * Polyfills the browser environment with the necessary APIs for the server.\n * Currently, this includes:\n * - `window`\n * - `document`\n * - `fetch`\n * - `crypto`\n */\nexport async function polyfillBrowser() {\n await polyfillCrypto();\n await polyfillFetch();\n await polyfillJsDom();\n}\n"],"names":[],"mappings":";;;;AAYA,eAAsB,eAAkB,GAAA;AACtC,EAAA,MAAM,cAAe,EAAA,CAAA;AACrB,EAAA,MAAM,aAAc,EAAA,CAAA;AACpB,EAAA,MAAM,aAAc,EAAA,CAAA;AACtB;;;;"}
|