@wener/utils 1.1.13 → 1.1.14

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.
Files changed (61) hide show
  1. package/dist/LICENSE.txt +1 -135
  2. package/dist/cjs/index.cjs +1 -1
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/server.cjs +1 -1
  5. package/dist/cjs/server.cjs.map +1 -1
  6. package/dist/esm/index.js +2 -2
  7. package/dist/esm/index.js.map +1 -1
  8. package/dist/esm/server.js +1 -1
  9. package/dist/esm/server.js.map +1 -1
  10. package/dist/system/index.js +2 -2
  11. package/dist/system/index.js.map +1 -1
  12. package/dist/system/server.js +1 -1
  13. package/dist/system/server.js.map +1 -1
  14. package/lib/server.js +3 -1
  15. package/lib/server.js.map +1 -1
  16. package/lib/servers/createFetchWithProxy.js +13 -0
  17. package/lib/servers/createFetchWithProxy.js.map +1 -0
  18. package/lib/servers/{createProxyFetch.js → createFetchWithProxyByNodeFetch.js} +6 -3
  19. package/lib/servers/createFetchWithProxyByNodeFetch.js.map +1 -0
  20. package/lib/servers/createFetchWithProxyByUndici.js +28 -0
  21. package/lib/servers/createFetchWithProxyByUndici.js.map +1 -0
  22. package/package.json +20 -28
  23. package/src/asyncs/createLazyPromise.test.ts +21 -21
  24. package/src/crypto/hashing.test.ts +10 -12
  25. package/src/crypto/pem/__snapshots__/pem.test.ts.snap +18 -0
  26. package/src/crypto/pem/pem.test.ts +14 -17
  27. package/src/crypto/ulid.test.ts +9 -9
  28. package/src/i18n/createTranslate.test.ts +76 -88
  29. package/src/io/ArrayBuffer.test-d.ts +4 -2
  30. package/src/io/ArrayBuffers.base64.test.ts +17 -17
  31. package/src/io/ArrayBuffers.test.ts +8 -8
  32. package/src/io/Buffer.test.ts +4 -4
  33. package/src/io/isBuffer.test.ts +4 -4
  34. package/src/io/isTransferable.test.ts +7 -6
  35. package/src/isomorphics/structuredClone.test.ts +4 -4
  36. package/src/langs/deepEqual.test.ts +4 -4
  37. package/src/langs/langs.test.ts +3 -3
  38. package/src/libs/ms.test.ts +311 -0
  39. package/src/logging/logger.test.ts +8 -8
  40. package/src/modules/parseModuleId.test.ts +3 -3
  41. package/src/objects/get.test-d.ts +30 -22
  42. package/src/objects/parseObjectPath.test.ts +3 -3
  43. package/src/objects/set.test.ts +98 -117
  44. package/src/server.ts +3 -1
  45. package/src/servers/createFetchWithLogger.ts +75 -0
  46. package/src/servers/createFetchWithProxy.ts +12 -0
  47. package/src/servers/{createProxyFetch.ts → createFetchWithProxyByNodeFetch.ts} +4 -1
  48. package/src/servers/createFetchWithProxyByUndici.ts +36 -0
  49. package/src/servers/polyfillBrowser.test.ts +9 -9
  50. package/src/strings/renderTemplate.test.ts +6 -9
  51. package/src/validations/parseTimestamp.test.ts +4 -4
  52. package/dist/cjs/index-da9513d6.js +0 -13
  53. package/dist/cjs/index-da9513d6.js.map +0 -1
  54. package/dist/esm/index-c696799a.js +0 -13
  55. package/dist/esm/index-c696799a.js.map +0 -1
  56. package/dist/system/index-2dfef0f3.js +0 -13
  57. package/dist/system/index-2dfef0f3.js.map +0 -1
  58. package/lib/servers/createProxyFetch.js.map +0 -1
  59. package/src/crypto/pem/pem.test.ts.md +0 -24
  60. package/src/crypto/pem/pem.test.ts.snap +0 -0
  61. package/src/objects/get.test.ts +0 -63
