@luckylillia-dev/luckylillia 0.0.0-stage → 9.0.1
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/chunks/preload-helper-D5R8FHQt.js +342 -0
- package/chunks/preload-helper-D5R8FHQt.js.map +1 -0
- package/default_config.json +83 -0
- package/llbot-core.js +35013 -0
- package/llbot-core.js.map +1 -0
- package/llbot.js +138 -0
- package/llbot.js.map +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/commands.d.ts +86 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/commands.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/config.d.ts +14 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/config.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/ffmpeg.d.ts +41 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/ffmpeg.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/http.d.ts +88 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/http.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/index.d.ts +17 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/index.js +6 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/internal.d.ts +430 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/internal.js +7 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/manifest.d.ts +68 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/manifest.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/server.d.ts +23 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/server.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/storage.d.ts +21 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/storage.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/testing.d.ts +71 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/testing.js +1123 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/universal.d.ts +299 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/universal.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/webui.d.ts +762 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/webui.js +9 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/package.json +63 -0
- package/node_modules/@satorijs/element/jsx-dev-runtime.d.ts +3 -0
- package/node_modules/@satorijs/element/jsx-runtime.d.ts +3 -0
- package/node_modules/@satorijs/element/lib/index.cjs +447 -0
- package/node_modules/@satorijs/element/lib/index.d.ts +116 -0
- package/node_modules/@satorijs/element/lib/index.mjs +455 -0
- package/node_modules/@satorijs/element/package.json +60 -0
- package/node_modules/@satorijs/element/src/index.ts +559 -0
- package/node_modules/@satorijs/protocol/lib/index.cjs +187 -0
- package/node_modules/@satorijs/protocol/lib/index.d.ts +328 -0
- package/node_modules/@satorijs/protocol/lib/index.mjs +148 -0
- package/node_modules/@satorijs/protocol/package.json +44 -0
- package/node_modules/@satorijs/protocol/src/index.ts +513 -0
- package/node_modules/@standard-schema/spec/LICENSE +21 -0
- package/node_modules/@standard-schema/spec/README.md +198 -0
- package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
- package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.js +0 -0
- package/node_modules/@standard-schema/spec/package.json +52 -0
- package/node_modules/cordis/README.md +10 -0
- package/node_modules/cordis/bin.js +16 -0
- package/node_modules/cordis/lib/context.d.ts +32 -0
- package/node_modules/cordis/lib/events.d.ts +62 -0
- package/node_modules/cordis/lib/fiber.d.ts +85 -0
- package/node_modules/cordis/lib/index.d.ts +7 -0
- package/node_modules/cordis/lib/index.js +1577 -0
- package/node_modules/cordis/lib/logger.d.ts +74 -0
- package/node_modules/cordis/lib/reflect.d.ts +54 -0
- package/node_modules/cordis/lib/registry.d.ts +78 -0
- package/node_modules/cordis/lib/service.d.ts +19 -0
- package/node_modules/cordis/lib/utils.d.ts +50 -0
- package/node_modules/cordis/package.json +49 -0
- package/node_modules/cosmokit/LICENSE +21 -0
- package/node_modules/cosmokit/README.md +24 -0
- package/node_modules/cosmokit/lib/index.cjs +419 -0
- package/node_modules/cosmokit/lib/index.cjs.map +6 -0
- package/node_modules/cosmokit/lib/index.d.ts +142 -0
- package/node_modules/cosmokit/lib/index.mjs +357 -0
- package/node_modules/cosmokit/lib/index.mjs.map +6 -0
- package/node_modules/cosmokit/package.json +57 -0
- package/node_modules/cosmokit/src/array.ts +35 -0
- package/node_modules/cosmokit/src/index.ts +5 -0
- package/node_modules/cosmokit/src/misc.ts +57 -0
- package/node_modules/cosmokit/src/string.ts +101 -0
- package/node_modules/cosmokit/src/time.ts +91 -0
- package/node_modules/cosmokit/src/types.ts +131 -0
- package/node_modules/schemastery/README.md +342 -0
- package/node_modules/schemastery/lib/index.cjs +648 -0
- package/node_modules/schemastery/lib/index.cjs.map +6 -0
- package/node_modules/schemastery/lib/index.d.ts +138 -0
- package/node_modules/schemastery/lib/index.mjs +656 -0
- package/node_modules/schemastery/lib/index.mjs.map +6 -0
- package/node_modules/schemastery/package.json +32 -0
- package/node_modules/schemastery/src/index.ts +841 -0
- package/node_modules/undici/LICENSE +21 -0
- package/node_modules/undici/README.md +741 -0
- package/node_modules/undici/docs/docs/api/Agent.md +84 -0
- package/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
- package/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
- package/node_modules/undici/docs/docs/api/CacheStore.md +164 -0
- package/node_modules/undici/docs/docs/api/Client.md +290 -0
- package/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
- package/node_modules/undici/docs/docs/api/Connector.md +115 -0
- package/node_modules/undici/docs/docs/api/ContentType.md +57 -0
- package/node_modules/undici/docs/docs/api/Cookies.md +128 -0
- package/node_modules/undici/docs/docs/api/Debug.md +62 -0
- package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +317 -0
- package/node_modules/undici/docs/docs/api/Dispatcher.md +1393 -0
- package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +159 -0
- package/node_modules/undici/docs/docs/api/Errors.md +49 -0
- package/node_modules/undici/docs/docs/api/EventSource.md +45 -0
- package/node_modules/undici/docs/docs/api/Fetch.md +60 -0
- package/node_modules/undici/docs/docs/api/GlobalInstallation.md +139 -0
- package/node_modules/undici/docs/docs/api/H2CClient.md +263 -0
- package/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
- package/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
- package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
- package/node_modules/undici/docs/docs/api/MockClient.md +81 -0
- package/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
- package/node_modules/undici/docs/docs/api/MockPool.md +555 -0
- package/node_modules/undici/docs/docs/api/Pool.md +84 -0
- package/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
- package/node_modules/undici/docs/docs/api/ProxyAgent.md +229 -0
- package/node_modules/undici/docs/docs/api/RedirectHandler.md +93 -0
- package/node_modules/undici/docs/docs/api/RetryAgent.md +50 -0
- package/node_modules/undici/docs/docs/api/RetryHandler.md +118 -0
- package/node_modules/undici/docs/docs/api/RoundRobinPool.md +145 -0
- package/node_modules/undici/docs/docs/api/SnapshotAgent.md +616 -0
- package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +275 -0
- package/node_modules/undici/docs/docs/api/Util.md +25 -0
- package/node_modules/undici/docs/docs/api/WebSocket.md +141 -0
- package/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
- package/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
- package/node_modules/undici/docs/docs/best-practices/crawling.md +58 -0
- package/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
- package/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
- package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +224 -0
- package/node_modules/undici/docs/docs/best-practices/writing-tests.md +63 -0
- package/node_modules/undici/index-fetch.js +65 -0
- package/node_modules/undici/index.d.ts +3 -0
- package/node_modules/undici/index.js +234 -0
- package/node_modules/undici/lib/api/abort-signal.js +59 -0
- package/node_modules/undici/lib/api/api-connect.js +110 -0
- package/node_modules/undici/lib/api/api-pipeline.js +252 -0
- package/node_modules/undici/lib/api/api-request.js +214 -0
- package/node_modules/undici/lib/api/api-stream.js +209 -0
- package/node_modules/undici/lib/api/api-upgrade.js +111 -0
- package/node_modules/undici/lib/api/index.js +7 -0
- package/node_modules/undici/lib/api/readable.js +580 -0
- package/node_modules/undici/lib/cache/memory-cache-store.js +279 -0
- package/node_modules/undici/lib/cache/sqlite-cache-store.js +467 -0
- package/node_modules/undici/lib/core/connect.js +159 -0
- package/node_modules/undici/lib/core/constants.js +143 -0
- package/node_modules/undici/lib/core/diagnostics.js +227 -0
- package/node_modules/undici/lib/core/errors.js +477 -0
- package/node_modules/undici/lib/core/request.js +485 -0
- package/node_modules/undici/lib/core/socks5-client.js +422 -0
- package/node_modules/undici/lib/core/socks5-utils.js +212 -0
- package/node_modules/undici/lib/core/symbols.js +76 -0
- package/node_modules/undici/lib/core/tree.js +160 -0
- package/node_modules/undici/lib/core/util.js +992 -0
- package/node_modules/undici/lib/dispatcher/agent.js +162 -0
- package/node_modules/undici/lib/dispatcher/balanced-pool.js +221 -0
- package/node_modules/undici/lib/dispatcher/client-h1.js +1744 -0
- package/node_modules/undici/lib/dispatcher/client-h2.js +1056 -0
- package/node_modules/undici/lib/dispatcher/client.js +669 -0
- package/node_modules/undici/lib/dispatcher/dispatcher-base.js +196 -0
- package/node_modules/undici/lib/dispatcher/dispatcher.js +48 -0
- package/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +146 -0
- package/node_modules/undici/lib/dispatcher/fixed-queue.js +135 -0
- package/node_modules/undici/lib/dispatcher/h2c-client.js +51 -0
- package/node_modules/undici/lib/dispatcher/pool-base.js +214 -0
- package/node_modules/undici/lib/dispatcher/pool.js +118 -0
- package/node_modules/undici/lib/dispatcher/proxy-agent.js +319 -0
- package/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
- package/node_modules/undici/lib/dispatcher/round-robin-pool.js +137 -0
- package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +260 -0
- package/node_modules/undici/lib/encoding/index.js +33 -0
- package/node_modules/undici/lib/global.js +59 -0
- package/node_modules/undici/lib/handler/cache-handler.js +824 -0
- package/node_modules/undici/lib/handler/cache-revalidation-handler.js +124 -0
- package/node_modules/undici/lib/handler/decorator-handler.js +67 -0
- package/node_modules/undici/lib/handler/deduplication-handler.js +504 -0
- package/node_modules/undici/lib/handler/redirect-handler.js +245 -0
- package/node_modules/undici/lib/handler/retry-handler.js +504 -0
- package/node_modules/undici/lib/handler/unwrap-handler.js +106 -0
- package/node_modules/undici/lib/handler/wrap-handler.js +105 -0
- package/node_modules/undici/lib/interceptor/cache.js +621 -0
- package/node_modules/undici/lib/interceptor/decompress.js +561 -0
- package/node_modules/undici/lib/interceptor/deduplicate.js +117 -0
- package/node_modules/undici/lib/interceptor/dns.js +571 -0
- package/node_modules/undici/lib/interceptor/dump.js +99 -0
- package/node_modules/undici/lib/interceptor/redirect.js +21 -0
- package/node_modules/undici/lib/interceptor/response-error.js +95 -0
- package/node_modules/undici/lib/interceptor/retry.js +19 -0
- package/node_modules/undici/lib/llhttp/constants.d.ts +195 -0
- package/node_modules/undici/lib/llhttp/constants.js +531 -0
- package/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
- package/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
- package/node_modules/undici/lib/llhttp/utils.d.ts +2 -0
- package/node_modules/undici/lib/llhttp/utils.js +12 -0
- package/node_modules/undici/lib/mock/mock-agent.js +232 -0
- package/node_modules/undici/lib/mock/mock-call-history.js +248 -0
- package/node_modules/undici/lib/mock/mock-client.js +68 -0
- package/node_modules/undici/lib/mock/mock-errors.js +29 -0
- package/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
- package/node_modules/undici/lib/mock/mock-pool.js +68 -0
- package/node_modules/undici/lib/mock/mock-symbols.js +32 -0
- package/node_modules/undici/lib/mock/mock-utils.js +486 -0
- package/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
- package/node_modules/undici/lib/mock/snapshot-agent.js +353 -0
- package/node_modules/undici/lib/mock/snapshot-recorder.js +588 -0
- package/node_modules/undici/lib/mock/snapshot-utils.js +158 -0
- package/node_modules/undici/lib/util/cache.js +676 -0
- package/node_modules/undici/lib/util/date.js +670 -0
- package/node_modules/undici/lib/util/promise.js +28 -0
- package/node_modules/undici/lib/util/runtime-features.js +124 -0
- package/node_modules/undici/lib/util/stats.js +32 -0
- package/node_modules/undici/lib/util/timers.js +425 -0
- package/node_modules/undici/lib/web/cache/cache.js +864 -0
- package/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
- package/node_modules/undici/lib/web/cache/util.js +45 -0
- package/node_modules/undici/lib/web/cookies/constants.js +12 -0
- package/node_modules/undici/lib/web/cookies/index.js +201 -0
- package/node_modules/undici/lib/web/cookies/parse.js +315 -0
- package/node_modules/undici/lib/web/cookies/util.js +371 -0
- package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +575 -0
- package/node_modules/undici/lib/web/eventsource/eventsource.js +504 -0
- package/node_modules/undici/lib/web/eventsource/util.js +29 -0
- package/node_modules/undici/lib/web/fetch/LICENSE +21 -0
- package/node_modules/undici/lib/web/fetch/body.js +509 -0
- package/node_modules/undici/lib/web/fetch/constants.js +131 -0
- package/node_modules/undici/lib/web/fetch/data-url.js +596 -0
- package/node_modules/undici/lib/web/fetch/formdata-parser.js +586 -0
- package/node_modules/undici/lib/web/fetch/formdata.js +259 -0
- package/node_modules/undici/lib/web/fetch/global.js +40 -0
- package/node_modules/undici/lib/web/fetch/headers.js +719 -0
- package/node_modules/undici/lib/web/fetch/index.js +2413 -0
- package/node_modules/undici/lib/web/fetch/request.js +1115 -0
- package/node_modules/undici/lib/web/fetch/response.js +641 -0
- package/node_modules/undici/lib/web/fetch/util.js +1522 -0
- package/node_modules/undici/lib/web/infra/index.js +243 -0
- package/node_modules/undici/lib/web/subresource-integrity/Readme.md +9 -0
- package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +307 -0
- package/node_modules/undici/lib/web/webidl/index.js +1006 -0
- package/node_modules/undici/lib/web/websocket/connection.js +339 -0
- package/node_modules/undici/lib/web/websocket/constants.js +126 -0
- package/node_modules/undici/lib/web/websocket/events.js +331 -0
- package/node_modules/undici/lib/web/websocket/frame.js +133 -0
- package/node_modules/undici/lib/web/websocket/permessage-deflate.js +105 -0
- package/node_modules/undici/lib/web/websocket/receiver.js +520 -0
- package/node_modules/undici/lib/web/websocket/sender.js +109 -0
- package/node_modules/undici/lib/web/websocket/stream/websocketerror.js +104 -0
- package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +496 -0
- package/node_modules/undici/lib/web/websocket/util.js +347 -0
- package/node_modules/undici/lib/web/websocket/websocket.js +758 -0
- package/node_modules/undici/package.json +152 -0
- package/node_modules/undici/scripts/strip-comments.js +10 -0
- package/node_modules/undici/types/README.md +6 -0
- package/node_modules/undici/types/agent.d.ts +32 -0
- package/node_modules/undici/types/api.d.ts +43 -0
- package/node_modules/undici/types/balanced-pool.d.ts +30 -0
- package/node_modules/undici/types/cache-interceptor.d.ts +179 -0
- package/node_modules/undici/types/cache.d.ts +36 -0
- package/node_modules/undici/types/client-stats.d.ts +15 -0
- package/node_modules/undici/types/client.d.ts +153 -0
- package/node_modules/undici/types/connector.d.ts +36 -0
- package/node_modules/undici/types/content-type.d.ts +21 -0
- package/node_modules/undici/types/cookies.d.ts +30 -0
- package/node_modules/undici/types/diagnostics-channel.d.ts +74 -0
- package/node_modules/undici/types/dispatcher.d.ts +275 -0
- package/node_modules/undici/types/env-http-proxy-agent.d.ts +22 -0
- package/node_modules/undici/types/errors.d.ts +177 -0
- package/node_modules/undici/types/eventsource.d.ts +66 -0
- package/node_modules/undici/types/fetch.d.ts +231 -0
- package/node_modules/undici/types/formdata.d.ts +114 -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/h2c-client.d.ts +73 -0
- package/node_modules/undici/types/handlers.d.ts +14 -0
- package/node_modules/undici/types/header.d.ts +160 -0
- package/node_modules/undici/types/index.d.ts +91 -0
- package/node_modules/undici/types/interceptors.d.ts +82 -0
- package/node_modules/undici/types/mock-agent.d.ts +68 -0
- package/node_modules/undici/types/mock-call-history.d.ts +111 -0
- package/node_modules/undici/types/mock-client.d.ts +27 -0
- package/node_modules/undici/types/mock-errors.d.ts +12 -0
- package/node_modules/undici/types/mock-interceptor.d.ts +94 -0
- package/node_modules/undici/types/mock-pool.d.ts +27 -0
- package/node_modules/undici/types/patch.d.ts +29 -0
- package/node_modules/undici/types/pool-stats.d.ts +19 -0
- package/node_modules/undici/types/pool.d.ts +41 -0
- package/node_modules/undici/types/proxy-agent.d.ts +29 -0
- package/node_modules/undici/types/readable.d.ts +68 -0
- package/node_modules/undici/types/retry-agent.d.ts +8 -0
- package/node_modules/undici/types/retry-handler.d.ts +125 -0
- package/node_modules/undici/types/round-robin-pool.d.ts +41 -0
- package/node_modules/undici/types/snapshot-agent.d.ts +109 -0
- package/node_modules/undici/types/socks5-proxy-agent.d.ts +25 -0
- package/node_modules/undici/types/util.d.ts +18 -0
- package/node_modules/undici/types/utility.d.ts +7 -0
- package/node_modules/undici/types/webidl.d.ts +347 -0
- package/node_modules/undici/types/websocket.d.ts +188 -0
- package/node_modules/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +548 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +22 -0
- package/node_modules/ws/lib/buffer-util.js +131 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +530 -0
- package/node_modules/ws/lib/receiver.js +743 -0
- package/node_modules/ws/lib/sender.js +607 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +562 -0
- package/node_modules/ws/lib/websocket.js +1407 -0
- package/node_modules/ws/package.json +74 -0
- package/node_modules/ws/wrapper.mjs +21 -0
- package/package.json +17 -4
- package/webui/assets/group-bot-profile-CYK81678.jpg +0 -0
- package/webui/assets/group-bot-settings-BBQBbfgh.jpg +0 -0
- package/webui/assets/index-CuH0UYYo.js +28 -0
- package/webui/assets/index-DjbPiYmB.css +2 -0
- package/webui/favicon.ico +0 -0
- package/webui/index.html +26 -0
- package/webui/logo-128.webp +0 -0
- package/webui/logo-192.webp +0 -0
- package/webui/logo-256.webp +0 -0
- package/webui/logo-64.webp +0 -0
- package/webui/logo.jpg +0 -0
- package/webui/plugin-shared/plugin-sdk-webui.js +3 -0
- package/webui/plugin-shared/react-dom.js +3 -0
- package/webui/plugin-shared/react-jsx-runtime.js +3 -0
- package/webui/plugin-shared/react.js +3 -0
- package//344/275/277/347/224/250/350/257/264/346/230/216.txt +6 -0
- package//346/233/264/346/226/260/346/227/245/345/277/227.txt +1091 -0
- package/README.md +0 -3
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
// src/misc.ts
|
|
2
|
+
function noop() {
|
|
3
|
+
}
|
|
4
|
+
function isNullable(value) {
|
|
5
|
+
return value === null || value === void 0;
|
|
6
|
+
}
|
|
7
|
+
function isNonNullable(value) {
|
|
8
|
+
return !isNullable(value);
|
|
9
|
+
}
|
|
10
|
+
function isPlainObject(data) {
|
|
11
|
+
return data && typeof data === "object" && !Array.isArray(data);
|
|
12
|
+
}
|
|
13
|
+
function filterKeys(object, filter) {
|
|
14
|
+
return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
|
|
15
|
+
}
|
|
16
|
+
function mapValues(object, transform) {
|
|
17
|
+
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
|
|
18
|
+
}
|
|
19
|
+
function pick(source, keys, forced) {
|
|
20
|
+
if (!keys) return { ...source };
|
|
21
|
+
const result = {};
|
|
22
|
+
for (const key of keys) {
|
|
23
|
+
if (forced || source[key] !== void 0) result[key] = source[key];
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
function omit(source, keys) {
|
|
28
|
+
if (!keys) return { ...source };
|
|
29
|
+
const result = { ...source };
|
|
30
|
+
for (const key of keys) {
|
|
31
|
+
Reflect.deleteProperty(result, key);
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function defineProperty(object, key, value) {
|
|
36
|
+
return Object.defineProperty(object, key, { writable: true, value, enumerable: false });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/array.ts
|
|
40
|
+
function contain(array1, array2) {
|
|
41
|
+
return array2.every((item) => array1.includes(item));
|
|
42
|
+
}
|
|
43
|
+
function intersection(array1, array2) {
|
|
44
|
+
return array1.filter((item) => array2.includes(item));
|
|
45
|
+
}
|
|
46
|
+
function difference(array1, array2) {
|
|
47
|
+
return array1.filter((item) => !array2.includes(item));
|
|
48
|
+
}
|
|
49
|
+
function union(array1, array2) {
|
|
50
|
+
return Array.from(/* @__PURE__ */ new Set([...array1, ...array2]));
|
|
51
|
+
}
|
|
52
|
+
function deduplicate(array) {
|
|
53
|
+
return [...new Set(array)];
|
|
54
|
+
}
|
|
55
|
+
function remove(list, item) {
|
|
56
|
+
const index = list?.indexOf(item);
|
|
57
|
+
if (index >= 0) {
|
|
58
|
+
list.splice(index, 1);
|
|
59
|
+
return true;
|
|
60
|
+
} else {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function makeArray(source) {
|
|
65
|
+
return Array.isArray(source) ? source : isNullable(source) ? [] : [source];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/types.ts
|
|
69
|
+
function is(type, value) {
|
|
70
|
+
if (arguments.length === 1) return (value2) => is(type, value2);
|
|
71
|
+
return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
|
|
72
|
+
}
|
|
73
|
+
function isArrayBufferLike(value) {
|
|
74
|
+
return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
|
|
75
|
+
}
|
|
76
|
+
function isArrayBufferSource(value) {
|
|
77
|
+
return isArrayBufferLike(value) || ArrayBuffer.isView(value);
|
|
78
|
+
}
|
|
79
|
+
var Binary;
|
|
80
|
+
((Binary2) => {
|
|
81
|
+
Binary2.is = isArrayBufferLike;
|
|
82
|
+
Binary2.isSource = isArrayBufferSource;
|
|
83
|
+
function fromSource(source) {
|
|
84
|
+
if (ArrayBuffer.isView(source)) {
|
|
85
|
+
return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
86
|
+
} else {
|
|
87
|
+
return source;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
Binary2.fromSource = fromSource;
|
|
91
|
+
function toBase64(source) {
|
|
92
|
+
source = fromSource(source);
|
|
93
|
+
if (typeof Buffer !== "undefined") {
|
|
94
|
+
return Buffer.from(source).toString("base64");
|
|
95
|
+
}
|
|
96
|
+
let binary = "";
|
|
97
|
+
const bytes = new Uint8Array(source);
|
|
98
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
99
|
+
binary += String.fromCharCode(bytes[i]);
|
|
100
|
+
}
|
|
101
|
+
return btoa(binary);
|
|
102
|
+
}
|
|
103
|
+
Binary2.toBase64 = toBase64;
|
|
104
|
+
function fromBase64(source) {
|
|
105
|
+
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
|
|
106
|
+
return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
|
|
107
|
+
}
|
|
108
|
+
Binary2.fromBase64 = fromBase64;
|
|
109
|
+
function toHex(source) {
|
|
110
|
+
source = fromSource(source);
|
|
111
|
+
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
|
|
112
|
+
return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
113
|
+
}
|
|
114
|
+
Binary2.toHex = toHex;
|
|
115
|
+
function fromHex(source) {
|
|
116
|
+
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
|
|
117
|
+
const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
|
|
118
|
+
const buffer = [];
|
|
119
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
120
|
+
buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
|
|
121
|
+
}
|
|
122
|
+
return Uint8Array.from(buffer).buffer;
|
|
123
|
+
}
|
|
124
|
+
Binary2.fromHex = fromHex;
|
|
125
|
+
})(Binary || (Binary = {}));
|
|
126
|
+
var base64ToArrayBuffer = Binary.fromBase64;
|
|
127
|
+
var arrayBufferToBase64 = Binary.toBase64;
|
|
128
|
+
var hexToArrayBuffer = Binary.fromHex;
|
|
129
|
+
var arrayBufferToHex = Binary.toHex;
|
|
130
|
+
function clone(source, refs = /* @__PURE__ */ new Map()) {
|
|
131
|
+
if (!source || typeof source !== "object") return source;
|
|
132
|
+
if (is("Date", source)) return new Date(source.valueOf());
|
|
133
|
+
if (is("RegExp", source)) return new RegExp(source.source, source.flags);
|
|
134
|
+
if (isArrayBufferLike(source)) return source.slice(0);
|
|
135
|
+
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
136
|
+
const cached = refs.get(source);
|
|
137
|
+
if (cached) return cached;
|
|
138
|
+
if (Array.isArray(source)) {
|
|
139
|
+
const result2 = [];
|
|
140
|
+
refs.set(source, result2);
|
|
141
|
+
source.forEach((value, index) => {
|
|
142
|
+
result2[index] = Reflect.apply(clone, null, [value, refs]);
|
|
143
|
+
});
|
|
144
|
+
return result2;
|
|
145
|
+
}
|
|
146
|
+
const result = Object.create(Object.getPrototypeOf(source));
|
|
147
|
+
refs.set(source, result);
|
|
148
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
149
|
+
const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
|
|
150
|
+
if ("value" in descriptor) {
|
|
151
|
+
descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
|
|
152
|
+
}
|
|
153
|
+
Reflect.defineProperty(result, key, descriptor);
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
function deepEqual(a, b, strict) {
|
|
158
|
+
if (a === b) return true;
|
|
159
|
+
if (!strict && isNullable(a) && isNullable(b)) return true;
|
|
160
|
+
if (typeof a !== typeof b) return false;
|
|
161
|
+
if (typeof a !== "object") return false;
|
|
162
|
+
if (!a || !b) return false;
|
|
163
|
+
function check(test, then) {
|
|
164
|
+
return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
|
|
165
|
+
}
|
|
166
|
+
return check(Array.isArray, (a2, b2) => a2.length === b2.length && a2.every((item, index) => deepEqual(item, b2[index]))) ?? check(is("Date"), (a2, b2) => a2.valueOf() === b2.valueOf()) ?? check(is("RegExp"), (a2, b2) => a2.source === b2.source && a2.flags === b2.flags) ?? check(isArrayBufferLike, (a2, b2) => {
|
|
167
|
+
if (a2.byteLength !== b2.byteLength) return false;
|
|
168
|
+
const viewA = new Uint8Array(a2);
|
|
169
|
+
const viewB = new Uint8Array(b2);
|
|
170
|
+
for (let i = 0; i < viewA.length; i++) {
|
|
171
|
+
if (viewA[i] !== viewB[i]) return false;
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}) ?? Object.keys({ ...a, ...b }).every((key) => deepEqual(a[key], b[key], strict));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/string.ts
|
|
178
|
+
function capitalize(source) {
|
|
179
|
+
return source.charAt(0).toUpperCase() + source.slice(1);
|
|
180
|
+
}
|
|
181
|
+
function uncapitalize(source) {
|
|
182
|
+
return source.charAt(0).toLowerCase() + source.slice(1);
|
|
183
|
+
}
|
|
184
|
+
function camelCase(source) {
|
|
185
|
+
return source.replace(/[_-][a-z]/g, (str) => str.slice(1).toUpperCase());
|
|
186
|
+
}
|
|
187
|
+
function tokenize(source, delimiters, delimiter) {
|
|
188
|
+
const output = [];
|
|
189
|
+
let state = 0 /* DELIM */;
|
|
190
|
+
for (let i = 0; i < source.length; i++) {
|
|
191
|
+
const code = source.charCodeAt(i);
|
|
192
|
+
if (code >= 65 && code <= 90) {
|
|
193
|
+
if (state === 1 /* UPPER */) {
|
|
194
|
+
const next = source.charCodeAt(i + 1);
|
|
195
|
+
if (next >= 97 && next <= 122) {
|
|
196
|
+
output.push(delimiter);
|
|
197
|
+
}
|
|
198
|
+
output.push(code + 32);
|
|
199
|
+
} else {
|
|
200
|
+
if (state !== 0 /* DELIM */) {
|
|
201
|
+
output.push(delimiter);
|
|
202
|
+
}
|
|
203
|
+
output.push(code + 32);
|
|
204
|
+
}
|
|
205
|
+
state = 1 /* UPPER */;
|
|
206
|
+
} else if (code >= 97 && code <= 122) {
|
|
207
|
+
output.push(code);
|
|
208
|
+
state = 2 /* LOWER */;
|
|
209
|
+
} else if (delimiters.includes(code)) {
|
|
210
|
+
if (state !== 0 /* DELIM */) {
|
|
211
|
+
output.push(delimiter);
|
|
212
|
+
}
|
|
213
|
+
state = 0 /* DELIM */;
|
|
214
|
+
} else {
|
|
215
|
+
output.push(code);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return String.fromCharCode(...output);
|
|
219
|
+
}
|
|
220
|
+
function paramCase(source) {
|
|
221
|
+
return tokenize(source, [45, 95], 45);
|
|
222
|
+
}
|
|
223
|
+
function snakeCase(source) {
|
|
224
|
+
return tokenize(source, [45, 95], 95);
|
|
225
|
+
}
|
|
226
|
+
var camelize = camelCase;
|
|
227
|
+
var hyphenate = paramCase;
|
|
228
|
+
function formatProperty(key) {
|
|
229
|
+
if (typeof key !== "string") return `[${key.toString()}]`;
|
|
230
|
+
return /^[a-z_$][\w$]*$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
231
|
+
}
|
|
232
|
+
function trimSlash(source) {
|
|
233
|
+
return source.replace(/\/$/, "");
|
|
234
|
+
}
|
|
235
|
+
function sanitize(source) {
|
|
236
|
+
if (!source.startsWith("/")) source = "/" + source;
|
|
237
|
+
return trimSlash(source);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/time.ts
|
|
241
|
+
var Time;
|
|
242
|
+
((Time2) => {
|
|
243
|
+
Time2.millisecond = 1;
|
|
244
|
+
Time2.second = 1e3;
|
|
245
|
+
Time2.minute = Time2.second * 60;
|
|
246
|
+
Time2.hour = Time2.minute * 60;
|
|
247
|
+
Time2.day = Time2.hour * 24;
|
|
248
|
+
Time2.week = Time2.day * 7;
|
|
249
|
+
let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
250
|
+
function setTimezoneOffset(offset) {
|
|
251
|
+
timezoneOffset = offset;
|
|
252
|
+
}
|
|
253
|
+
Time2.setTimezoneOffset = setTimezoneOffset;
|
|
254
|
+
function getTimezoneOffset() {
|
|
255
|
+
return timezoneOffset;
|
|
256
|
+
}
|
|
257
|
+
Time2.getTimezoneOffset = getTimezoneOffset;
|
|
258
|
+
function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
|
|
259
|
+
if (typeof date === "number") date = new Date(date);
|
|
260
|
+
if (offset === void 0) offset = timezoneOffset;
|
|
261
|
+
return Math.floor((date.valueOf() / Time2.minute - offset) / 1440);
|
|
262
|
+
}
|
|
263
|
+
Time2.getDateNumber = getDateNumber;
|
|
264
|
+
function fromDateNumber(value, offset) {
|
|
265
|
+
const date = new Date(value * Time2.day);
|
|
266
|
+
if (offset === void 0) offset = timezoneOffset;
|
|
267
|
+
return new Date(+date + offset * Time2.minute);
|
|
268
|
+
}
|
|
269
|
+
Time2.fromDateNumber = fromDateNumber;
|
|
270
|
+
const numeric = /\d+(?:\.\d+)?/.source;
|
|
271
|
+
const timeRegExp = new RegExp(`^${[
|
|
272
|
+
"w(?:eek(?:s)?)?",
|
|
273
|
+
"d(?:ay(?:s)?)?",
|
|
274
|
+
"h(?:our(?:s)?)?",
|
|
275
|
+
"m(?:in(?:ute)?(?:s)?)?",
|
|
276
|
+
"s(?:ec(?:ond)?(?:s)?)?"
|
|
277
|
+
].map((unit) => `(${numeric}${unit})?`).join("")}$`);
|
|
278
|
+
function parseTime(source) {
|
|
279
|
+
const capture = timeRegExp.exec(source);
|
|
280
|
+
if (!capture) return 0;
|
|
281
|
+
return (parseFloat(capture[1]) * Time2.week || 0) + (parseFloat(capture[2]) * Time2.day || 0) + (parseFloat(capture[3]) * Time2.hour || 0) + (parseFloat(capture[4]) * Time2.minute || 0) + (parseFloat(capture[5]) * Time2.second || 0);
|
|
282
|
+
}
|
|
283
|
+
Time2.parseTime = parseTime;
|
|
284
|
+
function parseDate(date) {
|
|
285
|
+
const parsed = parseTime(date);
|
|
286
|
+
if (parsed) {
|
|
287
|
+
date = Date.now() + parsed;
|
|
288
|
+
} else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) {
|
|
289
|
+
date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
|
|
290
|
+
} else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) {
|
|
291
|
+
date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
|
|
292
|
+
}
|
|
293
|
+
return date ? new Date(date) : /* @__PURE__ */ new Date();
|
|
294
|
+
}
|
|
295
|
+
Time2.parseDate = parseDate;
|
|
296
|
+
function format(ms) {
|
|
297
|
+
const abs = Math.abs(ms);
|
|
298
|
+
if (abs >= Time2.day - Time2.hour / 2) {
|
|
299
|
+
return Math.round(ms / Time2.day) + "d";
|
|
300
|
+
} else if (abs >= Time2.hour - Time2.minute / 2) {
|
|
301
|
+
return Math.round(ms / Time2.hour) + "h";
|
|
302
|
+
} else if (abs >= Time2.minute - Time2.second / 2) {
|
|
303
|
+
return Math.round(ms / Time2.minute) + "m";
|
|
304
|
+
} else if (abs >= Time2.second) {
|
|
305
|
+
return Math.round(ms / Time2.second) + "s";
|
|
306
|
+
}
|
|
307
|
+
return ms + "ms";
|
|
308
|
+
}
|
|
309
|
+
Time2.format = format;
|
|
310
|
+
function toDigits(source, length = 2) {
|
|
311
|
+
return source.toString().padStart(length, "0");
|
|
312
|
+
}
|
|
313
|
+
Time2.toDigits = toDigits;
|
|
314
|
+
function template(template2, time = /* @__PURE__ */ new Date()) {
|
|
315
|
+
return template2.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
|
|
316
|
+
}
|
|
317
|
+
Time2.template = template;
|
|
318
|
+
})(Time || (Time = {}));
|
|
319
|
+
export {
|
|
320
|
+
Binary,
|
|
321
|
+
Time,
|
|
322
|
+
arrayBufferToBase64,
|
|
323
|
+
arrayBufferToHex,
|
|
324
|
+
base64ToArrayBuffer,
|
|
325
|
+
camelCase,
|
|
326
|
+
camelize,
|
|
327
|
+
capitalize,
|
|
328
|
+
clone,
|
|
329
|
+
contain,
|
|
330
|
+
deduplicate,
|
|
331
|
+
deepEqual,
|
|
332
|
+
defineProperty,
|
|
333
|
+
difference,
|
|
334
|
+
filterKeys,
|
|
335
|
+
formatProperty,
|
|
336
|
+
hexToArrayBuffer,
|
|
337
|
+
hyphenate,
|
|
338
|
+
intersection,
|
|
339
|
+
is,
|
|
340
|
+
isNonNullable,
|
|
341
|
+
isNullable,
|
|
342
|
+
isPlainObject,
|
|
343
|
+
makeArray,
|
|
344
|
+
mapValues,
|
|
345
|
+
noop,
|
|
346
|
+
omit,
|
|
347
|
+
paramCase,
|
|
348
|
+
pick,
|
|
349
|
+
remove,
|
|
350
|
+
sanitize,
|
|
351
|
+
snakeCase,
|
|
352
|
+
trimSlash,
|
|
353
|
+
uncapitalize,
|
|
354
|
+
union,
|
|
355
|
+
mapValues as valueMap
|
|
356
|
+
};
|
|
357
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/misc.ts", "../src/array.ts", "../src/types.ts", "../src/string.ts", "../src/time.ts"],
|
|
4
|
+
"mappings": ";AAQO,SAAS,OAAY;AAAC;AAEtB,SAAS,WAAW,OAA8C;AACvE,SAAO,UAAU,QAAQ,UAAU;AACrC;AAEO,SAAS,cAAiB,OAAmC;AAClE,SAAO,CAAC,WAAW,KAAK;AAC1B;AAEO,SAAS,cAAc,MAAW;AACvC,SAAO,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,IAAI;AAChE;AAIO,SAAS,WAAW,QAAY,QAA8C;AACnF,SAAO,OAAO,YAAY,OAAO,QAAQ,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,KAAK,MAAM,OAAO,KAAK,KAAK,CAAC,CAAC;AAC/F;AAEO,SAAS,UAAkC,QAAoB,WAAoC;AACxG,SAAO,OAAO,YAAY,OAAO,QAAQ,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAM,UAAkB,OAAO,GAAG,CAAC,CAAC,CAAC;AAC/G;AAIO,SAAS,KAA0C,QAAW,MAAoB,QAAkB;AACzG,MAAI,CAAC,KAAM,QAAO,EAAE,GAAG,OAAO;AAC9B,QAAM,SAAS,CAAC;AAChB,aAAW,OAAO,MAAM;AACtB,QAAI,UAAU,OAAO,GAAG,MAAM,OAAW,QAAO,GAAG,IAAI,OA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AQ,MAAM,KAAK,YAAY,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,EACpD,QAAQ,MAAM,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,EAC3C,QAAQ,MAAM,SAAS,KAAK,QAAQ,CAAC,CAAC,EACtC,QAAQ,MAAM,SAAS,KAAK,SAAS,CAAC,CAAC,EACvC,QAAQ,MAAM,SAAS,KAAK,WAAW,CAAC,CAAC,EACzC,QAAQ,MAAM,SAAS,KAAK,WAAW,CAAC,CAAC,EACzC,QAAQ,OAAO,SAAS,KAAK,gBAAgB,GAAG,CAAC,CAAC;AAAA,EACvD;AAVO,EAAAD,MAAS;AAAA,GA/ED;",
|
|
5
|
+
"names": ["value", "Binary", "result", "a", "b", "Time", "template"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cosmokit",
|
|
3
|
+
"description": "A collection of common utilities",
|
|
4
|
+
"version": "1.8.1",
|
|
5
|
+
"packageManager": "yarn@4.12.0",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "lib/index.cjs",
|
|
9
|
+
"module": "lib/index.mjs",
|
|
10
|
+
"types": "lib/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"require": "./lib/index.cjs",
|
|
15
|
+
"import": "./lib/index.mjs"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/shigma/cosmokit.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/shigma/cosmokit/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/shigma/cosmokit",
|
|
31
|
+
"author": "Shigma <shigma10826@gmail.com>",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"compile:cjs": "esbuild src/index.ts --outfile=lib/index.cjs --bundle --sourcemap --sources-content=false --platform=node --target=es2022",
|
|
35
|
+
"compile:esm": "esbuild src/index.ts --outfile=lib/index.mjs --bundle --sourcemap --sources-content=false --platform=neutral --target=es2022",
|
|
36
|
+
"build": "yarn compile:cjs && yarn compile:esm && yarn dtsc",
|
|
37
|
+
"test": "mocha -r esbuild-register tests/*.spec.ts",
|
|
38
|
+
"test:text": "shx rm -rf coverage && c8 -r text yarn test",
|
|
39
|
+
"test:json": "shx rm -rf coverage && c8 -r json yarn test",
|
|
40
|
+
"test:html": "shx rm -rf coverage && c8 -r html yarn test"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@sinonjs/fake-timers": "^6.0.1",
|
|
44
|
+
"@types/chai": "^5.2.0",
|
|
45
|
+
"@types/mocha": "^10.0.10",
|
|
46
|
+
"@types/node": "^25.0.3",
|
|
47
|
+
"@types/sinonjs__fake-timers": "^6.0.4",
|
|
48
|
+
"c8": "^10.1.3",
|
|
49
|
+
"chai": "^5.2.0",
|
|
50
|
+
"dtsc": "^3.1.0",
|
|
51
|
+
"esbuild": "^0.27.2",
|
|
52
|
+
"esbuild-register": "^3.6.0",
|
|
53
|
+
"mocha": "^11.1.0",
|
|
54
|
+
"shx": "^0.4.0",
|
|
55
|
+
"typescript": "^5.8.2"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isNullable } from './misc'
|
|
2
|
+
|
|
3
|
+
export function contain(array1: readonly any[], array2: readonly any[]) {
|
|
4
|
+
return array2.every(item => array1.includes(item))
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function intersection<T>(array1: readonly T[], array2: readonly T[]) {
|
|
8
|
+
return array1.filter(item => array2.includes(item))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function difference<S>(array1: readonly S[], array2: readonly any[]) {
|
|
12
|
+
return array1.filter(item => !array2.includes(item))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function union<T>(array1: readonly T[], array2: readonly T[]) {
|
|
16
|
+
return Array.from(new Set([...array1, ...array2]))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function deduplicate<T>(array: readonly T[]) {
|
|
20
|
+
return [...new Set(array)]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function remove<T>(list: T[], item: T) {
|
|
24
|
+
const index = list?.indexOf(item)
|
|
25
|
+
if (index >= 0) {
|
|
26
|
+
list.splice(index, 1)
|
|
27
|
+
return true
|
|
28
|
+
} else {
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function makeArray<T>(source: null | undefined | T | T[]) {
|
|
34
|
+
return Array.isArray(source) ? source : isNullable(source) ? [] : [source]
|
|
35
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type Dict<T = any, K extends string | symbol = string> = { [key in K]: T }
|
|
2
|
+
export type Get<T extends {}, K> = K extends keyof T ? T[K] : never
|
|
3
|
+
export type Extract<S, T, U = S> = S extends T ? U : never
|
|
4
|
+
export type MaybeArray<T> = [T] extends [unknown[]] ? T : T | T[]
|
|
5
|
+
export type Promisify<T> = Promise<T extends Promise<infer S> ? S : T>
|
|
6
|
+
export type Awaitable<T> = [T] extends [Promise<unknown>] ? T : T | Promise<T>
|
|
7
|
+
export type Intersect<U> = (U extends any ? (arg: U) => void : never) extends ((arg: infer I) => void) ? I : never
|
|
8
|
+
|
|
9
|
+
export function noop(): any {}
|
|
10
|
+
|
|
11
|
+
export function isNullable(value: any): value is null | undefined | void {
|
|
12
|
+
return value === null || value === undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isNonNullable<T>(value: T): value is NonNullable<T> {
|
|
16
|
+
return !isNullable(value)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isPlainObject(data: any) {
|
|
20
|
+
return data && typeof data === 'object' && !Array.isArray(data)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function filterKeys<T, K extends string, U extends K>(object: Dict<T, K>, filter: (key: K, value: T) => key is U): Dict<T, U>
|
|
24
|
+
export function filterKeys<T, K extends string>(object: Dict<T, K>, filter: (key: K, value: T) => boolean): Dict<T, K>
|
|
25
|
+
export function filterKeys(object: {}, filter: (key: string, value: any) => boolean) {
|
|
26
|
+
return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function mapValues<U, T, K extends string>(object: Dict<T, K>, transform: (value: T, key: K) => U) {
|
|
30
|
+
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, (transform as any)(value, key)])) as Dict<U, K>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { mapValues as valueMap }
|
|
34
|
+
|
|
35
|
+
export function pick<T extends object, K extends keyof T>(source: T, keys?: Iterable<K>, forced?: boolean) {
|
|
36
|
+
if (!keys) return { ...source }
|
|
37
|
+
const result = {} as Pick<T, K>
|
|
38
|
+
for (const key of keys) {
|
|
39
|
+
if (forced || source[key] !== undefined) result[key] = source[key]
|
|
40
|
+
}
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function omit<T, K extends keyof T>(source: T, keys?: Iterable<K>) {
|
|
45
|
+
if (!keys) return { ...source }
|
|
46
|
+
const result = { ...source } as Omit<T, K>
|
|
47
|
+
for (const key of keys) {
|
|
48
|
+
Reflect.deleteProperty(result, key)
|
|
49
|
+
}
|
|
50
|
+
return result
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function defineProperty<T, K extends keyof T>(object: T, key: K, value: T[K]): T
|
|
54
|
+
export function defineProperty<T, K extends keyof any>(object: T, key: K, value: any): T
|
|
55
|
+
export function defineProperty<T, K extends keyof any>(object: T, key: K, value: any) {
|
|
56
|
+
return Object.defineProperty(object, key, { writable: true, value, enumerable: false })
|
|
57
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export function capitalize(source: string) {
|
|
2
|
+
return source.charAt(0).toUpperCase() + source.slice(1)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function uncapitalize(source: string) {
|
|
6
|
+
return source.charAt(0).toLowerCase() + source.slice(1)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function camelCase(source: string) {
|
|
10
|
+
return source.replace(/[_-][a-z]/g, str => str.slice(1).toUpperCase())
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const enum State {
|
|
14
|
+
DELIM,
|
|
15
|
+
UPPER,
|
|
16
|
+
LOWER,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function tokenize(source: string, delimiters: number[], delimiter: number) {
|
|
20
|
+
const output: number[] = []
|
|
21
|
+
let state = State.DELIM
|
|
22
|
+
for (let i = 0; i < source.length; i++) {
|
|
23
|
+
const code = source.charCodeAt(i)
|
|
24
|
+
if (code >= 65 && code <= 90) {
|
|
25
|
+
if (state === State.UPPER) {
|
|
26
|
+
const next = source.charCodeAt(i + 1)
|
|
27
|
+
if (next >= 97 && next <= 122) {
|
|
28
|
+
output.push(delimiter)
|
|
29
|
+
}
|
|
30
|
+
output.push(code + 32)
|
|
31
|
+
} else {
|
|
32
|
+
if (state !== State.DELIM) {
|
|
33
|
+
output.push(delimiter)
|
|
34
|
+
}
|
|
35
|
+
output.push(code + 32)
|
|
36
|
+
}
|
|
37
|
+
state = State.UPPER
|
|
38
|
+
} else if (code >= 97 && code <= 122) {
|
|
39
|
+
output.push(code)
|
|
40
|
+
state = State.LOWER
|
|
41
|
+
} else if (delimiters.includes(code)) {
|
|
42
|
+
if (state !== State.DELIM) {
|
|
43
|
+
output.push(delimiter)
|
|
44
|
+
}
|
|
45
|
+
state = State.DELIM
|
|
46
|
+
} else {
|
|
47
|
+
output.push(code)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return String.fromCharCode(...output)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function paramCase(source: string) {
|
|
54
|
+
return tokenize(source, [45, 95], 45)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function snakeCase(source: string) {
|
|
58
|
+
return tokenize(source, [45, 95], 95)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const camelize = camelCase
|
|
62
|
+
export const hyphenate = paramCase
|
|
63
|
+
|
|
64
|
+
namespace Letter {
|
|
65
|
+
/* eslint-disable @typescript-eslint/member-delimiter-style */
|
|
66
|
+
interface LowerToUpper {
|
|
67
|
+
a: 'A', b: 'B', c: 'C', d: 'D', e: 'E', f: 'F', g: 'G', h: 'H', i: 'I', j: 'J', k: 'K', l: 'L', m: 'M',
|
|
68
|
+
n: 'N', o: 'O', p: 'P', q: 'Q', r: 'R', s: 'S', t: 'T', u: 'U', v: 'V', w: 'W', x: 'X', y: 'Y', z: 'Z',
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface UpperToLower {
|
|
72
|
+
A: 'a', B: 'b', C: 'c', D: 'd', E: 'e', F: 'f', G: 'g', H: 'h', I: 'i', J: 'j', K: 'k', L: 'l', M: 'm',
|
|
73
|
+
N: 'n', O: 'o', P: 'p', Q: 'q', R: 'r', S: 's', T: 't', U: 'u', V: 'v', W: 'w', X: 'x', Y: 'y', Z: 'z',
|
|
74
|
+
}
|
|
75
|
+
/* eslint-enable @typescript-eslint/member-delimiter-style */
|
|
76
|
+
|
|
77
|
+
export type Upper = keyof UpperToLower
|
|
78
|
+
export type Lower = keyof LowerToUpper
|
|
79
|
+
|
|
80
|
+
export type ToUpper<S extends string> = S extends Lower ? LowerToUpper[S] : S
|
|
81
|
+
export type ToLower<S extends string, P extends string = ''> = S extends Upper ? `${P}${UpperToLower[S]}` : S
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
85
|
+
export type camelize<S extends string> = S extends `${infer L}-${infer M}${infer R}` ? `${L}${Letter.ToUpper<M>}${camelize<R>}` : S
|
|
86
|
+
export type hyphenate<S extends string> = S extends `${infer L}${infer R}` ? `${Letter.ToLower<L, '-'>}${hyphenate<R>}` : S
|
|
87
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
88
|
+
|
|
89
|
+
export function formatProperty(key: keyof any) {
|
|
90
|
+
if (typeof key !== 'string') return `[${key.toString()}]`
|
|
91
|
+
return /^[a-z_$][\w$]*$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function trimSlash(source: string) {
|
|
95
|
+
return source.replace(/\/$/, '')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function sanitize(source: string) {
|
|
99
|
+
if (!source.startsWith('/')) source = '/' + source
|
|
100
|
+
return trimSlash(source)
|
|
101
|
+
}
|