@depup/nitro 3.0.260311-beta-depup.0
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/LICENSE +27 -0
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/THIRD-PARTY-LICENSES.md +1646 -0
- package/dist/_build/common.mjs +29361 -0
- package/dist/_build/rolldown.mjs +173 -0
- package/dist/_build/rollup.mjs +194 -0
- package/dist/_build/vite.build.mjs +18 -0
- package/dist/_chunks/nitro.mjs +1159 -0
- package/dist/_chunks/nitro2.mjs +102 -0
- package/dist/_chunks/nitro3.mjs +129 -0
- package/dist/_chunks/utils.mjs +272 -0
- package/dist/_common.mjs +35 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +519 -0
- package/dist/_libs/_.mjs +3 -0
- package/dist/_libs/_2.mjs +2 -0
- package/dist/_libs/_3.mjs +3 -0
- package/dist/_libs/_4.mjs +2 -0
- package/dist/_libs/_5.mjs +3 -0
- package/dist/_libs/_6.mjs +4 -0
- package/dist/_libs/_7.mjs +5 -0
- package/dist/_libs/c12+rc9.mjs +812 -0
- package/dist/_libs/c12+readdirp+chokidar.d.mts +230 -0
- package/dist/_libs/citty.mjs +361 -0
- package/dist/_libs/commondir+is-reference.mjs +1311 -0
- package/dist/_libs/compatx.d.mts +47 -0
- package/dist/_libs/compatx.mjs +45 -0
- package/dist/_libs/esbuild.d.mts +20 -0
- package/dist/_libs/escape-string-regexp.mjs +7 -0
- package/dist/_libs/estree+pluginutils.d.mts +241 -0
- package/dist/_libs/estree-walker.mjs +184 -0
- package/dist/_libs/exsolve.d.mts +1 -0
- package/dist/_libs/hasown+resolve+deepmerge.mjs +1949 -0
- package/dist/_libs/httpxy.d.mts +82 -0
- package/dist/_libs/httpxy.mjs +671 -0
- package/dist/_libs/js-tokens.d.mts +1 -0
- package/dist/_libs/klona.mjs +37 -0
- package/dist/_libs/magic-string.d.mts +220 -0
- package/dist/_libs/mlly.d.mts +57 -0
- package/dist/_libs/nypm+tinyexec.mjs +845 -0
- package/dist/_libs/perfect-debounce.mjs +88 -0
- package/dist/_libs/pkg-types.d.mts +23 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/plugin-inject.mjs +131 -0
- package/dist/_libs/plugin-json.mjs +34 -0
- package/dist/_libs/pluginutils.mjs +646 -0
- package/dist/_libs/readdirp+chokidar.mjs +1606 -0
- package/dist/_libs/remapping.mjs +115 -0
- package/dist/_libs/resolve-uri+gen-mapping.mjs +442 -0
- package/dist/_libs/rou3.d.mts +44 -0
- package/dist/_libs/rou3.mjs +496 -0
- package/dist/_libs/std-env.d.mts +12 -0
- package/dist/_libs/strip-literal.d.mts +1 -0
- package/dist/_libs/tsconfck.mjs +813 -0
- package/dist/_libs/ultrahtml.mjs +127 -0
- package/dist/_libs/unimport+unplugin.mjs +1684 -0
- package/dist/_libs/unplugin+unimport.d.mts +423 -0
- package/dist/_libs/unwasm.d.mts +29 -0
- package/dist/_presets.mjs +1759 -0
- package/dist/builder.d.mts +64 -0
- package/dist/builder.mjs +15 -0
- package/dist/cli/_chunks/build.mjs +47 -0
- package/dist/cli/_chunks/common.mjs +14 -0
- package/dist/cli/_chunks/deploy.mjs +40 -0
- package/dist/cli/_chunks/dev.mjs +62 -0
- package/dist/cli/_chunks/docs.mjs +30 -0
- package/dist/cli/_chunks/list.mjs +25 -0
- package/dist/cli/_chunks/prepare.mjs +17 -0
- package/dist/cli/_chunks/preview.mjs +51 -0
- package/dist/cli/_chunks/run.mjs +53 -0
- package/dist/cli/_chunks/task.mjs +14 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +22 -0
- package/dist/node_modules/@poppinss/colors/build/index.js +139 -0
- package/dist/node_modules/@poppinss/colors/package.json +118 -0
- package/dist/node_modules/@poppinss/dumper/build/chunk-26HALFTP.js +602 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/console/main.js +441 -0
- package/dist/node_modules/@poppinss/dumper/build/formatters/html/main.js +725 -0
- package/dist/node_modules/@poppinss/dumper/package.json +122 -0
- package/dist/node_modules/@poppinss/exception/build/index.js +44 -0
- package/dist/node_modules/@poppinss/exception/package.json +109 -0
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +1354 -0
- package/dist/node_modules/@sindresorhus/is/distribution/utilities.js +3 -0
- package/dist/node_modules/@sindresorhus/is/package.json +81 -0
- package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -0
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -0
- package/dist/node_modules/@speed-highlight/core/package.json +94 -0
- package/dist/node_modules/cookie-es/dist/index.mjs +262 -0
- package/dist/node_modules/cookie-es/package.json +37 -0
- package/dist/node_modules/croner/dist/croner.js +1 -0
- package/dist/node_modules/croner/package.json +73 -0
- package/dist/node_modules/defu/dist/defu.mjs +69 -0
- package/dist/node_modules/defu/package.json +43 -0
- package/dist/node_modules/destr/dist/index.mjs +72 -0
- package/dist/node_modules/destr/package.json +47 -0
- package/dist/node_modules/error-stack-parser-es/dist/index.mjs +38 -0
- package/dist/node_modules/error-stack-parser-es/dist/lite.mjs +167 -0
- package/dist/node_modules/error-stack-parser-es/package.json +83 -0
- package/dist/node_modules/get-port-please/dist/index.mjs +430 -0
- package/dist/node_modules/get-port-please/package.json +39 -0
- package/dist/node_modules/kleur/index.mjs +110 -0
- package/dist/node_modules/kleur/package.json +51 -0
- package/dist/node_modules/rendu/dist/index.mjs +380 -0
- package/dist/node_modules/rendu/package.json +47 -0
- package/dist/node_modules/scule/dist/index.mjs +80 -0
- package/dist/node_modules/scule/package.json +43 -0
- package/dist/node_modules/source-map/lib/array-set.js +100 -0
- package/dist/node_modules/source-map/lib/base64-vlq.js +94 -0
- package/dist/node_modules/source-map/lib/base64.js +19 -0
- package/dist/node_modules/source-map/lib/binary-search.js +113 -0
- package/dist/node_modules/source-map/lib/mapping-list.js +83 -0
- package/dist/node_modules/source-map/lib/mappings.wasm +0 -0
- package/dist/node_modules/source-map/lib/read-wasm.js +27 -0
- package/dist/node_modules/source-map/lib/source-map-consumer.js +1081 -0
- package/dist/node_modules/source-map/lib/source-map-generator.js +439 -0
- package/dist/node_modules/source-map/lib/source-node.js +430 -0
- package/dist/node_modules/source-map/lib/url.js +13 -0
- package/dist/node_modules/source-map/lib/util.js +444 -0
- package/dist/node_modules/source-map/lib/wasm.js +138 -0
- package/dist/node_modules/source-map/package.json +79 -0
- package/dist/node_modules/source-map/source-map.js +10 -0
- package/dist/node_modules/supports-color/index.js +202 -0
- package/dist/node_modules/supports-color/package.json +64 -0
- package/dist/node_modules/ufo/dist/index.mjs +645 -0
- package/dist/node_modules/ufo/package.json +48 -0
- package/dist/node_modules/unctx/dist/index.mjs +131 -0
- package/dist/node_modules/unctx/package.json +67 -0
- package/dist/node_modules/youch/build/helpers-B9BQYaS6.js +23 -0
- package/dist/node_modules/youch/build/index.js +212 -0
- package/dist/node_modules/youch/build/public/error_cause/style.css +5 -0
- package/dist/node_modules/youch/build/public/error_info/script.js +13 -0
- package/dist/node_modules/youch/build/public/error_info/style.css +145 -0
- package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
- package/dist/node_modules/youch/build/public/error_stack/script.js +72 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +219 -0
- package/dist/node_modules/youch/build/public/error_stack_source/style.css +123 -0
- package/dist/node_modules/youch/build/public/header/script.js +14 -0
- package/dist/node_modules/youch/build/public/header/style.css +56 -0
- package/dist/node_modules/youch/build/public/layout/script.js +12 -0
- package/dist/node_modules/youch/build/public/layout/style.css +435 -0
- package/dist/node_modules/youch/build/public_dir-C5bujZKB.js +25 -0
- package/dist/node_modules/youch/build/src/templates/error_cause/main.js +44 -0
- package/dist/node_modules/youch/build/src/templates/error_info/main.js +72 -0
- package/dist/node_modules/youch/build/src/templates/error_metadata/main.js +65 -0
- package/dist/node_modules/youch/build/src/templates/error_stack/main.js +152 -0
- package/dist/node_modules/youch/build/src/templates/error_stack_source/main.js +46 -0
- package/dist/node_modules/youch/build/src/templates/header/main.js +24 -0
- package/dist/node_modules/youch/build/src/templates/layout/main.js +27 -0
- package/dist/node_modules/youch/package.json +135 -0
- package/dist/node_modules/youch-core/build/index.js +316 -0
- package/dist/node_modules/youch-core/package.json +124 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +20 -0
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +15 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +23 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +14 -0
- package/dist/presets/aws-lambda/runtime/_utils.mjs +116 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +31 -0
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +13 -0
- package/dist/presets/azure/runtime/_utils.mjs +50 -0
- package/dist/presets/azure/runtime/azure-swa.mjs +30 -0
- package/dist/presets/bun/runtime/bun.mjs +40 -0
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +87 -0
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +72 -0
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +17 -0
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +39 -0
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +96 -0
- package/dist/presets/cloudflare/runtime/shims/workers.dev.mjs +27 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +19 -0
- package/dist/presets/deno/runtime/deno-server.mjs +39 -0
- package/dist/presets/netlify/runtime/netlify-edge.mjs +20 -0
- package/dist/presets/netlify/runtime/netlify.mjs +20 -0
- package/dist/presets/node/runtime/node-cluster.mjs +54 -0
- package/dist/presets/node/runtime/node-middleware.mjs +14 -0
- package/dist/presets/node/runtime/node-server.mjs +47 -0
- package/dist/presets/standard/runtime/server.mjs +4 -0
- package/dist/presets/stormkit/runtime/stormkit.mjs +27 -0
- package/dist/presets/vercel/runtime/cron-handler.mjs +25 -0
- package/dist/presets/vercel/runtime/isr.mjs +19 -0
- package/dist/presets/vercel/runtime/vercel.node.mjs +24 -0
- package/dist/presets/vercel/runtime/vercel.web.mjs +23 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +91 -0
- package/dist/presets/zeabur/runtime/zeabur.mjs +4 -0
- package/dist/presets/zephyr/runtime/server.mjs +3 -0
- package/dist/runtime/app.d.mts +1 -0
- package/dist/runtime/app.mjs +1 -0
- package/dist/runtime/cache.d.mts +1 -0
- package/dist/runtime/cache.mjs +1 -0
- package/dist/runtime/config.d.mts +3 -0
- package/dist/runtime/config.mjs +4 -0
- package/dist/runtime/context.d.mts +1 -0
- package/dist/runtime/context.mjs +1 -0
- package/dist/runtime/database.d.mts +1 -0
- package/dist/runtime/database.mjs +1 -0
- package/dist/runtime/internal/app.d.mts +16 -0
- package/dist/runtime/internal/app.mjs +208 -0
- package/dist/runtime/internal/cache.d.mts +7 -0
- package/dist/runtime/internal/cache.mjs +41 -0
- package/dist/runtime/internal/context.d.mts +14 -0
- package/dist/runtime/internal/context.mjs +24 -0
- package/dist/runtime/internal/database.d.mts +2 -0
- package/dist/runtime/internal/database.mjs +12 -0
- package/dist/runtime/internal/empty.mjs +0 -0
- package/dist/runtime/internal/error/dev.d.mts +10 -0
- package/dist/runtime/internal/error/dev.mjs +121 -0
- package/dist/runtime/internal/error/hooks.d.mts +1 -0
- package/dist/runtime/internal/error/hooks.mjs +9 -0
- package/dist/runtime/internal/error/prod.d.mts +6 -0
- package/dist/runtime/internal/error/prod.mjs +40 -0
- package/dist/runtime/internal/error/utils.d.mts +8 -0
- package/dist/runtime/internal/error/utils.mjs +3 -0
- package/dist/runtime/internal/meta.d.mts +2 -0
- package/dist/runtime/internal/meta.mjs +3 -0
- package/dist/runtime/internal/plugin.d.mts +3 -0
- package/dist/runtime/internal/plugin.mjs +4 -0
- package/dist/runtime/internal/route-rules.d.mts +9 -0
- package/dist/runtime/internal/route-rules.mjs +72 -0
- package/dist/runtime/internal/routes/dev-tasks.d.mts +3 -0
- package/dist/runtime/internal/routes/dev-tasks.mjs +25 -0
- package/dist/runtime/internal/routes/openapi.d.mts +3 -0
- package/dist/runtime/internal/routes/openapi.mjs +94 -0
- package/dist/runtime/internal/routes/renderer-template.d.mts +2 -0
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +3 -0
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +19 -0
- package/dist/runtime/internal/routes/renderer-template.mjs +4 -0
- package/dist/runtime/internal/routes/scalar.d.mts +3 -0
- package/dist/runtime/internal/routes/scalar.mjs +193 -0
- package/dist/runtime/internal/routes/swagger.d.mts +3 -0
- package/dist/runtime/internal/routes/swagger.mjs +42 -0
- package/dist/runtime/internal/runtime-config.d.mts +9 -0
- package/dist/runtime/internal/runtime-config.mjs +54 -0
- package/dist/runtime/internal/static.d.mts +3 -0
- package/dist/runtime/internal/static.mjs +67 -0
- package/dist/runtime/internal/storage.d.mts +2 -0
- package/dist/runtime/internal/storage.mjs +6 -0
- package/dist/runtime/internal/task.d.mts +19 -0
- package/dist/runtime/internal/task.mjs +69 -0
- package/dist/runtime/internal/vite/dev-entry.mjs +18 -0
- package/dist/runtime/internal/vite/dev-worker.mjs +264 -0
- package/dist/runtime/internal/vite/ssr-renderer.mjs +6 -0
- package/dist/runtime/meta.d.mts +5 -0
- package/dist/runtime/meta.mjs +27 -0
- package/dist/runtime/nitro.d.mts +11 -0
- package/dist/runtime/nitro.mjs +34 -0
- package/dist/runtime/runtime-config.d.mts +1 -0
- package/dist/runtime/runtime-config.mjs +1 -0
- package/dist/runtime/storage.d.mts +1 -0
- package/dist/runtime/storage.mjs +1 -0
- package/dist/runtime/task.d.mts +1 -0
- package/dist/runtime/task.mjs +1 -0
- package/dist/runtime/virtual/_runtime_warn.d.mts +1 -0
- package/dist/runtime/virtual/_runtime_warn.mjs +5 -0
- package/dist/runtime/virtual/database.d.mts +8 -0
- package/dist/runtime/virtual/database.mjs +2 -0
- package/dist/runtime/virtual/error-handler.d.mts +6 -0
- package/dist/runtime/virtual/error-handler.mjs +9 -0
- package/dist/runtime/virtual/feature-flags.d.mts +7 -0
- package/dist/runtime/virtual/feature-flags.mjs +7 -0
- package/dist/runtime/virtual/plugins.d.mts +3 -0
- package/dist/runtime/virtual/plugins.mjs +2 -0
- package/dist/runtime/virtual/polyfills.d.mts +3 -0
- package/dist/runtime/virtual/polyfills.mjs +2 -0
- package/dist/runtime/virtual/public-assets.d.mts +9 -0
- package/dist/runtime/virtual/public-assets.mjs +8 -0
- package/dist/runtime/virtual/renderer-template.d.mts +4 -0
- package/dist/runtime/virtual/renderer-template.mjs +7 -0
- package/dist/runtime/virtual/routing-meta.d.mts +7 -0
- package/dist/runtime/virtual/routing-meta.mjs +2 -0
- package/dist/runtime/virtual/routing.d.mts +8 -0
- package/dist/runtime/virtual/routing.mjs +11 -0
- package/dist/runtime/virtual/runtime-config.d.mts +3 -0
- package/dist/runtime/virtual/runtime-config.mjs +5 -0
- package/dist/runtime/virtual/server-assets.d.mts +7 -0
- package/dist/runtime/virtual/server-assets.mjs +12 -0
- package/dist/runtime/virtual/storage.d.mts +3 -0
- package/dist/runtime/virtual/storage.mjs +5 -0
- package/dist/runtime/virtual/tasks.d.mts +10 -0
- package/dist/runtime/virtual/tasks.mjs +3 -0
- package/dist/runtime/vite.d.mts +8 -0
- package/dist/runtime/vite.mjs +9 -0
- package/dist/types/index.d.mts +3010 -0
- package/dist/types/index.mjs +1 -0
- package/dist/vite.d.mts +52 -0
- package/dist/vite.mjs +740 -0
- package/lib/h3.d.mts +1 -0
- package/lib/h3.mjs +1 -0
- package/lib/tsconfig.json +27 -0
- package/lib/vite.types.d.mts +26 -0
- package/lib/vite.types.mjs +2 -0
- package/package.json +256 -0
- package/skills/nitro/SKILL.md +10 -0
- package/skills/nitro/docs/TOC.md +83 -0
- package/skills/nitro/docs/_navigation.json +679 -0
- package/skills/nitro/docs/config/index.md +1147 -0
- package/skills/nitro/docs/deploy/index.md +64 -0
- package/skills/nitro/docs/deploy/providers/alwaysdata.md +50 -0
- package/skills/nitro/docs/deploy/providers/aws-amplify.md +81 -0
- package/skills/nitro/docs/deploy/providers/aws.md +47 -0
- package/skills/nitro/docs/deploy/providers/azure.md +72 -0
- package/skills/nitro/docs/deploy/providers/cleavr.md +33 -0
- package/skills/nitro/docs/deploy/providers/cloudflare.md +375 -0
- package/skills/nitro/docs/deploy/providers/deno-deploy.md +66 -0
- package/skills/nitro/docs/deploy/providers/digitalocean.md +46 -0
- package/skills/nitro/docs/deploy/providers/firebase.md +32 -0
- package/skills/nitro/docs/deploy/providers/flightcontrol.md +67 -0
- package/skills/nitro/docs/deploy/providers/genezio.md +67 -0
- package/skills/nitro/docs/deploy/providers/github-pages.md +68 -0
- package/skills/nitro/docs/deploy/providers/gitlab-pages.md +37 -0
- package/skills/nitro/docs/deploy/providers/heroku.md +84 -0
- package/skills/nitro/docs/deploy/providers/iis.md +38 -0
- package/skills/nitro/docs/deploy/providers/koyeb.md +109 -0
- package/skills/nitro/docs/deploy/providers/netlify.md +47 -0
- package/skills/nitro/docs/deploy/providers/platform-sh.md +37 -0
- package/skills/nitro/docs/deploy/providers/render.md +37 -0
- package/skills/nitro/docs/deploy/providers/stormkit.md +24 -0
- package/skills/nitro/docs/deploy/providers/vercel.md +179 -0
- package/skills/nitro/docs/deploy/providers/zeabur.md +19 -0
- package/skills/nitro/docs/deploy/providers/zephyr.md +99 -0
- package/skills/nitro/docs/deploy/providers/zerops.md +102 -0
- package/skills/nitro/docs/deploy/runtimes/bun.md +15 -0
- package/skills/nitro/docs/deploy/runtimes/deno.md +19 -0
- package/skills/nitro/docs/deploy/runtimes/node.md +63 -0
- package/skills/nitro/docs/docs/assets.md +166 -0
- package/skills/nitro/docs/docs/cache.md +408 -0
- package/skills/nitro/docs/docs/configuration.md +256 -0
- package/skills/nitro/docs/docs/database.md +185 -0
- package/skills/nitro/docs/docs/index.md +56 -0
- package/skills/nitro/docs/docs/lifecycle.md +204 -0
- package/skills/nitro/docs/docs/migration.md +215 -0
- package/skills/nitro/docs/docs/nightly.md +31 -0
- package/skills/nitro/docs/docs/plugins.md +164 -0
- package/skills/nitro/docs/docs/quick-start.md +110 -0
- package/skills/nitro/docs/docs/renderer.md +322 -0
- package/skills/nitro/docs/docs/routing.md +711 -0
- package/skills/nitro/docs/docs/server-entry.md +239 -0
- package/skills/nitro/docs/docs/storage.md +261 -0
- package/skills/nitro/docs/docs/tasks.md +277 -0
- package/skills/nitro/docs/examples/api-routes.md +145 -0
- package/skills/nitro/docs/examples/auto-imports.md +93 -0
- package/skills/nitro/docs/examples/cached-handler.md +81 -0
- package/skills/nitro/docs/examples/custom-error-handler.md +98 -0
- package/skills/nitro/docs/examples/database.md +157 -0
- package/skills/nitro/docs/examples/elysia.md +70 -0
- package/skills/nitro/docs/examples/express.md +78 -0
- package/skills/nitro/docs/examples/fastify.md +79 -0
- package/skills/nitro/docs/examples/hello-world.md +68 -0
- package/skills/nitro/docs/examples/hono.md +74 -0
- package/skills/nitro/docs/examples/import-alias.md +100 -0
- package/skills/nitro/docs/examples/index.md +3 -0
- package/skills/nitro/docs/examples/middleware.md +91 -0
- package/skills/nitro/docs/examples/mono-jsx.md +68 -0
- package/skills/nitro/docs/examples/nano-jsx.md +70 -0
- package/skills/nitro/docs/examples/plugins.md +91 -0
- package/skills/nitro/docs/examples/renderer.md +113 -0
- package/skills/nitro/docs/examples/runtime-config.md +97 -0
- package/skills/nitro/docs/examples/server-fetch.md +87 -0
- package/skills/nitro/docs/examples/shiki.md +198 -0
- package/skills/nitro/docs/examples/virtual-routes.md +74 -0
- package/skills/nitro/docs/examples/vite-nitro-plugin.md +79 -0
- package/skills/nitro/docs/examples/vite-rsc.md +1041 -0
- package/skills/nitro/docs/examples/vite-ssr-html.md +217 -0
- package/skills/nitro/docs/examples/vite-ssr-preact.md +247 -0
- package/skills/nitro/docs/examples/vite-ssr-react.md +226 -0
- package/skills/nitro/docs/examples/vite-ssr-solid.md +256 -0
- package/skills/nitro/docs/examples/vite-ssr-tsr-react.md +442 -0
- package/skills/nitro/docs/examples/vite-ssr-tss-react.md +444 -0
- package/skills/nitro/docs/examples/vite-ssr-vue-router.md +616 -0
- package/skills/nitro/docs/examples/vite-trpc.md +335 -0
- package/skills/nitro/docs/examples/websocket.md +282 -0
- package/skills/nitro/docs/index.md +121 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { FastResponse } from "srvx";
|
|
2
|
+
|
|
3
|
+
//#region src/parser.ts
|
|
4
|
+
function parseTemplate(template) {
|
|
5
|
+
if (!template) return [];
|
|
6
|
+
template = template.replace(/<script\s+server\s*>([\s\S]*?)<\/script>/gi, (_m, code) => `<?js${code}?>`);
|
|
7
|
+
template = template.replace(/{{\s*(.+)\s*}}|{{{\s*(.+)\s*}}}/g, (_m, code) => {
|
|
8
|
+
if (code[0] === "{") return `<?=${code.slice(1, -1).trim()}?>`;
|
|
9
|
+
return `<?=htmlspecialchars(${code.trim()})?>`;
|
|
10
|
+
});
|
|
11
|
+
const tokens = [];
|
|
12
|
+
const re = /<\?(?:js)?(?<equals>=)?(?<value>[\s\S]*?)\?>/g;
|
|
13
|
+
let cursor = 0;
|
|
14
|
+
let match;
|
|
15
|
+
while (match = re.exec(template)) {
|
|
16
|
+
const { equals, value } = match.groups || {};
|
|
17
|
+
const matchStart = match.index;
|
|
18
|
+
const matchEnd = matchStart + match[0].length;
|
|
19
|
+
if (matchStart > cursor) {
|
|
20
|
+
const textContent = template.slice(cursor, matchStart);
|
|
21
|
+
if (textContent) tokens.push({
|
|
22
|
+
type: "text",
|
|
23
|
+
contents: textContent
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (equals) tokens.push({
|
|
27
|
+
type: "expr",
|
|
28
|
+
contents: value || ""
|
|
29
|
+
});
|
|
30
|
+
else tokens.push({
|
|
31
|
+
type: "code",
|
|
32
|
+
contents: value || ""
|
|
33
|
+
});
|
|
34
|
+
cursor = matchEnd;
|
|
35
|
+
}
|
|
36
|
+
if (cursor < template.length) {
|
|
37
|
+
const remainingText = template.slice(cursor);
|
|
38
|
+
if (remainingText) tokens.push({
|
|
39
|
+
type: "text",
|
|
40
|
+
contents: remainingText
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return tokens;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a template string contains template syntax.
|
|
47
|
+
*/
|
|
48
|
+
function hasTemplateSyntax(template) {
|
|
49
|
+
return /(?:<script\s+server\s*>[\s\S]*?<\/script>)|(?:<\?(?:js)?=?[\s\S]*?\?>)|(?:\{\{[\s\S]*?\}\})/i.test(template);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/_runtime.ts
|
|
54
|
+
function runtimeStream(body) {
|
|
55
|
+
return `const __chunks__ = [];const echo = (chunk) => { __chunks__.push(chunk); };${body};
|
|
56
|
+
function concatStreams(chunks) {
|
|
57
|
+
const encoder = new TextEncoder();
|
|
58
|
+
return new ReadableStream({
|
|
59
|
+
async pull(controller) {
|
|
60
|
+
for (let chunk of chunks) {
|
|
61
|
+
if (typeof chunk === 'function'){
|
|
62
|
+
chunk = chunk();
|
|
63
|
+
}
|
|
64
|
+
if (chunk instanceof Promise) {
|
|
65
|
+
chunk = await chunk;
|
|
66
|
+
if (!chunk) continue;
|
|
67
|
+
if (chunk instanceof Response){
|
|
68
|
+
chunk = chunk.body;
|
|
69
|
+
}
|
|
70
|
+
if (!(chunk instanceof ReadableStream)) {
|
|
71
|
+
controller.enqueue(chunk instanceof Uint8Array ? chunk : encoder.encode(chunk));
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (chunk instanceof ReadableStream) {
|
|
76
|
+
const reader = chunk.getReader();
|
|
77
|
+
while (true) {
|
|
78
|
+
const { value, done } = await reader.read();
|
|
79
|
+
if (done) break;
|
|
80
|
+
controller.enqueue(value);
|
|
81
|
+
}
|
|
82
|
+
reader.releaseLock();
|
|
83
|
+
} else {
|
|
84
|
+
controller.enqueue(chunk instanceof Uint8Array ? chunk : encoder.encode(chunk));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
controller.close();
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return concatStreams(__chunks__);
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
function runtimeText(body) {
|
|
95
|
+
return `const __chunks__ = [];const echo = (chunk) => { __chunks__.push(chunk); };${body};
|
|
96
|
+
let __out__ = "";
|
|
97
|
+
for(let chunk of __chunks__){
|
|
98
|
+
if (typeof chunk === 'function'){
|
|
99
|
+
chunk = chunk();
|
|
100
|
+
}
|
|
101
|
+
if (chunk instanceof Promise){
|
|
102
|
+
chunk = await chunk;
|
|
103
|
+
}
|
|
104
|
+
if (chunk instanceof Response){
|
|
105
|
+
chunk = chunk.body;
|
|
106
|
+
}
|
|
107
|
+
if (chunk instanceof ReadableStream){
|
|
108
|
+
const reader = chunk.getReader();
|
|
109
|
+
while(true){
|
|
110
|
+
const {value, done} = await reader.read();
|
|
111
|
+
if(done) break;
|
|
112
|
+
__out__ += typeof value === "string" ? value : new TextDecoder().decode(value);
|
|
113
|
+
}
|
|
114
|
+
reader.releaseLock();
|
|
115
|
+
} else {
|
|
116
|
+
__out__ += typeof chunk === "string" ? chunk : new TextDecoder().decode(chunk);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return __out__;
|
|
120
|
+
`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/compiler.ts
|
|
125
|
+
/**
|
|
126
|
+
* Compile a template string into a render function.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* import { compileTemplate } from "rendu";
|
|
131
|
+
*
|
|
132
|
+
* const template = `
|
|
133
|
+
* <h1>{{ title }}</h1>
|
|
134
|
+
* <ul>
|
|
135
|
+
* <? for (const item of items) { ?>
|
|
136
|
+
* <li>{{ item }}</li>
|
|
137
|
+
* <? } ?>
|
|
138
|
+
* </ul>
|
|
139
|
+
* `;
|
|
140
|
+
*
|
|
141
|
+
* const render = compileTemplate(template, { stream: false });
|
|
142
|
+
*
|
|
143
|
+
* const html = await render({ title: "My List", items: ["Item 1", "Item 2", "Item 3"] });
|
|
144
|
+
* console.log(html);
|
|
145
|
+
* // Output:
|
|
146
|
+
* // <h1>My List</h1>
|
|
147
|
+
* // <ul>
|
|
148
|
+
* // <li>Item 1</li>
|
|
149
|
+
* // <li>Item 2</li>
|
|
150
|
+
* // <li>Item 3</li>
|
|
151
|
+
* // </ul>
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
function compileTemplate(template, opts = {}) {
|
|
155
|
+
const body = compileTemplateToString(template, opts, false);
|
|
156
|
+
const sourcemaps = opts.filename ? `\n//# sourceURL=${opts.filename}` : "";
|
|
157
|
+
try {
|
|
158
|
+
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
|
|
159
|
+
return new AsyncFunction("__context__", body + sourcemaps);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
throw new SyntaxError(`Template syntax error: ${error.message}`, {});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Compile a template string into a render function code string.
|
|
166
|
+
*
|
|
167
|
+
* **Note:** This function is for advanced use cases where you need the generated code as a string.
|
|
168
|
+
*/
|
|
169
|
+
function compileTemplateToString(template, opts, asyncWrapper) {
|
|
170
|
+
const parts = [];
|
|
171
|
+
const tokens = parseTemplate(template);
|
|
172
|
+
for (const token of tokens) switch (token.type) {
|
|
173
|
+
case "text":
|
|
174
|
+
if (opts.preserveLines) for (const line of token.contents.split("\n")) parts.push(`echo(${JSON.stringify(line + "\n")})\n`);
|
|
175
|
+
else parts.push(`echo(${JSON.stringify(token.contents)})`);
|
|
176
|
+
break;
|
|
177
|
+
case "expr":
|
|
178
|
+
parts.push(`echo(${token.contents})`);
|
|
179
|
+
break;
|
|
180
|
+
case "code":
|
|
181
|
+
parts.push(token.contents);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
let body = parts.join(opts.preserveLines ? ";" : "\n");
|
|
185
|
+
body = opts.contextKeys ? `const {${opts.contextKeys.join(",")}}=__context__;${body}` : `with(__context__){${body}}`;
|
|
186
|
+
body = opts.stream === false ? runtimeText(body) : runtimeStream(body);
|
|
187
|
+
return asyncWrapper === false ? body : `(async (__context__) => {${body}})`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region node_modules/.pnpm/cookie-es@2.0.0/node_modules/cookie-es/dist/index.mjs
|
|
192
|
+
function parse(str, options) {
|
|
193
|
+
if (typeof str !== "string") throw new TypeError("argument str must be a string");
|
|
194
|
+
const obj = {};
|
|
195
|
+
const opt = options || {};
|
|
196
|
+
const dec = opt.decode || decode;
|
|
197
|
+
let index = 0;
|
|
198
|
+
while (index < str.length) {
|
|
199
|
+
const eqIdx = str.indexOf("=", index);
|
|
200
|
+
if (eqIdx === -1) break;
|
|
201
|
+
let endIdx = str.indexOf(";", index);
|
|
202
|
+
if (endIdx === -1) endIdx = str.length;
|
|
203
|
+
else if (endIdx < eqIdx) {
|
|
204
|
+
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const key = str.slice(index, eqIdx).trim();
|
|
208
|
+
if (opt?.filter && !opt?.filter(key)) {
|
|
209
|
+
index = endIdx + 1;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (void 0 === obj[key]) {
|
|
213
|
+
let val = str.slice(eqIdx + 1, endIdx).trim();
|
|
214
|
+
if (val.codePointAt(0) === 34) val = val.slice(1, -1);
|
|
215
|
+
obj[key] = tryDecode(val, dec);
|
|
216
|
+
}
|
|
217
|
+
index = endIdx + 1;
|
|
218
|
+
}
|
|
219
|
+
return obj;
|
|
220
|
+
}
|
|
221
|
+
function decode(str) {
|
|
222
|
+
return str.includes("%") ? decodeURIComponent(str) : str;
|
|
223
|
+
}
|
|
224
|
+
function tryDecode(str, decode2) {
|
|
225
|
+
try {
|
|
226
|
+
return decode2(str);
|
|
227
|
+
} catch {
|
|
228
|
+
return str;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const fieldContentRegExp = /^[\u0009\u0020-\u007E\u0080-\u00FF]+$/;
|
|
232
|
+
function serialize(name, value, options) {
|
|
233
|
+
const opt = options || {};
|
|
234
|
+
const enc = opt.encode || encodeURIComponent;
|
|
235
|
+
if (typeof enc !== "function") throw new TypeError("option encode is invalid");
|
|
236
|
+
if (!fieldContentRegExp.test(name)) throw new TypeError("argument name is invalid");
|
|
237
|
+
const encodedValue = enc(value);
|
|
238
|
+
if (encodedValue && !fieldContentRegExp.test(encodedValue)) throw new TypeError("argument val is invalid");
|
|
239
|
+
let str = name + "=" + encodedValue;
|
|
240
|
+
if (void 0 !== opt.maxAge && opt.maxAge !== null) {
|
|
241
|
+
const maxAge = opt.maxAge - 0;
|
|
242
|
+
if (Number.isNaN(maxAge) || !Number.isFinite(maxAge)) throw new TypeError("option maxAge is invalid");
|
|
243
|
+
str += "; Max-Age=" + Math.floor(maxAge);
|
|
244
|
+
}
|
|
245
|
+
if (opt.domain) {
|
|
246
|
+
if (!fieldContentRegExp.test(opt.domain)) throw new TypeError("option domain is invalid");
|
|
247
|
+
str += "; Domain=" + opt.domain;
|
|
248
|
+
}
|
|
249
|
+
if (opt.path) {
|
|
250
|
+
if (!fieldContentRegExp.test(opt.path)) throw new TypeError("option path is invalid");
|
|
251
|
+
str += "; Path=" + opt.path;
|
|
252
|
+
}
|
|
253
|
+
if (opt.expires) {
|
|
254
|
+
if (!isDate(opt.expires) || Number.isNaN(opt.expires.valueOf())) throw new TypeError("option expires is invalid");
|
|
255
|
+
str += "; Expires=" + opt.expires.toUTCString();
|
|
256
|
+
}
|
|
257
|
+
if (opt.httpOnly) str += "; HttpOnly";
|
|
258
|
+
if (opt.secure) str += "; Secure";
|
|
259
|
+
if (opt.priority) switch (typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority) {
|
|
260
|
+
case "low":
|
|
261
|
+
str += "; Priority=Low";
|
|
262
|
+
break;
|
|
263
|
+
case "medium":
|
|
264
|
+
str += "; Priority=Medium";
|
|
265
|
+
break;
|
|
266
|
+
case "high":
|
|
267
|
+
str += "; Priority=High";
|
|
268
|
+
break;
|
|
269
|
+
default: throw new TypeError("option priority is invalid");
|
|
270
|
+
}
|
|
271
|
+
if (opt.sameSite) switch (typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite) {
|
|
272
|
+
case true:
|
|
273
|
+
str += "; SameSite=Strict";
|
|
274
|
+
break;
|
|
275
|
+
case "lax":
|
|
276
|
+
str += "; SameSite=Lax";
|
|
277
|
+
break;
|
|
278
|
+
case "strict":
|
|
279
|
+
str += "; SameSite=Strict";
|
|
280
|
+
break;
|
|
281
|
+
case "none":
|
|
282
|
+
str += "; SameSite=None";
|
|
283
|
+
break;
|
|
284
|
+
default: throw new TypeError("option sameSite is invalid");
|
|
285
|
+
}
|
|
286
|
+
if (opt.partitioned) str += "; Partitioned";
|
|
287
|
+
return str;
|
|
288
|
+
}
|
|
289
|
+
function isDate(val) {
|
|
290
|
+
return Object.prototype.toString.call(val) === "[object Date]" || val instanceof Date;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/render.ts
|
|
295
|
+
/**
|
|
296
|
+
* Renders an HTML template to a Response object.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* import { compileTemplate, renderToResponse } from "rendu";
|
|
301
|
+
*
|
|
302
|
+
* const render = compileTemplate(template, { stream: true });
|
|
303
|
+
*
|
|
304
|
+
* const response = await renderToResponse(render, { request });
|
|
305
|
+
* ```
|
|
306
|
+
* @param htmlTemplate The compiled HTML template.
|
|
307
|
+
* @param opts Options for rendering.
|
|
308
|
+
* @returns A Response object.
|
|
309
|
+
*/
|
|
310
|
+
async function renderToResponse(htmlTemplate, opts) {
|
|
311
|
+
const ctx = createRenderContext(opts);
|
|
312
|
+
const body = await htmlTemplate(ctx);
|
|
313
|
+
if (body instanceof Response) return body;
|
|
314
|
+
return new FastResponse(body, {
|
|
315
|
+
status: ctx.$RESPONSE.status,
|
|
316
|
+
statusText: ctx.$RESPONSE.statusText,
|
|
317
|
+
headers: ctx.$RESPONSE.headers
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
const RENDER_CONTEXT_KEYS = [
|
|
321
|
+
"htmlspecialchars",
|
|
322
|
+
"setCookie",
|
|
323
|
+
"redirect",
|
|
324
|
+
"$REQUEST",
|
|
325
|
+
"$METHOD",
|
|
326
|
+
"$URL",
|
|
327
|
+
"$HEADERS",
|
|
328
|
+
"$COOKIES",
|
|
329
|
+
"$RESPONSE"
|
|
330
|
+
];
|
|
331
|
+
function createRenderContext(options) {
|
|
332
|
+
const url = new URL(options.request?.url || "http://_");
|
|
333
|
+
const response = {
|
|
334
|
+
status: 200,
|
|
335
|
+
statusText: "OK",
|
|
336
|
+
headers: new Headers({ "Content-Type": "text/html ; charset=utf-8" })
|
|
337
|
+
};
|
|
338
|
+
const $COOKIES = lazyCookies(options.request);
|
|
339
|
+
const setCookie = (name, value, sOpts = {}) => {
|
|
340
|
+
response.headers.append("Set-Cookie", serialize(name, value, sOpts));
|
|
341
|
+
};
|
|
342
|
+
const redirect = (to, status = 302) => {
|
|
343
|
+
response.status = status;
|
|
344
|
+
response.headers.set("Location", to);
|
|
345
|
+
};
|
|
346
|
+
return {
|
|
347
|
+
...options.context,
|
|
348
|
+
htmlspecialchars,
|
|
349
|
+
setCookie,
|
|
350
|
+
redirect,
|
|
351
|
+
$REQUEST: options.request,
|
|
352
|
+
$METHOD: options.request?.method,
|
|
353
|
+
$URL: url,
|
|
354
|
+
$HEADERS: options.request?.headers,
|
|
355
|
+
$COOKIES,
|
|
356
|
+
$RESPONSE: response
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function lazyCookies(req) {
|
|
360
|
+
if (!req) return {};
|
|
361
|
+
let parsed;
|
|
362
|
+
return new Proxy(Object.freeze(Object.create(null)), { get(_, prop) {
|
|
363
|
+
if (typeof prop !== "string") return void 0;
|
|
364
|
+
parsed ??= parse(req.headers.get("cookie") || "");
|
|
365
|
+
return parsed[prop];
|
|
366
|
+
} });
|
|
367
|
+
}
|
|
368
|
+
function htmlspecialchars(s) {
|
|
369
|
+
const htmlSpecialCharsMap = {
|
|
370
|
+
"&": "&",
|
|
371
|
+
"<": "<",
|
|
372
|
+
">": ">",
|
|
373
|
+
"\"": """,
|
|
374
|
+
"'": "'"
|
|
375
|
+
};
|
|
376
|
+
return String(s).replace(/[&<>"']/g, (c) => htmlSpecialCharsMap[c] || c);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
//#endregion
|
|
380
|
+
export { RENDER_CONTEXT_KEYS, compileTemplate, compileTemplateToString, createRenderContext, hasTemplateSyntax, renderToResponse };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rendu",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "",
|
|
5
|
+
"repository": "h3js/rendu",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"bin": "./dist/cli.mjs",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "obuild",
|
|
19
|
+
"dev": "vitest dev",
|
|
20
|
+
"lint": "eslint . && prettier -c .",
|
|
21
|
+
"lint:fix": "automd && eslint . --fix && prettier -w .",
|
|
22
|
+
"prepack": "pnpm build",
|
|
23
|
+
"play": "pnpm rendu playground",
|
|
24
|
+
"release": "pnpm test && pnpm build && changelogen --release && npm publish && git push --follow-tags",
|
|
25
|
+
"rendu": "node ./src/cli.ts",
|
|
26
|
+
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
|
|
27
|
+
"test:types": "tsc --noEmit --skipLibCheck"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"srvx": "^0.9.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^24.9.1",
|
|
34
|
+
"@vitest/coverage-v8": "^4.0.4",
|
|
35
|
+
"automd": "^0.4.2",
|
|
36
|
+
"changelogen": "^0.6.2",
|
|
37
|
+
"cookie-es": "^2.0.0",
|
|
38
|
+
"eslint": "^9.38.0",
|
|
39
|
+
"eslint-config-unjs": "^0.5.0",
|
|
40
|
+
"obuild": "^0.3.0",
|
|
41
|
+
"prettier": "^3.6.2",
|
|
42
|
+
"rendu": "^0.0.6",
|
|
43
|
+
"typescript": "^5.9.3",
|
|
44
|
+
"vitest": "^4.0.4"
|
|
45
|
+
},
|
|
46
|
+
"packageManager": "pnpm@10.19.0"
|
|
47
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const NUMBER_CHAR_RE = /\d/;
|
|
2
|
+
const STR_SPLITTERS = ["-", "_", "/", "."];
|
|
3
|
+
function isUppercase(char = "") {
|
|
4
|
+
if (NUMBER_CHAR_RE.test(char)) {
|
|
5
|
+
return void 0;
|
|
6
|
+
}
|
|
7
|
+
return char !== char.toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
function splitByCase(str, separators) {
|
|
10
|
+
const splitters = separators ?? STR_SPLITTERS;
|
|
11
|
+
const parts = [];
|
|
12
|
+
if (!str || typeof str !== "string") {
|
|
13
|
+
return parts;
|
|
14
|
+
}
|
|
15
|
+
let buff = "";
|
|
16
|
+
let previousUpper;
|
|
17
|
+
let previousSplitter;
|
|
18
|
+
for (const char of str) {
|
|
19
|
+
const isSplitter = splitters.includes(char);
|
|
20
|
+
if (isSplitter === true) {
|
|
21
|
+
parts.push(buff);
|
|
22
|
+
buff = "";
|
|
23
|
+
previousUpper = void 0;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const isUpper = isUppercase(char);
|
|
27
|
+
if (previousSplitter === false) {
|
|
28
|
+
if (previousUpper === false && isUpper === true) {
|
|
29
|
+
parts.push(buff);
|
|
30
|
+
buff = char;
|
|
31
|
+
previousUpper = isUpper;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
35
|
+
const lastChar = buff.at(-1);
|
|
36
|
+
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
37
|
+
buff = lastChar + char;
|
|
38
|
+
previousUpper = isUpper;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
buff += char;
|
|
43
|
+
previousUpper = isUpper;
|
|
44
|
+
previousSplitter = isSplitter;
|
|
45
|
+
}
|
|
46
|
+
parts.push(buff);
|
|
47
|
+
return parts;
|
|
48
|
+
}
|
|
49
|
+
function upperFirst(str) {
|
|
50
|
+
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
51
|
+
}
|
|
52
|
+
function lowerFirst(str) {
|
|
53
|
+
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
54
|
+
}
|
|
55
|
+
function pascalCase(str, opts) {
|
|
56
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
57
|
+
}
|
|
58
|
+
function camelCase(str, opts) {
|
|
59
|
+
return lowerFirst(pascalCase(str || "", opts));
|
|
60
|
+
}
|
|
61
|
+
function kebabCase(str, joiner) {
|
|
62
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
63
|
+
}
|
|
64
|
+
function snakeCase(str) {
|
|
65
|
+
return kebabCase(str || "", "_");
|
|
66
|
+
}
|
|
67
|
+
function flatCase(str) {
|
|
68
|
+
return kebabCase(str || "", "");
|
|
69
|
+
}
|
|
70
|
+
function trainCase(str, opts) {
|
|
71
|
+
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("-");
|
|
72
|
+
}
|
|
73
|
+
const titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;
|
|
74
|
+
function titleCase(str, opts) {
|
|
75
|
+
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map(
|
|
76
|
+
(p) => titleCaseExceptions.test(p) ? p.toLowerCase() : upperFirst(opts?.normalize ? p.toLowerCase() : p)
|
|
77
|
+
).join(" ");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { camelCase, flatCase, isUppercase, kebabCase, lowerFirst, pascalCase, snakeCase, splitByCase, titleCase, trainCase, upperFirst };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "scule",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "String case utils",
|
|
5
|
+
"repository": "unjs/scule",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"import": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"./*": "./*"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
|
+
"module": "./dist/index.mjs",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "unbuild",
|
|
24
|
+
"dev": "vitest dev --typecheck",
|
|
25
|
+
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
|
|
26
|
+
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
|
|
27
|
+
"prepack": "pnpm run build",
|
|
28
|
+
"release": "pnpm test && changelogen --release --push && npm publish",
|
|
29
|
+
"test": "pnpm lint && vitest run --typecheck --coverage"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^20.11.3",
|
|
33
|
+
"@vitest/coverage-v8": "^1.2.0",
|
|
34
|
+
"changelogen": "^0.5.5",
|
|
35
|
+
"eslint": "^8.56.0",
|
|
36
|
+
"eslint-config-unjs": "^0.2.1",
|
|
37
|
+
"prettier": "^3.2.2",
|
|
38
|
+
"typescript": "^5.3.3",
|
|
39
|
+
"unbuild": "^2.0.0",
|
|
40
|
+
"vitest": "^1.2.0"
|
|
41
|
+
},
|
|
42
|
+
"packageManager": "pnpm@8.14.1"
|
|
43
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
|
4
|
+
* Licensed under the New BSD license. See LICENSE or:
|
|
5
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A data structure which is a combination of an array and a set. Adding a new
|
|
10
|
+
* member is O(1), testing for membership is O(1), and finding the index of an
|
|
11
|
+
* element is O(1). Removing elements from the set is not supported. Only
|
|
12
|
+
* strings are supported for membership.
|
|
13
|
+
*/
|
|
14
|
+
class ArraySet {
|
|
15
|
+
constructor() {
|
|
16
|
+
this._array = [];
|
|
17
|
+
this._set = new Map();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Static method for creating ArraySet instances from an existing array.
|
|
22
|
+
*/
|
|
23
|
+
static fromArray(aArray, aAllowDuplicates) {
|
|
24
|
+
const set = new ArraySet();
|
|
25
|
+
for (let i = 0, len = aArray.length; i < len; i++) {
|
|
26
|
+
set.add(aArray[i], aAllowDuplicates);
|
|
27
|
+
}
|
|
28
|
+
return set;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Return how many unique items are in this ArraySet. If duplicates have been
|
|
33
|
+
* added, than those do not count towards the size.
|
|
34
|
+
*
|
|
35
|
+
* @returns Number
|
|
36
|
+
*/
|
|
37
|
+
size() {
|
|
38
|
+
return this._set.size;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Add the given string to this set.
|
|
43
|
+
*
|
|
44
|
+
* @param String aStr
|
|
45
|
+
*/
|
|
46
|
+
add(aStr, aAllowDuplicates) {
|
|
47
|
+
const isDuplicate = this.has(aStr);
|
|
48
|
+
const idx = this._array.length;
|
|
49
|
+
if (!isDuplicate || aAllowDuplicates) {
|
|
50
|
+
this._array.push(aStr);
|
|
51
|
+
}
|
|
52
|
+
if (!isDuplicate) {
|
|
53
|
+
this._set.set(aStr, idx);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Is the given string a member of this set?
|
|
59
|
+
*
|
|
60
|
+
* @param String aStr
|
|
61
|
+
*/
|
|
62
|
+
has(aStr) {
|
|
63
|
+
return this._set.has(aStr);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* What is the index of the given string in the array?
|
|
68
|
+
*
|
|
69
|
+
* @param String aStr
|
|
70
|
+
*/
|
|
71
|
+
indexOf(aStr) {
|
|
72
|
+
const idx = this._set.get(aStr);
|
|
73
|
+
if (idx >= 0) {
|
|
74
|
+
return idx;
|
|
75
|
+
}
|
|
76
|
+
throw new Error('"' + aStr + '" is not in the set.');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* What is the element at the given index?
|
|
81
|
+
*
|
|
82
|
+
* @param Number aIdx
|
|
83
|
+
*/
|
|
84
|
+
at(aIdx) {
|
|
85
|
+
if (aIdx >= 0 && aIdx < this._array.length) {
|
|
86
|
+
return this._array[aIdx];
|
|
87
|
+
}
|
|
88
|
+
throw new Error("No element indexed by " + aIdx);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns the array representation of this set (which has the proper indices
|
|
93
|
+
* indicated by indexOf). Note that this is a copy of the internal array used
|
|
94
|
+
* for storing the members so that no one can mess with internal state.
|
|
95
|
+
*/
|
|
96
|
+
toArray() {
|
|
97
|
+
return this._array.slice();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.ArraySet = ArraySet;
|