@wener/utils 1.1.14 → 1.1.15
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/cjs/{globalThis-ee7c1669.js → getGlobalThis-304f74e0.js} +2 -2
- package/dist/cjs/getGlobalThis-304f74e0.js.map +1 -0
- package/dist/cjs/index.cjs +16 -5
- 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/esm/{globalThis-000611c3.js → getGlobalThis-b7ad0cf9.js} +2 -2
- package/dist/esm/getGlobalThis-b7ad0cf9.js.map +1 -0
- package/dist/esm/index.js +15 -4
- 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/system/getGlobalThis-8951eb0e.js +2 -0
- package/dist/system/getGlobalThis-8951eb0e.js.map +1 -0
- package/dist/system/index.js +16 -5
- package/dist/system/index.js.map +1 -1
- package/dist/system/server.js +1 -1
- package/dist/system/server.js.map +1 -1
- package/lib/asyncs/timeout.js.map +1 -1
- package/lib/browsers/download.js.map +1 -1
- package/lib/browsers/loaders.js.map +1 -1
- package/lib/crypto/getRandomValues.js +2 -1
- package/lib/crypto/getRandomValues.js.map +1 -1
- package/lib/crypto/randomUUID.js +2 -1
- package/lib/crypto/randomUUID.js.map +1 -1
- package/lib/fetch/createFetchWith.js +25 -0
- package/lib/fetch/createFetchWith.js.map +1 -0
- package/lib/fetch/createFetchWithLogging.js +21 -0
- package/lib/fetch/createFetchWithLogging.js.map +1 -0
- package/lib/fetch/dumpRequest.js +46 -0
- package/lib/fetch/dumpRequest.js.map +1 -0
- package/lib/fetch/dumpResponse.js +23 -0
- package/lib/fetch/dumpResponse.js.map +1 -0
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/io/ArrayBuffers.js +2 -2
- package/lib/io/ArrayBuffers.js.map +1 -1
- package/lib/io/isTransferable.js +2 -1
- package/lib/io/isTransferable.js.map +1 -1
- package/lib/isomorphics/structuredClone.js +2 -1
- package/lib/isomorphics/structuredClone.js.map +1 -1
- package/lib/logging/createLogger.js.map +1 -1
- package/lib/objects/get.js.map +1 -1
- package/lib/objects/set.js.map +1 -1
- package/lib/servers/createFetchWithProxy.js +0 -1
- package/lib/servers/createFetchWithProxy.js.map +1 -1
- package/lib/servers/createFetchWithProxyByNodeFetch.js +2 -1
- package/lib/servers/createFetchWithProxyByNodeFetch.js.map +1 -1
- package/lib/servers/polyfillCrypto.js +2 -1
- package/lib/servers/polyfillCrypto.js.map +1 -1
- package/lib/servers/polyfillJsDom.js +2 -1
- package/lib/servers/polyfillJsDom.js.map +1 -1
- package/package.json +37 -35
- package/src/asyncs/timeout.ts +3 -1
- package/src/browsers/download.ts +3 -1
- package/src/browsers/loaders.ts +6 -2
- package/src/crypto/getRandomValues.ts +2 -1
- package/src/crypto/randomUUID.ts +3 -1
- package/src/fetch/createFetchWith.ts +32 -0
- package/src/fetch/createFetchWithLogging.ts +20 -0
- package/src/fetch/dumpRequest.ts +51 -0
- package/src/fetch/dumpResponse.ts +28 -0
- package/src/fetch/index.ts +4 -0
- package/src/index.ts +4 -2
- package/src/io/ArrayBuffers.ts +2 -2
- package/src/io/isTransferable.ts +3 -1
- package/src/isomorphics/structuredClone.ts +3 -1
- package/src/logging/createLogger.ts +15 -5
- package/src/objects/get.ts +1 -1
- package/src/objects/set.ts +1 -1
- package/src/servers/createFetchWithProxyByNodeFetch.ts +3 -2
- package/src/servers/polyfillCrypto.ts +2 -1
- package/src/servers/polyfillJsDom.ts +3 -1
- package/src/servers/polyfillWebSocket.ts +2 -1
- package/dist/cjs/globalThis-ee7c1669.js.map +0 -1
- package/dist/esm/globalThis-000611c3.js.map +0 -1
- package/dist/system/globalThis-7bba6592.js +0 -2
- package/dist/system/globalThis-7bba6592.js.map +0 -1
- package/lib/isomorphics/globalThis.js +0 -6
- package/lib/isomorphics/globalThis.js.map +0 -1
- package/src/isomorphics/globalThis.ts +0 -3
- package/src/servers/createFetchWithLogger.ts +0 -75
package/lib/objects/set.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set.js","sources":["../../src/objects/set.ts"],"sourcesContent":["import type { ObjectKey, ObjectPath} from './parseObjectPath';\nimport { parseObjectPath } from './parseObjectPath';\n\n/**\n * Deep set\n *\n * {@link https://github.com/lukeed/dset dset}\n */\nexport function set<T extends object, V>(obj: T, key: ObjectKey | ObjectPath, val: V, merging = true) {\n const path = parseObjectPath(key);\n let i = 0;\n const len = path.length;\n let current: any = obj;\n let x, k;\n while (i < len) {\n k = path[i++];\n if (k === '__proto__' || k === 'constructor' || k === 'prototype') break;\n // noinspection PointlessArithmeticExpressionJS\n current = current[k] =\n i === len\n ? merging\n ? merge(current[k], val)\n : val\n : typeof (x = current[k]) === typeof path\n ? x\n : // @ts-expect-error hacky type check\n path[i] * 0 !== 0 || !!~('' + path[i]).indexOf('.') // eslint-disable-line\n ? {}\n : [];\n }\n}\n\nexport function merge(a: any, b: any) {\n let k;\n if (typeof a === 'object' && typeof b === 'object') {\n if (Array.isArray(a) && Array.isArray(b)) {\n for (k = 0; k < b.length; k++) {\n a[k] = merge(a[k], b[k]);\n }\n } else {\n for (k in b) {\n if (k === '__proto__' || k === 'constructor' || k === 'prototype') break;\n a[k] = merge(a[k], b[k]);\n }\n }\n return a;\n }\n return b;\n}\n"],"names":[],"mappings":";;AAQO,SAAS,GAAyB,CAAA,GAAA,EAAQ,GAA6B,EAAA,GAAA,EAAQ,UAAU,IAAM,EAAA;AACpG,EAAM,MAAA,IAAA,GAAO,gBAAgB,GAAG,CAAA,CAAA;AAChC,EAAA,IAAI,CAAI,GAAA,CAAA,CAAA;AACR,EAAA,MAAM,MAAM,IAAK,CAAA,MAAA,CAAA;AACjB,EAAA,IAAI,OAAe,GAAA,GAAA,CAAA;AACnB,EAAA,IAAI,CAAG,EAAA,CAAA,CAAA;AACP,EAAA,OAAO,IAAI,GA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AAI,KAAM,CAAA,CAAA,CAAE,CAAC,CAAG,EAAA,CAAA,CAAE,CAAC,CAAC,CAAA,CAAA;AAAA,OACzB;AAAA,KACF;AACA,IAAO,OAAA,CAAA,CAAA;AAAA,GACT;AACA,EAAO,OAAA,CAAA,CAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"set.js","sources":["../../src/objects/set.ts"],"sourcesContent":["import type { ObjectKey, ObjectPath } from './parseObjectPath';\nimport { parseObjectPath } from './parseObjectPath';\n\n/**\n * Deep set\n *\n * {@link https://github.com/lukeed/dset dset}\n */\nexport function set<T extends object, V>(obj: T, key: ObjectKey | ObjectPath, val: V, merging = true) {\n const path = parseObjectPath(key);\n let i = 0;\n const len = path.length;\n let current: any = obj;\n let x, k;\n while (i < len) {\n k = path[i++];\n if (k === '__proto__' || k === 'constructor' || k === 'prototype') break;\n // noinspection PointlessArithmeticExpressionJS\n current = current[k] =\n i === len\n ? merging\n ? merge(current[k], val)\n : val\n : typeof (x = current[k]) === typeof path\n ? x\n : // @ts-expect-error hacky type check\n path[i] * 0 !== 0 || !!~('' + path[i]).indexOf('.') // eslint-disable-line\n ? {}\n : [];\n }\n}\n\nexport function merge(a: any, b: any) {\n let k;\n if (typeof a === 'object' && typeof b === 'object') {\n if (Array.isArray(a) && Array.isArray(b)) {\n for (k = 0; k < b.length; k++) {\n a[k] = merge(a[k], b[k]);\n }\n } else {\n for (k in b) {\n if (k === '__proto__' || k === 'constructor' || k === 'prototype') break;\n a[k] = merge(a[k], b[k]);\n }\n }\n return a;\n }\n return b;\n}\n"],"names":[],"mappings":";;AAQO,SAAS,GAAyB,CAAA,GAAA,EAAQ,GAA6B,EAAA,GAAA,EAAQ,UAAU,IAAM,EAAA;AACpG,EAAM,MAAA,IAAA,GAAO,gBAAgB,GAAG,CAAA,CAAA;AAChC,EAAA,IAAI,CAAI,GAAA,CAAA,CAAA;AACR,EAAA,MAAM,MAAM,IAAK,CAAA,MAAA,CAAA;AACjB,EAAA,IAAI,O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AM,KAAA,aAAA,IAAiB,CAAM,KAAA,WAAA;AAAa,UAAA,MAAA;AACnE,QAAE,CAAA,CAAA,CAAC,IAAI,KAAM,CAAA,CAAA,CAAE,CAAC,CAAG,EAAA,CAAA,CAAE,CAAC,CAAC,CAAA,CAAA;AAAA,OACzB;AAAA,KACF;AACA,IAAO,OAAA,CAAA,CAAA;AAAA,GACT;AACA,EAAO,OAAA,CAAA,CAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFetchWithProxy.js","sources":["../../src/servers/createFetchWithProxy.ts"],"sourcesContent":["import { FetchLike } from '../fetch';\nimport { createFetchWithProxyByNodeFetch } from '../server';\nimport { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici';\n\nexport function createFetchWithProxy({ proxy, fetch }: { proxy?: string; fetch?: FetchLike }): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n return parseInt(process.versions.node) >= 18\n ? createFetchWithProxyByUndici({ proxy, fetch })\n : createFetchWithProxyByNodeFetch({ proxy, fetch });\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createFetchWithProxy.js","sources":["../../src/servers/createFetchWithProxy.ts"],"sourcesContent":["import { FetchLike } from '../fetch';\nimport { createFetchWithProxyByNodeFetch } from '../server';\nimport { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici';\n\nexport function createFetchWithProxy({ proxy, fetch }: { proxy?: string; fetch?: FetchLike }): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n return parseInt(process.versions.node) >= 18\n ? createFetchWithProxyByUndici({ proxy, fetch })\n : createFetchWithProxyByNodeFetch({ proxy, fetch });\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,oBAAqB,CAAA,EAAE,KAAO,EAAA,KAAA,EAA2D,EAAA;AACvG,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,OAAO,SAAS,UAAW,CAAA,KAAA,CAAA;AAAA,GAC7B;AACA,EAAA,OAAO,SAAS,OAAQ,CAAA,QAAA,CAAS,IAAI,CAAA,IAAK,KACtC,4BAA6B,CAAA,EAAE,KAAO,EAAA,KAAA,EAAO,CAC7C,GAAA,+BAAA,CAAgC,EAAE,KAAA,EAAO,OAAO,CAAA,CAAA;AACtD;;;;"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis.js';
|
|
2
2
|
|
|
3
3
|
function createFetchWithProxyByNodeFetch({
|
|
4
4
|
proxy,
|
|
5
5
|
fetch
|
|
6
6
|
} = {}) {
|
|
7
|
+
const globalThis = getGlobalThis();
|
|
7
8
|
if (!proxy) {
|
|
8
9
|
return fetch || globalThis.fetch;
|
|
9
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFetchWithProxyByNodeFetch.js","sources":["../../src/servers/createFetchWithProxyByNodeFetch.ts"],"sourcesContent":["import { type FetchLike } from '../fetch';\nimport {
|
|
1
|
+
{"version":3,"file":"createFetchWithProxyByNodeFetch.js","sources":["../../src/servers/createFetchWithProxyByNodeFetch.ts"],"sourcesContent":["import { type FetchLike } from '../fetch';\nimport { getGlobalThis } from '../isomorphics/getGlobalThis';\n\nexport function createFetchWithProxyByNodeFetch({\n proxy,\n fetch,\n}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {\n const globalThis = getGlobalThis();\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n\n let agent: any;\n const Request = globalThis.Request;\n let NodeRequest: any;\n let NodeFetch: any;\n return async (url, init?: RequestInit) => {\n if (!agent) {\n const { default: createHttpsProxyAgent } = await import('https-proxy-agent');\n agent = (createHttpsProxyAgent as any)(proxy);\n }\n\n // node-fetch 才可以,node v18 fetch 不支持\n if (!NodeRequest) {\n ({ Request: NodeRequest, default: NodeFetch } = await import('node-fetch'));\n }\n\n fetch ||= NodeFetch;\n\n if (url instanceof Request) {\n return (fetch as any)(new Request(url, { agent } as any));\n }\n if ((url as any) instanceof NodeRequest) {\n return (fetch as any)(new NodeRequest(url, { agent } as any));\n }\n return (fetch as any)(url, {\n ...init,\n agent,\n } as any);\n };\n}\n"],"names":[],"mappings":";;AAGO,SAAS,+BAAgC,CAAA;AAAA,EAC9C,KAAA;AAAA,EACA,KAAA;AACF,CAAA,GAA2C,EAAe,EAAA;AACxD,EAAA,MAAM,aAAa,aAAc,EAAA,CAAA;AACjC,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,OAAO,SAAS,UAAW,CAAA,KAAA,CAAA;AAAA,GAC7B;AAEA,EAAI,IAAA,KAAA,CAAA;AACJ,EAAA,MAAM,UAAU,UAAW,CAAA,OAAA,CAAA;AAC3B,EAAI,IAAA,WAAA,CAAA;AACJ,EAAI,IAAA,SAAA,CAAA;AACJ,EAAO,OAAA,OAAO,KAAK,IAAuB,KAAA;AACxC,IAAA,IAAI,CAAC,KAAO,EAAA;AACV,MAAA,MAAM,EAAE,OAAS,EAAA,qBAAA,EAA0B,GAAA,MAAM,OAAO,mBAAmB,CAAA,CAAA;AAC3E,MAAA,KAAA,GAAS,sBAA8B,KAAK,CAAA,CAAA;AAAA,KAC9C;AAGA,IAAA,IAAI,CAAC,WAAa,EAAA;AAChB,MAAC,CAAA,EAAE,SAAS,WAAa,EAAA,OAAA,EAAS,WAAc,GAAA,MAAM,OAAO,YAAY,CAAA,EAAA;AAAA,KAC3E;AAEA,IAAU,KAAA,KAAA,KAAA,GAAA,SAAA,CAAA,CAAA;AAEV,IAAA,IAAI,eAAe,OAAS,EAAA;AAC1B,MAAA,OAAQ,MAAc,IAAI,OAAA,CAAQ,KAAK,EAAE,KAAA,EAAc,CAAC,CAAA,CAAA;AAAA,KAC1D;AACA,IAAA,IAAK,eAAuB,WAAa,EAAA;AACvC,MAAA,OAAQ,MAAc,IAAI,WAAA,CAAY,KAAK,EAAE,KAAA,EAAc,CAAC,CAAA,CAAA;AAAA,KAC9D;AACA,IAAA,OAAQ,MAAc,GAAK,EAAA;AAAA,MACzB,GAAG,IAAA;AAAA,MACH,KAAA;AAAA,KACM,CAAA,CAAA;AAAA,GACV,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyfillCrypto.js","sources":["../../src/servers/polyfillCrypto.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"polyfillCrypto.js","sources":["../../src/servers/polyfillCrypto.ts"],"sourcesContent":["import { getGlobalThis } from '../isomorphics/getGlobalThis';\n\nexport async function polyfillCrypto() {\n const globalThis = getGlobalThis();\n if ('crypto' in globalThis) {\n return false;\n }\n (globalThis as any).crypto = (await import('node:crypto')).webcrypto as Crypto;\n return true;\n}\n"],"names":[],"mappings":";;AAEA,eAAsB,cAAiB,GAAA;AACrC,EAAA,MAAM,aAAa,aAAc,EAAA,CAAA;AACjC,EAAA,IAAI,YAAY,UAAY,EAAA;AAC1B,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACA,EAAC,UAAmB,CAAA,MAAA,GAAA,CAAU,MAAM,OAAO,aAAa,CAAG,EAAA,SAAA,CAAA;AAC3D,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis.js';
|
|
2
2
|
|
|
3
3
|
async function polyfillJsDom() {
|
|
4
4
|
if (typeof window !== "undefined") {
|
|
5
5
|
return false;
|
|
6
6
|
}
|
|
7
|
+
const globalThis = getGlobalThis();
|
|
7
8
|
const { ResourceLoader, JSDOM } = await import('jsdom');
|
|
8
9
|
class Window {
|
|
9
10
|
constructor(opts = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyfillJsDom.js","sources":["../../src/servers/polyfillJsDom.ts"],"sourcesContent":["import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport {
|
|
1
|
+
{"version":3,"file":"polyfillJsDom.js","sources":["../../src/servers/polyfillJsDom.ts"],"sourcesContent":["import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { getGlobalThis } from '../isomorphics/getGlobalThis';\n\nexport async function polyfillJsDom() {\n if (typeof window !== 'undefined') {\n return false;\n }\n\n const globalThis = getGlobalThis();\n\n const { ResourceLoader, JSDOM } = await import('jsdom');\n\n // https://github.com/lukechilds/window/blob/master/src/index.js\n // eslint-disable-next-line @typescript-eslint/no-extraneous-class\n class Window {\n constructor(opts: ResourceLoaderConstructorOptions & ConstructorOptions = {}) {\n const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;\n const resources = new ResourceLoader({\n proxy,\n strictSSL,\n userAgent,\n });\n return new JSDOM(\n '',\n Object.assign(jsdomOpts, {\n resources,\n }),\n ).window;\n }\n }\n\n // https://github.com/lukechilds/browser-env/blob/master/src/index.js\n // Default jsdom config.\n // These settings must override any custom settings to make sure we can iterate\n // over the window object.\n const defaultJsdomConfig = {\n // features: {\n // FetchExternalResources: false,\n // ProcessExternalResources: false,\n // },\n };\n // IIFE executed on import to return an array of global Node.js properties that\n // conflict with global browser properties.\n const protectedProperties = (() =>\n Object.getOwnPropertyNames(new Window(defaultJsdomConfig)).filter(\n (prop) => typeof globalThis[prop as keyof typeof globalThis] !== 'undefined',\n ))();\n\n function installEnv(...args: any[]) {\n // Sets up global browser environment\n // Extract options from args\n const properties = args.filter((arg: any) => Array.isArray(arg))[0];\n const userJsdomConfig = args.filter((arg: any) => !Array.isArray(arg))[0];\n\n // Create window object\n const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));\n\n // Get all global browser properties\n Object.getOwnPropertyNames(window)\n\n // Remove protected properties\n .filter((prop) => !protectedProperties.includes(prop))\n\n // If we're only applying specific required properties remove everything else\n .filter((prop) => !(properties && properties.indexOf(prop) === -1))\n .filter((prop) => {\n switch (prop) {\n case 'undefined':\n return false;\n }\n return true;\n })\n\n // Copy what's left to the Node.js global scope\n .forEach((prop) => {\n // console.debug(`define globalThis.${prop}`);\n Object.defineProperty(globalThis, prop, {\n configurable: true,\n get: () => window[prop as keyof Window] as any,\n });\n });\n\n return window;\n }\n\n installEnv({ url: 'http://localhost' });\n return true;\n}\n"],"names":["window"],"mappings":";;AAGA,eAAsB,aAAgB,GAAA;AACpC,EAAI,IAAA,OAAO,WAAW,WAAa,EAAA;AACjC,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,aAAa,aAAc,EAAA,CAAA;AAEjC,EAAA,MAAM,EAAE,cAAgB,EAAA,KAAA,EAAU,GAAA,MAAM,OAAO,OAAO,CAAA,CAAA;AAItD,EAAA,MAAM,MAAO,CAAA;AAAA,IACX,WAAA,CAAY,IAA8D,GAAA,EAAI,EAAA;AAC5E,MAAA,MAAM,EAAE,KAAO,EAAA,SAAA,EAAW,SAAW,EAAA,GAAG,WAAc,GAAA,IAAA,CAAA;AACtD,MAAM,MAAA,SAAA,GAAY,IAAI,cAAe,CAAA;AAAA,QACnC,KAAA;AAAA,QACA,SAAA;AAAA,QACA,SAAA;AAAA,OACD,CAAA,CAAA;AACD,MAAA,OAAO,IAAI,KAAA;AAAA,QACT,EAAA;AAAA,QACA,MAAA,CAAO,OAAO,SAAW,EAAA;AAAA,UACvB,SAAA;AAAA,SACD,CAAA;AAAA,OACD,CAAA,MAAA,CAAA;AAAA,KACJ;AAAA,GACF;AAMA,EAAA,MAAM,kBAAqB,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAK3B,CAAA;AAGA,EAAM,MAAA,mBAAA,GAAA,CAAuB,MAC3B,MAAO,CAAA,mBAAA,CAAoB,IAAI,MAAO,CAAA,kBAAkB,CAAC,CAAE,CAAA,MAAA;AAAA,IACzD,CAAC,IAAA,KAAS,OAAO,UAAA,CAAW,IAA+B,CAAM,KAAA,WAAA;AAAA,GAChE,GAAA,CAAA;AAEL,EAAA,SAAS,cAAc,IAAa,EAAA;AAGlC,IAAM,MAAA,UAAA,GAAa,IAAK,CAAA,MAA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": "@wener/utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Utils for daily use",
|
|
6
6
|
"repository": {
|
|
@@ -12,25 +12,6 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"main": "dist/cjs/index.cjs",
|
|
14
14
|
"module": "lib/index.js",
|
|
15
|
-
"exports": {
|
|
16
|
-
".": {
|
|
17
|
-
"types": "./src/index.ts",
|
|
18
|
-
"typescript": "./src/index.ts",
|
|
19
|
-
"system": "./dist/system/index.js",
|
|
20
|
-
"import": "./lib/index.js"
|
|
21
|
-
},
|
|
22
|
-
"./types": {
|
|
23
|
-
"types": "./types.d.ts"
|
|
24
|
-
},
|
|
25
|
-
"./server": {
|
|
26
|
-
"types": "./src/server.ts",
|
|
27
|
-
"typescript": "./src/server.ts",
|
|
28
|
-
"system": "./dist/system/server.js",
|
|
29
|
-
"import": "./lib/server.js"
|
|
30
|
-
},
|
|
31
|
-
"./src/*": "./src/*",
|
|
32
|
-
"./package.json": "./package.json"
|
|
33
|
-
},
|
|
34
15
|
"types": "src/index.ts",
|
|
35
16
|
"files": [
|
|
36
17
|
"dist",
|
|
@@ -50,28 +31,33 @@
|
|
|
50
31
|
"template",
|
|
51
32
|
"lodash"
|
|
52
33
|
],
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@types/lodash": "^4.14.194",
|
|
55
|
-
"@types/ws": "^8.5.4",
|
|
56
|
-
"https-proxy-agent": "^5.0.1",
|
|
57
|
-
"lodash": "^4.17.21"
|
|
58
|
-
},
|
|
59
|
-
"publishConfig": {
|
|
60
|
-
"registry": "https://registry.npmjs.org",
|
|
61
|
-
"access": "public"
|
|
62
|
-
},
|
|
63
34
|
"peerDependencies": {
|
|
64
35
|
"https-proxy-agent": "*",
|
|
65
36
|
"undici": "*"
|
|
66
37
|
},
|
|
67
38
|
"peerDependenciesMeta": {
|
|
68
|
-
"
|
|
39
|
+
"https-proxy-agent": {
|
|
69
40
|
"optional": true
|
|
70
41
|
},
|
|
71
|
-
"
|
|
42
|
+
"node-fetch": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"undici": {
|
|
72
46
|
"optional": true
|
|
73
47
|
}
|
|
74
48
|
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/lodash": "^4.14.195",
|
|
51
|
+
"@types/ws": "^8.5.4",
|
|
52
|
+
"https-proxy-agent": "^7.0.0",
|
|
53
|
+
"lodash": "^4.17.21",
|
|
54
|
+
"node-fetch": "^3.3.1",
|
|
55
|
+
"undici": "^5.22.1"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"registry": "https://registry.npmjs.org",
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
75
61
|
"sideEffects": false,
|
|
76
62
|
"rollup": {
|
|
77
63
|
"input": [
|
|
@@ -83,13 +69,29 @@
|
|
|
83
69
|
"node-fetch"
|
|
84
70
|
]
|
|
85
71
|
},
|
|
86
|
-
"dependencies": {
|
|
87
|
-
"undici": "^5.22.0"
|
|
88
|
-
},
|
|
89
72
|
"scripts": {
|
|
90
73
|
"build": "make prepublish",
|
|
91
74
|
"clean": "make clean",
|
|
92
75
|
"dev": "make dev",
|
|
93
76
|
"test": "make test"
|
|
77
|
+
},
|
|
78
|
+
"exports": {
|
|
79
|
+
".": {
|
|
80
|
+
"types": "./src/index.ts",
|
|
81
|
+
"typescript": "./src/index.ts",
|
|
82
|
+
"system": "./dist/system/index.js",
|
|
83
|
+
"import": "./lib/index.js"
|
|
84
|
+
},
|
|
85
|
+
"./types": {
|
|
86
|
+
"types": "./types.d.ts"
|
|
87
|
+
},
|
|
88
|
+
"./server": {
|
|
89
|
+
"types": "./src/server.ts",
|
|
90
|
+
"typescript": "./src/server.ts",
|
|
91
|
+
"system": "./dist/system/server.js",
|
|
92
|
+
"import": "./lib/server.js"
|
|
93
|
+
},
|
|
94
|
+
"./src/*": "./src/*",
|
|
95
|
+
"./package.json": "./package.json"
|
|
94
96
|
}
|
|
95
97
|
}
|
package/src/asyncs/timeout.ts
CHANGED
|
@@ -4,7 +4,9 @@ export function timeout<T = any>(v: Promise<T>, ms: number): Promise<T> {
|
|
|
4
4
|
return Promise.race([
|
|
5
5
|
v,
|
|
6
6
|
new Promise((_resolve, reject) => {
|
|
7
|
-
timeout = setTimeout(() => {
|
|
7
|
+
timeout = setTimeout(() => {
|
|
8
|
+
reject(error);
|
|
9
|
+
}, ms);
|
|
8
10
|
}),
|
|
9
11
|
]).then(
|
|
10
12
|
(v) => {
|
package/src/browsers/download.ts
CHANGED
|
@@ -26,7 +26,9 @@ export function download(filename: string, data: any, { type = 'application/octe
|
|
|
26
26
|
|
|
27
27
|
if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {
|
|
28
28
|
a.href = URL.createObjectURL(data);
|
|
29
|
-
closer = () => {
|
|
29
|
+
closer = () => {
|
|
30
|
+
URL.revokeObjectURL(a.href);
|
|
31
|
+
};
|
|
30
32
|
} else {
|
|
31
33
|
console.error(`invalid download data`, data);
|
|
32
34
|
throw new Error(`can not download ${Object.getPrototypeOf(data)}`);
|
package/src/browsers/loaders.ts
CHANGED
|
@@ -4,13 +4,17 @@ function load(
|
|
|
4
4
|
reject: (v: any) => void,
|
|
5
5
|
options: { attributes: Record<string, string> } | undefined,
|
|
6
6
|
) {
|
|
7
|
-
el.onload = () => {
|
|
7
|
+
el.onload = () => {
|
|
8
|
+
resolve(el);
|
|
9
|
+
};
|
|
8
10
|
el.onerror = (e) => {
|
|
9
11
|
el.remove();
|
|
10
12
|
reject(e);
|
|
11
13
|
};
|
|
12
14
|
const { attributes = {} } = options || {};
|
|
13
|
-
Object.entries(attributes).forEach(([k, v]) => {
|
|
15
|
+
Object.entries(attributes).forEach(([k, v]) => {
|
|
16
|
+
el.setAttribute(k, v);
|
|
17
|
+
});
|
|
14
18
|
|
|
15
19
|
document.head.appendChild(el);
|
|
16
20
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
2
2
|
import type { TypedArray } from '../io/ArrayBuffers';
|
|
3
|
-
import {
|
|
3
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis';
|
|
4
4
|
import { getNodeCrypto } from './getNodeCrypto';
|
|
5
5
|
|
|
6
|
+
const globalThis = getGlobalThis();
|
|
6
7
|
export let getRandomValues: <T extends Exclude<TypedArray, Float32Array | Float64Array>>(typedArray: T) => T =
|
|
7
8
|
globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) ||
|
|
8
9
|
(globalThis as any).msCrypto?.getRandomValues?.bind((globalThis as any).msCrypto) ||
|
package/src/crypto/randomUUID.ts
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MaybePromise } from '../asyncs/MaybePromise';
|
|
2
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis';
|
|
3
|
+
import { FetchLike } from './index';
|
|
4
|
+
|
|
5
|
+
export function createFetchWith({
|
|
6
|
+
fetch = getGlobalThis().fetch,
|
|
7
|
+
onRequest = (ctx) => ctx.next(ctx.url, ctx.req),
|
|
8
|
+
onResponse = (ctx) => ctx.res,
|
|
9
|
+
}: {
|
|
10
|
+
fetch?: FetchLike;
|
|
11
|
+
onRequest?: (ctx: {
|
|
12
|
+
url: string;
|
|
13
|
+
req: RequestInit;
|
|
14
|
+
next: (url: string, req: RequestInit) => Promise<Response>;
|
|
15
|
+
}) => MaybePromise<Response | void>;
|
|
16
|
+
onResponse?: (ctx: { url: string; req: RequestInit; res: Response }) => MaybePromise<Response>;
|
|
17
|
+
}): FetchLike {
|
|
18
|
+
return async (urlOrRequest, init) => {
|
|
19
|
+
const url = String(urlOrRequest);
|
|
20
|
+
let req: RequestInit = init || {};
|
|
21
|
+
const res =
|
|
22
|
+
(await onRequest({
|
|
23
|
+
url,
|
|
24
|
+
req,
|
|
25
|
+
next: (url, init) => {
|
|
26
|
+
req = init;
|
|
27
|
+
return fetch(url, init);
|
|
28
|
+
},
|
|
29
|
+
})) ?? (await fetch(url, init));
|
|
30
|
+
return onResponse({ url, req, res });
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { dumpRequest } from './dumpRequest';
|
|
2
|
+
import { createFetchWith, dumpResponse, FetchLike } from './index';
|
|
3
|
+
|
|
4
|
+
export function createFetchWithLogging({
|
|
5
|
+
fetch,
|
|
6
|
+
log = console.log,
|
|
7
|
+
}: {
|
|
8
|
+
fetch?: FetchLike;
|
|
9
|
+
log?: (s: string) => void;
|
|
10
|
+
} = {}): FetchLike {
|
|
11
|
+
return createFetchWith({
|
|
12
|
+
fetch,
|
|
13
|
+
onRequest: ({ url, req }) => {
|
|
14
|
+
void dumpRequest({ url, req, log });
|
|
15
|
+
},
|
|
16
|
+
onResponse: ({ url, req, res }) => {
|
|
17
|
+
return dumpResponse({ url, req, res, log });
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export function dumpRequest({
|
|
2
|
+
url,
|
|
3
|
+
req = {},
|
|
4
|
+
log = console.log,
|
|
5
|
+
}: {
|
|
6
|
+
url: string;
|
|
7
|
+
req?: RequestInit;
|
|
8
|
+
log?: (s: string) => void;
|
|
9
|
+
}) {
|
|
10
|
+
const { method = 'GET' } = req;
|
|
11
|
+
let out = `-> ${method} ${url}
|
|
12
|
+
${Array.from(new Headers(req.headers).entries())
|
|
13
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
14
|
+
.join('\n')}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
let done: Promise<string> | undefined;
|
|
18
|
+
if (req.body) {
|
|
19
|
+
if (req.body instanceof ReadableStream) {
|
|
20
|
+
const [a, b] = req.body.tee();
|
|
21
|
+
req.body = a;
|
|
22
|
+
const signal = req.signal;
|
|
23
|
+
done = Promise.resolve().then(async () => {
|
|
24
|
+
const reader = b.getReader();
|
|
25
|
+
log(out);
|
|
26
|
+
while (true) {
|
|
27
|
+
if (signal?.aborted) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let { done, value } = await reader.read();
|
|
32
|
+
value instanceof Uint8Array && (value = new TextDecoder().decode(value));
|
|
33
|
+
out += value;
|
|
34
|
+
log(value);
|
|
35
|
+
if (!done) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// maybe for archive
|
|
40
|
+
out += `\n`;
|
|
41
|
+
return out;
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
out += `
|
|
45
|
+
${req.body}
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
log(out);
|
|
49
|
+
}
|
|
50
|
+
return done || Promise.resolve(out);
|
|
51
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export async function dumpResponse({
|
|
2
|
+
res,
|
|
3
|
+
url,
|
|
4
|
+
req,
|
|
5
|
+
log = console.log,
|
|
6
|
+
}: {
|
|
7
|
+
res: Response;
|
|
8
|
+
url: string;
|
|
9
|
+
req: RequestInit;
|
|
10
|
+
log?: (s: string) => void;
|
|
11
|
+
}) {
|
|
12
|
+
let out = `<- ${res.status} ${res.statusText} ${req.method} ${url}
|
|
13
|
+
${Array.from(res.headers.entries())
|
|
14
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
15
|
+
.join('\n')}
|
|
16
|
+
`;
|
|
17
|
+
let contentType = res.headers.get('content-type');
|
|
18
|
+
// TODO text/event-stream
|
|
19
|
+
if (contentType?.includes('application/json') || contentType?.includes('text/plain')) {
|
|
20
|
+
const body = await res.text();
|
|
21
|
+
out += `\n${body}\n`;
|
|
22
|
+
res = new Response(body, res);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
log(out);
|
|
26
|
+
|
|
27
|
+
return res;
|
|
28
|
+
}
|
package/src/fetch/index.ts
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
1
|
export type FetchLike = (url: string | Request, init?: RequestInit) => Promise<Response>;
|
|
2
|
+
export { createFetchWith } from './createFetchWith';
|
|
3
|
+
export { createFetchWithLogging } from './createFetchWithLogging';
|
|
4
|
+
export { dumpRequest } from './dumpRequest';
|
|
5
|
+
export { dumpResponse } from './dumpResponse';
|
package/src/index.ts
CHANGED
|
@@ -72,8 +72,9 @@ export { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';
|
|
|
72
72
|
|
|
73
73
|
// polyfills
|
|
74
74
|
export { getGlobalThis } from './isomorphics/getGlobalThis';
|
|
75
|
-
export { globalThis } from './isomorphics/globalThis';
|
|
76
75
|
export { structuredClone } from './isomorphics/structuredClone';
|
|
76
|
+
// should not export as sideEffect
|
|
77
|
+
// export { globalThis } from './isomorphics/globalThis';
|
|
77
78
|
|
|
78
79
|
// crypto
|
|
79
80
|
export { randomUUID } from './crypto/randomUUID';
|
|
@@ -86,7 +87,8 @@ export { PEM } from './crypto/pem/pem';
|
|
|
86
87
|
// misc
|
|
87
88
|
export { createRandom } from './maths/random';
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
// network
|
|
91
|
+
export { type FetchLike, createFetchWith, createFetchWithLogging, dumpResponse, dumpRequest } from './fetch';
|
|
90
92
|
|
|
91
93
|
// bundled
|
|
92
94
|
export { default as ms } from './libs/ms';
|
package/src/io/ArrayBuffers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis';
|
|
2
2
|
import { classOf } from '../langs/classOf';
|
|
3
3
|
import { decodeBase64ToArrayBuffer, encodeArrayBufferToBase64 } from './base64';
|
|
4
4
|
import { isBuffer } from './isBuffer';
|
|
@@ -74,7 +74,7 @@ export class ArrayBuffers {
|
|
|
74
74
|
|
|
75
75
|
static isNativeBufferAvailable() {
|
|
76
76
|
// eslint-disable-next-line no-return-assign
|
|
77
|
-
return (this.#isBufferAvailable ??= !(
|
|
77
|
+
return (this.#isBufferAvailable ??= !(getGlobalThis().Buffer as any)?.isPollyfill?.());
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
static isNativeBufferAllowed() {
|
package/src/io/isTransferable.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint no-proto:0 */
|
|
2
2
|
import { classOf } from '../langs/classOf';
|
|
3
|
-
import {
|
|
3
|
+
import { getGlobalThis } from './getGlobalThis';
|
|
4
|
+
|
|
5
|
+
const globalThis = getGlobalThis();
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Clone an object using structured cloning algorithm
|
|
@@ -12,11 +12,21 @@ export function createLogger(
|
|
|
12
12
|
context: object = {},
|
|
13
13
|
): LoggerWithChild {
|
|
14
14
|
return {
|
|
15
|
-
trace: (...values) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
trace: (...values) => {
|
|
16
|
+
write({ ...context, level: 'trace', values });
|
|
17
|
+
},
|
|
18
|
+
debug: (...values) => {
|
|
19
|
+
write({ ...context, level: 'debug', values });
|
|
20
|
+
},
|
|
21
|
+
info: (...values) => {
|
|
22
|
+
write({ ...context, level: 'info', values });
|
|
23
|
+
},
|
|
24
|
+
warn: (...values) => {
|
|
25
|
+
write({ ...context, level: 'warn', values });
|
|
26
|
+
},
|
|
27
|
+
error: (...values) => {
|
|
28
|
+
write({ ...context, level: 'error', values });
|
|
29
|
+
},
|
|
20
30
|
child: (ctx) => createLogger(write, { ...context, ...ctx }),
|
|
21
31
|
};
|
|
22
32
|
}
|
package/src/objects/get.ts
CHANGED
package/src/objects/set.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type FetchLike } from '../fetch';
|
|
2
|
-
import {
|
|
2
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis';
|
|
3
3
|
|
|
4
4
|
export function createFetchWithProxyByNodeFetch({
|
|
5
5
|
proxy,
|
|
6
6
|
fetch,
|
|
7
7
|
}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {
|
|
8
|
+
const globalThis = getGlobalThis();
|
|
8
9
|
if (!proxy) {
|
|
9
10
|
return fetch || globalThis.fetch;
|
|
10
11
|
}
|
|
@@ -16,7 +17,7 @@ export function createFetchWithProxyByNodeFetch({
|
|
|
16
17
|
return async (url, init?: RequestInit) => {
|
|
17
18
|
if (!agent) {
|
|
18
19
|
const { default: createHttpsProxyAgent } = await import('https-proxy-agent');
|
|
19
|
-
agent = createHttpsProxyAgent(proxy);
|
|
20
|
+
agent = (createHttpsProxyAgent as any)(proxy);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
// node-fetch 才可以,node v18 fetch 不支持
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';
|
|
2
|
-
import {
|
|
2
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis';
|
|
3
3
|
|
|
4
4
|
export async function polyfillJsDom() {
|
|
5
5
|
if (typeof window !== 'undefined') {
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
const globalThis = getGlobalThis();
|
|
10
|
+
|
|
9
11
|
const { ResourceLoader, JSDOM } = await import('jsdom');
|
|
10
12
|
|
|
11
13
|
// https://github.com/lukechilds/window/blob/master/src/index.js
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { MaybePromise } from '../asyncs/MaybePromise';
|
|
2
|
-
import {
|
|
2
|
+
import { getGlobalThis } from '../isomorphics/getGlobalThis';
|
|
3
3
|
|
|
4
4
|
export function polyfillWebSocket(ws: any): boolean;
|
|
5
5
|
export function polyfillWebSocket(ws?: undefined): Promise<boolean>;
|
|
6
6
|
export function polyfillWebSocket(ws?: any): MaybePromise<boolean> {
|
|
7
|
+
const globalThis = getGlobalThis();
|
|
7
8
|
if ('WebSocket' in globalThis) {
|
|
8
9
|
return false;
|
|
9
10
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"globalThis-ee7c1669.js","sources":["../../src/isomorphics/getGlobalThis.ts","../../src/isomorphics/globalThis.ts"],"sourcesContent":["declare const global: typeof globalThis;\n\n/**\n * isomorphic globalThis\n *\n * globalThis supported by ff 65, Chrome 71, Node 12, babel\n *\n * non-standard globalThis supported for Alipay Miniprogram\n *\n * @see https://caniuse.com/#search=globalThis\n * @see https://v8.dev/features/globalthis\n */\nexport const getGlobalThis = (): typeof globalThis => {\n if (typeof globalThis !== 'undefined') return globalThis;\n if (typeof self !== 'undefined') return self;\n if (typeof window !== 'undefined') return window;\n if (typeof global !== 'undefined') return global as any;\n if (typeof this !== 'undefined') return this as any;\n throw new Error('Unable to locate global `this`');\n};\n","import { getGlobalThis } from './getGlobalThis';\n\nexport const globalThis = getGlobalThis();\n"],"names":["getGlobalThis","globalThis"],"mappings":"AAYO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAMA,EAAgB,CAAyB,CAAA,CAAA,CAAA,CACpD,GAAI,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAe,IAAa,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAC9C,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,KAAS,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,KACxC,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,OAAW,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAC1C,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,OAAO,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,OAAO,CAE1C,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,IAAI,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAgC,CAClD,CAAA,CCjBaC,EAAaD,CAAc,CAAA,CAAA;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"globalThis-000611c3.js","sources":["../../src/isomorphics/getGlobalThis.ts","../../src/isomorphics/globalThis.ts"],"sourcesContent":["declare const global: typeof globalThis;\n\n/**\n * isomorphic globalThis\n *\n * globalThis supported by ff 65, Chrome 71, Node 12, babel\n *\n * non-standard globalThis supported for Alipay Miniprogram\n *\n * @see https://caniuse.com/#search=globalThis\n * @see https://v8.dev/features/globalthis\n */\nexport const getGlobalThis = (): typeof globalThis => {\n if (typeof globalThis !== 'undefined') return globalThis;\n if (typeof self !== 'undefined') return self;\n if (typeof window !== 'undefined') return window;\n if (typeof global !== 'undefined') return global as any;\n if (typeof this !== 'undefined') return this as any;\n throw new Error('Unable to locate global `this`');\n};\n","import { getGlobalThis } from './getGlobalThis';\n\nexport const globalThis = getGlobalThis();\n"],"names":["getGlobalThis","globalThis"],"mappings":"AAYO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAMA,CAAgB,CAAA,CAAA,CAAA,CAAA,CAAyB,CACpD,CAAA,CAAA,CAAI,OAAO,CAAe,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAC9C,GAAI,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,KACxC,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAC1C,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,OAAW,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAE1C,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,IAAI,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAgC,CAClD,CAAA,CCjBaC,EAAaD,CAAc,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
System.register([],function(t){"use strict";return{execute:function(){const e=t("a",()=>{if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global;throw new Error("Unable to locate global `this`")}),o=t("g",e())}}});
|
|
2
|
-
//# sourceMappingURL=globalThis-7bba6592.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"globalThis-7bba6592.js","sources":["../../src/isomorphics/getGlobalThis.ts","../../src/isomorphics/globalThis.ts"],"sourcesContent":["declare const global: typeof globalThis;\n\n/**\n * isomorphic globalThis\n *\n * globalThis supported by ff 65, Chrome 71, Node 12, babel\n *\n * non-standard globalThis supported for Alipay Miniprogram\n *\n * @see https://caniuse.com/#search=globalThis\n * @see https://v8.dev/features/globalthis\n */\nexport const getGlobalThis = (): typeof globalThis => {\n if (typeof globalThis !== 'undefined') return globalThis;\n if (typeof self !== 'undefined') return self;\n if (typeof window !== 'undefined') return window;\n if (typeof global !== 'undefined') return global as any;\n if (typeof this !== 'undefined') return this as any;\n throw new Error('Unable to locate global `this`');\n};\n","import { getGlobalThis } from './getGlobalThis';\n\nexport const globalThis = getGlobalThis();\n"],"names":["getGlobalThis","globalThis"],"mappings":"sEAYa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAA,QAAgB,CAAyB,CAAA,CAAA,CAAA,CACpD,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAe,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAC9C,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,OAAO,CACxC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAW,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAC1C,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAW,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAE1C,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAgC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAClD,CAAA,CAAA,CCjBaC,KAAaD,CAAAA,CAAAA,CAAAA,CAAAA,CAAc,CAAA;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"globalThis.js","sources":["../../src/isomorphics/globalThis.ts"],"sourcesContent":["import { getGlobalThis } from './getGlobalThis';\n\nexport const globalThis = getGlobalThis();\n"],"names":[],"mappings":";;AAEO,MAAM,aAAa,aAAc;;;;"}
|