@@ -1,2 +1,2 @@
1
- System.register(["./globalThis-7bba6592.js"],function(g,y){"use strict";var c;return{setters:[function(p){c=p.g}],execute:function(){g({createProxyFetch:d,polyfillBrowser:b,polyfillCrypto:p,polyfillFetch:w,polyfillJsDom:h});async function p(){return"crypto"in c?!1:(c.crypto=(await y.import("node:crypto")).webcrypto,!0)}function w(a){if("fetch"in globalThis)return!1;if(a){const{default:r,Response:n,Headers:l,Request:i,AbortError:u,FetchError:e,FormData:s,Blob:f,File:o}=a;return Object.assign(globalThis,{fetch:r,Response:n,Headers:l,Request:i,AbortError:u,FetchError:e,FormData:s,Blob:f,File:o}),!0}return y.import("node-fetch").then(r=>w(r))}async function h(){if(typeof window<"u")return!1;const{ResourceLoader:a,JSDOM:r}=await y.import("jsdom");class n{constructor(s={}){const{proxy:f,strictSSL:o,userAgent:t,...F}=s,O=new a({proxy:f,strictSSL:o,userAgent:t});return new r("",Object.assign(F,{resources:O})).window}}const l={},i=(()=>Object.getOwnPropertyNames(new n(l)).filter(e=>typeof c[e]<"u"))();function u(...e){const s=e.filter(t=>Array.isArray(t))[0],f=e.filter(t=>!Array.isArray(t))[0],o=new n(Object.assign({},f,l));return Object.getOwnPropertyNames(o).filter(t=>!i.includes(t)).filter(t=>!(s&&s.indexOf(t)===-1)).filter(t=>{switch(t){case"undefined":return!1}return!0}).forEach(t=>{Object.defineProperty(c,t,{configurable:!0,get:()=>o[t]})}),o}return u({url:"http://localhost"}),!0}async function b(){await p(),await w(),await h()}function d(a,r){if(!a)return r||c.fetch;let n;const l=c.Request;let i,u;return async(e,s)=>{if(!n){const{default:f}=await y.import("./index-2dfef0f3.js").then(function(o){return o.i});n=f(a)}return i||({Request:i,default:u}=await y.import("node-fetch")),r||=u,e instanceof l?r(new l(e,{agent:n})):e instanceof i?r(new i(e,{agent:n})):r(e,{...s,agent:n})}}}}});
1
+ System.register(["./globalThis-7bba6592.js"],function(b,u){"use strict";var f;return{setters:[function(h){f=h.g}],execute:function(){b({createFetchWithProxy:F,createFetchWithProxyByNodeFetch:d,createFetchWithProxyByUndici:g,polyfillBrowser:x,polyfillCrypto:h,polyfillFetch:p,polyfillJsDom:w});async function h(){return"crypto"in f?!1:(f.crypto=(await u.import("node:crypto")).webcrypto,!0)}function p(r){if("fetch"in globalThis)return!1;if(r){const{default:t,Response:o,Headers:i,Request:c,AbortError:s,FetchError:e,FormData:a,Blob:l,File:y}=r;return Object.assign(globalThis,{fetch:t,Response:o,Headers:i,Request:c,AbortError:s,FetchError:e,FormData:a,Blob:l,File:y}),!0}return u.import("node-fetch").then(t=>p(t))}async function w(){if(typeof window<"u")return!1;const{ResourceLoader:r,JSDOM:t}=await u.import("jsdom");class o{constructor(a={}){const{proxy:l,strictSSL:y,userAgent:n,...m}=a,O=new r({proxy:l,strictSSL:y,userAgent:n});return new t("",Object.assign(m,{resources:O})).window}}const i={},c=(()=>Object.getOwnPropertyNames(new o(i)).filter(e=>typeof f[e]<"u"))();function s(...e){const a=e.filter(n=>Array.isArray(n))[0],l=e.filter(n=>!Array.isArray(n))[0],y=new o(Object.assign({},l,i));return Object.getOwnPropertyNames(y).filter(n=>!c.includes(n)).filter(n=>!(a&&a.indexOf(n)===-1)).filter(n=>{switch(n){case"undefined":return!1}return!0}).forEach(n=>{Object.defineProperty(f,n,{configurable:!0,get:()=>y[n]})}),y}return s({url:"http://localhost"}),!0}async function x(){await h(),await p(),await w()}function d({proxy:r,fetch:t}={}){if(!r)return t||f.fetch;let o;const i=f.Request;let c,s;return async(e,a)=>{if(!o){const{default:l}=await u.import("https-proxy-agent");o=l(r)}return c||({Request:c,default:s}=await u.import("node-fetch")),t||=s,e instanceof i?t(new i(e,{agent:o})):e instanceof c?t(new c(e,{agent:o})):t(e,{...a,agent:o})}}function g({proxy:r,fetch:t,undici:o}={}){if(!r)return t||globalThis.fetch;let i;return async(...c)=>{const s=c[1]||={};if(s.body instanceof ReadableStream&&(s.duplex||="half"),!i){o||=u.import("undici");const e=await o,a=e.ProxyAgent;t||=e.fetch,i=new a(r)}return s.dispatcher=i,await t(...c)}}function F({proxy:r,fetch:t}){return r?parseInt(process.versions.node)>=18?g({proxy:r,fetch:t}):d({proxy:r,fetch:t}):t||globalThis.fetch}}}});
2
2
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sources":["../../src/servers/polyfillCrypto.ts","../../src/servers/polyfillFetch.ts","../../src/servers/polyfillJsDom.ts","../../src/servers/polyfillBrowser.ts","../../src/servers/createProxyFetch.ts"],"sourcesContent":["import { globalThis } from '../isomorphics/globalThis';\n\nexport async function polyfillCrypto() {\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","import type { MaybePromise } from '../asyncs/MaybePromise';\n\nexport function polyfillFetch(nodeFetch: typeof import('node-fetch')): boolean;\nexport function polyfillFetch(nodeFetch?: undefined): Promise<boolean>;\nexport function polyfillFetch(nodeFetch?: typeof import('node-fetch')): MaybePromise<boolean> {\n if ('fetch' in globalThis) {\n return false;\n }\n // sync mode\n if (nodeFetch) {\n const { default: fetch, Response, Headers, Request, AbortError, FetchError, FormData, Blob, File } = nodeFetch;\n Object.assign(globalThis, {\n fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n });\n // abort controller\n return true;\n }\n return import('node-fetch').then((v) => polyfillFetch(v));\n}\n","import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { globalThis } from '../isomorphics/globalThis';\n\nexport async function polyfillJsDom() {\n if (typeof window !== 'undefined') {\n return false;\n }\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","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","import { type FetchLike } from '../fetch';\nimport { globalThis } from '../isomorphics/globalThis';\n\nexport function createProxyFetch(proxy?: string, fetch?: FetchLike): FetchLike {\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(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":["polyfillCrypto","globalThis","polyfillFetch","nodeFetch","fetch","Response","Headers","Request","AbortError","FetchError","FormData","Blob","File","module","v","polyfillJsDom","ResourceLoader","JSDOM","Window","opts","proxy","strictSSL","userAgent","jsdomOpts","resources","defaultJsdomConfig","protectedProperties","prop","installEnv","args","properties","arg","userJsdomConfig","window","polyfillBrowser","createProxyFetch","agent","NodeRequest","NodeFetch","url","init","createHttpsProxyAgent"],"mappings":"gOAEsB,eAAAA,CAAiB,CAAA,CAAA,CACrC,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAYC,CACP,CAAA,CAAA,CAAA,CAAA,CAERA,EAAmB,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAG,UACpD,CACT,CAAA,CAAA,CCJO,CAASC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAcC,CAAgE,CAAA,CAC5F,GAAI,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACb,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAGT,CAAIA,CAAAA,CAAAA,CAAAA,CAAW,CACb,CAAM,CAAA,CAAA,CAAA,CAAA,CAAE,CAASC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAA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AAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACF,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAASA,EAAa,CAASC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAU,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,UAAa,YAAY,CAG3ElC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAUkC,CAENC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAehC,CACTH,CAAAA,CAAAA,CAAc,IAAIG,CAAQgC,CAAAA,CAAAA,CAAK,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAH,CAAM,CAAQ,CAAC,CAErDG,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAuBF,CAClBjC,CAAAA,CAAAA,CAAc,CAAIiC,CAAAA,CAAAA,CAAAA,CAAAA,CAAYE,EAAK,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAH,CAAM,CAAQ,CAAC,CAAA,CAEtDhC,EAAcmC,CAAK,CAAA,CACzB,CAAGC,CAAAA,CAAAA,CAAAA,CACH,CAAAJ,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACF,CAAQ,CACV,CACF;"}
1
+ {"version":3,"file":"server.js","sources":["../../src/servers/polyfillCrypto.ts","../../src/servers/polyfillFetch.ts","../../src/servers/polyfillJsDom.ts","../../src/servers/polyfillBrowser.ts","../../src/servers/createFetchWithProxyByNodeFetch.ts","../../src/servers/createFetchWithProxyByUndici.ts","../../src/servers/createFetchWithProxy.ts"],"sourcesContent":["import { globalThis } from '../isomorphics/globalThis';\n\nexport async function polyfillCrypto() {\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","import type { MaybePromise } from '../asyncs/MaybePromise';\n\nexport function polyfillFetch(nodeFetch: typeof import('node-fetch')): boolean;\nexport function polyfillFetch(nodeFetch?: undefined): Promise<boolean>;\nexport function polyfillFetch(nodeFetch?: typeof import('node-fetch')): MaybePromise<boolean> {\n if ('fetch' in globalThis) {\n return false;\n }\n // sync mode\n if (nodeFetch) {\n const { default: fetch, Response, Headers, Request, AbortError, FetchError, FormData, Blob, File } = nodeFetch;\n Object.assign(globalThis, {\n fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n });\n // abort controller\n return true;\n }\n return import('node-fetch').then((v) => polyfillFetch(v));\n}\n","import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { globalThis } from '../isomorphics/globalThis';\n\nexport async function polyfillJsDom() {\n if (typeof window !== 'undefined') {\n return false;\n }\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","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","import { type FetchLike } from '../fetch';\nimport { globalThis } from '../isomorphics/globalThis';\n\nexport function createFetchWithProxyByNodeFetch({\n proxy,\n fetch,\n}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {\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(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","import { MaybePromise } from 'rollup';\nimport { FetchLike } from '../fetch';\n\nexport function createFetchWithProxyByUndici({\n proxy,\n fetch,\n undici,\n}: {\n proxy?: string;\n fetch?: FetchLike;\n undici?: MaybePromise<{ fetch: any; ProxyAgent: any }>;\n} = {}): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n let agent: any;\n return async (...args) => {\n const init: RequestInit & { duplex?: string; dispatcher?: any } = (args[1] ||= {});\n if (init.body instanceof ReadableStream) {\n // https://github.com/nodejs/node/issues/46221\n init.duplex ||= 'half';\n }\n if (!agent) {\n // if in next use 'next/dist/compiled/undici'\n undici ||= import('undici');\n const mod = await undici;\n const ProxyAgent = mod.ProxyAgent;\n fetch ||= mod.fetch;\n agent = new ProxyAgent(proxy);\n // https://github.com/nodejs/node/issues/43187#issuecomment-1134634174\n // (global as any)[Symbol.for('undici.globalDispatcher.1')] = agent;\n }\n init.dispatcher = agent;\n return await fetch!(...args);\n };\n}\n","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":["polyfillCrypto","globalThis","polyfillFetch","nodeFetch","fetch","Response","Headers","Request","AbortError","FetchError","FormData","Blob","File","module","v","polyfillJsDom","ResourceLoader","JSDOM","Window","opts","proxy","strictSSL","userAgent","jsdomOpts","resources","defaultJsdomConfig","protectedProperties","prop","installEnv","args","properties","arg","userJsdomConfig","window","polyfillBrowser","createFetchWithProxyByNodeFetch","agent","NodeRequest","NodeFetch","url","init","createHttpsProxyAgent","createFetchWithProxyByUndici","undici","mod","ProxyAgent","createFetchWithProxy"],"mappings":"oSAEsB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAA,CAAiB,CAAA,CAAA,CACrC,MAAI,CAAYC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACP,CAERA,CAAAA,CAAAA,CAAAA,CAAAA,CAAmB,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,aAAa,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACpD,CACT,CAAA,CAAA,CCJO,CAASC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAcC,CAAgE,CAAA,CAC5F,GAAI,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACb,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAGT,CAAIA,CAAAA,CAAAA,CAAAA,CAAW,CACb,CAAA,CAAA,CAAA,CAAA,CAAM,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAASC,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAC,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAC,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAC,EAAS,CA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,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACX,MAAMhC,CAAO,CAAA,CAAA,CAAA,CAAGyB,CAAI,CAC7B,CACF,CC/BgB,CAAAiB,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAqB,CAAE,CAAA1B,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAO,CAAAhB,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAM,CAAqD,CAAA,CACvG,CAAKgB,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAGE,SAAS,CAAQ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAK,CACtCsB,CAAAA,CAAAA,CAAAA,CAA6B,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAtB,EAAO,CAAAhB,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAM,CAAC,CAAA,CAC7C+B,CAAgC,CAAA,CAAE,CAAAf,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAO,MAAAhB,CAAM,CAAC,CAJ3CA,CAAAA,CAAAA,CAAAA,CAAS,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAK/B;"}
package/lib/server.js CHANGED
@@ -2,5 +2,7 @@ export { polyfillCrypto } from './servers/polyfillCrypto.js';
2
2
  export { polyfillFetch } from './servers/polyfillFetch.js';
3
3
  export { polyfillJsDom } from './servers/polyfillJsDom.js';
4
4
  export { polyfillBrowser } from './servers/polyfillBrowser.js';
5
- export { createProxyFetch } from './servers/createProxyFetch.js';
5
+ export { createFetchWithProxyByNodeFetch } from './servers/createFetchWithProxyByNodeFetch.js';
6
+ export { createFetchWithProxyByUndici } from './servers/createFetchWithProxyByUndici.js';
7
+ export { createFetchWithProxy } from './servers/createFetchWithProxy.js';
6
8
  //# sourceMappingURL=server.js.map
package/lib/server.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,13 @@
1
+ import '../isomorphics/globalThis.js';
2
+ import { createFetchWithProxyByNodeFetch } from './createFetchWithProxyByNodeFetch.js';
3
+ import { createFetchWithProxyByUndici } from './createFetchWithProxyByUndici.js';
4
+
5
+ function createFetchWithProxy({ proxy, fetch }) {
6
+ if (!proxy) {
7
+ return fetch || globalThis.fetch;
8
+ }
9
+ return parseInt(process.versions.node) >= 18 ? createFetchWithProxyByUndici({ proxy, fetch }) : createFetchWithProxyByNodeFetch({ proxy, fetch });
10
+ }
11
+
12
+ export { createFetchWithProxy };
13
+ //# sourceMappingURL=createFetchWithProxy.js.map
@@ -0,0 +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":";;;;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,6 +1,9 @@
1
1
  import { globalThis } from '../isomorphics/globalThis.js';
2
2
 
3
- function createProxyFetch(proxy, fetch) {
3
+ function createFetchWithProxyByNodeFetch({
4
+ proxy,
5
+ fetch
6
+ } = {}) {
4
7
  if (!proxy) {
5
8
  return fetch || globalThis.fetch;
6
9
  }
@@ -30,5 +33,5 @@ function createProxyFetch(proxy, fetch) {
30
33
  };
31
34
  }
32
35
 
33
- export { createProxyFetch };
34
- //# sourceMappingURL=createProxyFetch.js.map
36
+ export { createFetchWithProxyByNodeFetch };
37
+ //# sourceMappingURL=createFetchWithProxyByNodeFetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFetchWithProxyByNodeFetch.js","sources":["../../src/servers/createFetchWithProxyByNodeFetch.ts"],"sourcesContent":["import { type FetchLike } from '../fetch';\nimport { globalThis } from '../isomorphics/globalThis';\n\nexport function createFetchWithProxyByNodeFetch({\n proxy,\n fetch,\n}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {\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(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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1,28 @@
1
+ function createFetchWithProxyByUndici({
2
+ proxy,
3
+ fetch,
4
+ undici
5
+ } = {}) {
6
+ if (!proxy) {
7
+ return fetch || globalThis.fetch;
8
+ }
9
+ let agent;
10
+ return async (...args) => {
11
+ const init = args[1] || (args[1] = {});
12
+ if (init.body instanceof ReadableStream) {
13
+ init.duplex || (init.duplex = "half");
14
+ }
15
+ if (!agent) {
16
+ undici || (undici = import('undici'));
17
+ const mod = await undici;
18
+ const ProxyAgent = mod.ProxyAgent;
19
+ fetch || (fetch = mod.fetch);
20
+ agent = new ProxyAgent(proxy);
21
+ }
22
+ init.dispatcher = agent;
23
+ return await fetch(...args);
24
+ };
25
+ }
26
+
27
+ export { createFetchWithProxyByUndici };
28
+ //# sourceMappingURL=createFetchWithProxyByUndici.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFetchWithProxyByUndici.js","sources":["../../src/servers/createFetchWithProxyByUndici.ts"],"sourcesContent":["import { MaybePromise } from 'rollup';\nimport { FetchLike } from '../fetch';\n\nexport function createFetchWithProxyByUndici({\n proxy,\n fetch,\n undici,\n}: {\n proxy?: string;\n fetch?: FetchLike;\n undici?: MaybePromise<{ fetch: any; ProxyAgent: any }>;\n} = {}): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n let agent: any;\n return async (...args) => {\n const init: RequestInit & { duplex?: string; dispatcher?: any } = (args[1] ||= {});\n if (init.body instanceof ReadableStream) {\n // https://github.com/nodejs/node/issues/46221\n init.duplex ||= 'half';\n }\n if (!agent) {\n // if in next use 'next/dist/compiled/undici'\n undici ||= import('undici');\n const mod = await undici;\n const ProxyAgent = mod.ProxyAgent;\n fetch ||= mod.fetch;\n agent = new ProxyAgent(proxy);\n // https://github.com/nodejs/node/issues/43187#issuecomment-1134634174\n // (global as any)[Symbol.for('undici.globalDispatcher.1')] = agent;\n }\n init.dispatcher = agent;\n return await fetch!(...args);\n };\n}\n"],"names":[],"mappings":"AAGO,SAAS,4BAA6B,CAAA;AAAA,EAC3C,KAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AACF,CAAA,GAII,EAAe,EAAA;AACjB,EAAA,IAAI,CAAC,KAAO,EAAA;AACV,IAAA,OAAO,SAAS,UAAW,CAAA,KAAA,CAAA;AAAA,GAC7B;AACA,EAAI,IAAA,KAAA,CAAA;AACJ,EAAA,OAAO,UAAU,IAAS,KAAA;AACxB,IAAM,MAAA,IAAA,GAA6D,sBAAY,EAAC,CAAA,CAAA;AAChF,IAAI,IAAA,IAAA,CAAK,gBAAgB,cAAgB,EAAA;AAEvC,MAAK,IAAA,CAAA,MAAA,KAAL,KAAK,MAAW,GAAA,MAAA,CAAA,CAAA;AAAA,KAClB;AACA,IAAA,IAAI,CAAC,KAAO,EAAA;AAEV,MAAA,MAAA,KAAA,MAAA,GAAW,OAAO,QAAQ,CAAA,CAAA,CAAA;AAC1B,MAAA,MAAM,MAAM,MAAM,MAAA,CAAA;AAClB,MAAA,MAAM,aAAa,GAAI,CAAA,UAAA,CAAA;AACvB,MAAA,KAAA,KAAA,KAAA,GAAU,GAAI,CAAA,KAAA,CAAA,CAAA;AACd,MAAQ,KAAA,GAAA,IAAI,WAAW,KAAK,CAAA,CAAA;AAAA,KAG9B;AACA,IAAA,IAAA,CAAK,UAAa,GAAA,KAAA,CAAA;AAClB,IAAO,OAAA,MAAM,KAAO,CAAA,GAAG,IAAI,CAAA,CAAA;AAAA,GAC7B,CAAA;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "type": "module",
5
5
  "description": "Utils for daily use",
6
6
  "repository": {
@@ -16,11 +16,8 @@
16
16
  ".": {
17
17
  "types": "./src/index.ts",
18
18
  "typescript": "./src/index.ts",
19
- "import": "./lib/index.js",
20
- "system": {
21
- "default": "./dist/system/index.js"
22
- },
23
- "require": "./dist/cjs/index.cjs"
19
+ "system": "./dist/system/index.js",
20
+ "import": "./lib/index.js"
24
21
  },
25
22
  "./types": {
26
23
  "types": "./types.d.ts"
@@ -28,11 +25,8 @@
28
25
  "./server": {
29
26
  "types": "./src/server.ts",
30
27
  "typescript": "./src/server.ts",
31
- "import": "./lib/server.js",
32
- "system": {
33
- "default": "./dist/system/server.js"
34
- },
35
- "require": "./dist/cjs/server.cjs"
28
+ "system": "./dist/system/server.js",
29
+ "import": "./lib/server.js"
36
30
  },
37
31
  "./src/*": "./src/*",
38
32
  "./package.json": "./package.json"
@@ -57,29 +51,28 @@
57
51
  "lodash"
58
52
  ],
59
53
  "devDependencies": {
60
- "@types/lodash": "^4.14.191",
54
+ "@types/lodash": "^4.14.194",
61
55
  "@types/ws": "^8.5.4",
62
- "ava": "^5.1.1",
63
56
  "https-proxy-agent": "^5.0.1",
64
- "lodash": "^4.17.21",
65
- "tsd": "^0.25.0"
57
+ "lodash": "^4.17.21"
66
58
  },
67
59
  "publishConfig": {
68
60
  "registry": "https://registry.npmjs.org",
69
61
  "access": "public"
70
62
  },
71
- "sideEffects": false,
72
- "ava": {
73
- "extensions": {
74
- "ts": "module"
63
+ "peerDependencies": {
64
+ "https-proxy-agent": "*",
65
+ "undici": "*"
66
+ },
67
+ "peerDependenciesMeta": {
68
+ "undici": {
69
+ "optional": true
75
70
  },
76
- "nodeArguments": [
77
- "--conditions=typescript",
78
- "--experimental-import-meta-resolve",
79
- "--require=@wener/wode/suppress-experimental.cjs",
80
- "--loader=tsx"
81
- ]
71
+ "https-proxy-agent": {
72
+ "optional": true
73
+ }
82
74
  },
75
+ "sideEffects": false,
83
76
  "rollup": {
84
77
  "input": [
85
78
  "./src/index.ts",
@@ -90,9 +83,8 @@
90
83
  "node-fetch"
91
84
  ]
92
85
  },
93
- "typedoc": {
94
- "entryPoint": "./src/typedoc.ts",
95
- "readmeFile": "./README.md"
86
+ "dependencies": {
87
+ "undici": "^5.22.0"
96
88
  },
97
89
  "scripts": {
98
90
  "build": "make prepublish",
@@ -1,54 +1,54 @@
1
- import test from 'ava';
1
+ import { test, expect } from 'vitest';
2
2
  import { createLazyPromise } from './createLazyPromise';
3
3
  import { sleep } from './sleep';
4
4
 
5
- test('basic', async (t) => {
5
+ test('basic', async () => {
6
6
  const promise = createLazyPromise();
7
7
  let r = 0;
8
8
  void promise.then((v) => (r = v));
9
- t.is(r, 0);
9
+ expect(r).toBe(0);
10
10
  const { resolve, reject } = promise;
11
- t.truthy(resolve);
12
- t.truthy(reject);
11
+ expect(resolve).toBeTruthy();
12
+ expect(reject).toBeTruthy();
13
13
  resolve(1);
14
- t.is(r, 0);
14
+ expect(r).toBe(0);
15
15
  await promise;
16
- t.is(r, 1);
16
+ expect(r).toBe(1);
17
17
  });
18
18
 
19
- test('manual resolve skip exec', async (t) => {
19
+ test('manual resolve skip exec', async () => {
20
20
  const promise = createLazyPromise<number>(() => {
21
- t.fail();
21
+ expect.fail();
22
22
  });
23
23
  promise.resolve(-1);
24
- t.is(await promise, -1);
24
+ expect(await promise).toBe(-1);
25
25
  });
26
26
 
27
- test('exec', async (t) => {
27
+ test('exec', async () => {
28
28
  let r = 0;
29
29
  const promise = createLazyPromise((resolve) => {
30
30
  r++;
31
31
  resolve(10);
32
32
  });
33
33
  await sleep(10);
34
- t.is(r, 0);
35
- t.is(await promise, 10);
36
- t.is(r, 1);
34
+ expect(r).toBe(0);
35
+ expect(await promise).toBe(10);
36
+ expect(r).toBe(1);
37
37
  promise.resolve(20);
38
- t.is(await promise, 10);
38
+ expect(await promise).toBe(10);
39
39
  });
40
40
 
41
- test('exec auto', async (t) => {
41
+ test('exec auto', async () => {
42
42
  let r = 0;
43
43
  const promise = createLazyPromise(() => {
44
44
  r++;
45
45
  return 10;
46
46
  });
47
47
  await sleep(10);
48
- t.is(r, 0);
48
+ expect(r).toBe(0);
49
49
  void promise.then(() => undefined);
50
- t.is(await promise, 10);
51
- t.is(r, 1);
52
- t.is(await promise, 10);
53
- t.is(r, 1);
50
+ expect(await promise).toBe(10);
51
+ expect(r).toBe(1);
52
+ expect(await promise).toBe(10);
53
+ expect(r).toBe(1);
54
54
  });
@@ -1,30 +1,28 @@
1
- import test from 'ava';
1
+ import { test, beforeAll, expect } from 'vitest';
2
2
  import { polyfillCrypto } from '../servers/polyfillCrypto';
3
3
  import { isUUID } from '../validations/isUUID';
4
4
  import { hex } from './base';
5
5
  import { sha1, sha256, sha384, sha512 } from './hashing';
6
6
  import { _randomUUID } from './randomUUID';
7
7
 
8
- test.before(async () => {
8
+ beforeAll(async () => {
9
9
  await polyfillCrypto();
10
10
  });
11
11
 
12
- test('sha', async (t) => {
13
- t.is(hex(await sha1('')), 'da39a3ee5e6b4b0d3255bfef95601890afd80709');
14
- t.is(hex(await sha1('abc')), 'a9993e364706816aba3e25717850c26c9cd0d89d');
15
- t.is(hex(await sha256('')), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
16
- t.is(
17
- hex(await sha384('')),
12
+ test('sha', async () => {
13
+ expect(hex(await sha1(''))).toBe('da39a3ee5e6b4b0d3255bfef95601890afd80709');
14
+ expect(hex(await sha1('abc'))).toBe('a9993e364706816aba3e25717850c26c9cd0d89d');
15
+ expect(hex(await sha256(''))).toBe('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
16
+ expect(hex(await sha384(''))).toBe(
18
17
  '38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b',
19
18
  );
20
- t.is(
21
- hex(await sha512('')),
19
+ expect(hex(await sha512(''))).toBe(
22
20
  'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e',
23
21
  );
24
22
  });
25
23
 
26
- test('randomUUID', (t) => {
24
+ test('randomUUID', () => {
27
25
  for (let i = 0; i < 20; i++) {
28
- t.true(isUUID(_randomUUID()));
26
+ expect(isUUID(_randomUUID())).toBeTruthy();
29
27
  }
30
28
  });
@@ -0,0 +1,18 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`cases 1`] = `
4
+ "-----BEGIN RSA PRIVATE KEY-----
5
+ SGVsbG8=
6
+ -----END RSA PRIVATE KEY-----
7
+ "
8
+ `;
9
+
10
+ exports[`cases 2`] = `
11
+ "-----BEGIN RSA PRIVATE KEY-----
12
+ Name: N-:1/=
13
+ Age: 1234
14
+
15
+ TmljZQ==
16
+ -----END RSA PRIVATE KEY-----
17
+ "
18
+ `;
@@ -1,10 +1,10 @@
1
- import test from 'ava';
1
+ import { expect, test } from 'vitest';
2
2
  import { ArrayBuffers } from '../../io/ArrayBuffers';
3
3
  import { PEM } from './pem';
4
4
 
5
5
  const { decode, encode } = PEM;
6
6
 
7
- test('pem', (t) => {
7
+ test('pem', () => {
8
8
  const pem = `-----BEGIN RSA PRIVATE KEY-----
9
9
  Proc-Type: 4,ENCRYPTED
10
10
  DEK-Info: DES-EDE3-CBC,ABC
@@ -27,10 +27,10 @@ MDAwMDAwMDAwMDAwMDAwMA==
27
27
  head: 'Nice\n',
28
28
  tail: 'Hello\n',
29
29
  };
30
- t.deepEqual(decode(input), out);
31
- t.is(encode(out.block), pem);
30
+ expect(decode(input)).toEqual(out);
31
+ expect(encode(out.block)).toBe(pem);
32
32
  });
33
- test('cases', (t) => {
33
+ test('cases', () => {
34
34
  for (const b of [
35
35
  {
36
36
  type: 'RSA PRIVATE KEY',
@@ -47,17 +47,14 @@ test('cases', (t) => {
47
47
  ]) {
48
48
  const s = encode(b);
49
49
  const act = decode(s);
50
- t.deepEqual(
51
- {
52
- ...act.block,
53
- bytes: ArrayBuffers.toString(act.block.bytes),
54
- },
55
- {
56
- header: {},
57
- ...b,
58
- bytes: ArrayBuffers.toString(b.bytes),
59
- },
60
- );
61
- t.snapshot(s);
50
+ expect({
51
+ ...act.block,
52
+ bytes: ArrayBuffers.toString(act.block.bytes),
53
+ }).toStrictEqual({
54
+ header: {},
55
+ ...b,
56
+ bytes: ArrayBuffers.toString(b.bytes),
57
+ });
58
+ expect(s).matchSnapshot();
62
59
  }
63
60
  });
@@ -1,7 +1,7 @@
1
- import test from 'ava';
1
+ import { expect, test } from 'vitest';
2
2
  import { createULID, isULID, parseULID } from './ulid';
3
3
 
4
- test('ulid', (t) => {
4
+ test('ulid', () => {
5
5
  // monotonic
6
6
  {
7
7
  let lastTime = 0;
@@ -13,18 +13,18 @@ test('ulid', (t) => {
13
13
  });
14
14
 
15
15
  const ulid1 = ulid();
16
- t.is(parseULID(ulid1).timestamp, lastTime);
17
- t.true(isULID(ulid1), ulid1);
16
+ expect(parseULID(ulid1).timestamp).toBe(lastTime);
17
+ expect(isULID(ulid1), ulid1).toBeTruthy();
18
18
 
19
19
  const ulid2 = ulid();
20
- t.true(ulid1 < ulid2);
21
- t.true(isULID(ulid2), ulid2);
22
- t.is(parseULID(ulid2).timestamp, lastTime);
20
+ expect(ulid1 < ulid2).toBeTruthy();
21
+ expect(isULID(ulid2), ulid2).toBeTruthy();
22
+ expect(parseULID(ulid2).timestamp).toBe(lastTime);
23
23
  }
24
24
 
25
25
  {
26
26
  const next = createULID();
27
- t.true(isULID(next().toLowerCase()));
28
- t.true(isULID('ttttttttttrrrrrrrrrrrrrrrr'));
27
+ expect(isULID(next().toLowerCase())).toBeTruthy();
28
+ expect(isULID('ttttttttttrrrrrrrrrrrrrrrr')).toBeTruthy();
29
29
  }
30
30
  });