ali-skills 0.0.21 → 0.0.22
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/node_modules/@ali/cli-skills/dist/cli.mjs +1214 -287
- package/node_modules/@ali/cli-skills/package.json +5 -2
- package/node_modules/@ali/o2-open-client/.editorconfig +11 -0
- package/node_modules/@ali/o2-open-client/README.md +80 -0
- package/node_modules/@ali/o2-open-client/abc.json +8 -0
- package/node_modules/@ali/o2-open-client/es/browser/ee.d.ts +23 -0
- package/node_modules/@ali/o2-open-client/es/browser/ee.js +82 -0
- package/node_modules/@ali/o2-open-client/es/browser/entry.d.ts +32 -0
- package/node_modules/@ali/o2-open-client/es/browser/entry.js +306 -0
- package/node_modules/@ali/o2-open-client/es/browser/escape.d.ts +12 -0
- package/node_modules/@ali/o2-open-client/es/browser/escape.js +178 -0
- package/node_modules/@ali/o2-open-client/es/browser/fetch.d.ts +1 -0
- package/node_modules/@ali/o2-open-client/es/browser/fetch.js +14 -0
- package/node_modules/@ali/o2-open-client/es/browser/index.d.ts +1 -0
- package/node_modules/@ali/o2-open-client/es/browser/index.js +1 -0
- package/node_modules/@ali/o2-open-client/es/common/constant.d.ts +42 -0
- package/node_modules/@ali/o2-open-client/es/common/constant.js +53 -0
- package/node_modules/@ali/o2-open-client/es/common/format.d.ts +14 -0
- package/node_modules/@ali/o2-open-client/es/common/format.js +43 -0
- package/node_modules/@ali/o2-open-client/es/common/service-meta.d.ts +33 -0
- package/node_modules/@ali/o2-open-client/es/common/service-meta.js +33 -0
- package/node_modules/@ali/o2-open-client/es/index.d.ts +1 -0
- package/node_modules/@ali/o2-open-client/es/index.js +8 -0
- package/node_modules/@ali/o2-open-client/es/node/config.d.ts +47 -0
- package/node_modules/@ali/o2-open-client/es/node/config.js +188 -0
- package/node_modules/@ali/o2-open-client/es/node/escape.d.ts +22 -0
- package/node_modules/@ali/o2-open-client/es/node/escape.js +131 -0
- package/node_modules/@ali/o2-open-client/es/node/help.d.ts +10 -0
- package/node_modules/@ali/o2-open-client/es/node/help.js +96 -0
- package/node_modules/@ali/o2-open-client/es/node/index.d.ts +48 -0
- package/node_modules/@ali/o2-open-client/es/node/index.js +247 -0
- package/node_modules/@ali/o2-open-client/es/node/token-handler.d.ts +1 -0
- package/node_modules/@ali/o2-open-client/es/node/token-handler.js +21 -0
- package/node_modules/@ali/o2-open-client/lib/browser/ee.d.ts +23 -0
- package/node_modules/@ali/o2-open-client/lib/browser/ee.js +86 -0
- package/node_modules/@ali/o2-open-client/lib/browser/entry.d.ts +32 -0
- package/node_modules/@ali/o2-open-client/lib/browser/entry.js +310 -0
- package/node_modules/@ali/o2-open-client/lib/browser/escape.d.ts +12 -0
- package/node_modules/@ali/o2-open-client/lib/browser/escape.js +185 -0
- package/node_modules/@ali/o2-open-client/lib/browser/fetch.d.ts +1 -0
- package/node_modules/@ali/o2-open-client/lib/browser/fetch.js +18 -0
- package/node_modules/@ali/o2-open-client/lib/common/constant.d.ts +42 -0
- package/node_modules/@ali/o2-open-client/lib/common/constant.js +56 -0
- package/node_modules/@ali/o2-open-client/lib/common/format.d.ts +14 -0
- package/node_modules/@ali/o2-open-client/lib/common/format.js +48 -0
- package/node_modules/@ali/o2-open-client/lib/common/service-meta.d.ts +33 -0
- package/node_modules/@ali/o2-open-client/lib/common/service-meta.js +36 -0
- package/node_modules/@ali/o2-open-client/lib/index.d.ts +1 -0
- package/node_modules/@ali/o2-open-client/lib/index.js +20 -0
- package/node_modules/@ali/o2-open-client/lib/node/config.d.ts +47 -0
- package/node_modules/@ali/o2-open-client/lib/node/config.js +192 -0
- package/node_modules/@ali/o2-open-client/lib/node/escape.d.ts +22 -0
- package/node_modules/@ali/o2-open-client/lib/node/escape.js +137 -0
- package/node_modules/@ali/o2-open-client/lib/node/help.d.ts +10 -0
- package/node_modules/@ali/o2-open-client/lib/node/help.js +100 -0
- package/node_modules/@ali/o2-open-client/lib/node/index.d.ts +48 -0
- package/node_modules/@ali/o2-open-client/lib/node/index.js +250 -0
- package/node_modules/@ali/o2-open-client/lib/node/token-handler.d.ts +1 -0
- package/node_modules/@ali/o2-open-client/lib/node/token-handler.js +25 -0
- package/node_modules/@ali/o2-open-client/package.json +46 -0
- package/node_modules/@ali/o2-open-client/playwright.config.ts +54 -0
- package/node_modules/@ali/o2-open-client/tsconfig.es.json +31 -0
- package/node_modules/@ali/o2-open-client/tsconfig.json +31 -0
- package/node_modules/@ali/o2-open-client/tsx2doc.config.js +5 -0
- package/node_modules/@ali/o2-open-client/typings/index.d.ts +36 -0
- package/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/@types/node/README.md +15 -0
- package/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/node_modules/@types/node/assert.d.ts +1062 -0
- package/node_modules/@types/node/async_hooks.d.ts +605 -0
- package/node_modules/@types/node/buffer.buffer.d.ts +471 -0
- package/node_modules/@types/node/buffer.d.ts +1936 -0
- package/node_modules/@types/node/child_process.d.ts +1475 -0
- package/node_modules/@types/node/cluster.d.ts +577 -0
- package/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
- package/node_modules/@types/node/compatibility/index.d.ts +9 -0
- package/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
- package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/node_modules/@types/node/console.d.ts +452 -0
- package/node_modules/@types/node/constants.d.ts +21 -0
- package/node_modules/@types/node/crypto.d.ts +4590 -0
- package/node_modules/@types/node/dgram.d.ts +597 -0
- package/node_modules/@types/node/diagnostics_channel.d.ts +578 -0
- package/node_modules/@types/node/dns/promises.d.ts +479 -0
- package/node_modules/@types/node/dns.d.ts +871 -0
- package/node_modules/@types/node/domain.d.ts +170 -0
- package/node_modules/@types/node/events.d.ts +977 -0
- package/node_modules/@types/node/fs/promises.d.ts +1270 -0
- package/node_modules/@types/node/fs.d.ts +4375 -0
- package/node_modules/@types/node/globals.d.ts +172 -0
- package/node_modules/@types/node/globals.typedarray.d.ts +38 -0
- package/node_modules/@types/node/http.d.ts +2049 -0
- package/node_modules/@types/node/http2.d.ts +2631 -0
- package/node_modules/@types/node/https.d.ts +578 -0
- package/node_modules/@types/node/index.d.ts +93 -0
- package/node_modules/@types/node/inspector.generated.d.ts +3966 -0
- package/node_modules/@types/node/module.d.ts +539 -0
- package/node_modules/@types/node/net.d.ts +1031 -0
- package/node_modules/@types/node/os.d.ts +506 -0
- package/node_modules/@types/node/package.json +140 -0
- package/node_modules/@types/node/path.d.ts +200 -0
- package/node_modules/@types/node/perf_hooks.d.ts +961 -0
- package/node_modules/@types/node/process.d.ts +1961 -0
- package/node_modules/@types/node/punycode.d.ts +117 -0
- package/node_modules/@types/node/querystring.d.ts +152 -0
- package/node_modules/@types/node/readline/promises.d.ts +162 -0
- package/node_modules/@types/node/readline.d.ts +589 -0
- package/node_modules/@types/node/repl.d.ts +430 -0
- package/node_modules/@types/node/sea.d.ts +153 -0
- package/node_modules/@types/node/stream/consumers.d.ts +38 -0
- package/node_modules/@types/node/stream/promises.d.ts +90 -0
- package/node_modules/@types/node/stream/web.d.ts +533 -0
- package/node_modules/@types/node/stream.d.ts +1698 -0
- package/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/node_modules/@types/node/test.d.ts +1787 -0
- package/node_modules/@types/node/timers/promises.d.ts +108 -0
- package/node_modules/@types/node/timers.d.ts +286 -0
- package/node_modules/@types/node/tls.d.ts +1259 -0
- package/node_modules/@types/node/trace_events.d.ts +197 -0
- package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
- package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +34 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +93 -0
- package/node_modules/@types/node/tty.d.ts +208 -0
- package/node_modules/@types/node/url.d.ts +964 -0
- package/node_modules/@types/node/util.d.ts +2331 -0
- package/node_modules/@types/node/v8.d.ts +809 -0
- package/node_modules/@types/node/vm.d.ts +1001 -0
- package/node_modules/@types/node/wasi.d.ts +181 -0
- package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
- package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
- package/node_modules/@types/node/web-globals/events.d.ts +97 -0
- package/node_modules/@types/node/web-globals/fetch.d.ts +55 -0
- package/node_modules/@types/node/worker_threads.d.ts +715 -0
- package/node_modules/@types/node/zlib.d.ts +598 -0
- package/node_modules/ansi-styles/index.d.ts +345 -0
- package/node_modules/ansi-styles/index.js +163 -0
- package/node_modules/ansi-styles/license +9 -0
- package/node_modules/ansi-styles/package.json +56 -0
- package/node_modules/ansi-styles/readme.md +152 -0
- package/node_modules/await-event/LICENSE +22 -0
- package/node_modules/await-event/README.md +48 -0
- package/node_modules/await-event/index.js +13 -0
- package/node_modules/await-event/package.json +33 -0
- package/node_modules/await-first/LICENSE +21 -0
- package/node_modules/await-first/README.md +80 -0
- package/node_modules/await-first/lib/index.js +21 -0
- package/node_modules/await-first/package.json +49 -0
- package/node_modules/byte/LICENSE.txt +21 -0
- package/node_modules/byte/README.md +207 -0
- package/node_modules/byte/lib/byte.js +635 -0
- package/node_modules/byte/lib/number.js +82 -0
- package/node_modules/byte/package.json +61 -0
- package/node_modules/chalk/index.d.ts +415 -0
- package/node_modules/chalk/license +9 -0
- package/node_modules/chalk/package.json +68 -0
- package/node_modules/chalk/readme.md +341 -0
- package/node_modules/chalk/source/index.js +229 -0
- package/node_modules/chalk/source/templates.js +134 -0
- package/node_modules/chalk/source/util.js +39 -0
- package/node_modules/circular-json-for-egg/LICENSE.txt +19 -0
- package/node_modules/circular-json-for-egg/README.md +148 -0
- package/node_modules/circular-json-for-egg/build/circular-json.amd.js +2 -0
- package/node_modules/circular-json-for-egg/build/circular-json.js +2 -0
- package/node_modules/circular-json-for-egg/build/circular-json.max.amd.js +210 -0
- package/node_modules/circular-json-for-egg/build/circular-json.max.js +210 -0
- package/node_modules/circular-json-for-egg/build/circular-json.node.js +207 -0
- package/node_modules/circular-json-for-egg/package.json +42 -0
- package/node_modules/cluster-client/LICENSE +21 -0
- package/node_modules/cluster-client/README.md +319 -0
- package/node_modules/cluster-client/index.js +66 -0
- package/node_modules/cluster-client/lib/api_client.js +74 -0
- package/node_modules/cluster-client/lib/connection.js +180 -0
- package/node_modules/cluster-client/lib/const.js +5 -0
- package/node_modules/cluster-client/lib/default_logger.js +11 -0
- package/node_modules/cluster-client/lib/default_transcode.js +6 -0
- package/node_modules/cluster-client/lib/follower.js +331 -0
- package/node_modules/cluster-client/lib/index.js +213 -0
- package/node_modules/cluster-client/lib/leader.js +437 -0
- package/node_modules/cluster-client/lib/protocol/byte_buffer.js +8 -0
- package/node_modules/cluster-client/lib/protocol/packet.js +103 -0
- package/node_modules/cluster-client/lib/protocol/request.js +17 -0
- package/node_modules/cluster-client/lib/protocol/response.js +14 -0
- package/node_modules/cluster-client/lib/server.js +256 -0
- package/node_modules/cluster-client/lib/symbol.js +20 -0
- package/node_modules/cluster-client/lib/utils.js +103 -0
- package/node_modules/cluster-client/lib/wrapper/base.js +210 -0
- package/node_modules/cluster-client/lib/wrapper/cluster.js +57 -0
- package/node_modules/cluster-client/lib/wrapper/single.js +192 -0
- package/node_modules/cluster-client/package.json +60 -0
- package/node_modules/co/LICENSE +22 -0
- package/node_modules/co/Readme.md +212 -0
- package/node_modules/co/index.js +237 -0
- package/node_modules/co/package.json +34 -0
- package/node_modules/color-convert/LICENSE +21 -0
- package/node_modules/color-convert/README.md +68 -0
- package/node_modules/color-convert/conversions.js +839 -0
- package/node_modules/color-convert/index.js +81 -0
- package/node_modules/color-convert/package.json +48 -0
- package/node_modules/color-convert/route.js +97 -0
- package/node_modules/color-name/LICENSE +8 -0
- package/node_modules/color-name/README.md +11 -0
- package/node_modules/color-name/index.js +152 -0
- package/node_modules/color-name/package.json +28 -0
- package/node_modules/core-util-is/LICENSE +19 -0
- package/node_modules/core-util-is/README.md +3 -0
- package/node_modules/core-util-is/lib/util.js +107 -0
- package/node_modules/core-util-is/package.json +38 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/depd/History.md +103 -0
- package/node_modules/depd/LICENSE +22 -0
- package/node_modules/depd/Readme.md +280 -0
- package/node_modules/depd/index.js +538 -0
- package/node_modules/depd/lib/browser/index.js +77 -0
- package/node_modules/depd/package.json +45 -0
- package/node_modules/ee-first/LICENSE +22 -0
- package/node_modules/ee-first/README.md +80 -0
- package/node_modules/ee-first/index.js +95 -0
- package/node_modules/ee-first/package.json +29 -0
- package/node_modules/egg-errors/LICENSE +21 -0
- package/node_modules/egg-errors/README.md +259 -0
- package/node_modules/egg-errors/lib/base.d.ts +10 -0
- package/node_modules/egg-errors/lib/base.js +28 -0
- package/node_modules/egg-errors/lib/base_error.d.ts +6 -0
- package/node_modules/egg-errors/lib/base_error.js +13 -0
- package/node_modules/egg-errors/lib/base_exception.d.ts +6 -0
- package/node_modules/egg-errors/lib/base_exception.js +13 -0
- package/node_modules/egg-errors/lib/error.d.ts +6 -0
- package/node_modules/egg-errors/lib/error.js +13 -0
- package/node_modules/egg-errors/lib/error_options.d.ts +5 -0
- package/node_modules/egg-errors/lib/error_options.js +6 -0
- package/node_modules/egg-errors/lib/error_type.d.ts +6 -0
- package/node_modules/egg-errors/lib/error_type.js +10 -0
- package/node_modules/egg-errors/lib/exception.d.ts +6 -0
- package/node_modules/egg-errors/lib/exception.js +13 -0
- package/node_modules/egg-errors/lib/framework/formatter.d.ts +6 -0
- package/node_modules/egg-errors/lib/framework/formatter.js +29 -0
- package/node_modules/egg-errors/lib/framework/framework_base_error.d.ts +10 -0
- package/node_modules/egg-errors/lib/framework/framework_base_error.js +32 -0
- package/node_modules/egg-errors/lib/http/400.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/400.js +13 -0
- package/node_modules/egg-errors/lib/http/401.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/401.js +13 -0
- package/node_modules/egg-errors/lib/http/402.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/402.js +13 -0
- package/node_modules/egg-errors/lib/http/403.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/403.js +13 -0
- package/node_modules/egg-errors/lib/http/404.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/404.js +13 -0
- package/node_modules/egg-errors/lib/http/405.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/405.js +13 -0
- package/node_modules/egg-errors/lib/http/406.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/406.js +13 -0
- package/node_modules/egg-errors/lib/http/407.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/407.js +13 -0
- package/node_modules/egg-errors/lib/http/408.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/408.js +13 -0
- package/node_modules/egg-errors/lib/http/409.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/409.js +13 -0
- package/node_modules/egg-errors/lib/http/410.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/410.js +13 -0
- package/node_modules/egg-errors/lib/http/411.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/411.js +13 -0
- package/node_modules/egg-errors/lib/http/412.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/412.js +13 -0
- package/node_modules/egg-errors/lib/http/413.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/413.js +13 -0
- package/node_modules/egg-errors/lib/http/414.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/414.js +13 -0
- package/node_modules/egg-errors/lib/http/415.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/415.js +13 -0
- package/node_modules/egg-errors/lib/http/416.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/416.js +13 -0
- package/node_modules/egg-errors/lib/http/417.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/417.js +13 -0
- package/node_modules/egg-errors/lib/http/418.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/418.js +13 -0
- package/node_modules/egg-errors/lib/http/421.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/421.js +13 -0
- package/node_modules/egg-errors/lib/http/422.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/422.js +13 -0
- package/node_modules/egg-errors/lib/http/423.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/423.js +13 -0
- package/node_modules/egg-errors/lib/http/424.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/424.js +13 -0
- package/node_modules/egg-errors/lib/http/425.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/425.js +13 -0
- package/node_modules/egg-errors/lib/http/426.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/426.js +13 -0
- package/node_modules/egg-errors/lib/http/428.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/428.js +13 -0
- package/node_modules/egg-errors/lib/http/429.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/429.js +13 -0
- package/node_modules/egg-errors/lib/http/431.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/431.js +13 -0
- package/node_modules/egg-errors/lib/http/451.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/451.js +13 -0
- package/node_modules/egg-errors/lib/http/500.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/500.js +13 -0
- package/node_modules/egg-errors/lib/http/501.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/501.js +13 -0
- package/node_modules/egg-errors/lib/http/502.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/502.js +13 -0
- package/node_modules/egg-errors/lib/http/503.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/503.js +13 -0
- package/node_modules/egg-errors/lib/http/504.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/504.js +13 -0
- package/node_modules/egg-errors/lib/http/505.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/505.js +13 -0
- package/node_modules/egg-errors/lib/http/506.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/506.js +13 -0
- package/node_modules/egg-errors/lib/http/507.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/507.js +13 -0
- package/node_modules/egg-errors/lib/http/508.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/508.js +13 -0
- package/node_modules/egg-errors/lib/http/509.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/509.js +13 -0
- package/node_modules/egg-errors/lib/http/510.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/510.js +13 -0
- package/node_modules/egg-errors/lib/http/511.d.ts +5 -0
- package/node_modules/egg-errors/lib/http/511.js +13 -0
- package/node_modules/egg-errors/lib/http/http_error.d.ts +10 -0
- package/node_modules/egg-errors/lib/http/http_error.js +13 -0
- package/node_modules/egg-errors/lib/http/http_error_options.d.ts +6 -0
- package/node_modules/egg-errors/lib/http/http_error_options.js +7 -0
- package/node_modules/egg-errors/lib/http/http_header.d.ts +3 -0
- package/node_modules/egg-errors/lib/http/http_header.js +3 -0
- package/node_modules/egg-errors/lib/index.d.ts +50 -0
- package/node_modules/egg-errors/lib/index.js +149 -0
- package/node_modules/egg-errors/package.json +49 -0
- package/node_modules/egg-logger/LICENSE +21 -0
- package/node_modules/egg-logger/README.md +128 -0
- package/node_modules/egg-logger/README.zh-CN.md +125 -0
- package/node_modules/egg-logger/index.d.ts +233 -0
- package/node_modules/egg-logger/index.js +18 -0
- package/node_modules/egg-logger/lib/egg/console_logger.js +36 -0
- package/node_modules/egg-logger/lib/egg/context_logger.js +43 -0
- package/node_modules/egg-logger/lib/egg/custom_logger.js +10 -0
- package/node_modules/egg-logger/lib/egg/error_logger.js +31 -0
- package/node_modules/egg-logger/lib/egg/logger.js +128 -0
- package/node_modules/egg-logger/lib/egg/loggers.js +163 -0
- package/node_modules/egg-logger/lib/level.js +34 -0
- package/node_modules/egg-logger/lib/logger.js +170 -0
- package/node_modules/egg-logger/lib/transports/console.js +52 -0
- package/node_modules/egg-logger/lib/transports/file.js +134 -0
- package/node_modules/egg-logger/lib/transports/file_buffer.js +113 -0
- package/node_modules/egg-logger/lib/transports/transport.js +129 -0
- package/node_modules/egg-logger/lib/utils.js +296 -0
- package/node_modules/egg-logger/package.json +54 -0
- package/node_modules/escape-html/LICENSE +24 -0
- package/node_modules/escape-html/Readme.md +43 -0
- package/node_modules/escape-html/index.js +78 -0
- package/node_modules/escape-html/package.json +24 -0
- package/node_modules/extend-shallow/LICENSE +21 -0
- package/node_modules/extend-shallow/README.md +61 -0
- package/node_modules/extend-shallow/index.js +33 -0
- package/node_modules/extend-shallow/package.json +56 -0
- package/node_modules/has-flag/index.d.ts +39 -0
- package/node_modules/has-flag/index.js +8 -0
- package/node_modules/has-flag/license +9 -0
- package/node_modules/has-flag/package.json +46 -0
- package/node_modules/has-flag/readme.md +89 -0
- package/node_modules/heartbeats/.eslintrc +151 -0
- package/node_modules/heartbeats/.npmignore +28 -0
- package/node_modules/heartbeats/.travis.yml +10 -0
- package/node_modules/heartbeats/LICENSE +21 -0
- package/node_modules/heartbeats/README.md +323 -0
- package/node_modules/heartbeats/lib/beatevent.js +35 -0
- package/node_modules/heartbeats/lib/heart.js +178 -0
- package/node_modules/heartbeats/lib/pulse.js +39 -0
- package/node_modules/heartbeats/main.js +34 -0
- package/node_modules/heartbeats/package.json +39 -0
- package/node_modules/heartbeats/test/benchmark.js +138 -0
- package/node_modules/heartbeats/test/spawn.js +16 -0
- package/node_modules/heartbeats/test/test.js +158 -0
- package/node_modules/httpx/README.md +96 -0
- package/node_modules/httpx/lib/index.d.ts +31 -0
- package/node_modules/httpx/lib/index.js +396 -0
- package/node_modules/httpx/package.json +36 -0
- package/node_modules/iconv-lite/.github/dependabot.yml +11 -0
- package/node_modules/iconv-lite/.idea/codeStyles/Project.xml +47 -0
- package/node_modules/iconv-lite/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/node_modules/iconv-lite/.idea/iconv-lite.iml +12 -0
- package/node_modules/iconv-lite/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/node_modules/iconv-lite/.idea/modules.xml +8 -0
- package/node_modules/iconv-lite/.idea/vcs.xml +6 -0
- package/node_modules/iconv-lite/Changelog.md +212 -0
- package/node_modules/iconv-lite/LICENSE +21 -0
- package/node_modules/iconv-lite/README.md +130 -0
- package/node_modules/iconv-lite/encodings/dbcs-codec.js +597 -0
- package/node_modules/iconv-lite/encodings/dbcs-data.js +188 -0
- package/node_modules/iconv-lite/encodings/index.js +23 -0
- package/node_modules/iconv-lite/encodings/internal.js +198 -0
- package/node_modules/iconv-lite/encodings/sbcs-codec.js +72 -0
- package/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
- package/node_modules/iconv-lite/encodings/sbcs-data.js +179 -0
- package/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
- package/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
- package/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
- package/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
- package/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
- package/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
- package/node_modules/iconv-lite/encodings/tables/gbk-added.json +56 -0
- package/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
- package/node_modules/iconv-lite/encodings/utf16.js +197 -0
- package/node_modules/iconv-lite/encodings/utf32.js +319 -0
- package/node_modules/iconv-lite/encodings/utf7.js +290 -0
- package/node_modules/iconv-lite/lib/bom-handling.js +52 -0
- package/node_modules/iconv-lite/lib/index.d.ts +41 -0
- package/node_modules/iconv-lite/lib/index.js +180 -0
- package/node_modules/iconv-lite/lib/streams.js +109 -0
- package/node_modules/iconv-lite/package.json +44 -0
- package/node_modules/ip/README.md +90 -0
- package/node_modules/ip/lib/ip.js +496 -0
- package/node_modules/ip/package.json +25 -0
- package/node_modules/is-class-hotfix/.editorconfig +23 -0
- package/node_modules/is-class-hotfix/.gitattributes +2 -0
- package/node_modules/is-class-hotfix/CHANGELOG.md +7 -0
- package/node_modules/is-class-hotfix/LICENSE.md +21 -0
- package/node_modules/is-class-hotfix/README.md +35 -0
- package/node_modules/is-class-hotfix/bower.json +24 -0
- package/node_modules/is-class-hotfix/is-class.js +28 -0
- package/node_modules/is-class-hotfix/package.json +31 -0
- package/node_modules/is-class-hotfix/test/babel-class.js +27 -0
- package/node_modules/is-class-hotfix/test/is-class.js +31 -0
- package/node_modules/is-extendable/LICENSE +21 -0
- package/node_modules/is-extendable/README.md +72 -0
- package/node_modules/is-extendable/index.js +13 -0
- package/node_modules/is-extendable/package.json +51 -0
- package/node_modules/is-type-of/LICENSE +21 -0
- package/node_modules/is-type-of/README.md +105 -0
- package/node_modules/is-type-of/index.d.ts +65 -0
- package/node_modules/is-type-of/index.js +125 -0
- package/node_modules/is-type-of/package.json +45 -0
- package/node_modules/isstream/.jshintrc +59 -0
- package/node_modules/isstream/.npmignore +1 -0
- package/node_modules/isstream/.travis.yml +12 -0
- package/node_modules/isstream/LICENSE.md +11 -0
- package/node_modules/isstream/README.md +66 -0
- package/node_modules/isstream/isstream.js +27 -0
- package/node_modules/isstream/package.json +33 -0
- package/node_modules/isstream/test.js +168 -0
- package/node_modules/json-stringify-safe/.npmignore +1 -0
- package/node_modules/json-stringify-safe/CHANGELOG.md +14 -0
- package/node_modules/json-stringify-safe/LICENSE +15 -0
- package/node_modules/json-stringify-safe/Makefile +35 -0
- package/node_modules/json-stringify-safe/README.md +52 -0
- package/node_modules/json-stringify-safe/package.json +31 -0
- package/node_modules/json-stringify-safe/stringify.js +27 -0
- package/node_modules/json-stringify-safe/test/mocha.opts +2 -0
- package/node_modules/json-stringify-safe/test/stringify_test.js +246 -0
- package/node_modules/kitx/LICENSE +21 -0
- package/node_modules/kitx/README.md +35 -0
- package/node_modules/kitx/lib/index.d.ts +45 -0
- package/node_modules/kitx/lib/index.js +289 -0
- package/node_modules/kitx/package.json +41 -0
- package/node_modules/long/LICENSE +202 -0
- package/node_modules/long/README.md +246 -0
- package/node_modules/long/dist/long.js +2 -0
- package/node_modules/long/dist/long.js.map +1 -0
- package/node_modules/long/index.js +1 -0
- package/node_modules/long/package.json +34 -0
- package/node_modules/long/src/long.js +1323 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/node_modules/p-timeout/index.d.ts +113 -0
- package/node_modules/p-timeout/index.js +71 -0
- package/node_modules/p-timeout/license +9 -0
- package/node_modules/p-timeout/package.json +44 -0
- package/node_modules/p-timeout/readme.md +117 -0
- package/node_modules/safer-buffer/LICENSE +21 -0
- package/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/node_modules/safer-buffer/Readme.md +156 -0
- package/node_modules/safer-buffer/dangerous.js +58 -0
- package/node_modules/safer-buffer/package.json +34 -0
- package/node_modules/safer-buffer/safer.js +77 -0
- package/node_modules/safer-buffer/tests.js +406 -0
- package/node_modules/sdk-base/LICENSE +21 -0
- package/node_modules/sdk-base/README.md +165 -0
- package/node_modules/sdk-base/index.d.ts +29 -0
- package/node_modules/sdk-base/index.js +251 -0
- package/node_modules/sdk-base/package.json +54 -0
- package/node_modules/serialize-json/LICENSE +21 -0
- package/node_modules/serialize-json/README.md +74 -0
- package/node_modules/serialize-json/lib/decoder.js +190 -0
- package/node_modules/serialize-json/lib/encoder.js +200 -0
- package/node_modules/serialize-json/lib/index.js +15 -0
- package/node_modules/serialize-json/package.json +53 -0
- package/node_modules/supports-color/browser.js +5 -0
- package/node_modules/supports-color/index.js +135 -0
- package/node_modules/supports-color/license +9 -0
- package/node_modules/supports-color/package.json +53 -0
- package/node_modules/supports-color/readme.md +76 -0
- package/node_modules/tcp-base/LICENSE +21 -0
- package/node_modules/tcp-base/README.md +134 -0
- package/node_modules/tcp-base/lib/base.js +456 -0
- package/node_modules/tcp-base/package.json +44 -0
- package/node_modules/undici-types/LICENSE +21 -0
- package/node_modules/undici-types/README.md +6 -0
- package/node_modules/undici-types/agent.d.ts +31 -0
- package/node_modules/undici-types/api.d.ts +43 -0
- package/node_modules/undici-types/balanced-pool.d.ts +29 -0
- package/node_modules/undici-types/cache.d.ts +36 -0
- package/node_modules/undici-types/client.d.ts +108 -0
- package/node_modules/undici-types/connector.d.ts +34 -0
- package/node_modules/undici-types/content-type.d.ts +21 -0
- package/node_modules/undici-types/cookies.d.ts +28 -0
- package/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
- package/node_modules/undici-types/dispatcher.d.ts +256 -0
- package/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
- package/node_modules/undici-types/errors.d.ts +149 -0
- package/node_modules/undici-types/eventsource.d.ts +61 -0
- package/node_modules/undici-types/fetch.d.ts +209 -0
- package/node_modules/undici-types/file.d.ts +39 -0
- package/node_modules/undici-types/filereader.d.ts +54 -0
- package/node_modules/undici-types/formdata.d.ts +108 -0
- package/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/node_modules/undici-types/global-origin.d.ts +7 -0
- package/node_modules/undici-types/handlers.d.ts +15 -0
- package/node_modules/undici-types/header.d.ts +4 -0
- package/node_modules/undici-types/index.d.ts +71 -0
- package/node_modules/undici-types/interceptors.d.ts +17 -0
- package/node_modules/undici-types/mock-agent.d.ts +50 -0
- package/node_modules/undici-types/mock-client.d.ts +25 -0
- package/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/node_modules/undici-types/mock-interceptor.d.ts +93 -0
- package/node_modules/undici-types/mock-pool.d.ts +25 -0
- package/node_modules/undici-types/package.json +55 -0
- package/node_modules/undici-types/patch.d.ts +33 -0
- package/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/node_modules/undici-types/pool.d.ts +39 -0
- package/node_modules/undici-types/proxy-agent.d.ts +28 -0
- package/node_modules/undici-types/readable.d.ts +65 -0
- package/node_modules/undici-types/retry-agent.d.ts +8 -0
- package/node_modules/undici-types/retry-handler.d.ts +116 -0
- package/node_modules/undici-types/util.d.ts +18 -0
- package/node_modules/undici-types/webidl.d.ts +228 -0
- package/node_modules/undici-types/websocket.d.ts +150 -0
- package/node_modules/unescape/LICENSE +21 -0
- package/node_modules/unescape/README.md +134 -0
- package/node_modules/unescape/index.js +103 -0
- package/node_modules/unescape/package.json +67 -0
- package/node_modules/utility/LICENSE.txt +21 -0
- package/node_modules/utility/README.md +370 -0
- package/node_modules/utility/dist/commonjs/array.d.ts +11 -0
- package/node_modules/utility/dist/commonjs/array.js +46 -0
- package/node_modules/utility/dist/commonjs/crypto.d.ts +86 -0
- package/node_modules/utility/dist/commonjs/crypto.js +159 -0
- package/node_modules/utility/dist/commonjs/date.d.ts +63 -0
- package/node_modules/utility/dist/commonjs/date.js +219 -0
- package/node_modules/utility/dist/commonjs/fs.d.ts +6 -0
- package/node_modules/utility/dist/commonjs/fs.js +20 -0
- package/node_modules/utility/dist/commonjs/function.d.ts +12 -0
- package/node_modules/utility/dist/commonjs/function.js +35 -0
- package/node_modules/utility/dist/commonjs/index.d.ts +12 -0
- package/node_modules/utility/dist/commonjs/index.js +29 -0
- package/node_modules/utility/dist/commonjs/json.d.ts +14 -0
- package/node_modules/utility/dist/commonjs/json.js +41 -0
- package/node_modules/utility/dist/commonjs/number.d.ts +24 -0
- package/node_modules/utility/dist/commonjs/number.js +66 -0
- package/node_modules/utility/dist/commonjs/object.d.ts +20 -0
- package/node_modules/utility/dist/commonjs/object.js +73 -0
- package/node_modules/utility/dist/commonjs/optimize.d.ts +21 -0
- package/node_modules/utility/dist/commonjs/optimize.js +60 -0
- package/node_modules/utility/dist/commonjs/package.json +3 -0
- package/node_modules/utility/dist/commonjs/string.d.ts +29 -0
- package/node_modules/utility/dist/commonjs/string.js +126 -0
- package/node_modules/utility/dist/commonjs/timeout.d.ts +6 -0
- package/node_modules/utility/dist/commonjs/timeout.js +34 -0
- package/node_modules/utility/dist/commonjs/web.d.ts +29 -0
- package/node_modules/utility/dist/commonjs/web.js +61 -0
- package/node_modules/utility/dist/esm/array.d.ts +11 -0
- package/node_modules/utility/dist/esm/array.js +42 -0
- package/node_modules/utility/dist/esm/crypto.d.ts +86 -0
- package/node_modules/utility/dist/esm/crypto.js +146 -0
- package/node_modules/utility/dist/esm/date.d.ts +63 -0
- package/node_modules/utility/dist/esm/date.js +204 -0
- package/node_modules/utility/dist/esm/fs.d.ts +6 -0
- package/node_modules/utility/dist/esm/fs.js +17 -0
- package/node_modules/utility/dist/esm/function.d.ts +12 -0
- package/node_modules/utility/dist/esm/function.js +28 -0
- package/node_modules/utility/dist/esm/index.d.ts +12 -0
- package/node_modules/utility/dist/esm/index.js +13 -0
- package/node_modules/utility/dist/esm/json.d.ts +14 -0
- package/node_modules/utility/dist/esm/json.js +34 -0
- package/node_modules/utility/dist/esm/number.d.ts +24 -0
- package/node_modules/utility/dist/esm/number.js +60 -0
- package/node_modules/utility/dist/esm/object.d.ts +20 -0
- package/node_modules/utility/dist/esm/object.js +67 -0
- package/node_modules/utility/dist/esm/optimize.d.ts +21 -0
- package/node_modules/utility/dist/esm/optimize.js +54 -0
- package/node_modules/utility/dist/esm/package.json +3 -0
- package/node_modules/utility/dist/esm/string.d.ts +29 -0
- package/node_modules/utility/dist/esm/string.js +118 -0
- package/node_modules/utility/dist/esm/timeout.d.ts +6 -0
- package/node_modules/utility/dist/esm/timeout.js +28 -0
- package/node_modules/utility/dist/esm/web.d.ts +29 -0
- package/node_modules/utility/dist/esm/web.js +52 -0
- package/node_modules/utility/dist/package.json +4 -0
- package/node_modules/utility/package.json +85 -0
- package/node_modules/utility/src/array.ts +44 -0
- package/node_modules/utility/src/crypto.ts +160 -0
- package/node_modules/utility/src/date.ts +232 -0
- package/node_modules/utility/src/fs.ts +17 -0
- package/node_modules/utility/src/function.ts +30 -0
- package/node_modules/utility/src/index.ts +12 -0
- package/node_modules/utility/src/json.ts +48 -0
- package/node_modules/utility/src/number.ts +63 -0
- package/node_modules/utility/src/object.ts +72 -0
- package/node_modules/utility/src/optimize.ts +62 -0
- package/node_modules/utility/src/string.ts +132 -0
- package/node_modules/utility/src/timeout.ts +37 -0
- package/node_modules/utility/src/web.ts +53 -0
- package/node_modules/ylru/LICENSE +25 -0
- package/node_modules/ylru/README.md +120 -0
- package/node_modules/ylru/dist/commonjs/index.d.ts +21 -0
- package/node_modules/ylru/dist/commonjs/index.js +112 -0
- package/node_modules/ylru/dist/commonjs/package.json +3 -0
- package/node_modules/ylru/dist/esm/index.d.ts +21 -0
- package/node_modules/ylru/dist/esm/index.js +108 -0
- package/node_modules/ylru/dist/esm/package.json +3 -0
- package/node_modules/ylru/package.json +71 -0
- package/node_modules/ylru/src/index.ts +124 -0
- package/package.json +2 -2
- package/node_modules/@ali/cli-skills/dist/_chunks/libs/abort-controller.mjs +0 -424
- package/node_modules/@ali/cli-skills/dist/_chunks/libs/archiver.mjs +0 -19586
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "utility",
|
|
3
|
+
"version": "2.5.0",
|
|
4
|
+
"description": "A collection of useful utilities.",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"lint": "eslint src test --ext ts",
|
|
7
|
+
"pretest": "npm run lint -- --fix && npm run prepublishOnly",
|
|
8
|
+
"test": "egg-bin test",
|
|
9
|
+
"test-local": "egg-bin test",
|
|
10
|
+
"preci": "npm run lint && npm run prepublishOnly && attw --pack",
|
|
11
|
+
"ci": "egg-bin cov",
|
|
12
|
+
"prepublishOnly": "tshy && tshy-after"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"escape-html": "^1.0.3",
|
|
16
|
+
"unescape": "^1.0.1",
|
|
17
|
+
"ylru": "^2.0.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@arethetypeswrong/cli": "^0.17.1",
|
|
21
|
+
"@eggjs/tsconfig": "^1.3.3",
|
|
22
|
+
"@types/escape-html": "^1.0.4",
|
|
23
|
+
"@types/mocha": "^10.0.6",
|
|
24
|
+
"@types/node": "22",
|
|
25
|
+
"beautify-benchmark": "^0.2.4",
|
|
26
|
+
"benchmark": "^2.1.4",
|
|
27
|
+
"egg-bin": "^6.5.2",
|
|
28
|
+
"eslint": "^8.54.0",
|
|
29
|
+
"eslint-config-egg": "^13.0.0",
|
|
30
|
+
"moment": "^2.22.2",
|
|
31
|
+
"object-assign": "^4.1.1",
|
|
32
|
+
"optimized": "^1.2.0",
|
|
33
|
+
"time-require": "^0.1.2",
|
|
34
|
+
"tsd": "^0.28.1",
|
|
35
|
+
"tshy": "^3.0.2",
|
|
36
|
+
"tshy-after": "^1.0.0",
|
|
37
|
+
"typescript": "^5.2.2"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/node-modules/utility",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git://github.com/node-modules/utility.git"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"utility",
|
|
46
|
+
"util",
|
|
47
|
+
"utils",
|
|
48
|
+
"sha256",
|
|
49
|
+
"sha1",
|
|
50
|
+
"hash",
|
|
51
|
+
"hex"
|
|
52
|
+
],
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">= 16.0.0"
|
|
55
|
+
},
|
|
56
|
+
"author": "fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)",
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"type": "module",
|
|
59
|
+
"tshy": {
|
|
60
|
+
"exports": {
|
|
61
|
+
"./package.json": "./package.json",
|
|
62
|
+
".": "./src/index.ts"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"exports": {
|
|
66
|
+
"./package.json": "./package.json",
|
|
67
|
+
".": {
|
|
68
|
+
"import": {
|
|
69
|
+
"types": "./dist/esm/index.d.ts",
|
|
70
|
+
"default": "./dist/esm/index.js"
|
|
71
|
+
},
|
|
72
|
+
"require": {
|
|
73
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
74
|
+
"default": "./dist/commonjs/index.js"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"files": [
|
|
79
|
+
"dist",
|
|
80
|
+
"src"
|
|
81
|
+
],
|
|
82
|
+
"main": "./dist/commonjs/index.js",
|
|
83
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
84
|
+
"module": "./dist/esm/index.js"
|
|
85
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array random slice with items count
|
|
3
|
+
*/
|
|
4
|
+
export function randomSlice<T = any>(arr: T[], num?: number): T[] {
|
|
5
|
+
if (!num || num >= arr.length) {
|
|
6
|
+
return arr.slice();
|
|
7
|
+
}
|
|
8
|
+
const index = Math.floor(Math.random() * arr.length);
|
|
9
|
+
const a: T[] = [];
|
|
10
|
+
for (let i = 0, j = index; i < num; i++) {
|
|
11
|
+
a.push(arr[j++]);
|
|
12
|
+
if (j === arr.length) {
|
|
13
|
+
j = 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Remove one exists element from an array
|
|
21
|
+
* @param {Array} arr input array
|
|
22
|
+
* @param {Number} index - remove element index
|
|
23
|
+
* @return {Array} the array instance
|
|
24
|
+
*/
|
|
25
|
+
export function spliceOne<T = any>(arr: T[], index: number): T[] {
|
|
26
|
+
if (index < 0) {
|
|
27
|
+
index = arr.length + index;
|
|
28
|
+
// still negative, not found element
|
|
29
|
+
if (index < 0) {
|
|
30
|
+
return arr;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// don't touch
|
|
35
|
+
if (index >= arr.length) {
|
|
36
|
+
return arr;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (let i = index, k = i + 1, n = arr.length; k < n; i += 1, k += 1) {
|
|
40
|
+
arr[i] = arr[k];
|
|
41
|
+
}
|
|
42
|
+
arr.pop();
|
|
43
|
+
return arr;
|
|
44
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { createHash, createHmac, BinaryToTextEncoding } from 'node:crypto';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
|
|
4
|
+
type HashInput = string | Buffer | ArrayBuffer | DataView | object;
|
|
5
|
+
type HashMethod = (method: string, data: HashInput, outputEncoding?: BinaryToTextEncoding) => string;
|
|
6
|
+
|
|
7
|
+
const nativeHash = 'hash' in crypto ? crypto.hash as HashMethod : null;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* hash
|
|
11
|
+
*
|
|
12
|
+
* @param {String} method hash method, e.g.: 'md5', 'sha1'
|
|
13
|
+
* @param {String|Buffer|ArrayBuffer|TypedArray|DataView|Object} s input value
|
|
14
|
+
* @param {String} [format] output string format, could be 'hex' or 'base64'. default is 'hex'.
|
|
15
|
+
* @return {String} md5 hash string
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export function hash(method: string, s: HashInput, format?: BinaryToTextEncoding): string {
|
|
19
|
+
if (s instanceof ArrayBuffer) {
|
|
20
|
+
s = Buffer.from(s);
|
|
21
|
+
}
|
|
22
|
+
const isBuffer = Buffer.isBuffer(s) || ArrayBuffer.isView(s);
|
|
23
|
+
if (!isBuffer && typeof s === 'object') {
|
|
24
|
+
s = JSON.stringify(sortObject(s));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (nativeHash) {
|
|
28
|
+
// try to use crypto.hash first
|
|
29
|
+
// https://nodejs.org/en/blog/release/v21.7.0#crypto-implement-cryptohash
|
|
30
|
+
return nativeHash(method, s, format);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const sum = createHash(method);
|
|
34
|
+
sum.update(s as string, isBuffer ? 'binary' : 'utf8');
|
|
35
|
+
return sum.digest(format || 'hex');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* md5 hash
|
|
40
|
+
*
|
|
41
|
+
* @param {String|Buffer|Object} s input value
|
|
42
|
+
* @param {String} [format] output string format, could be 'hex' or 'base64'. default is 'hex'.
|
|
43
|
+
* @return {String} md5 hash string
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export function md5(s: HashInput, format?: BinaryToTextEncoding): string {
|
|
47
|
+
return hash('md5', s, format);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* sha1 hash
|
|
52
|
+
*
|
|
53
|
+
* @param {String|Buffer|Object} s input value
|
|
54
|
+
* @param {String} [format] output string format, could be 'hex' or 'base64'. default is 'hex'.
|
|
55
|
+
* @return {String} sha1 hash string
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export function sha1(s: HashInput, format?: BinaryToTextEncoding): string {
|
|
59
|
+
return hash('sha1', s, format);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* sha256 hash
|
|
64
|
+
*
|
|
65
|
+
* @param {String|Buffer|Object} s input value
|
|
66
|
+
* @param {String} [format] output string format, could be 'hex' or 'base64'. default is 'hex'.
|
|
67
|
+
* @return {String} sha256 hash string
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export function sha256(s: HashInput, format?: BinaryToTextEncoding): string {
|
|
71
|
+
return hash('sha256', s, format);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* sha512 hash
|
|
76
|
+
*
|
|
77
|
+
* @param {String|Buffer|Object} s input value
|
|
78
|
+
* @param {String} [format] output string format, could be 'hex' or 'base64'. default is 'hex'.
|
|
79
|
+
* @return {String} sha512 hash string
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export function sha512(s: HashInput, format?: BinaryToTextEncoding): string {
|
|
83
|
+
return hash('sha512', s, format);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* HMAC algorithm.
|
|
88
|
+
*
|
|
89
|
+
* Equal bash:
|
|
90
|
+
*
|
|
91
|
+
* ```bash
|
|
92
|
+
* $ echo -n "$data" | openssl dgst -binary -$algorithm -hmac "$key" | openssl $encoding
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @param {String} algorithm dependent on the available algorithms supported by the version of OpenSSL on the platform.
|
|
96
|
+
* Examples are 'sha1', 'md5', 'sha256', 'sha512', etc.
|
|
97
|
+
* On recent releases, `openssl list-message-digest-algorithms` will display the available digest algorithms.
|
|
98
|
+
* @param {String} key the hmac key to be used.
|
|
99
|
+
* @param {String|Buffer} data content string.
|
|
100
|
+
* @param {String} [encoding='base64'] default encoding is base64
|
|
101
|
+
* @return {String} digest string.
|
|
102
|
+
*/
|
|
103
|
+
export function hmac(algorithm: string, key: string, data: string | Buffer, encoding?: BinaryToTextEncoding): string {
|
|
104
|
+
encoding = encoding || 'base64';
|
|
105
|
+
const hmac = createHmac(algorithm, key);
|
|
106
|
+
hmac.update(data as string, Buffer.isBuffer(data) ? 'binary' : 'utf8');
|
|
107
|
+
return hmac.digest(encoding);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Base64 encode string.
|
|
112
|
+
*
|
|
113
|
+
* @param {String|Buffer} s input value
|
|
114
|
+
* @param {Boolean} [urlSafe=false] Encode string s using a URL-safe alphabet,
|
|
115
|
+
* which substitutes - instead of + and _ instead of / in the standard Base64 alphabet.
|
|
116
|
+
* @return {String} base64 encode format string.
|
|
117
|
+
*/
|
|
118
|
+
export function base64encode(s: string | Buffer, urlSafe?: boolean): string {
|
|
119
|
+
if (!Buffer.isBuffer(s)) {
|
|
120
|
+
s = Buffer.from(s);
|
|
121
|
+
}
|
|
122
|
+
let encode = s.toString('base64');
|
|
123
|
+
if (urlSafe) {
|
|
124
|
+
encode = encode.replace(/\+/g, '-').replace(/\//g, '_');
|
|
125
|
+
}
|
|
126
|
+
return encode;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Base64 string decode.
|
|
131
|
+
*
|
|
132
|
+
* @param {String} encodeStr base64 encoding string.
|
|
133
|
+
* @param {Boolean} [urlSafe=false] Decode string s using a URL-safe alphabet,
|
|
134
|
+
* which substitutes - instead of + and _ instead of / in the standard Base64 alphabet.
|
|
135
|
+
* @param {encoding} [encoding=utf8] if encoding = buffer, will return Buffer instance
|
|
136
|
+
* @return {String|Buffer} plain text.
|
|
137
|
+
*/
|
|
138
|
+
export function base64decode(encodeStr: string, urlSafe?: boolean, encoding?: BufferEncoding | 'buffer'): string | Buffer {
|
|
139
|
+
if (urlSafe) {
|
|
140
|
+
encodeStr = encodeStr.replace(/\-/g, '+').replace(/_/g, '/');
|
|
141
|
+
}
|
|
142
|
+
const buf = Buffer.from(encodeStr, 'base64');
|
|
143
|
+
if (encoding === 'buffer') {
|
|
144
|
+
return buf;
|
|
145
|
+
}
|
|
146
|
+
return buf.toString(encoding || 'utf8');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function sortObject(o: any) {
|
|
150
|
+
if (!o || Array.isArray(o) || typeof o !== 'object') {
|
|
151
|
+
return o;
|
|
152
|
+
}
|
|
153
|
+
const keys = Object.keys(o);
|
|
154
|
+
keys.sort();
|
|
155
|
+
const values: any[] = [];
|
|
156
|
+
for (const k of keys) {
|
|
157
|
+
values.push([ k, sortObject(o[k]) ]);
|
|
158
|
+
}
|
|
159
|
+
return values;
|
|
160
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { LRU } from 'ylru';
|
|
2
|
+
const lru = new LRU(1000); // Cache up to 1000 entries
|
|
3
|
+
|
|
4
|
+
export function resetTimezone(date: Date) {
|
|
5
|
+
let TIMEZONE: string = '';
|
|
6
|
+
const offsetInMinutes = date.getTimezoneOffset();
|
|
7
|
+
const _hourOffset: number = Math.floor(-offsetInMinutes / 60);
|
|
8
|
+
const _minuteOffset: number = Math.abs(offsetInMinutes % 60);
|
|
9
|
+
|
|
10
|
+
TIMEZONE += _hourOffset >= 0 ? '+' : '-';
|
|
11
|
+
TIMEZONE += `${String(Math.abs(_hourOffset)).padStart(2, '0')}${String(_minuteOffset).padStart(2, '0')}`;
|
|
12
|
+
|
|
13
|
+
return TIMEZONE;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const MONTHS: Record<string, string> = {
|
|
17
|
+
'01': 'Jan',
|
|
18
|
+
'02': 'Feb',
|
|
19
|
+
'03': 'Mar',
|
|
20
|
+
'04': 'Apr',
|
|
21
|
+
'05': 'May',
|
|
22
|
+
'06': 'Jun',
|
|
23
|
+
'07': 'Jul',
|
|
24
|
+
'08': 'Aug',
|
|
25
|
+
'09': 'Sep',
|
|
26
|
+
// eslint-disable-next-line quote-props
|
|
27
|
+
'10': 'Oct',
|
|
28
|
+
// eslint-disable-next-line quote-props
|
|
29
|
+
'11': 'Nov',
|
|
30
|
+
// eslint-disable-next-line quote-props
|
|
31
|
+
'12': 'Dec',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* return `[ YYYY, MM, DD, HH, mm, ss ]` date string array
|
|
36
|
+
*/
|
|
37
|
+
export function getDateStringParts(d?: Date, onlyDate?: boolean) {
|
|
38
|
+
d = d || new Date();
|
|
39
|
+
const monthNum = d.getMonth() + 1;
|
|
40
|
+
const month = monthNum < 10 ? `0${monthNum}` : `${monthNum}`;
|
|
41
|
+
const dateNum = d.getDate();
|
|
42
|
+
const date = dateNum < 10 ? `0${dateNum}` : `${dateNum}`;
|
|
43
|
+
if (onlyDate) {
|
|
44
|
+
return [ `${d.getFullYear()}`, month, date ];
|
|
45
|
+
}
|
|
46
|
+
const hoursNum = d.getHours();
|
|
47
|
+
const hours = hoursNum < 10 ? `0${hoursNum}` : `${hoursNum}`;
|
|
48
|
+
const minutesNum = d.getMinutes();
|
|
49
|
+
const minutes = minutesNum < 10 ? `0${minutesNum}` : `${minutesNum}`;
|
|
50
|
+
const secondsNum = d.getSeconds();
|
|
51
|
+
const seconds = secondsNum < 10 ? `0${secondsNum}` : `${secondsNum}`;
|
|
52
|
+
return [ `${d.getFullYear()}`, month, date, hours, minutes, seconds ];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Access log format date. format: `moment().format('DD/MMM/YYYY:HH:mm:ss ZZ')`
|
|
57
|
+
*/
|
|
58
|
+
export function accessLogDate(d?: Date): string {
|
|
59
|
+
// 16/Apr/2013:16:40:09 +0800
|
|
60
|
+
d = d || new Date();
|
|
61
|
+
const [ year, month, date, hours, minutes, seconds ] = getDateStringParts(d);
|
|
62
|
+
const TIMEZONE = getTimezone(d);
|
|
63
|
+
return `${date}/${MONTHS[month]}/${year}:${hours}:${minutes}:${seconds} ${TIMEZONE}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getTimezone(d: Date) {
|
|
67
|
+
const key = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
|
|
68
|
+
const timeZone = lru.get(key);
|
|
69
|
+
if (timeZone === undefined) {
|
|
70
|
+
lru.set(key, resetTimezone(d), { maxAge: 86400000 }); // Cache for 24 hours
|
|
71
|
+
return lru.get(key);
|
|
72
|
+
}
|
|
73
|
+
return timeZone;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Normal log format date. format: `moment().format('YYYY-MM-DD HH:mm:ss.SSS')`
|
|
77
|
+
*/
|
|
78
|
+
export function logDate(msSep?: string): string;
|
|
79
|
+
export function logDate(d?: Date): string;
|
|
80
|
+
export function logDate(d?: Date | null, msSep?: string): string;
|
|
81
|
+
export function logDate(d?: Date | string | null, msSep?: string): string {
|
|
82
|
+
if (typeof d === 'string') {
|
|
83
|
+
// logDate(msSep)
|
|
84
|
+
msSep = d;
|
|
85
|
+
d = new Date();
|
|
86
|
+
} else {
|
|
87
|
+
// logDate(d, msSep)
|
|
88
|
+
d = d || new Date();
|
|
89
|
+
}
|
|
90
|
+
const [ year, month, date, hours, minutes, seconds ] = getDateStringParts(d);
|
|
91
|
+
const millisecondsNum = d.getMilliseconds();
|
|
92
|
+
let milliseconds = `${millisecondsNum}`;
|
|
93
|
+
if (millisecondsNum < 10) {
|
|
94
|
+
milliseconds = `00${millisecondsNum}`;
|
|
95
|
+
} else if (millisecondsNum < 100) {
|
|
96
|
+
milliseconds = `0${millisecondsNum}`;
|
|
97
|
+
}
|
|
98
|
+
msSep = msSep || '.';
|
|
99
|
+
return `${year}-${month}-${date} ${hours}:${minutes}:${seconds}${msSep}${milliseconds}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const YYYYMMDDHHmmssSSS = logDate;
|
|
103
|
+
|
|
104
|
+
export interface YYYYMMDDHHmmssOptions {
|
|
105
|
+
dateSep?: string;
|
|
106
|
+
timeSep?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* `moment().format('YYYY-MM-DD HH:mm:ss')` format date string.
|
|
111
|
+
*/
|
|
112
|
+
export function YYYYMMDDHHmmss(d?: Date | string | number, options?: YYYYMMDDHHmmssOptions): string {
|
|
113
|
+
d = d || new Date();
|
|
114
|
+
if (!(d instanceof Date)) {
|
|
115
|
+
d = new Date(d);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let dateSep = '-';
|
|
119
|
+
let timeSep = ':';
|
|
120
|
+
if (options?.dateSep) {
|
|
121
|
+
dateSep = options.dateSep;
|
|
122
|
+
}
|
|
123
|
+
if (options?.timeSep) {
|
|
124
|
+
timeSep = options.timeSep;
|
|
125
|
+
}
|
|
126
|
+
const [ year, month, date, hours, minutes, seconds ] = getDateStringParts(d);
|
|
127
|
+
return `${year}${dateSep}${month}${dateSep}${date} ${hours}${timeSep}${minutes}${timeSep}${seconds}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* `moment().format('YYYY-MM-DD')` format date string.
|
|
132
|
+
*/
|
|
133
|
+
export function YYYYMMDD(d?: Date | string, sep?: string): string {
|
|
134
|
+
if (typeof d === 'string') {
|
|
135
|
+
// YYYYMMDD(sep)
|
|
136
|
+
sep = d;
|
|
137
|
+
d = new Date();
|
|
138
|
+
} else {
|
|
139
|
+
// YYYYMMDD(d, sep)
|
|
140
|
+
d = d || new Date();
|
|
141
|
+
if (typeof sep !== 'string') {
|
|
142
|
+
sep = '-';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const [ year, month, date ] = getDateStringParts(d, true);
|
|
146
|
+
return `${year}${sep}${month}${sep}${date}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface DateStruct {
|
|
150
|
+
YYYYMMDD: number;
|
|
151
|
+
H: number;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* return datetime struct.
|
|
156
|
+
*
|
|
157
|
+
* @return {Object} date
|
|
158
|
+
* - {Number} YYYYMMDD, 20130401
|
|
159
|
+
* - {Number} H, 0, 1, 9, 12, 23
|
|
160
|
+
*/
|
|
161
|
+
export function datestruct(now?: Date): DateStruct {
|
|
162
|
+
now = now || new Date();
|
|
163
|
+
return {
|
|
164
|
+
YYYYMMDD: now.getFullYear() * 10000 + (now.getMonth() + 1) * 100 + now.getDate(),
|
|
165
|
+
H: now.getHours(),
|
|
166
|
+
} satisfies DateStruct;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Get Unix's timestamp in seconds.
|
|
171
|
+
*/
|
|
172
|
+
export function timestamp(t?: number | string): number | Date {
|
|
173
|
+
if (t) {
|
|
174
|
+
// convert timestamp to Date
|
|
175
|
+
// timestamp(timestampValue)
|
|
176
|
+
let v: number;
|
|
177
|
+
if (typeof t === 'string') {
|
|
178
|
+
v = Number(t);
|
|
179
|
+
} else {
|
|
180
|
+
v = t;
|
|
181
|
+
}
|
|
182
|
+
if (String(v).length === 10) {
|
|
183
|
+
v *= 1000;
|
|
184
|
+
}
|
|
185
|
+
return new Date(v);
|
|
186
|
+
}
|
|
187
|
+
// get current timestamp
|
|
188
|
+
return Math.round(Date.now() / 1000);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Parse timestamp to Date
|
|
193
|
+
*/
|
|
194
|
+
export function parseTimestamp(t: number | string): Date {
|
|
195
|
+
return timestamp(t) as Date;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Convert Date object to Unix timestamp in seconds.
|
|
200
|
+
*/
|
|
201
|
+
export function dateToUnixTimestamp(date: Date): number {
|
|
202
|
+
return Math.round(date.getTime() / 1000);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export enum DateFormat {
|
|
206
|
+
DateTimeWithTimeZone = 'DateTimeWithTimeZone',
|
|
207
|
+
DateTimeWithMilliSeconds = 'DateTimeWithMilliSeconds',
|
|
208
|
+
DateTimeWithSeconds = 'DateTimeWithSeconds',
|
|
209
|
+
UnixTimestamp = 'UnixTimestamp',
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Provide milliseconds, return a formatted string.
|
|
214
|
+
*/
|
|
215
|
+
export function getDateFromMilliseconds(milliseconds: number, format?: DateFormat): string {
|
|
216
|
+
if (!Number.isFinite(milliseconds)) {
|
|
217
|
+
throw new Error('Invalid milliseconds value');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
switch (format) {
|
|
221
|
+
case DateFormat.DateTimeWithTimeZone:
|
|
222
|
+
return accessLogDate(new Date(milliseconds));
|
|
223
|
+
case DateFormat.DateTimeWithMilliSeconds:
|
|
224
|
+
return logDate(new Date(milliseconds));
|
|
225
|
+
case DateFormat.DateTimeWithSeconds:
|
|
226
|
+
return YYYYMMDDHHmmss(new Date(milliseconds));
|
|
227
|
+
case DateFormat.UnixTimestamp:
|
|
228
|
+
return dateToUnixTimestamp(new Date(milliseconds)).toString();
|
|
229
|
+
default:
|
|
230
|
+
return YYYYMMDD(new Date(milliseconds));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Stats } from 'node:fs';
|
|
2
|
+
import { stat } from 'node:fs/promises';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Check if a file exists.
|
|
6
|
+
* Returns the file stats if it exists, or `false` if it doesn't.
|
|
7
|
+
*/
|
|
8
|
+
export async function exists(file: string): Promise<Stats | false> {
|
|
9
|
+
try {
|
|
10
|
+
return await stat(file);
|
|
11
|
+
} catch (err: any) {
|
|
12
|
+
if (err.code === 'ENOENT') {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
throw err;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A empty function.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
export function noop(..._args: any[]): any {
|
|
8
|
+
// noop
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get a function parameter's names.
|
|
13
|
+
*
|
|
14
|
+
* @param {Function} func any function
|
|
15
|
+
* @param {Boolean} [cache] default is true
|
|
16
|
+
* @return {Array} names
|
|
17
|
+
*/
|
|
18
|
+
export function getParamNames(func: (...args: any[]) => any, cache?: boolean): string[] {
|
|
19
|
+
const type = typeof func;
|
|
20
|
+
assert.equal(type, 'function', `The "func" must be a function. Received type "${type}"`);
|
|
21
|
+
|
|
22
|
+
cache = cache !== false;
|
|
23
|
+
if (cache && '__cache_names' in func) {
|
|
24
|
+
return func.__cache_names as string[];
|
|
25
|
+
}
|
|
26
|
+
const str = func.toString();
|
|
27
|
+
const names = str.slice(str.indexOf('(') + 1, str.indexOf(')')).match(/([^\s,]+)/g) || [];
|
|
28
|
+
Reflect.set(func, '__cache_names', names);
|
|
29
|
+
return names;
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './array.js';
|
|
2
|
+
export * from './crypto.js';
|
|
3
|
+
export * from './date.js';
|
|
4
|
+
export * from './function.js';
|
|
5
|
+
export * from './web.js';
|
|
6
|
+
export * from './json.js';
|
|
7
|
+
export * from './number.js';
|
|
8
|
+
export * from './string.js';
|
|
9
|
+
export * from './optimize.js';
|
|
10
|
+
export * from './object.js';
|
|
11
|
+
export * from './timeout.js';
|
|
12
|
+
export * from './fs.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { dirname } from 'node:path';
|
|
2
|
+
import { readFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { readFile, mkdir, writeFile } from 'node:fs/promises';
|
|
4
|
+
|
|
5
|
+
export function strictJSONParse<T extends object = object>(content: string): T {
|
|
6
|
+
const obj = JSON.parse(content) as T;
|
|
7
|
+
if (!obj || typeof obj !== 'object') {
|
|
8
|
+
throw new Error('JSON string is not object');
|
|
9
|
+
}
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function readJSONSync<T = any>(filepath: string): T {
|
|
14
|
+
return JSON.parse(readFileSync(filepath, 'utf8')) as T;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface JSONStringifyOptions {
|
|
18
|
+
/**
|
|
19
|
+
* A string or number that's used to insert white space (including indentation, line break characters, etc.)
|
|
20
|
+
* into the output JSON string for readability purposes.
|
|
21
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#space
|
|
22
|
+
*/
|
|
23
|
+
space?: number | string;
|
|
24
|
+
replacer?: (this: any, key: string, value: any) => any;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function writeJSONSync(filepath: string, content: string | object, options: JSONStringifyOptions = {}) {
|
|
28
|
+
options.space = options.space ?? 2;
|
|
29
|
+
if (typeof content === 'object') {
|
|
30
|
+
content = JSON.stringify(content, options.replacer, options.space) + '\n';
|
|
31
|
+
}
|
|
32
|
+
mkdirSync(dirname(filepath), { recursive: true });
|
|
33
|
+
writeFileSync(filepath, content);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function readJSON<T = any>(filepath: string): Promise<T> {
|
|
37
|
+
const content = await readFile(filepath, 'utf8');
|
|
38
|
+
return JSON.parse(content) as T;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function writeJSON(filepath: string, content: string | object, options: JSONStringifyOptions = {}) {
|
|
42
|
+
options.space = options.space ?? 2;
|
|
43
|
+
if (typeof content === 'object') {
|
|
44
|
+
content = JSON.stringify(content, options.replacer, options.space) + '\n';
|
|
45
|
+
}
|
|
46
|
+
await mkdir(dirname(filepath), { recursive: true });
|
|
47
|
+
await writeFile(filepath, content, 'utf8');
|
|
48
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// http://www.2ality.com/2013/10/safe-integers.html
|
|
2
|
+
// http://es6.ruanyifeng.com/#docs/number
|
|
3
|
+
export const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1;
|
|
4
|
+
export const MIN_SAFE_INTEGER = -MAX_SAFE_INTEGER;
|
|
5
|
+
export const MAX_SAFE_INTEGER_STR = String(MAX_SAFE_INTEGER);
|
|
6
|
+
const MAX_SAFE_INTEGER_STR_LENGTH = MAX_SAFE_INTEGER_STR.length;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Detect a number string can safe convert to Javascript Number.
|
|
10
|
+
*
|
|
11
|
+
* @param {String} s number format string, like `"123"`, `"-1000123123123123123123"`
|
|
12
|
+
*/
|
|
13
|
+
export function isSafeNumberString(s: string) {
|
|
14
|
+
if (s[0] === '-') {
|
|
15
|
+
s = s.substring(1);
|
|
16
|
+
}
|
|
17
|
+
if (s.length < MAX_SAFE_INTEGER_STR_LENGTH ||
|
|
18
|
+
(s.length === MAX_SAFE_INTEGER_STR_LENGTH && s <= MAX_SAFE_INTEGER_STR)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Convert string to Number if string in safe Number scope.
|
|
26
|
+
*
|
|
27
|
+
* @param {String} s number format string.
|
|
28
|
+
* @return {Number|String} success will return Number, otherwise return the original string.
|
|
29
|
+
*/
|
|
30
|
+
export function toSafeNumber(s: string | number): number | string {
|
|
31
|
+
if (typeof s === 'number') {
|
|
32
|
+
return s;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return isSafeNumberString(s) ? Number(s) : s;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Produces a random integer between the inclusive `lower` and `upper` bounds.
|
|
40
|
+
*
|
|
41
|
+
* @param {Number} lower The lower bound.
|
|
42
|
+
* @param {Number} upper The upper bound.
|
|
43
|
+
* @return {Number} Returns the random number.
|
|
44
|
+
*/
|
|
45
|
+
export function random(lower?: number, upper?: number): number {
|
|
46
|
+
// random()
|
|
47
|
+
if (lower === undefined) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
// random(lower) => random(0, lower)
|
|
51
|
+
if (upper === undefined) {
|
|
52
|
+
upper = lower;
|
|
53
|
+
lower = 0;
|
|
54
|
+
}
|
|
55
|
+
let temp: number;
|
|
56
|
+
// random(upper, lower)
|
|
57
|
+
if (lower > upper) {
|
|
58
|
+
temp = lower;
|
|
59
|
+
lower = upper;
|
|
60
|
+
upper = temp;
|
|
61
|
+
}
|
|
62
|
+
return Math.floor(lower + Math.random() * (upper - lower));
|
|
63
|
+
}
|