llama-stack-client 0.4.3 → 0.4.4
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/.devcontainer/devcontainer.json +15 -0
- package/.eslintrc.js +16 -0
- package/.github/workflows/ci.yml +88 -0
- package/.github/workflows/integration-tests.yml +133 -0
- package/.github/workflows/release-doctor.yml +19 -0
- package/.gitignore +12 -0
- package/.prettierignore +7 -0
- package/.prettierrc.json +7 -0
- package/.release-please-manifest.json +3 -0
- package/.stats.yml +4 -0
- package/Brewfile +1 -0
- package/CODE_OF_CONDUCT.md +80 -0
- package/CONTRIBUTING.md +98 -0
- package/README.md +22 -31
- package/SECURITY.md +27 -0
- package/api.md +484 -0
- package/bin/check-release-environment +18 -0
- package/bin/publish-npm +61 -0
- package/dist/CHANGELOG.md +352 -0
- package/dist/LICENSE +7 -0
- package/dist/README.md +355 -0
- package/{index.d.mts → dist/index.d.mts} +6 -12
- package/{index.d.ts → dist/index.d.ts} +6 -12
- package/{index.d.ts.map → dist/index.d.ts.map} +1 -1
- package/{index.js.map → dist/index.js.map} +1 -1
- package/dist/index.mjs.map +1 -0
- package/dist/package.json +108 -0
- package/{resources → dist/resources}/alpha/alpha.d.ts +2 -6
- package/dist/resources/alpha/alpha.d.ts.map +1 -0
- package/{resources → dist/resources}/alpha/alpha.js +0 -4
- package/dist/resources/alpha/alpha.js.map +1 -0
- package/{resources → dist/resources}/alpha/alpha.mjs +0 -4
- package/dist/resources/alpha/alpha.mjs.map +1 -0
- package/{resources → dist/resources}/alpha/benchmarks.d.ts +1 -37
- package/dist/resources/alpha/benchmarks.d.ts.map +1 -0
- package/{resources → dist/resources}/alpha/index.d.ts +1 -2
- package/dist/resources/alpha/index.d.ts.map +1 -0
- package/{resources → dist/resources}/alpha/index.js +1 -3
- package/dist/resources/alpha/index.js.map +1 -0
- package/{resources → dist/resources}/alpha/index.mjs +0 -1
- package/{resources → dist/resources}/alpha/index.mjs.map +1 -1
- package/dist/resources/alpha/post-training/index.d.ts +3 -0
- package/dist/resources/alpha/post-training/index.d.ts.map +1 -0
- package/{resources → dist/resources}/alpha/post-training/index.js.map +1 -1
- package/{resources → dist/resources}/alpha/post-training/index.mjs.map +1 -1
- package/{resources → dist/resources}/alpha/post-training/job.d.ts +4 -1
- package/dist/resources/alpha/post-training/job.d.ts.map +1 -0
- package/{resources → dist/resources}/alpha/post-training/post-training.d.ts +3 -6
- package/dist/resources/alpha/post-training/post-training.d.ts.map +1 -0
- package/{resources → dist/resources}/alpha/post-training/post-training.js.map +1 -1
- package/{resources → dist/resources}/alpha/post-training/post-training.mjs.map +1 -1
- package/{resources → dist/resources}/beta/datasets.d.ts +8 -89
- package/dist/resources/beta/datasets.d.ts.map +1 -0
- package/{resources → dist/resources}/chat/chat.d.ts +2 -2
- package/{resources → dist/resources}/chat/chat.d.ts.map +1 -1
- package/{resources → dist/resources}/chat/completions.d.ts +6 -6
- package/dist/resources/chat/completions.d.ts.map +1 -0
- package/{resources → dist/resources}/completions.d.ts +2 -2
- package/dist/resources/completions.d.ts.map +1 -0
- package/{resources → dist/resources}/conversations/conversations.d.ts +4 -32
- package/dist/resources/conversations/conversations.d.ts.map +1 -0
- package/{resources → dist/resources}/conversations/conversations.js.map +1 -1
- package/{resources → dist/resources}/conversations/conversations.mjs.map +1 -1
- package/{resources → dist/resources}/conversations/items.d.ts +12 -124
- package/dist/resources/conversations/items.d.ts.map +1 -0
- package/{resources → dist/resources}/conversations/items.js.map +1 -1
- package/{resources → dist/resources}/conversations/items.mjs.map +1 -1
- package/{resources → dist/resources}/index.d.ts +3 -3
- package/dist/resources/index.d.ts.map +1 -0
- package/{resources → dist/resources}/index.js.map +1 -1
- package/{resources → dist/resources}/index.mjs.map +1 -1
- package/dist/resources/inspect.d.ts +56 -0
- package/dist/resources/inspect.d.ts.map +1 -0
- package/{resources → dist/resources}/inspect.js +4 -0
- package/dist/resources/inspect.js.map +1 -0
- package/{resources → dist/resources}/inspect.mjs +4 -0
- package/dist/resources/inspect.mjs.map +1 -0
- package/dist/resources/providers.d.ts +28 -0
- package/dist/resources/providers.d.ts.map +1 -0
- package/{resources → dist/resources}/providers.js +4 -0
- package/dist/resources/providers.js.map +1 -0
- package/{resources → dist/resources}/providers.mjs +4 -0
- package/dist/resources/providers.mjs.map +1 -0
- package/{resources → dist/resources}/responses/input-items.d.ts +8 -64
- package/dist/resources/responses/input-items.d.ts.map +1 -0
- package/{resources → dist/resources}/responses/responses.d.ts +31 -479
- package/dist/resources/responses/responses.d.ts.map +1 -0
- package/{resources → dist/resources}/responses/responses.js.map +1 -1
- package/{resources → dist/resources}/responses/responses.mjs.map +1 -1
- package/dist/resources/routes.d.ts +26 -0
- package/dist/resources/routes.d.ts.map +1 -0
- package/{resources → dist/resources}/routes.js.map +1 -1
- package/{resources → dist/resources}/routes.mjs.map +1 -1
- package/{resources → dist/resources}/shared.d.ts +0 -86
- package/dist/resources/shared.d.ts.map +1 -0
- package/dist/src/_shims/MultipartBody.ts +15 -0
- package/dist/src/_shims/README.md +46 -0
- package/dist/src/_shims/auto/runtime-bun.ts +10 -0
- package/dist/src/_shims/auto/runtime-node.ts +10 -0
- package/dist/src/_shims/auto/runtime.ts +10 -0
- package/dist/src/_shims/auto/types-node.ts +10 -0
- package/dist/src/_shims/auto/types.d.ts +107 -0
- package/dist/src/_shims/auto/types.js +9 -0
- package/dist/src/_shims/auto/types.mjs +10 -0
- package/dist/src/_shims/bun-runtime.ts +20 -0
- package/dist/src/_shims/index.d.ts +89 -0
- package/dist/src/_shims/index.js +23 -0
- package/dist/src/_shims/index.mjs +18 -0
- package/dist/src/_shims/manual-types.d.ts +18 -0
- package/dist/src/_shims/manual-types.js +9 -0
- package/dist/src/_shims/manual-types.mjs +10 -0
- package/dist/src/_shims/node-runtime.ts +87 -0
- package/dist/src/_shims/node-types.d.ts +48 -0
- package/dist/src/_shims/node-types.js +9 -0
- package/dist/src/_shims/node-types.mjs +10 -0
- package/dist/src/_shims/registry.ts +73 -0
- package/dist/src/_shims/web-runtime.ts +109 -0
- package/dist/src/_shims/web-types.d.ts +89 -0
- package/dist/src/_shims/web-types.js +9 -0
- package/dist/src/_shims/web-types.mjs +10 -0
- package/dist/src/core.ts +1259 -0
- package/dist/src/error.ts +137 -0
- package/dist/src/index.ts +591 -0
- package/dist/src/internal/decoders/line.ts +182 -0
- package/dist/src/internal/qs/LICENSE.md +13 -0
- package/dist/src/internal/qs/README.md +3 -0
- package/dist/src/internal/qs/formats.ts +15 -0
- package/dist/src/internal/qs/index.ts +19 -0
- package/dist/src/internal/qs/stringify.ts +394 -0
- package/dist/src/internal/qs/types.ts +77 -0
- package/dist/src/internal/qs/utils.ts +271 -0
- package/dist/src/internal/stream-utils.ts +38 -0
- package/dist/src/lib/.keep +4 -0
- package/dist/src/lib/response-helpers.ts +60 -0
- package/dist/src/pagination.ts +134 -0
- package/dist/src/resource.ts +18 -0
- package/dist/src/resources/alpha/alpha.ts +85 -0
- package/dist/src/resources/alpha/benchmarks.ts +116 -0
- package/dist/src/resources/alpha/eval/eval.ts +234 -0
- package/dist/src/resources/alpha/eval/index.ts +19 -0
- package/dist/src/resources/alpha/eval/jobs.ts +41 -0
- package/dist/src/resources/alpha/eval.ts +10 -0
- package/dist/src/resources/alpha/index.ts +34 -0
- package/dist/src/resources/alpha/inference.ts +132 -0
- package/dist/src/resources/alpha/post-training/index.ts +25 -0
- package/dist/src/resources/alpha/post-training/job.ts +182 -0
- package/dist/src/resources/alpha/post-training/post-training.ts +369 -0
- package/dist/src/resources/alpha/post-training.ts +9 -0
- package/dist/src/resources/alpha.ts +9 -0
- package/dist/src/resources/batches.ts +572 -0
- package/dist/src/resources/beta/beta.ts +41 -0
- package/dist/src/resources/beta/datasets.ts +350 -0
- package/dist/src/resources/beta/index.ts +20 -0
- package/dist/src/resources/beta.ts +9 -0
- package/dist/src/resources/chat/chat.ts +246 -0
- package/dist/src/resources/chat/completions.ts +1875 -0
- package/dist/src/resources/chat/index.ts +19 -0
- package/dist/src/resources/chat.ts +9 -0
- package/dist/src/resources/completions.ts +235 -0
- package/dist/src/resources/conversations/conversations.ts +455 -0
- package/dist/src/resources/conversations/index.ts +25 -0
- package/dist/src/resources/conversations/items.ts +1221 -0
- package/dist/src/resources/conversations.ts +9 -0
- package/dist/src/resources/embeddings.ts +84 -0
- package/dist/src/resources/files.ts +184 -0
- package/dist/src/resources/index.ts +139 -0
- package/dist/src/resources/inspect.ts +81 -0
- package/dist/src/resources/models/index.ts +18 -0
- package/dist/src/resources/models/models.ts +179 -0
- package/dist/src/resources/models/openai.ts +22 -0
- package/dist/src/resources/models.ts +9 -0
- package/dist/src/resources/moderations.ts +61 -0
- package/dist/src/resources/prompts/index.ts +19 -0
- package/dist/src/resources/prompts/prompts.ts +171 -0
- package/dist/src/resources/prompts/versions.ts +26 -0
- package/dist/src/resources/prompts.ts +9 -0
- package/dist/src/resources/providers.ts +49 -0
- package/dist/src/resources/responses/index.ts +21 -0
- package/dist/src/resources/responses/input-items.ts +508 -0
- package/dist/src/resources/responses/responses.ts +3689 -0
- package/dist/src/resources/responses.ts +9 -0
- package/dist/src/resources/routes.ts +56 -0
- package/dist/src/resources/safety.ts +241 -0
- package/dist/src/resources/scoring-functions.ts +343 -0
- package/dist/src/resources/scoring.ts +197 -0
- package/dist/src/resources/shared.ts +418 -0
- package/dist/src/resources/shields.ts +98 -0
- package/dist/src/resources/tool-runtime.ts +217 -0
- package/dist/src/resources/toolgroups.ts +135 -0
- package/dist/src/resources/tools.ts +52 -0
- package/dist/src/resources/vector-io.ts +468 -0
- package/dist/src/resources/vector-stores/file-batches.ts +201 -0
- package/dist/src/resources/vector-stores/files.ts +358 -0
- package/dist/src/resources/vector-stores/index.ts +38 -0
- package/dist/src/resources/vector-stores/vector-stores.ts +402 -0
- package/dist/src/resources/vector-stores.ts +9 -0
- package/dist/src/resources.ts +7 -0
- package/dist/src/shims/node.ts +56 -0
- package/dist/src/shims/web.ts +56 -0
- package/dist/src/streaming.ts +297 -0
- package/dist/src/uploads.ts +261 -0
- package/dist/src/version.ts +7 -0
- package/dist/version.d.ts +2 -0
- package/{version.js → dist/version.js} +1 -1
- package/{version.mjs → dist/version.mjs} +1 -1
- package/examples/.keep +4 -0
- package/jest.config.ts +29 -0
- package/package.json +55 -35
- package/release-please-config.json +64 -0
- package/scripts/bootstrap +30 -0
- package/scripts/build +56 -0
- package/scripts/fast-format +40 -0
- package/scripts/format +8 -0
- package/scripts/lint +11 -0
- package/scripts/mock +41 -0
- package/scripts/test +56 -0
- package/scripts/utils/check-is-in-git-install.sh +15 -0
- package/scripts/utils/check-version.cjs +27 -0
- package/scripts/utils/fix-index-exports.cjs +21 -0
- package/scripts/utils/git-swap.sh +19 -0
- package/scripts/utils/make-dist-package-json.cjs +28 -0
- package/scripts/utils/postprocess-files.cjs +172 -0
- package/scripts/utils/upload-artifact.sh +33 -0
- package/src/_shims/auto/runtime-deno.ts +10 -0
- package/src/_shims/auto/types-deno.ts +10 -0
- package/src/_shims/auto/types.d.ts +18 -18
- package/src/_shims/index-deno.ts +118 -0
- package/src/_shims/index.d.ts +1 -1
- package/src/_shims/index.mjs +1 -1
- package/src/index.ts +16 -11
- package/src/resources/alpha/alpha.ts +0 -8
- package/src/resources/alpha/benchmarks.ts +1 -37
- package/src/resources/alpha/index.ts +0 -2
- package/src/resources/alpha/post-training/index.ts +1 -1
- package/src/resources/alpha/post-training/job.ts +5 -0
- package/src/resources/alpha/post-training/post-training.ts +2 -5
- package/src/resources/beta/datasets.ts +8 -89
- package/src/resources/chat/chat.ts +4 -4
- package/src/resources/chat/completions.ts +12 -12
- package/src/resources/completions.ts +4 -4
- package/src/resources/conversations/conversations.ts +7 -43
- package/src/resources/conversations/items.ts +21 -165
- package/src/resources/index.ts +3 -3
- package/src/resources/inspect.ts +57 -3
- package/src/resources/providers.ts +16 -5
- package/src/resources/responses/input-items.ts +14 -86
- package/src/resources/responses/responses.ts +45 -654
- package/src/resources/routes.ts +14 -10
- package/src/resources/shared.ts +0 -95
- package/src/version.ts +1 -1
- package/tests/api-resources/alpha/benchmarks.test.ts +94 -0
- package/tests/api-resources/alpha/eval/eval.test.ts +186 -0
- package/tests/api-resources/alpha/eval/jobs.test.ts +68 -0
- package/tests/api-resources/alpha/inference.test.ts +38 -0
- package/tests/api-resources/alpha/post-training/job.test.ts +77 -0
- package/tests/api-resources/alpha/post-training/post-training.test.ts +124 -0
- package/tests/api-resources/batches.test.ts +100 -0
- package/tests/api-resources/beta/datasets.test.ts +135 -0
- package/tests/api-resources/chat/completions.test.ts +102 -0
- package/tests/api-resources/completions.test.ts +48 -0
- package/tests/api-resources/conversations/conversations.test.ts +76 -0
- package/tests/api-resources/conversations/items.test.ts +98 -0
- package/tests/api-resources/embeddings.test.ts +35 -0
- package/tests/api-resources/files.test.ts +118 -0
- package/tests/api-resources/inspect.test.ts +50 -0
- package/tests/api-resources/models/models.test.ts +89 -0
- package/tests/api-resources/models/openai.test.ts +32 -0
- package/tests/api-resources/moderations.test.ts +29 -0
- package/tests/api-resources/prompts/prompts.test.ts +125 -0
- package/tests/api-resources/prompts/versions.test.ts +32 -0
- package/tests/api-resources/providers.test.ts +50 -0
- package/tests/api-resources/responses/input-items.test.ts +43 -0
- package/tests/api-resources/responses/responses.test.ts +118 -0
- package/tests/api-resources/routes.test.ts +39 -0
- package/tests/api-resources/safety.test.ts +37 -0
- package/tests/api-resources/scoring-functions.test.ts +100 -0
- package/tests/api-resources/scoring.test.ts +73 -0
- package/tests/api-resources/shields.test.ts +88 -0
- package/tests/api-resources/tool-runtime.test.ts +61 -0
- package/tests/api-resources/toolgroups.test.ts +91 -0
- package/tests/api-resources/tools.test.ts +57 -0
- package/tests/api-resources/vector-io.test.ts +75 -0
- package/tests/api-resources/vector-stores/file-batches.test.ts +107 -0
- package/tests/api-resources/vector-stores/files.test.ts +147 -0
- package/tests/api-resources/vector-stores/vector-stores.test.ts +122 -0
- package/tests/form.test.ts +71 -0
- package/tests/index.test.ts +438 -0
- package/tests/internal/decoders/line.test.ts +134 -0
- package/tests/qs/empty-keys-cases.ts +277 -0
- package/tests/qs/stringify.test.ts +2238 -0
- package/tests/qs/utils.test.ts +175 -0
- package/tests/responses.test.ts +91 -0
- package/tests/streaming.test.ts +250 -0
- package/tests/stringifyQuery.test.ts +29 -0
- package/tests/uploads.test.ts +71 -0
- package/tsc-multi.json +7 -0
- package/tsconfig.build.json +18 -0
- package/tsconfig.deno.json +15 -0
- package/tsconfig.dist-src.json +11 -0
- package/tsconfig.json +38 -0
- package/index.mjs.map +0 -1
- package/resources/alpha/admin.d.ts +0 -41
- package/resources/alpha/admin.d.ts.map +0 -1
- package/resources/alpha/admin.js +0 -46
- package/resources/alpha/admin.js.map +0 -1
- package/resources/alpha/admin.mjs +0 -42
- package/resources/alpha/admin.mjs.map +0 -1
- package/resources/alpha/alpha.d.ts.map +0 -1
- package/resources/alpha/alpha.js.map +0 -1
- package/resources/alpha/alpha.mjs.map +0 -1
- package/resources/alpha/benchmarks.d.ts.map +0 -1
- package/resources/alpha/index.d.ts.map +0 -1
- package/resources/alpha/index.js.map +0 -1
- package/resources/alpha/post-training/index.d.ts +0 -3
- package/resources/alpha/post-training/index.d.ts.map +0 -1
- package/resources/alpha/post-training/job.d.ts.map +0 -1
- package/resources/alpha/post-training/post-training.d.ts.map +0 -1
- package/resources/beta/datasets.d.ts.map +0 -1
- package/resources/chat/completions.d.ts.map +0 -1
- package/resources/completions.d.ts.map +0 -1
- package/resources/conversations/conversations.d.ts.map +0 -1
- package/resources/conversations/items.d.ts.map +0 -1
- package/resources/index.d.ts.map +0 -1
- package/resources/inspect.d.ts +0 -14
- package/resources/inspect.d.ts.map +0 -1
- package/resources/inspect.js.map +0 -1
- package/resources/inspect.mjs.map +0 -1
- package/resources/providers.d.ts +0 -21
- package/resources/providers.d.ts.map +0 -1
- package/resources/providers.js.map +0 -1
- package/resources/providers.mjs.map +0 -1
- package/resources/responses/input-items.d.ts.map +0 -1
- package/resources/responses/responses.d.ts.map +0 -1
- package/resources/routes.d.ts +0 -27
- package/resources/routes.d.ts.map +0 -1
- package/resources/shared.d.ts.map +0 -1
- package/src/resources/alpha/admin.ts +0 -84
- package/version.d.ts +0 -2
- /package/{_shims → dist/_shims}/MultipartBody.d.ts +0 -0
- /package/{_shims → dist/_shims}/MultipartBody.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/MultipartBody.js +0 -0
- /package/{_shims → dist/_shims}/MultipartBody.js.map +0 -0
- /package/{_shims → dist/_shims}/MultipartBody.mjs +0 -0
- /package/{_shims → dist/_shims}/MultipartBody.mjs.map +0 -0
- /package/{_shims → dist/_shims}/README.md +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.d.ts +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.js +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.js.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.mjs +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-bun.mjs.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.d.ts +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.js +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.js.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.mjs +0 -0
- /package/{_shims → dist/_shims}/auto/runtime-node.mjs.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.d.ts +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.js +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.js.map +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.mjs +0 -0
- /package/{_shims → dist/_shims}/auto/runtime.mjs.map +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.d.ts +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.js +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.js.map +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.mjs +0 -0
- /package/{_shims → dist/_shims}/auto/types-node.mjs.map +0 -0
- /package/{_shims → dist/_shims}/auto/types.d.ts +0 -0
- /package/{_shims → dist/_shims}/auto/types.js +0 -0
- /package/{_shims → dist/_shims}/auto/types.mjs +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.d.ts +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.js +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.js.map +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.mjs +0 -0
- /package/{_shims → dist/_shims}/bun-runtime.mjs.map +0 -0
- /package/{_shims → dist/_shims}/index.d.ts +0 -0
- /package/{_shims → dist/_shims}/index.js +0 -0
- /package/{_shims → dist/_shims}/index.mjs +0 -0
- /package/{_shims → dist/_shims}/manual-types.d.ts +0 -0
- /package/{_shims → dist/_shims}/manual-types.js +0 -0
- /package/{_shims → dist/_shims}/manual-types.mjs +0 -0
- /package/{_shims → dist/_shims}/node-runtime.d.ts +0 -0
- /package/{_shims → dist/_shims}/node-runtime.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/node-runtime.js +0 -0
- /package/{_shims → dist/_shims}/node-runtime.js.map +0 -0
- /package/{_shims → dist/_shims}/node-runtime.mjs +0 -0
- /package/{_shims → dist/_shims}/node-runtime.mjs.map +0 -0
- /package/{_shims → dist/_shims}/node-types.d.ts +0 -0
- /package/{_shims → dist/_shims}/node-types.js +0 -0
- /package/{_shims → dist/_shims}/node-types.mjs +0 -0
- /package/{_shims → dist/_shims}/registry.d.ts +0 -0
- /package/{_shims → dist/_shims}/registry.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/registry.js +0 -0
- /package/{_shims → dist/_shims}/registry.js.map +0 -0
- /package/{_shims → dist/_shims}/registry.mjs +0 -0
- /package/{_shims → dist/_shims}/registry.mjs.map +0 -0
- /package/{_shims → dist/_shims}/web-runtime.d.ts +0 -0
- /package/{_shims → dist/_shims}/web-runtime.d.ts.map +0 -0
- /package/{_shims → dist/_shims}/web-runtime.js +0 -0
- /package/{_shims → dist/_shims}/web-runtime.js.map +0 -0
- /package/{_shims → dist/_shims}/web-runtime.mjs +0 -0
- /package/{_shims → dist/_shims}/web-runtime.mjs.map +0 -0
- /package/{_shims → dist/_shims}/web-types.d.ts +0 -0
- /package/{_shims → dist/_shims}/web-types.js +0 -0
- /package/{_shims → dist/_shims}/web-types.mjs +0 -0
- /package/{core.d.ts → dist/core.d.ts} +0 -0
- /package/{core.d.ts.map → dist/core.d.ts.map} +0 -0
- /package/{core.js → dist/core.js} +0 -0
- /package/{core.js.map → dist/core.js.map} +0 -0
- /package/{core.mjs → dist/core.mjs} +0 -0
- /package/{core.mjs.map → dist/core.mjs.map} +0 -0
- /package/{error.d.ts → dist/error.d.ts} +0 -0
- /package/{error.d.ts.map → dist/error.d.ts.map} +0 -0
- /package/{error.js → dist/error.js} +0 -0
- /package/{error.js.map → dist/error.js.map} +0 -0
- /package/{error.mjs → dist/error.mjs} +0 -0
- /package/{error.mjs.map → dist/error.mjs.map} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{index.mjs → dist/index.mjs} +0 -0
- /package/{internal → dist/internal}/decoders/line.d.ts +0 -0
- /package/{internal → dist/internal}/decoders/line.d.ts.map +0 -0
- /package/{internal → dist/internal}/decoders/line.js +0 -0
- /package/{internal → dist/internal}/decoders/line.js.map +0 -0
- /package/{internal → dist/internal}/decoders/line.mjs +0 -0
- /package/{internal → dist/internal}/decoders/line.mjs.map +0 -0
- /package/{internal → dist/internal}/qs/formats.d.ts +0 -0
- /package/{internal → dist/internal}/qs/formats.d.ts.map +0 -0
- /package/{internal → dist/internal}/qs/formats.js +0 -0
- /package/{internal → dist/internal}/qs/formats.js.map +0 -0
- /package/{internal → dist/internal}/qs/formats.mjs +0 -0
- /package/{internal → dist/internal}/qs/formats.mjs.map +0 -0
- /package/{internal → dist/internal}/qs/index.d.ts +0 -0
- /package/{internal → dist/internal}/qs/index.d.ts.map +0 -0
- /package/{internal → dist/internal}/qs/index.js +0 -0
- /package/{internal → dist/internal}/qs/index.js.map +0 -0
- /package/{internal → dist/internal}/qs/index.mjs +0 -0
- /package/{internal → dist/internal}/qs/index.mjs.map +0 -0
- /package/{internal → dist/internal}/qs/stringify.d.ts +0 -0
- /package/{internal → dist/internal}/qs/stringify.d.ts.map +0 -0
- /package/{internal → dist/internal}/qs/stringify.js +0 -0
- /package/{internal → dist/internal}/qs/stringify.js.map +0 -0
- /package/{internal → dist/internal}/qs/stringify.mjs +0 -0
- /package/{internal → dist/internal}/qs/stringify.mjs.map +0 -0
- /package/{internal → dist/internal}/qs/types.d.ts +0 -0
- /package/{internal → dist/internal}/qs/types.d.ts.map +0 -0
- /package/{internal → dist/internal}/qs/types.js +0 -0
- /package/{internal → dist/internal}/qs/types.js.map +0 -0
- /package/{internal → dist/internal}/qs/types.mjs +0 -0
- /package/{internal → dist/internal}/qs/types.mjs.map +0 -0
- /package/{internal → dist/internal}/qs/utils.d.ts +0 -0
- /package/{internal → dist/internal}/qs/utils.d.ts.map +0 -0
- /package/{internal → dist/internal}/qs/utils.js +0 -0
- /package/{internal → dist/internal}/qs/utils.js.map +0 -0
- /package/{internal → dist/internal}/qs/utils.mjs +0 -0
- /package/{internal → dist/internal}/qs/utils.mjs.map +0 -0
- /package/{internal → dist/internal}/stream-utils.d.ts +0 -0
- /package/{internal → dist/internal}/stream-utils.d.ts.map +0 -0
- /package/{internal → dist/internal}/stream-utils.js +0 -0
- /package/{internal → dist/internal}/stream-utils.js.map +0 -0
- /package/{internal → dist/internal}/stream-utils.mjs +0 -0
- /package/{internal → dist/internal}/stream-utils.mjs.map +0 -0
- /package/{lib → dist/lib}/response-helpers.d.ts +0 -0
- /package/{lib → dist/lib}/response-helpers.d.ts.map +0 -0
- /package/{lib → dist/lib}/response-helpers.js +0 -0
- /package/{lib → dist/lib}/response-helpers.js.map +0 -0
- /package/{lib → dist/lib}/response-helpers.mjs +0 -0
- /package/{lib → dist/lib}/response-helpers.mjs.map +0 -0
- /package/{pagination.d.ts → dist/pagination.d.ts} +0 -0
- /package/{pagination.d.ts.map → dist/pagination.d.ts.map} +0 -0
- /package/{pagination.js → dist/pagination.js} +0 -0
- /package/{pagination.js.map → dist/pagination.js.map} +0 -0
- /package/{pagination.mjs → dist/pagination.mjs} +0 -0
- /package/{pagination.mjs.map → dist/pagination.mjs.map} +0 -0
- /package/{resource.d.ts → dist/resource.d.ts} +0 -0
- /package/{resource.d.ts.map → dist/resource.d.ts.map} +0 -0
- /package/{resource.js → dist/resource.js} +0 -0
- /package/{resource.js.map → dist/resource.js.map} +0 -0
- /package/{resource.mjs → dist/resource.mjs} +0 -0
- /package/{resource.mjs.map → dist/resource.mjs.map} +0 -0
- /package/{resources → dist/resources}/alpha/benchmarks.js +0 -0
- /package/{resources → dist/resources}/alpha/benchmarks.js.map +0 -0
- /package/{resources → dist/resources}/alpha/benchmarks.mjs +0 -0
- /package/{resources → dist/resources}/alpha/benchmarks.mjs.map +0 -0
- /package/{resources → dist/resources}/alpha/eval/eval.d.ts +0 -0
- /package/{resources → dist/resources}/alpha/eval/eval.d.ts.map +0 -0
- /package/{resources → dist/resources}/alpha/eval/eval.js +0 -0
- /package/{resources → dist/resources}/alpha/eval/eval.js.map +0 -0
- /package/{resources → dist/resources}/alpha/eval/eval.mjs +0 -0
- /package/{resources → dist/resources}/alpha/eval/eval.mjs.map +0 -0
- /package/{resources → dist/resources}/alpha/eval/index.d.ts +0 -0
- /package/{resources → dist/resources}/alpha/eval/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/alpha/eval/index.js +0 -0
- /package/{resources → dist/resources}/alpha/eval/index.js.map +0 -0
- /package/{resources → dist/resources}/alpha/eval/index.mjs +0 -0
- /package/{resources → dist/resources}/alpha/eval/index.mjs.map +0 -0
- /package/{resources → dist/resources}/alpha/eval/jobs.d.ts +0 -0
- /package/{resources → dist/resources}/alpha/eval/jobs.d.ts.map +0 -0
- /package/{resources → dist/resources}/alpha/eval/jobs.js +0 -0
- /package/{resources → dist/resources}/alpha/eval/jobs.js.map +0 -0
- /package/{resources → dist/resources}/alpha/eval/jobs.mjs +0 -0
- /package/{resources → dist/resources}/alpha/eval/jobs.mjs.map +0 -0
- /package/{resources → dist/resources}/alpha/eval.d.ts +0 -0
- /package/{resources → dist/resources}/alpha/eval.d.ts.map +0 -0
- /package/{resources → dist/resources}/alpha/eval.js +0 -0
- /package/{resources → dist/resources}/alpha/eval.js.map +0 -0
- /package/{resources → dist/resources}/alpha/eval.mjs +0 -0
- /package/{resources → dist/resources}/alpha/eval.mjs.map +0 -0
- /package/{resources → dist/resources}/alpha/inference.d.ts +0 -0
- /package/{resources → dist/resources}/alpha/inference.d.ts.map +0 -0
- /package/{resources → dist/resources}/alpha/inference.js +0 -0
- /package/{resources → dist/resources}/alpha/inference.js.map +0 -0
- /package/{resources → dist/resources}/alpha/inference.mjs +0 -0
- /package/{resources → dist/resources}/alpha/inference.mjs.map +0 -0
- /package/{resources → dist/resources}/alpha/post-training/index.js +0 -0
- /package/{resources → dist/resources}/alpha/post-training/index.mjs +0 -0
- /package/{resources → dist/resources}/alpha/post-training/job.js +0 -0
- /package/{resources → dist/resources}/alpha/post-training/job.js.map +0 -0
- /package/{resources → dist/resources}/alpha/post-training/job.mjs +0 -0
- /package/{resources → dist/resources}/alpha/post-training/job.mjs.map +0 -0
- /package/{resources → dist/resources}/alpha/post-training/post-training.js +0 -0
- /package/{resources → dist/resources}/alpha/post-training/post-training.mjs +0 -0
- /package/{resources → dist/resources}/alpha/post-training.d.ts +0 -0
- /package/{resources → dist/resources}/alpha/post-training.d.ts.map +0 -0
- /package/{resources → dist/resources}/alpha/post-training.js +0 -0
- /package/{resources → dist/resources}/alpha/post-training.js.map +0 -0
- /package/{resources → dist/resources}/alpha/post-training.mjs +0 -0
- /package/{resources → dist/resources}/alpha/post-training.mjs.map +0 -0
- /package/{resources → dist/resources}/alpha.d.ts +0 -0
- /package/{resources → dist/resources}/alpha.d.ts.map +0 -0
- /package/{resources → dist/resources}/alpha.js +0 -0
- /package/{resources → dist/resources}/alpha.js.map +0 -0
- /package/{resources → dist/resources}/alpha.mjs +0 -0
- /package/{resources → dist/resources}/alpha.mjs.map +0 -0
- /package/{resources → dist/resources}/batches.d.ts +0 -0
- /package/{resources → dist/resources}/batches.d.ts.map +0 -0
- /package/{resources → dist/resources}/batches.js +0 -0
- /package/{resources → dist/resources}/batches.js.map +0 -0
- /package/{resources → dist/resources}/batches.mjs +0 -0
- /package/{resources → dist/resources}/batches.mjs.map +0 -0
- /package/{resources → dist/resources}/beta/beta.d.ts +0 -0
- /package/{resources → dist/resources}/beta/beta.d.ts.map +0 -0
- /package/{resources → dist/resources}/beta/beta.js +0 -0
- /package/{resources → dist/resources}/beta/beta.js.map +0 -0
- /package/{resources → dist/resources}/beta/beta.mjs +0 -0
- /package/{resources → dist/resources}/beta/beta.mjs.map +0 -0
- /package/{resources → dist/resources}/beta/datasets.js +0 -0
- /package/{resources → dist/resources}/beta/datasets.js.map +0 -0
- /package/{resources → dist/resources}/beta/datasets.mjs +0 -0
- /package/{resources → dist/resources}/beta/datasets.mjs.map +0 -0
- /package/{resources → dist/resources}/beta/index.d.ts +0 -0
- /package/{resources → dist/resources}/beta/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/beta/index.js +0 -0
- /package/{resources → dist/resources}/beta/index.js.map +0 -0
- /package/{resources → dist/resources}/beta/index.mjs +0 -0
- /package/{resources → dist/resources}/beta/index.mjs.map +0 -0
- /package/{resources → dist/resources}/beta.d.ts +0 -0
- /package/{resources → dist/resources}/beta.d.ts.map +0 -0
- /package/{resources → dist/resources}/beta.js +0 -0
- /package/{resources → dist/resources}/beta.js.map +0 -0
- /package/{resources → dist/resources}/beta.mjs +0 -0
- /package/{resources → dist/resources}/beta.mjs.map +0 -0
- /package/{resources → dist/resources}/chat/chat.js +0 -0
- /package/{resources → dist/resources}/chat/chat.js.map +0 -0
- /package/{resources → dist/resources}/chat/chat.mjs +0 -0
- /package/{resources → dist/resources}/chat/chat.mjs.map +0 -0
- /package/{resources → dist/resources}/chat/completions.js +0 -0
- /package/{resources → dist/resources}/chat/completions.js.map +0 -0
- /package/{resources → dist/resources}/chat/completions.mjs +0 -0
- /package/{resources → dist/resources}/chat/completions.mjs.map +0 -0
- /package/{resources → dist/resources}/chat/index.d.ts +0 -0
- /package/{resources → dist/resources}/chat/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/chat/index.js +0 -0
- /package/{resources → dist/resources}/chat/index.js.map +0 -0
- /package/{resources → dist/resources}/chat/index.mjs +0 -0
- /package/{resources → dist/resources}/chat/index.mjs.map +0 -0
- /package/{resources → dist/resources}/chat.d.ts +0 -0
- /package/{resources → dist/resources}/chat.d.ts.map +0 -0
- /package/{resources → dist/resources}/chat.js +0 -0
- /package/{resources → dist/resources}/chat.js.map +0 -0
- /package/{resources → dist/resources}/chat.mjs +0 -0
- /package/{resources → dist/resources}/chat.mjs.map +0 -0
- /package/{resources → dist/resources}/completions.js +0 -0
- /package/{resources → dist/resources}/completions.js.map +0 -0
- /package/{resources → dist/resources}/completions.mjs +0 -0
- /package/{resources → dist/resources}/completions.mjs.map +0 -0
- /package/{resources → dist/resources}/conversations/conversations.js +0 -0
- /package/{resources → dist/resources}/conversations/conversations.mjs +0 -0
- /package/{resources → dist/resources}/conversations/index.d.ts +0 -0
- /package/{resources → dist/resources}/conversations/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/conversations/index.js +0 -0
- /package/{resources → dist/resources}/conversations/index.js.map +0 -0
- /package/{resources → dist/resources}/conversations/index.mjs +0 -0
- /package/{resources → dist/resources}/conversations/index.mjs.map +0 -0
- /package/{resources → dist/resources}/conversations/items.js +0 -0
- /package/{resources → dist/resources}/conversations/items.mjs +0 -0
- /package/{resources → dist/resources}/conversations.d.ts +0 -0
- /package/{resources → dist/resources}/conversations.d.ts.map +0 -0
- /package/{resources → dist/resources}/conversations.js +0 -0
- /package/{resources → dist/resources}/conversations.js.map +0 -0
- /package/{resources → dist/resources}/conversations.mjs +0 -0
- /package/{resources → dist/resources}/conversations.mjs.map +0 -0
- /package/{resources → dist/resources}/embeddings.d.ts +0 -0
- /package/{resources → dist/resources}/embeddings.d.ts.map +0 -0
- /package/{resources → dist/resources}/embeddings.js +0 -0
- /package/{resources → dist/resources}/embeddings.js.map +0 -0
- /package/{resources → dist/resources}/embeddings.mjs +0 -0
- /package/{resources → dist/resources}/embeddings.mjs.map +0 -0
- /package/{resources → dist/resources}/files.d.ts +0 -0
- /package/{resources → dist/resources}/files.d.ts.map +0 -0
- /package/{resources → dist/resources}/files.js +0 -0
- /package/{resources → dist/resources}/files.js.map +0 -0
- /package/{resources → dist/resources}/files.mjs +0 -0
- /package/{resources → dist/resources}/files.mjs.map +0 -0
- /package/{resources → dist/resources}/index.js +0 -0
- /package/{resources → dist/resources}/index.mjs +0 -0
- /package/{resources → dist/resources}/models/index.d.ts +0 -0
- /package/{resources → dist/resources}/models/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/models/index.js +0 -0
- /package/{resources → dist/resources}/models/index.js.map +0 -0
- /package/{resources → dist/resources}/models/index.mjs +0 -0
- /package/{resources → dist/resources}/models/index.mjs.map +0 -0
- /package/{resources → dist/resources}/models/models.d.ts +0 -0
- /package/{resources → dist/resources}/models/models.d.ts.map +0 -0
- /package/{resources → dist/resources}/models/models.js +0 -0
- /package/{resources → dist/resources}/models/models.js.map +0 -0
- /package/{resources → dist/resources}/models/models.mjs +0 -0
- /package/{resources → dist/resources}/models/models.mjs.map +0 -0
- /package/{resources → dist/resources}/models/openai.d.ts +0 -0
- /package/{resources → dist/resources}/models/openai.d.ts.map +0 -0
- /package/{resources → dist/resources}/models/openai.js +0 -0
- /package/{resources → dist/resources}/models/openai.js.map +0 -0
- /package/{resources → dist/resources}/models/openai.mjs +0 -0
- /package/{resources → dist/resources}/models/openai.mjs.map +0 -0
- /package/{resources → dist/resources}/models.d.ts +0 -0
- /package/{resources → dist/resources}/models.d.ts.map +0 -0
- /package/{resources → dist/resources}/models.js +0 -0
- /package/{resources → dist/resources}/models.js.map +0 -0
- /package/{resources → dist/resources}/models.mjs +0 -0
- /package/{resources → dist/resources}/models.mjs.map +0 -0
- /package/{resources → dist/resources}/moderations.d.ts +0 -0
- /package/{resources → dist/resources}/moderations.d.ts.map +0 -0
- /package/{resources → dist/resources}/moderations.js +0 -0
- /package/{resources → dist/resources}/moderations.js.map +0 -0
- /package/{resources → dist/resources}/moderations.mjs +0 -0
- /package/{resources → dist/resources}/moderations.mjs.map +0 -0
- /package/{resources → dist/resources}/prompts/index.d.ts +0 -0
- /package/{resources → dist/resources}/prompts/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/prompts/index.js +0 -0
- /package/{resources → dist/resources}/prompts/index.js.map +0 -0
- /package/{resources → dist/resources}/prompts/index.mjs +0 -0
- /package/{resources → dist/resources}/prompts/index.mjs.map +0 -0
- /package/{resources → dist/resources}/prompts/prompts.d.ts +0 -0
- /package/{resources → dist/resources}/prompts/prompts.d.ts.map +0 -0
- /package/{resources → dist/resources}/prompts/prompts.js +0 -0
- /package/{resources → dist/resources}/prompts/prompts.js.map +0 -0
- /package/{resources → dist/resources}/prompts/prompts.mjs +0 -0
- /package/{resources → dist/resources}/prompts/prompts.mjs.map +0 -0
- /package/{resources → dist/resources}/prompts/versions.d.ts +0 -0
- /package/{resources → dist/resources}/prompts/versions.d.ts.map +0 -0
- /package/{resources → dist/resources}/prompts/versions.js +0 -0
- /package/{resources → dist/resources}/prompts/versions.js.map +0 -0
- /package/{resources → dist/resources}/prompts/versions.mjs +0 -0
- /package/{resources → dist/resources}/prompts/versions.mjs.map +0 -0
- /package/{resources → dist/resources}/prompts.d.ts +0 -0
- /package/{resources → dist/resources}/prompts.d.ts.map +0 -0
- /package/{resources → dist/resources}/prompts.js +0 -0
- /package/{resources → dist/resources}/prompts.js.map +0 -0
- /package/{resources → dist/resources}/prompts.mjs +0 -0
- /package/{resources → dist/resources}/prompts.mjs.map +0 -0
- /package/{resources → dist/resources}/responses/index.d.ts +0 -0
- /package/{resources → dist/resources}/responses/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/responses/index.js +0 -0
- /package/{resources → dist/resources}/responses/index.js.map +0 -0
- /package/{resources → dist/resources}/responses/index.mjs +0 -0
- /package/{resources → dist/resources}/responses/index.mjs.map +0 -0
- /package/{resources → dist/resources}/responses/input-items.js +0 -0
- /package/{resources → dist/resources}/responses/input-items.js.map +0 -0
- /package/{resources → dist/resources}/responses/input-items.mjs +0 -0
- /package/{resources → dist/resources}/responses/input-items.mjs.map +0 -0
- /package/{resources → dist/resources}/responses/responses.js +0 -0
- /package/{resources → dist/resources}/responses/responses.mjs +0 -0
- /package/{resources → dist/resources}/responses.d.ts +0 -0
- /package/{resources → dist/resources}/responses.d.ts.map +0 -0
- /package/{resources → dist/resources}/responses.js +0 -0
- /package/{resources → dist/resources}/responses.js.map +0 -0
- /package/{resources → dist/resources}/responses.mjs +0 -0
- /package/{resources → dist/resources}/responses.mjs.map +0 -0
- /package/{resources → dist/resources}/routes.js +0 -0
- /package/{resources → dist/resources}/routes.mjs +0 -0
- /package/{resources → dist/resources}/safety.d.ts +0 -0
- /package/{resources → dist/resources}/safety.d.ts.map +0 -0
- /package/{resources → dist/resources}/safety.js +0 -0
- /package/{resources → dist/resources}/safety.js.map +0 -0
- /package/{resources → dist/resources}/safety.mjs +0 -0
- /package/{resources → dist/resources}/safety.mjs.map +0 -0
- /package/{resources → dist/resources}/scoring-functions.d.ts +0 -0
- /package/{resources → dist/resources}/scoring-functions.d.ts.map +0 -0
- /package/{resources → dist/resources}/scoring-functions.js +0 -0
- /package/{resources → dist/resources}/scoring-functions.js.map +0 -0
- /package/{resources → dist/resources}/scoring-functions.mjs +0 -0
- /package/{resources → dist/resources}/scoring-functions.mjs.map +0 -0
- /package/{resources → dist/resources}/scoring.d.ts +0 -0
- /package/{resources → dist/resources}/scoring.d.ts.map +0 -0
- /package/{resources → dist/resources}/scoring.js +0 -0
- /package/{resources → dist/resources}/scoring.js.map +0 -0
- /package/{resources → dist/resources}/scoring.mjs +0 -0
- /package/{resources → dist/resources}/scoring.mjs.map +0 -0
- /package/{resources → dist/resources}/shared.js +0 -0
- /package/{resources → dist/resources}/shared.js.map +0 -0
- /package/{resources → dist/resources}/shared.mjs +0 -0
- /package/{resources → dist/resources}/shared.mjs.map +0 -0
- /package/{resources → dist/resources}/shields.d.ts +0 -0
- /package/{resources → dist/resources}/shields.d.ts.map +0 -0
- /package/{resources → dist/resources}/shields.js +0 -0
- /package/{resources → dist/resources}/shields.js.map +0 -0
- /package/{resources → dist/resources}/shields.mjs +0 -0
- /package/{resources → dist/resources}/shields.mjs.map +0 -0
- /package/{resources → dist/resources}/tool-runtime.d.ts +0 -0
- /package/{resources → dist/resources}/tool-runtime.d.ts.map +0 -0
- /package/{resources → dist/resources}/tool-runtime.js +0 -0
- /package/{resources → dist/resources}/tool-runtime.js.map +0 -0
- /package/{resources → dist/resources}/tool-runtime.mjs +0 -0
- /package/{resources → dist/resources}/tool-runtime.mjs.map +0 -0
- /package/{resources → dist/resources}/toolgroups.d.ts +0 -0
- /package/{resources → dist/resources}/toolgroups.d.ts.map +0 -0
- /package/{resources → dist/resources}/toolgroups.js +0 -0
- /package/{resources → dist/resources}/toolgroups.js.map +0 -0
- /package/{resources → dist/resources}/toolgroups.mjs +0 -0
- /package/{resources → dist/resources}/toolgroups.mjs.map +0 -0
- /package/{resources → dist/resources}/tools.d.ts +0 -0
- /package/{resources → dist/resources}/tools.d.ts.map +0 -0
- /package/{resources → dist/resources}/tools.js +0 -0
- /package/{resources → dist/resources}/tools.js.map +0 -0
- /package/{resources → dist/resources}/tools.mjs +0 -0
- /package/{resources → dist/resources}/tools.mjs.map +0 -0
- /package/{resources → dist/resources}/vector-io.d.ts +0 -0
- /package/{resources → dist/resources}/vector-io.d.ts.map +0 -0
- /package/{resources → dist/resources}/vector-io.js +0 -0
- /package/{resources → dist/resources}/vector-io.js.map +0 -0
- /package/{resources → dist/resources}/vector-io.mjs +0 -0
- /package/{resources → dist/resources}/vector-io.mjs.map +0 -0
- /package/{resources → dist/resources}/vector-stores/file-batches.d.ts +0 -0
- /package/{resources → dist/resources}/vector-stores/file-batches.d.ts.map +0 -0
- /package/{resources → dist/resources}/vector-stores/file-batches.js +0 -0
- /package/{resources → dist/resources}/vector-stores/file-batches.js.map +0 -0
- /package/{resources → dist/resources}/vector-stores/file-batches.mjs +0 -0
- /package/{resources → dist/resources}/vector-stores/file-batches.mjs.map +0 -0
- /package/{resources → dist/resources}/vector-stores/files.d.ts +0 -0
- /package/{resources → dist/resources}/vector-stores/files.d.ts.map +0 -0
- /package/{resources → dist/resources}/vector-stores/files.js +0 -0
- /package/{resources → dist/resources}/vector-stores/files.js.map +0 -0
- /package/{resources → dist/resources}/vector-stores/files.mjs +0 -0
- /package/{resources → dist/resources}/vector-stores/files.mjs.map +0 -0
- /package/{resources → dist/resources}/vector-stores/index.d.ts +0 -0
- /package/{resources → dist/resources}/vector-stores/index.d.ts.map +0 -0
- /package/{resources → dist/resources}/vector-stores/index.js +0 -0
- /package/{resources → dist/resources}/vector-stores/index.js.map +0 -0
- /package/{resources → dist/resources}/vector-stores/index.mjs +0 -0
- /package/{resources → dist/resources}/vector-stores/index.mjs.map +0 -0
- /package/{resources → dist/resources}/vector-stores/vector-stores.d.ts +0 -0
- /package/{resources → dist/resources}/vector-stores/vector-stores.d.ts.map +0 -0
- /package/{resources → dist/resources}/vector-stores/vector-stores.js +0 -0
- /package/{resources → dist/resources}/vector-stores/vector-stores.js.map +0 -0
- /package/{resources → dist/resources}/vector-stores/vector-stores.mjs +0 -0
- /package/{resources → dist/resources}/vector-stores/vector-stores.mjs.map +0 -0
- /package/{resources → dist/resources}/vector-stores.d.ts +0 -0
- /package/{resources → dist/resources}/vector-stores.d.ts.map +0 -0
- /package/{resources → dist/resources}/vector-stores.js +0 -0
- /package/{resources → dist/resources}/vector-stores.js.map +0 -0
- /package/{resources → dist/resources}/vector-stores.mjs +0 -0
- /package/{resources → dist/resources}/vector-stores.mjs.map +0 -0
- /package/{resources.d.ts → dist/resources.d.ts} +0 -0
- /package/{resources.d.ts.map → dist/resources.d.ts.map} +0 -0
- /package/{resources.js → dist/resources.js} +0 -0
- /package/{resources.js.map → dist/resources.js.map} +0 -0
- /package/{resources.mjs → dist/resources.mjs} +0 -0
- /package/{resources.mjs.map → dist/resources.mjs.map} +0 -0
- /package/{shims → dist/shims}/node.d.ts +0 -0
- /package/{shims → dist/shims}/node.d.ts.map +0 -0
- /package/{shims → dist/shims}/node.js +0 -0
- /package/{shims → dist/shims}/node.js.map +0 -0
- /package/{shims → dist/shims}/node.mjs +0 -0
- /package/{shims → dist/shims}/node.mjs.map +0 -0
- /package/{shims → dist/shims}/web.d.ts +0 -0
- /package/{shims → dist/shims}/web.d.ts.map +0 -0
- /package/{shims → dist/shims}/web.js +0 -0
- /package/{shims → dist/shims}/web.js.map +0 -0
- /package/{shims → dist/shims}/web.mjs +0 -0
- /package/{shims → dist/shims}/web.mjs.map +0 -0
- /package/{src → dist/src}/tsconfig.json +0 -0
- /package/{streaming.d.ts → dist/streaming.d.ts} +0 -0
- /package/{streaming.d.ts.map → dist/streaming.d.ts.map} +0 -0
- /package/{streaming.js → dist/streaming.js} +0 -0
- /package/{streaming.js.map → dist/streaming.js.map} +0 -0
- /package/{streaming.mjs → dist/streaming.mjs} +0 -0
- /package/{streaming.mjs.map → dist/streaming.mjs.map} +0 -0
- /package/{uploads.d.ts → dist/uploads.d.ts} +0 -0
- /package/{uploads.d.ts.map → dist/uploads.d.ts.map} +0 -0
- /package/{uploads.js → dist/uploads.js} +0 -0
- /package/{uploads.js.map → dist/uploads.js.map} +0 -0
- /package/{uploads.mjs → dist/uploads.mjs} +0 -0
- /package/{uploads.mjs.map → dist/uploads.mjs.map} +0 -0
- /package/{version.d.ts.map → dist/version.d.ts.map} +0 -0
- /package/{version.js.map → dist/version.js.map} +0 -0
- /package/{version.mjs.map → dist/version.mjs.map} +0 -0
|
@@ -0,0 +1,2238 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
// All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// This source code is licensed under the terms described in the LICENSE file in
|
|
5
|
+
// the root directory of this source tree.
|
|
6
|
+
|
|
7
|
+
import iconv from 'iconv-lite';
|
|
8
|
+
import { stringify } from 'llama-stack-client/internal/qs';
|
|
9
|
+
import { encode } from 'llama-stack-client/internal/qs/utils';
|
|
10
|
+
import { StringifyOptions } from 'llama-stack-client/internal/qs/types';
|
|
11
|
+
import { empty_test_cases } from './empty-keys-cases';
|
|
12
|
+
import assert from 'assert';
|
|
13
|
+
|
|
14
|
+
describe('stringify()', function () {
|
|
15
|
+
test('stringifies a querystring object', function () {
|
|
16
|
+
expect(stringify({ a: 'b' })).toBe('a=b');
|
|
17
|
+
expect(stringify({ a: 1 })).toBe('a=1');
|
|
18
|
+
expect(stringify({ a: 1, b: 2 })).toBe('a=1&b=2');
|
|
19
|
+
expect(stringify({ a: 'A_Z' })).toBe('a=A_Z');
|
|
20
|
+
expect(stringify({ a: '€' })).toBe('a=%E2%82%AC');
|
|
21
|
+
expect(stringify({ a: '' })).toBe('a=%EE%80%80');
|
|
22
|
+
expect(stringify({ a: 'א' })).toBe('a=%D7%90');
|
|
23
|
+
expect(stringify({ a: '𐐷' })).toBe('a=%F0%90%90%B7');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('stringifies falsy values', function () {
|
|
27
|
+
expect(stringify(undefined)).toBe('');
|
|
28
|
+
expect(stringify(null)).toBe('');
|
|
29
|
+
expect(stringify(null, { strictNullHandling: true })).toBe('');
|
|
30
|
+
expect(stringify(false)).toBe('');
|
|
31
|
+
expect(stringify(0)).toBe('');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('stringifies symbols', function () {
|
|
35
|
+
expect(stringify(Symbol.iterator)).toBe('');
|
|
36
|
+
expect(stringify([Symbol.iterator])).toBe('0=Symbol%28Symbol.iterator%29');
|
|
37
|
+
expect(stringify({ a: Symbol.iterator })).toBe('a=Symbol%28Symbol.iterator%29');
|
|
38
|
+
expect(stringify({ a: [Symbol.iterator] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe(
|
|
39
|
+
'a[]=Symbol%28Symbol.iterator%29',
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('stringifies bigints', function () {
|
|
44
|
+
var three = BigInt(3);
|
|
45
|
+
// @ts-expect-error
|
|
46
|
+
var encodeWithN = function (value, defaultEncoder, charset) {
|
|
47
|
+
var result = defaultEncoder(value, defaultEncoder, charset);
|
|
48
|
+
return typeof value === 'bigint' ? result + 'n' : result;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
expect(stringify(three)).toBe('');
|
|
52
|
+
expect(stringify([three])).toBe('0=3');
|
|
53
|
+
expect(stringify([three], { encoder: encodeWithN })).toBe('0=3n');
|
|
54
|
+
expect(stringify({ a: three })).toBe('a=3');
|
|
55
|
+
expect(stringify({ a: three }, { encoder: encodeWithN })).toBe('a=3n');
|
|
56
|
+
expect(stringify({ a: [three] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe('a[]=3');
|
|
57
|
+
expect(
|
|
58
|
+
stringify({ a: [three] }, { encodeValuesOnly: true, encoder: encodeWithN, arrayFormat: 'brackets' }),
|
|
59
|
+
).toBe('a[]=3n');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('encodes dot in key of object when encodeDotInKeys and allowDots is provided', function () {
|
|
63
|
+
expect(
|
|
64
|
+
stringify({ 'name.obj': { first: 'John', last: 'Doe' } }, { allowDots: false, encodeDotInKeys: false }),
|
|
65
|
+
).toBe('name.obj%5Bfirst%5D=John&name.obj%5Blast%5D=Doe');
|
|
66
|
+
expect(
|
|
67
|
+
stringify({ 'name.obj': { first: 'John', last: 'Doe' } }, { allowDots: true, encodeDotInKeys: false }),
|
|
68
|
+
).toBe('name.obj.first=John&name.obj.last=Doe');
|
|
69
|
+
expect(
|
|
70
|
+
stringify({ 'name.obj': { first: 'John', last: 'Doe' } }, { allowDots: false, encodeDotInKeys: true }),
|
|
71
|
+
).toBe('name%252Eobj%5Bfirst%5D=John&name%252Eobj%5Blast%5D=Doe');
|
|
72
|
+
expect(
|
|
73
|
+
stringify({ 'name.obj': { first: 'John', last: 'Doe' } }, { allowDots: true, encodeDotInKeys: true }),
|
|
74
|
+
).toBe('name%252Eobj.first=John&name%252Eobj.last=Doe');
|
|
75
|
+
|
|
76
|
+
// st.equal(
|
|
77
|
+
// stringify(
|
|
78
|
+
// { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
79
|
+
// { allowDots: false, encodeDotInKeys: false },
|
|
80
|
+
// ),
|
|
81
|
+
// 'name.obj.subobject%5Bfirst.godly.name%5D=John&name.obj.subobject%5Blast%5D=Doe',
|
|
82
|
+
// 'with allowDots false and encodeDotInKeys false',
|
|
83
|
+
// );
|
|
84
|
+
// st.equal(
|
|
85
|
+
// stringify(
|
|
86
|
+
// { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
87
|
+
// { allowDots: true, encodeDotInKeys: false },
|
|
88
|
+
// ),
|
|
89
|
+
// 'name.obj.subobject.first.godly.name=John&name.obj.subobject.last=Doe',
|
|
90
|
+
// 'with allowDots false and encodeDotInKeys false',
|
|
91
|
+
// );
|
|
92
|
+
// st.equal(
|
|
93
|
+
// stringify(
|
|
94
|
+
// { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
95
|
+
// { allowDots: false, encodeDotInKeys: true },
|
|
96
|
+
// ),
|
|
97
|
+
// 'name%252Eobj%252Esubobject%5Bfirst.godly.name%5D=John&name%252Eobj%252Esubobject%5Blast%5D=Doe',
|
|
98
|
+
// 'with allowDots false and encodeDotInKeys true',
|
|
99
|
+
// );
|
|
100
|
+
// st.equal(
|
|
101
|
+
// stringify(
|
|
102
|
+
// { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
103
|
+
// { allowDots: true, encodeDotInKeys: true },
|
|
104
|
+
// ),
|
|
105
|
+
// 'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',
|
|
106
|
+
// 'with allowDots true and encodeDotInKeys true',
|
|
107
|
+
// );
|
|
108
|
+
expect(
|
|
109
|
+
stringify(
|
|
110
|
+
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
111
|
+
{ allowDots: false, encodeDotInKeys: false },
|
|
112
|
+
),
|
|
113
|
+
).toBe('name.obj.subobject%5Bfirst.godly.name%5D=John&name.obj.subobject%5Blast%5D=Doe');
|
|
114
|
+
expect(
|
|
115
|
+
stringify(
|
|
116
|
+
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
117
|
+
{ allowDots: true, encodeDotInKeys: false },
|
|
118
|
+
),
|
|
119
|
+
).toBe('name.obj.subobject.first.godly.name=John&name.obj.subobject.last=Doe');
|
|
120
|
+
expect(
|
|
121
|
+
stringify(
|
|
122
|
+
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
123
|
+
{ allowDots: false, encodeDotInKeys: true },
|
|
124
|
+
),
|
|
125
|
+
).toBe('name%252Eobj%252Esubobject%5Bfirst.godly.name%5D=John&name%252Eobj%252Esubobject%5Blast%5D=Doe');
|
|
126
|
+
expect(
|
|
127
|
+
stringify(
|
|
128
|
+
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
129
|
+
{ allowDots: true, encodeDotInKeys: true },
|
|
130
|
+
),
|
|
131
|
+
).toBe('name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('should encode dot in key of object, and automatically set allowDots to `true` when encodeDotInKeys is true and allowDots in undefined', function () {
|
|
135
|
+
// st.equal(
|
|
136
|
+
// stringify(
|
|
137
|
+
// { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
138
|
+
// { encodeDotInKeys: true },
|
|
139
|
+
// ),
|
|
140
|
+
// 'name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe',
|
|
141
|
+
// 'with allowDots undefined and encodeDotInKeys true',
|
|
142
|
+
// );
|
|
143
|
+
expect(
|
|
144
|
+
stringify(
|
|
145
|
+
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
146
|
+
{ encodeDotInKeys: true },
|
|
147
|
+
),
|
|
148
|
+
).toBe('name%252Eobj%252Esubobject.first%252Egodly%252Ename=John&name%252Eobj%252Esubobject.last=Doe');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('should encode dot in key of object when encodeDotInKeys and allowDots is provided, and nothing else when encodeValuesOnly is provided', function () {
|
|
152
|
+
// st.equal(
|
|
153
|
+
// stringify(
|
|
154
|
+
// { 'name.obj': { first: 'John', last: 'Doe' } },
|
|
155
|
+
// {
|
|
156
|
+
// encodeDotInKeys: true,
|
|
157
|
+
// allowDots: true,
|
|
158
|
+
// encodeValuesOnly: true,
|
|
159
|
+
// },
|
|
160
|
+
// ),
|
|
161
|
+
// 'name%2Eobj.first=John&name%2Eobj.last=Doe',
|
|
162
|
+
// );
|
|
163
|
+
expect(
|
|
164
|
+
stringify(
|
|
165
|
+
{ 'name.obj': { first: 'John', last: 'Doe' } },
|
|
166
|
+
{
|
|
167
|
+
encodeDotInKeys: true,
|
|
168
|
+
allowDots: true,
|
|
169
|
+
encodeValuesOnly: true,
|
|
170
|
+
},
|
|
171
|
+
),
|
|
172
|
+
).toBe('name%2Eobj.first=John&name%2Eobj.last=Doe');
|
|
173
|
+
|
|
174
|
+
// st.equal(
|
|
175
|
+
// stringify(
|
|
176
|
+
// { 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
177
|
+
// { allowDots: true, encodeDotInKeys: true, encodeValuesOnly: true },
|
|
178
|
+
// ),
|
|
179
|
+
// 'name%2Eobj%2Esubobject.first%2Egodly%2Ename=John&name%2Eobj%2Esubobject.last=Doe',
|
|
180
|
+
// );
|
|
181
|
+
expect(
|
|
182
|
+
stringify(
|
|
183
|
+
{ 'name.obj.subobject': { 'first.godly.name': 'John', last: 'Doe' } },
|
|
184
|
+
{ allowDots: true, encodeDotInKeys: true, encodeValuesOnly: true },
|
|
185
|
+
),
|
|
186
|
+
).toBe('name%2Eobj%2Esubobject.first%2Egodly%2Ename=John&name%2Eobj%2Esubobject.last=Doe');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('throws when `commaRoundTrip` is not a boolean', function () {
|
|
190
|
+
// st['throws'](
|
|
191
|
+
// function () {
|
|
192
|
+
// stringify({}, { commaRoundTrip: 'not a boolean' });
|
|
193
|
+
// },
|
|
194
|
+
// TypeError,
|
|
195
|
+
// 'throws when `commaRoundTrip` is not a boolean',
|
|
196
|
+
// );
|
|
197
|
+
expect(() => {
|
|
198
|
+
// @ts-expect-error
|
|
199
|
+
stringify({}, { commaRoundTrip: 'not a boolean' });
|
|
200
|
+
}).toThrow(TypeError);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('throws when `encodeDotInKeys` is not a boolean', function () {
|
|
204
|
+
// st['throws'](function () {
|
|
205
|
+
// stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 'foobar' });
|
|
206
|
+
// }, TypeError);
|
|
207
|
+
expect(() => {
|
|
208
|
+
// @ts-expect-error
|
|
209
|
+
stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 'foobar' });
|
|
210
|
+
}).toThrow(TypeError);
|
|
211
|
+
|
|
212
|
+
// st['throws'](function () {
|
|
213
|
+
// stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 0 });
|
|
214
|
+
// }, TypeError);
|
|
215
|
+
expect(() => {
|
|
216
|
+
// @ts-expect-error
|
|
217
|
+
stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 0 });
|
|
218
|
+
}).toThrow(TypeError);
|
|
219
|
+
|
|
220
|
+
// st['throws'](function () {
|
|
221
|
+
// stringify({ a: [], b: 'zz' }, { encodeDotInKeys: NaN });
|
|
222
|
+
// }, TypeError);
|
|
223
|
+
expect(() => {
|
|
224
|
+
// @ts-expect-error
|
|
225
|
+
stringify({ a: [], b: 'zz' }, { encodeDotInKeys: NaN });
|
|
226
|
+
}).toThrow(TypeError);
|
|
227
|
+
|
|
228
|
+
// st['throws'](function () {
|
|
229
|
+
// stringify({ a: [], b: 'zz' }, { encodeDotInKeys: null });
|
|
230
|
+
// }, TypeError);
|
|
231
|
+
expect(() => {
|
|
232
|
+
// @ts-expect-error
|
|
233
|
+
stringify({ a: [], b: 'zz' }, { encodeDotInKeys: null });
|
|
234
|
+
}).toThrow(TypeError);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('adds query prefix', function () {
|
|
238
|
+
// st.equal(stringify({ a: 'b' }, { addQueryPrefix: true }), '?a=b');
|
|
239
|
+
expect(stringify({ a: 'b' }, { addQueryPrefix: true })).toBe('?a=b');
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test('with query prefix, outputs blank string given an empty object', function () {
|
|
243
|
+
// st.equal(stringify({}, { addQueryPrefix: true }), '');
|
|
244
|
+
expect(stringify({}, { addQueryPrefix: true })).toBe('');
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('stringifies nested falsy values', function () {
|
|
248
|
+
// st.equal(stringify({ a: { b: { c: null } } }), 'a%5Bb%5D%5Bc%5D=');
|
|
249
|
+
// st.equal(
|
|
250
|
+
// stringify({ a: { b: { c: null } } }, { strictNullHandling: true }),
|
|
251
|
+
// 'a%5Bb%5D%5Bc%5D',
|
|
252
|
+
// );
|
|
253
|
+
// st.equal(stringify({ a: { b: { c: false } } }), 'a%5Bb%5D%5Bc%5D=false');
|
|
254
|
+
expect(stringify({ a: { b: { c: null } } })).toBe('a%5Bb%5D%5Bc%5D=');
|
|
255
|
+
expect(stringify({ a: { b: { c: null } } }, { strictNullHandling: true })).toBe('a%5Bb%5D%5Bc%5D');
|
|
256
|
+
expect(stringify({ a: { b: { c: false } } })).toBe('a%5Bb%5D%5Bc%5D=false');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('stringifies a nested object', function () {
|
|
260
|
+
// st.equal(stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
|
|
261
|
+
// st.equal(stringify({ a: { b: { c: { d: 'e' } } } }), 'a%5Bb%5D%5Bc%5D%5Bd%5D=e');
|
|
262
|
+
expect(stringify({ a: { b: 'c' } })).toBe('a%5Bb%5D=c');
|
|
263
|
+
expect(stringify({ a: { b: { c: { d: 'e' } } } })).toBe('a%5Bb%5D%5Bc%5D%5Bd%5D=e');
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test('`allowDots` option: stringifies a nested object with dots notation', function () {
|
|
267
|
+
// st.equal(stringify({ a: { b: 'c' } }, { allowDots: true }), 'a.b=c');
|
|
268
|
+
// st.equal(stringify({ a: { b: { c: { d: 'e' } } } }, { allowDots: true }), 'a.b.c.d=e');
|
|
269
|
+
expect(stringify({ a: { b: 'c' } }, { allowDots: true })).toBe('a.b=c');
|
|
270
|
+
expect(stringify({ a: { b: { c: { d: 'e' } } } }, { allowDots: true })).toBe('a.b.c.d=e');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test('stringifies an array value', function () {
|
|
274
|
+
// st.equal(
|
|
275
|
+
// stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'indices' }),
|
|
276
|
+
// 'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',
|
|
277
|
+
// 'indices => indices',
|
|
278
|
+
// );
|
|
279
|
+
// st.equal(
|
|
280
|
+
// stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'brackets' }),
|
|
281
|
+
// 'a%5B%5D=b&a%5B%5D=c&a%5B%5D=d',
|
|
282
|
+
// 'brackets => brackets',
|
|
283
|
+
// );
|
|
284
|
+
// st.equal(
|
|
285
|
+
// stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma' }),
|
|
286
|
+
// 'a=b%2Cc%2Cd',
|
|
287
|
+
// 'comma => comma',
|
|
288
|
+
// );
|
|
289
|
+
// st.equal(
|
|
290
|
+
// stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma', commaRoundTrip: true }),
|
|
291
|
+
// 'a=b%2Cc%2Cd',
|
|
292
|
+
// 'comma round trip => comma',
|
|
293
|
+
// );
|
|
294
|
+
// st.equal(
|
|
295
|
+
// stringify({ a: ['b', 'c', 'd'] }),
|
|
296
|
+
// 'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',
|
|
297
|
+
// 'default => indices',
|
|
298
|
+
// );
|
|
299
|
+
expect(stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'indices' })).toBe(
|
|
300
|
+
'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',
|
|
301
|
+
);
|
|
302
|
+
expect(stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'brackets' })).toBe(
|
|
303
|
+
'a%5B%5D=b&a%5B%5D=c&a%5B%5D=d',
|
|
304
|
+
);
|
|
305
|
+
expect(stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma' })).toBe('a=b%2Cc%2Cd');
|
|
306
|
+
expect(stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma', commaRoundTrip: true })).toBe(
|
|
307
|
+
'a=b%2Cc%2Cd',
|
|
308
|
+
);
|
|
309
|
+
expect(stringify({ a: ['b', 'c', 'd'] })).toBe('a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('`skipNulls` option', function () {
|
|
313
|
+
// st.equal(
|
|
314
|
+
// stringify({ a: 'b', c: null }, { skipNulls: true }),
|
|
315
|
+
// 'a=b',
|
|
316
|
+
// 'omits nulls when asked',
|
|
317
|
+
// );
|
|
318
|
+
expect(stringify({ a: 'b', c: null }, { skipNulls: true })).toBe('a=b');
|
|
319
|
+
|
|
320
|
+
// st.equal(
|
|
321
|
+
// stringify({ a: { b: 'c', d: null } }, { skipNulls: true }),
|
|
322
|
+
// 'a%5Bb%5D=c',
|
|
323
|
+
// 'omits nested nulls when asked',
|
|
324
|
+
// );
|
|
325
|
+
expect(stringify({ a: { b: 'c', d: null } }, { skipNulls: true })).toBe('a%5Bb%5D=c');
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test('omits array indices when asked', function () {
|
|
329
|
+
// st.equal(stringify({ a: ['b', 'c', 'd'] }, { indices: false }), 'a=b&a=c&a=d');
|
|
330
|
+
expect(stringify({ a: ['b', 'c', 'd'] }, { indices: false })).toBe('a=b&a=c&a=d');
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('omits object key/value pair when value is empty array', function () {
|
|
334
|
+
// st.equal(stringify({ a: [], b: 'zz' }), 'b=zz');
|
|
335
|
+
expect(stringify({ a: [], b: 'zz' })).toBe('b=zz');
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('should not omit object key/value pair when value is empty array and when asked', function () {
|
|
339
|
+
// st.equal(stringify({ a: [], b: 'zz' }), 'b=zz');
|
|
340
|
+
// st.equal(stringify({ a: [], b: 'zz' }, { allowEmptyArrays: false }), 'b=zz');
|
|
341
|
+
// st.equal(stringify({ a: [], b: 'zz' }, { allowEmptyArrays: true }), 'a[]&b=zz');
|
|
342
|
+
expect(stringify({ a: [], b: 'zz' })).toBe('b=zz');
|
|
343
|
+
expect(stringify({ a: [], b: 'zz' }, { allowEmptyArrays: false })).toBe('b=zz');
|
|
344
|
+
expect(stringify({ a: [], b: 'zz' }, { allowEmptyArrays: true })).toBe('a[]&b=zz');
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test('should throw when allowEmptyArrays is not of type boolean', function () {
|
|
348
|
+
// st['throws'](function () {
|
|
349
|
+
// stringify({ a: [], b: 'zz' }, { allowEmptyArrays: 'foobar' });
|
|
350
|
+
// }, TypeError);
|
|
351
|
+
expect(() => {
|
|
352
|
+
// @ts-expect-error
|
|
353
|
+
stringify({ a: [], b: 'zz' }, { allowEmptyArrays: 'foobar' });
|
|
354
|
+
}).toThrow(TypeError);
|
|
355
|
+
|
|
356
|
+
// st['throws'](function () {
|
|
357
|
+
// stringify({ a: [], b: 'zz' }, { allowEmptyArrays: 0 });
|
|
358
|
+
// }, TypeError);
|
|
359
|
+
expect(() => {
|
|
360
|
+
// @ts-expect-error
|
|
361
|
+
stringify({ a: [], b: 'zz' }, { allowEmptyArrays: 0 });
|
|
362
|
+
}).toThrow(TypeError);
|
|
363
|
+
|
|
364
|
+
// st['throws'](function () {
|
|
365
|
+
// stringify({ a: [], b: 'zz' }, { allowEmptyArrays: NaN });
|
|
366
|
+
// }, TypeError);
|
|
367
|
+
expect(() => {
|
|
368
|
+
// @ts-expect-error
|
|
369
|
+
stringify({ a: [], b: 'zz' }, { allowEmptyArrays: NaN });
|
|
370
|
+
}).toThrow(TypeError);
|
|
371
|
+
|
|
372
|
+
// st['throws'](function () {
|
|
373
|
+
// stringify({ a: [], b: 'zz' }, { allowEmptyArrays: null });
|
|
374
|
+
// }, TypeError);
|
|
375
|
+
expect(() => {
|
|
376
|
+
// @ts-expect-error
|
|
377
|
+
stringify({ a: [], b: 'zz' }, { allowEmptyArrays: null });
|
|
378
|
+
}).toThrow(TypeError);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
test('allowEmptyArrays + strictNullHandling', function () {
|
|
382
|
+
// st.equal(
|
|
383
|
+
// stringify({ testEmptyArray: [] }, { strictNullHandling: true, allowEmptyArrays: true }),
|
|
384
|
+
// 'testEmptyArray[]',
|
|
385
|
+
// );
|
|
386
|
+
expect(stringify({ testEmptyArray: [] }, { strictNullHandling: true, allowEmptyArrays: true })).toBe(
|
|
387
|
+
'testEmptyArray[]',
|
|
388
|
+
);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
describe('stringifies an array value with one item vs multiple items', function () {
|
|
392
|
+
test('non-array item', function () {
|
|
393
|
+
// s2t.equal(
|
|
394
|
+
// stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
|
|
395
|
+
// 'a=c',
|
|
396
|
+
// );
|
|
397
|
+
// s2t.equal(
|
|
398
|
+
// stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
399
|
+
// 'a=c',
|
|
400
|
+
// );
|
|
401
|
+
// s2t.equal(stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c');
|
|
402
|
+
// s2t.equal(stringify({ a: 'c' }, { encodeValuesOnly: true }), 'a=c');
|
|
403
|
+
expect(stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe('a=c');
|
|
404
|
+
expect(stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe('a=c');
|
|
405
|
+
expect(stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'comma' })).toBe('a=c');
|
|
406
|
+
expect(stringify({ a: 'c' }, { encodeValuesOnly: true })).toBe('a=c');
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test('array with a single item', function () {
|
|
410
|
+
// s2t.equal(
|
|
411
|
+
// stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
|
|
412
|
+
// 'a[0]=c',
|
|
413
|
+
// );
|
|
414
|
+
// s2t.equal(
|
|
415
|
+
// stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
416
|
+
// 'a[]=c',
|
|
417
|
+
// );
|
|
418
|
+
// s2t.equal(
|
|
419
|
+
// stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),
|
|
420
|
+
// 'a=c',
|
|
421
|
+
// );
|
|
422
|
+
// s2t.equal(
|
|
423
|
+
// stringify(
|
|
424
|
+
// { a: ['c'] },
|
|
425
|
+
// { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true },
|
|
426
|
+
// ),
|
|
427
|
+
// 'a[]=c',
|
|
428
|
+
// ); // so it parses back as an array
|
|
429
|
+
// s2t.equal(stringify({ a: ['c'] }, { encodeValuesOnly: true }), 'a[0]=c');
|
|
430
|
+
expect(stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe('a[0]=c');
|
|
431
|
+
expect(stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe('a[]=c');
|
|
432
|
+
expect(stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma' })).toBe('a=c');
|
|
433
|
+
expect(
|
|
434
|
+
stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true }),
|
|
435
|
+
).toBe('a[]=c');
|
|
436
|
+
expect(stringify({ a: ['c'] }, { encodeValuesOnly: true })).toBe('a[0]=c');
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
test('array with multiple items', function () {
|
|
440
|
+
// s2t.equal(
|
|
441
|
+
// stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
|
|
442
|
+
// 'a[0]=c&a[1]=d',
|
|
443
|
+
// );
|
|
444
|
+
// s2t.equal(
|
|
445
|
+
// stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
446
|
+
// 'a[]=c&a[]=d',
|
|
447
|
+
// );
|
|
448
|
+
// s2t.equal(
|
|
449
|
+
// stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),
|
|
450
|
+
// 'a=c,d',
|
|
451
|
+
// );
|
|
452
|
+
// s2t.equal(
|
|
453
|
+
// stringify(
|
|
454
|
+
// { a: ['c', 'd'] },
|
|
455
|
+
// { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true },
|
|
456
|
+
// ),
|
|
457
|
+
// 'a=c,d',
|
|
458
|
+
// );
|
|
459
|
+
// s2t.equal(stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true }), 'a[0]=c&a[1]=d');
|
|
460
|
+
expect(stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe(
|
|
461
|
+
'a[0]=c&a[1]=d',
|
|
462
|
+
);
|
|
463
|
+
expect(stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe(
|
|
464
|
+
'a[]=c&a[]=d',
|
|
465
|
+
);
|
|
466
|
+
expect(stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma' })).toBe('a=c,d');
|
|
467
|
+
expect(
|
|
468
|
+
stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true }),
|
|
469
|
+
).toBe('a=c,d');
|
|
470
|
+
expect(stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true })).toBe('a[0]=c&a[1]=d');
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
test('array with multiple items with a comma inside', function () {
|
|
474
|
+
// s2t.equal(
|
|
475
|
+
// stringify({ a: ['c,d', 'e'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),
|
|
476
|
+
// 'a=c%2Cd,e',
|
|
477
|
+
// );
|
|
478
|
+
// s2t.equal(stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma' }), 'a=c%2Cd%2Ce');
|
|
479
|
+
expect(stringify({ a: ['c,d', 'e'] }, { encodeValuesOnly: true, arrayFormat: 'comma' })).toBe(
|
|
480
|
+
'a=c%2Cd,e',
|
|
481
|
+
);
|
|
482
|
+
expect(stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma' })).toBe('a=c%2Cd%2Ce');
|
|
483
|
+
|
|
484
|
+
// s2t.equal(
|
|
485
|
+
// stringify(
|
|
486
|
+
// { a: ['c,d', 'e'] },
|
|
487
|
+
// { encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true },
|
|
488
|
+
// ),
|
|
489
|
+
// 'a=c%2Cd,e',
|
|
490
|
+
// );
|
|
491
|
+
// s2t.equal(
|
|
492
|
+
// stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma', commaRoundTrip: true }),
|
|
493
|
+
// 'a=c%2Cd%2Ce',
|
|
494
|
+
// );
|
|
495
|
+
expect(
|
|
496
|
+
stringify(
|
|
497
|
+
{ a: ['c,d', 'e'] },
|
|
498
|
+
{ encodeValuesOnly: true, arrayFormat: 'comma', commaRoundTrip: true },
|
|
499
|
+
),
|
|
500
|
+
).toBe('a=c%2Cd,e');
|
|
501
|
+
expect(stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma', commaRoundTrip: true })).toBe(
|
|
502
|
+
'a=c%2Cd%2Ce',
|
|
503
|
+
);
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
test('stringifies a nested array value', function () {
|
|
508
|
+
expect(stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe(
|
|
509
|
+
'a[b][0]=c&a[b][1]=d',
|
|
510
|
+
);
|
|
511
|
+
expect(stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe(
|
|
512
|
+
'a[b][]=c&a[b][]=d',
|
|
513
|
+
);
|
|
514
|
+
expect(stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'comma' })).toBe(
|
|
515
|
+
'a[b]=c,d',
|
|
516
|
+
);
|
|
517
|
+
expect(stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true })).toBe('a[b][0]=c&a[b][1]=d');
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
test('stringifies comma and empty array values', function () {
|
|
521
|
+
// st.equal(
|
|
522
|
+
// stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'indices' }),
|
|
523
|
+
// 'a[0]=,&a[1]=&a[2]=c,d%',
|
|
524
|
+
// );
|
|
525
|
+
// st.equal(
|
|
526
|
+
// stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'brackets' }),
|
|
527
|
+
// 'a[]=,&a[]=&a[]=c,d%',
|
|
528
|
+
// );
|
|
529
|
+
// st.equal(
|
|
530
|
+
// stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'comma' }),
|
|
531
|
+
// 'a=,,,c,d%',
|
|
532
|
+
// );
|
|
533
|
+
// st.equal(
|
|
534
|
+
// stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'repeat' }),
|
|
535
|
+
// 'a=,&a=&a=c,d%',
|
|
536
|
+
// );
|
|
537
|
+
expect(stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'indices' })).toBe(
|
|
538
|
+
'a[0]=,&a[1]=&a[2]=c,d%',
|
|
539
|
+
);
|
|
540
|
+
expect(stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'brackets' })).toBe(
|
|
541
|
+
'a[]=,&a[]=&a[]=c,d%',
|
|
542
|
+
);
|
|
543
|
+
expect(stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'comma' })).toBe('a=,,,c,d%');
|
|
544
|
+
expect(stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'repeat' })).toBe(
|
|
545
|
+
'a=,&a=&a=c,d%',
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
// st.equal(
|
|
549
|
+
// stringify(
|
|
550
|
+
// { a: [',', '', 'c,d%'] },
|
|
551
|
+
// { encode: true, encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
552
|
+
// ),
|
|
553
|
+
// 'a[0]=%2C&a[1]=&a[2]=c%2Cd%25',
|
|
554
|
+
// );
|
|
555
|
+
// st.equal(
|
|
556
|
+
// stringify(
|
|
557
|
+
// { a: [',', '', 'c,d%'] },
|
|
558
|
+
// { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
559
|
+
// ),
|
|
560
|
+
// 'a[]=%2C&a[]=&a[]=c%2Cd%25',
|
|
561
|
+
// );
|
|
562
|
+
// st.equal(
|
|
563
|
+
// stringify(
|
|
564
|
+
// { a: [',', '', 'c,d%'] },
|
|
565
|
+
// { encode: true, encodeValuesOnly: true, arrayFormat: 'comma' },
|
|
566
|
+
// ),
|
|
567
|
+
// 'a=%2C,,c%2Cd%25',
|
|
568
|
+
// );
|
|
569
|
+
// st.equal(
|
|
570
|
+
// stringify(
|
|
571
|
+
// { a: [',', '', 'c,d%'] },
|
|
572
|
+
// { encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' },
|
|
573
|
+
// ),
|
|
574
|
+
// 'a=%2C&a=&a=c%2Cd%25',
|
|
575
|
+
// );
|
|
576
|
+
expect(
|
|
577
|
+
stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' }),
|
|
578
|
+
).toBe('a%5B0%5D=%2C&a%5B1%5D=&a%5B2%5D=c%2Cd%25');
|
|
579
|
+
expect(
|
|
580
|
+
stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
581
|
+
).toBe('a[]=%2C&a[]=&a[]=c%2Cd%25');
|
|
582
|
+
expect(
|
|
583
|
+
stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' }),
|
|
584
|
+
).toBe('a=%2C%2C%2Cc%2Cd%25');
|
|
585
|
+
expect(
|
|
586
|
+
stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }),
|
|
587
|
+
).toBe('a=%2C&a=&a=c%2Cd%25');
|
|
588
|
+
|
|
589
|
+
// st.equal(
|
|
590
|
+
// stringify(
|
|
591
|
+
// { a: [',', '', 'c,d%'] },
|
|
592
|
+
// { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' },
|
|
593
|
+
// ),
|
|
594
|
+
// 'a%5B0%5D=%2C&a%5B1%5D=&a%5B2%5D=c%2Cd%25',
|
|
595
|
+
// );
|
|
596
|
+
// st.equal(
|
|
597
|
+
// stringify(
|
|
598
|
+
// { a: [',', '', 'c,d%'] },
|
|
599
|
+
// { encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' },
|
|
600
|
+
// ),
|
|
601
|
+
// 'a%5B%5D=%2C&a%5B%5D=&a%5B%5D=c%2Cd%25',
|
|
602
|
+
// );
|
|
603
|
+
// st.equal(
|
|
604
|
+
// stringify(
|
|
605
|
+
// { a: [',', '', 'c,d%'] },
|
|
606
|
+
// { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' },
|
|
607
|
+
// ),
|
|
608
|
+
// 'a=%2C%2C%2Cc%2Cd%25',
|
|
609
|
+
// );
|
|
610
|
+
// st.equal(
|
|
611
|
+
// stringify(
|
|
612
|
+
// { a: [',', '', 'c,d%'] },
|
|
613
|
+
// { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' },
|
|
614
|
+
// ),
|
|
615
|
+
// 'a=%2C&a=&a=c%2Cd%25',
|
|
616
|
+
// );
|
|
617
|
+
expect(
|
|
618
|
+
stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }),
|
|
619
|
+
).toBe('a=%2C&a=&a=c%2Cd%25');
|
|
620
|
+
expect(
|
|
621
|
+
stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' }),
|
|
622
|
+
).toBe('a%5B0%5D=%2C&a%5B1%5D=&a%5B2%5D=c%2Cd%25');
|
|
623
|
+
expect(
|
|
624
|
+
stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
625
|
+
).toBe('a[]=%2C&a[]=&a[]=c%2Cd%25');
|
|
626
|
+
expect(
|
|
627
|
+
stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' }),
|
|
628
|
+
).toBe('a=%2C%2C%2Cc%2Cd%25');
|
|
629
|
+
expect(
|
|
630
|
+
stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }),
|
|
631
|
+
).toBe('a=%2C&a=&a=c%2Cd%25');
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
test('stringifies comma and empty non-array values', function () {
|
|
635
|
+
// st.equal(
|
|
636
|
+
// stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'indices' }),
|
|
637
|
+
// 'a=,&b=&c=c,d%',
|
|
638
|
+
// );
|
|
639
|
+
// st.equal(
|
|
640
|
+
// stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'brackets' }),
|
|
641
|
+
// 'a=,&b=&c=c,d%',
|
|
642
|
+
// );
|
|
643
|
+
// st.equal(
|
|
644
|
+
// stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'comma' }),
|
|
645
|
+
// 'a=,&b=&c=c,d%',
|
|
646
|
+
// );
|
|
647
|
+
// st.equal(
|
|
648
|
+
// stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'repeat' }),
|
|
649
|
+
// 'a=,&b=&c=c,d%',
|
|
650
|
+
// );
|
|
651
|
+
expect(stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'indices' })).toBe(
|
|
652
|
+
'a=,&b=&c=c,d%',
|
|
653
|
+
);
|
|
654
|
+
expect(stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'brackets' })).toBe(
|
|
655
|
+
'a=,&b=&c=c,d%',
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
// st.equal(
|
|
659
|
+
// stringify(
|
|
660
|
+
// { a: ',', b: '', c: 'c,d%' },
|
|
661
|
+
// { encode: true, encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
662
|
+
// ),
|
|
663
|
+
// 'a=%2C&b=&c=c%2Cd%25',
|
|
664
|
+
// );
|
|
665
|
+
// st.equal(
|
|
666
|
+
// stringify(
|
|
667
|
+
// { a: ',', b: '', c: 'c,d%' },
|
|
668
|
+
// { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
669
|
+
// ),
|
|
670
|
+
// 'a=%2C&b=&c=c%2Cd%25',
|
|
671
|
+
// );
|
|
672
|
+
// st.equal(
|
|
673
|
+
// stringify(
|
|
674
|
+
// { a: ',', b: '', c: 'c,d%' },
|
|
675
|
+
// { encode: true, encodeValuesOnly: true, arrayFormat: 'comma' },
|
|
676
|
+
// ),
|
|
677
|
+
// 'a=%2C&b=&c=c%2Cd%25',
|
|
678
|
+
// );
|
|
679
|
+
// st.equal(
|
|
680
|
+
// stringify(
|
|
681
|
+
// { a: ',', b: '', c: 'c,d%' },
|
|
682
|
+
// { encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' },
|
|
683
|
+
// ),
|
|
684
|
+
// 'a=%2C&b=&c=c%2Cd%25',
|
|
685
|
+
// );
|
|
686
|
+
expect(
|
|
687
|
+
stringify(
|
|
688
|
+
{ a: ',', b: '', c: 'c,d%' },
|
|
689
|
+
{ encode: true, encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
690
|
+
),
|
|
691
|
+
).toBe('a=%2C&b=&c=c%2Cd%25');
|
|
692
|
+
expect(
|
|
693
|
+
stringify(
|
|
694
|
+
{ a: ',', b: '', c: 'c,d%' },
|
|
695
|
+
{ encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
696
|
+
),
|
|
697
|
+
).toBe('a=%2C&b=&c=c%2Cd%25');
|
|
698
|
+
expect(
|
|
699
|
+
stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'comma' }),
|
|
700
|
+
).toBe('a=%2C&b=&c=c%2Cd%25');
|
|
701
|
+
expect(
|
|
702
|
+
stringify(
|
|
703
|
+
{ a: ',', b: '', c: 'c,d%' },
|
|
704
|
+
{ encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' },
|
|
705
|
+
),
|
|
706
|
+
).toBe('a=%2C&b=&c=c%2Cd%25');
|
|
707
|
+
|
|
708
|
+
// st.equal(
|
|
709
|
+
// stringify(
|
|
710
|
+
// { a: ',', b: '', c: 'c,d%' },
|
|
711
|
+
// { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' },
|
|
712
|
+
// ),
|
|
713
|
+
// 'a=%2C&b=&c=c%2Cd%25',
|
|
714
|
+
// );
|
|
715
|
+
// st.equal(
|
|
716
|
+
// stringify(
|
|
717
|
+
// { a: ',', b: '', c: 'c,d%' },
|
|
718
|
+
// { encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' },
|
|
719
|
+
// ),
|
|
720
|
+
// 'a=%2C&b=&c=c%2Cd%25',
|
|
721
|
+
// );
|
|
722
|
+
// st.equal(
|
|
723
|
+
// stringify(
|
|
724
|
+
// { a: ',', b: '', c: 'c,d%' },
|
|
725
|
+
// { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' },
|
|
726
|
+
// ),
|
|
727
|
+
// 'a=%2C&b=&c=c%2Cd%25',
|
|
728
|
+
// );
|
|
729
|
+
// st.equal(
|
|
730
|
+
// stringify(
|
|
731
|
+
// { a: ',', b: '', c: 'c,d%' },
|
|
732
|
+
// { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' },
|
|
733
|
+
// ),
|
|
734
|
+
// 'a=%2C&b=&c=c%2Cd%25',
|
|
735
|
+
// );
|
|
736
|
+
expect(
|
|
737
|
+
stringify(
|
|
738
|
+
{ a: ',', b: '', c: 'c,d%' },
|
|
739
|
+
{ encode: true, encodeValuesOnly: false, arrayFormat: 'indices' },
|
|
740
|
+
),
|
|
741
|
+
).toBe('a=%2C&b=&c=c%2Cd%25');
|
|
742
|
+
expect(
|
|
743
|
+
stringify(
|
|
744
|
+
{ a: ',', b: '', c: 'c,d%' },
|
|
745
|
+
{ encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' },
|
|
746
|
+
),
|
|
747
|
+
).toBe('a=%2C&b=&c=c%2Cd%25');
|
|
748
|
+
expect(
|
|
749
|
+
stringify(
|
|
750
|
+
{ a: ',', b: '', c: 'c,d%' },
|
|
751
|
+
{ encode: true, encodeValuesOnly: false, arrayFormat: 'comma' },
|
|
752
|
+
),
|
|
753
|
+
).toBe('a=%2C&b=&c=c%2Cd%25');
|
|
754
|
+
expect(
|
|
755
|
+
stringify(
|
|
756
|
+
{ a: ',', b: '', c: 'c,d%' },
|
|
757
|
+
{ encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' },
|
|
758
|
+
),
|
|
759
|
+
).toBe('a=%2C&b=&c=c%2Cd%25');
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
test('stringifies a nested array value with dots notation', function () {
|
|
763
|
+
// st.equal(
|
|
764
|
+
// stringify(
|
|
765
|
+
// { a: { b: ['c', 'd'] } },
|
|
766
|
+
// { allowDots: true, encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
767
|
+
// ),
|
|
768
|
+
// 'a.b[0]=c&a.b[1]=d',
|
|
769
|
+
// 'indices: stringifies with dots + indices',
|
|
770
|
+
// );
|
|
771
|
+
// st.equal(
|
|
772
|
+
// stringify(
|
|
773
|
+
// { a: { b: ['c', 'd'] } },
|
|
774
|
+
// { allowDots: true, encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
775
|
+
// ),
|
|
776
|
+
// 'a.b[]=c&a.b[]=d',
|
|
777
|
+
// 'brackets: stringifies with dots + brackets',
|
|
778
|
+
// );
|
|
779
|
+
// st.equal(
|
|
780
|
+
// stringify(
|
|
781
|
+
// { a: { b: ['c', 'd'] } },
|
|
782
|
+
// { allowDots: true, encodeValuesOnly: true, arrayFormat: 'comma' },
|
|
783
|
+
// ),
|
|
784
|
+
// 'a.b=c,d',
|
|
785
|
+
// 'comma: stringifies with dots + comma',
|
|
786
|
+
// );
|
|
787
|
+
// st.equal(
|
|
788
|
+
// stringify({ a: { b: ['c', 'd'] } }, { allowDots: true, encodeValuesOnly: true }),
|
|
789
|
+
// 'a.b[0]=c&a.b[1]=d',
|
|
790
|
+
// 'default: stringifies with dots + indices',
|
|
791
|
+
// );
|
|
792
|
+
expect(
|
|
793
|
+
stringify(
|
|
794
|
+
{ a: { b: ['c', 'd'] } },
|
|
795
|
+
{ allowDots: true, encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
796
|
+
),
|
|
797
|
+
).toBe('a.b[0]=c&a.b[1]=d');
|
|
798
|
+
expect(
|
|
799
|
+
stringify(
|
|
800
|
+
{ a: { b: ['c', 'd'] } },
|
|
801
|
+
{ allowDots: true, encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
802
|
+
),
|
|
803
|
+
).toBe('a.b[]=c&a.b[]=d');
|
|
804
|
+
expect(
|
|
805
|
+
stringify({ a: { b: ['c', 'd'] } }, { allowDots: true, encodeValuesOnly: true, arrayFormat: 'comma' }),
|
|
806
|
+
).toBe('a.b=c,d');
|
|
807
|
+
expect(stringify({ a: { b: ['c', 'd'] } }, { allowDots: true, encodeValuesOnly: true })).toBe(
|
|
808
|
+
'a.b[0]=c&a.b[1]=d',
|
|
809
|
+
);
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
test('stringifies an object inside an array', function () {
|
|
813
|
+
// st.equal(
|
|
814
|
+
// stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'indices', encodeValuesOnly: true }),
|
|
815
|
+
// 'a[0][b]=c',
|
|
816
|
+
// 'indices => indices',
|
|
817
|
+
// );
|
|
818
|
+
// st.equal(
|
|
819
|
+
// stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'repeat', encodeValuesOnly: true }),
|
|
820
|
+
// 'a[b]=c',
|
|
821
|
+
// 'repeat => repeat',
|
|
822
|
+
// );
|
|
823
|
+
// st.equal(
|
|
824
|
+
// stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'brackets', encodeValuesOnly: true }),
|
|
825
|
+
// 'a[][b]=c',
|
|
826
|
+
// 'brackets => brackets',
|
|
827
|
+
// );
|
|
828
|
+
// st.equal(
|
|
829
|
+
// stringify({ a: [{ b: 'c' }] }, { encodeValuesOnly: true }),
|
|
830
|
+
// 'a[0][b]=c',
|
|
831
|
+
// 'default => indices',
|
|
832
|
+
// );
|
|
833
|
+
expect(stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'indices', encodeValuesOnly: true })).toBe(
|
|
834
|
+
'a[0][b]=c',
|
|
835
|
+
);
|
|
836
|
+
expect(stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'repeat', encodeValuesOnly: true })).toBe('a[b]=c');
|
|
837
|
+
expect(stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'brackets', encodeValuesOnly: true })).toBe(
|
|
838
|
+
'a[][b]=c',
|
|
839
|
+
);
|
|
840
|
+
expect(stringify({ a: [{ b: 'c' }] }, { encodeValuesOnly: true })).toBe('a[0][b]=c');
|
|
841
|
+
|
|
842
|
+
// st.equal(
|
|
843
|
+
// stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'indices', encodeValuesOnly: true }),
|
|
844
|
+
// 'a[0][b][c][0]=1',
|
|
845
|
+
// 'indices => indices',
|
|
846
|
+
// );
|
|
847
|
+
// st.equal(
|
|
848
|
+
// stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'repeat', encodeValuesOnly: true }),
|
|
849
|
+
// 'a[b][c]=1',
|
|
850
|
+
// 'repeat => repeat',
|
|
851
|
+
// );
|
|
852
|
+
// st.equal(
|
|
853
|
+
// stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'brackets', encodeValuesOnly: true }),
|
|
854
|
+
// 'a[][b][c][]=1',
|
|
855
|
+
// 'brackets => brackets',
|
|
856
|
+
// );
|
|
857
|
+
// st.equal(
|
|
858
|
+
// stringify({ a: [{ b: { c: [1] } }] }, { encodeValuesOnly: true }),
|
|
859
|
+
// 'a[0][b][c][0]=1',
|
|
860
|
+
// 'default => indices',
|
|
861
|
+
// );
|
|
862
|
+
expect(stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'indices', encodeValuesOnly: true })).toBe(
|
|
863
|
+
'a[0][b][c][0]=1',
|
|
864
|
+
);
|
|
865
|
+
expect(stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'repeat', encodeValuesOnly: true })).toBe(
|
|
866
|
+
'a[b][c]=1',
|
|
867
|
+
);
|
|
868
|
+
expect(stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'brackets', encodeValuesOnly: true })).toBe(
|
|
869
|
+
'a[][b][c][]=1',
|
|
870
|
+
);
|
|
871
|
+
expect(stringify({ a: [{ b: { c: [1] } }] }, { encodeValuesOnly: true })).toBe('a[0][b][c][0]=1');
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
test('stringifies an array with mixed objects and primitives', function () {
|
|
875
|
+
// st.equal(
|
|
876
|
+
// stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
|
|
877
|
+
// 'a[0][b]=1&a[1]=2&a[2]=3',
|
|
878
|
+
// 'indices => indices',
|
|
879
|
+
// );
|
|
880
|
+
// st.equal(
|
|
881
|
+
// stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
882
|
+
// 'a[][b]=1&a[]=2&a[]=3',
|
|
883
|
+
// 'brackets => brackets',
|
|
884
|
+
// );
|
|
885
|
+
// st.equal(
|
|
886
|
+
// stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),
|
|
887
|
+
// '???',
|
|
888
|
+
// 'brackets => brackets',
|
|
889
|
+
// { skip: 'TODO: figure out what this should do' },
|
|
890
|
+
// );
|
|
891
|
+
// st.equal(
|
|
892
|
+
// stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true }),
|
|
893
|
+
// 'a[0][b]=1&a[1]=2&a[2]=3',
|
|
894
|
+
// 'default => indices',
|
|
895
|
+
// );
|
|
896
|
+
expect(stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe(
|
|
897
|
+
'a[0][b]=1&a[1]=2&a[2]=3',
|
|
898
|
+
);
|
|
899
|
+
expect(stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe(
|
|
900
|
+
'a[][b]=1&a[]=2&a[]=3',
|
|
901
|
+
);
|
|
902
|
+
// !Skipped: Figure out what this should do
|
|
903
|
+
// expect(
|
|
904
|
+
// stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),
|
|
905
|
+
// ).toBe('???');
|
|
906
|
+
expect(stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true })).toBe('a[0][b]=1&a[1]=2&a[2]=3');
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
test('stringifies an object inside an array with dots notation', function () {
|
|
910
|
+
// st.equal(
|
|
911
|
+
// stringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false, arrayFormat: 'indices' }),
|
|
912
|
+
// 'a[0].b=c',
|
|
913
|
+
// 'indices => indices',
|
|
914
|
+
// );
|
|
915
|
+
// st.equal(
|
|
916
|
+
// stringify(
|
|
917
|
+
// { a: [{ b: 'c' }] },
|
|
918
|
+
// { allowDots: true, encode: false, arrayFormat: 'brackets' },
|
|
919
|
+
// ),
|
|
920
|
+
// 'a[].b=c',
|
|
921
|
+
// 'brackets => brackets',
|
|
922
|
+
// );
|
|
923
|
+
// st.equal(
|
|
924
|
+
// stringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false }),
|
|
925
|
+
// 'a[0].b=c',
|
|
926
|
+
// 'default => indices',
|
|
927
|
+
// );
|
|
928
|
+
expect(stringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false, arrayFormat: 'indices' })).toBe(
|
|
929
|
+
'a[0].b=c',
|
|
930
|
+
);
|
|
931
|
+
expect(stringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false, arrayFormat: 'brackets' })).toBe(
|
|
932
|
+
'a[].b=c',
|
|
933
|
+
);
|
|
934
|
+
expect(stringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false })).toBe('a[0].b=c');
|
|
935
|
+
|
|
936
|
+
// st.equal(
|
|
937
|
+
// stringify(
|
|
938
|
+
// { a: [{ b: { c: [1] } }] },
|
|
939
|
+
// { allowDots: true, encode: false, arrayFormat: 'indices' },
|
|
940
|
+
// ),
|
|
941
|
+
// 'a[0].b.c[0]=1',
|
|
942
|
+
// 'indices => indices',
|
|
943
|
+
// );
|
|
944
|
+
// st.equal(
|
|
945
|
+
// stringify(
|
|
946
|
+
// { a: [{ b: { c: [1] } }] },
|
|
947
|
+
// { allowDots: true, encode: false, arrayFormat: 'brackets' },
|
|
948
|
+
// ),
|
|
949
|
+
// 'a[].b.c[]=1',
|
|
950
|
+
// 'brackets => brackets',
|
|
951
|
+
// );
|
|
952
|
+
// st.equal(
|
|
953
|
+
// stringify({ a: [{ b: { c: [1] } }] }, { allowDots: true, encode: false }),
|
|
954
|
+
// 'a[0].b.c[0]=1',
|
|
955
|
+
// 'default => indices',
|
|
956
|
+
// );
|
|
957
|
+
expect(
|
|
958
|
+
stringify({ a: [{ b: { c: [1] } }] }, { allowDots: true, encode: false, arrayFormat: 'indices' }),
|
|
959
|
+
).toBe('a[0].b.c[0]=1');
|
|
960
|
+
expect(
|
|
961
|
+
stringify({ a: [{ b: { c: [1] } }] }, { allowDots: true, encode: false, arrayFormat: 'brackets' }),
|
|
962
|
+
).toBe('a[].b.c[]=1');
|
|
963
|
+
expect(stringify({ a: [{ b: { c: [1] } }] }, { allowDots: true, encode: false })).toBe('a[0].b.c[0]=1');
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
test('does not omit object keys when indices = false', function () {
|
|
967
|
+
// st.equal(stringify({ a: [{ b: 'c' }] }, { indices: false }), 'a%5Bb%5D=c');
|
|
968
|
+
expect(stringify({ a: [{ b: 'c' }] }, { indices: false })).toBe('a%5Bb%5D=c');
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
test('uses indices notation for arrays when indices=true', function () {
|
|
972
|
+
// st.equal(stringify({ a: ['b', 'c'] }, { indices: true }), 'a%5B0%5D=b&a%5B1%5D=c');
|
|
973
|
+
expect(stringify({ a: ['b', 'c'] }, { indices: true })).toBe('a%5B0%5D=b&a%5B1%5D=c');
|
|
974
|
+
});
|
|
975
|
+
|
|
976
|
+
test('uses indices notation for arrays when no arrayFormat is specified', function () {
|
|
977
|
+
// st.equal(stringify({ a: ['b', 'c'] }), 'a%5B0%5D=b&a%5B1%5D=c');
|
|
978
|
+
expect(stringify({ a: ['b', 'c'] })).toBe('a%5B0%5D=b&a%5B1%5D=c');
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
test('uses indices notation for arrays when arrayFormat=indices', function () {
|
|
982
|
+
// st.equal(stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' }), 'a%5B0%5D=b&a%5B1%5D=c');
|
|
983
|
+
expect(stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })).toBe('a%5B0%5D=b&a%5B1%5D=c');
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
test('uses repeat notation for arrays when arrayFormat=repeat', function () {
|
|
987
|
+
// st.equal(stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' }), 'a=b&a=c');
|
|
988
|
+
expect(stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })).toBe('a=b&a=c');
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
test('uses brackets notation for arrays when arrayFormat=brackets', function () {
|
|
992
|
+
// st.equal(stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' }), 'a%5B%5D=b&a%5B%5D=c');
|
|
993
|
+
expect(stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })).toBe('a%5B%5D=b&a%5B%5D=c');
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
test('stringifies a complicated object', function () {
|
|
997
|
+
// st.equal(stringify({ a: { b: 'c', d: 'e' } }), 'a%5Bb%5D=c&a%5Bd%5D=e');
|
|
998
|
+
expect(stringify({ a: { b: 'c', d: 'e' } })).toBe('a%5Bb%5D=c&a%5Bd%5D=e');
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
test('stringifies an empty value', function () {
|
|
1002
|
+
// st.equal(stringify({ a: '' }), 'a=');
|
|
1003
|
+
// st.equal(stringify({ a: null }, { strictNullHandling: true }), 'a');
|
|
1004
|
+
expect(stringify({ a: '' })).toBe('a=');
|
|
1005
|
+
expect(stringify({ a: null }, { strictNullHandling: true })).toBe('a');
|
|
1006
|
+
|
|
1007
|
+
// st.equal(stringify({ a: '', b: '' }), 'a=&b=');
|
|
1008
|
+
// st.equal(stringify({ a: null, b: '' }, { strictNullHandling: true }), 'a&b=');
|
|
1009
|
+
expect(stringify({ a: '', b: '' })).toBe('a=&b=');
|
|
1010
|
+
expect(stringify({ a: null, b: '' }, { strictNullHandling: true })).toBe('a&b=');
|
|
1011
|
+
|
|
1012
|
+
// st.equal(stringify({ a: { b: '' } }), 'a%5Bb%5D=');
|
|
1013
|
+
// st.equal(stringify({ a: { b: null } }, { strictNullHandling: true }), 'a%5Bb%5D');
|
|
1014
|
+
// st.equal(stringify({ a: { b: null } }, { strictNullHandling: false }), 'a%5Bb%5D=');
|
|
1015
|
+
expect(stringify({ a: { b: '' } })).toBe('a%5Bb%5D=');
|
|
1016
|
+
expect(stringify({ a: { b: null } }, { strictNullHandling: true })).toBe('a%5Bb%5D');
|
|
1017
|
+
expect(stringify({ a: { b: null } }, { strictNullHandling: false })).toBe('a%5Bb%5D=');
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
test('stringifies an empty array in different arrayFormat', function () {
|
|
1021
|
+
// st.equal(stringify({ a: [], b: [null], c: 'c' }, { encode: false }), 'b[0]=&c=c');
|
|
1022
|
+
expect(stringify({ a: [], b: [null], c: 'c' }, { encode: false })).toBe('b[0]=&c=c');
|
|
1023
|
+
// arrayFormat default
|
|
1024
|
+
// st.equal(
|
|
1025
|
+
// stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices' }),
|
|
1026
|
+
// 'b[0]=&c=c',
|
|
1027
|
+
// );
|
|
1028
|
+
// st.equal(
|
|
1029
|
+
// stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets' }),
|
|
1030
|
+
// 'b[]=&c=c',
|
|
1031
|
+
// );
|
|
1032
|
+
// st.equal(
|
|
1033
|
+
// stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat' }),
|
|
1034
|
+
// 'b=&c=c',
|
|
1035
|
+
// );
|
|
1036
|
+
// st.equal(
|
|
1037
|
+
// stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma' }),
|
|
1038
|
+
// 'b=&c=c',
|
|
1039
|
+
// );
|
|
1040
|
+
// st.equal(
|
|
1041
|
+
// stringify(
|
|
1042
|
+
// { a: [], b: [null], c: 'c' },
|
|
1043
|
+
// { encode: false, arrayFormat: 'comma', commaRoundTrip: true },
|
|
1044
|
+
// ),
|
|
1045
|
+
// 'b[]=&c=c',
|
|
1046
|
+
// );
|
|
1047
|
+
expect(stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices' })).toBe(
|
|
1048
|
+
'b[0]=&c=c',
|
|
1049
|
+
);
|
|
1050
|
+
expect(stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets' })).toBe(
|
|
1051
|
+
'b[]=&c=c',
|
|
1052
|
+
);
|
|
1053
|
+
expect(stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat' })).toBe('b=&c=c');
|
|
1054
|
+
expect(stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma' })).toBe('b=&c=c');
|
|
1055
|
+
expect(
|
|
1056
|
+
stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', commaRoundTrip: true }),
|
|
1057
|
+
).toBe('b[]=&c=c');
|
|
1058
|
+
|
|
1059
|
+
// with strictNullHandling
|
|
1060
|
+
// st.equal(
|
|
1061
|
+
// stringify(
|
|
1062
|
+
// { a: [], b: [null], c: 'c' },
|
|
1063
|
+
// { encode: false, arrayFormat: 'indices', strictNullHandling: true },
|
|
1064
|
+
// ),
|
|
1065
|
+
// 'b[0]&c=c',
|
|
1066
|
+
// );
|
|
1067
|
+
// st.equal(
|
|
1068
|
+
// stringify(
|
|
1069
|
+
// { a: [], b: [null], c: 'c' },
|
|
1070
|
+
// { encode: false, arrayFormat: 'brackets', strictNullHandling: true },
|
|
1071
|
+
// ),
|
|
1072
|
+
// 'b[]&c=c',
|
|
1073
|
+
// );
|
|
1074
|
+
// st.equal(
|
|
1075
|
+
// stringify(
|
|
1076
|
+
// { a: [], b: [null], c: 'c' },
|
|
1077
|
+
// { encode: false, arrayFormat: 'repeat', strictNullHandling: true },
|
|
1078
|
+
// ),
|
|
1079
|
+
// 'b&c=c',
|
|
1080
|
+
// );
|
|
1081
|
+
// st.equal(
|
|
1082
|
+
// stringify(
|
|
1083
|
+
// { a: [], b: [null], c: 'c' },
|
|
1084
|
+
// { encode: false, arrayFormat: 'comma', strictNullHandling: true },
|
|
1085
|
+
// ),
|
|
1086
|
+
// 'b&c=c',
|
|
1087
|
+
// );
|
|
1088
|
+
// st.equal(
|
|
1089
|
+
// stringify(
|
|
1090
|
+
// { a: [], b: [null], c: 'c' },
|
|
1091
|
+
// { encode: false, arrayFormat: 'comma', strictNullHandling: true, commaRoundTrip: true },
|
|
1092
|
+
// ),
|
|
1093
|
+
// 'b[]&c=c',
|
|
1094
|
+
// );
|
|
1095
|
+
|
|
1096
|
+
expect(
|
|
1097
|
+
stringify(
|
|
1098
|
+
{ a: [], b: [null], c: 'c' },
|
|
1099
|
+
{ encode: false, arrayFormat: 'indices', strictNullHandling: true },
|
|
1100
|
+
),
|
|
1101
|
+
).toBe('b[0]&c=c');
|
|
1102
|
+
expect(
|
|
1103
|
+
stringify(
|
|
1104
|
+
{ a: [], b: [null], c: 'c' },
|
|
1105
|
+
{ encode: false, arrayFormat: 'brackets', strictNullHandling: true },
|
|
1106
|
+
),
|
|
1107
|
+
).toBe('b[]&c=c');
|
|
1108
|
+
expect(
|
|
1109
|
+
stringify(
|
|
1110
|
+
{ a: [], b: [null], c: 'c' },
|
|
1111
|
+
{ encode: false, arrayFormat: 'repeat', strictNullHandling: true },
|
|
1112
|
+
),
|
|
1113
|
+
).toBe('b&c=c');
|
|
1114
|
+
expect(
|
|
1115
|
+
stringify(
|
|
1116
|
+
{ a: [], b: [null], c: 'c' },
|
|
1117
|
+
{ encode: false, arrayFormat: 'comma', strictNullHandling: true },
|
|
1118
|
+
),
|
|
1119
|
+
).toBe('b&c=c');
|
|
1120
|
+
expect(
|
|
1121
|
+
stringify(
|
|
1122
|
+
{ a: [], b: [null], c: 'c' },
|
|
1123
|
+
{ encode: false, arrayFormat: 'comma', strictNullHandling: true, commaRoundTrip: true },
|
|
1124
|
+
),
|
|
1125
|
+
).toBe('b[]&c=c');
|
|
1126
|
+
|
|
1127
|
+
// with skipNulls
|
|
1128
|
+
// st.equal(
|
|
1129
|
+
// stringify(
|
|
1130
|
+
// { a: [], b: [null], c: 'c' },
|
|
1131
|
+
// { encode: false, arrayFormat: 'indices', skipNulls: true },
|
|
1132
|
+
// ),
|
|
1133
|
+
// 'c=c',
|
|
1134
|
+
// );
|
|
1135
|
+
// st.equal(
|
|
1136
|
+
// stringify(
|
|
1137
|
+
// { a: [], b: [null], c: 'c' },
|
|
1138
|
+
// { encode: false, arrayFormat: 'brackets', skipNulls: true },
|
|
1139
|
+
// ),
|
|
1140
|
+
// 'c=c',
|
|
1141
|
+
// );
|
|
1142
|
+
// st.equal(
|
|
1143
|
+
// stringify(
|
|
1144
|
+
// { a: [], b: [null], c: 'c' },
|
|
1145
|
+
// { encode: false, arrayFormat: 'repeat', skipNulls: true },
|
|
1146
|
+
// ),
|
|
1147
|
+
// 'c=c',
|
|
1148
|
+
// );
|
|
1149
|
+
// st.equal(
|
|
1150
|
+
// stringify(
|
|
1151
|
+
// { a: [], b: [null], c: 'c' },
|
|
1152
|
+
// { encode: false, arrayFormat: 'comma', skipNulls: true },
|
|
1153
|
+
// ),
|
|
1154
|
+
// 'c=c',
|
|
1155
|
+
// );
|
|
1156
|
+
expect(
|
|
1157
|
+
stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices', skipNulls: true }),
|
|
1158
|
+
).toBe('c=c');
|
|
1159
|
+
expect(
|
|
1160
|
+
stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets', skipNulls: true }),
|
|
1161
|
+
).toBe('c=c');
|
|
1162
|
+
expect(
|
|
1163
|
+
stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat', skipNulls: true }),
|
|
1164
|
+
).toBe('c=c');
|
|
1165
|
+
expect(
|
|
1166
|
+
stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', skipNulls: true }),
|
|
1167
|
+
).toBe('c=c');
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1170
|
+
test('stringifies a null object', function () {
|
|
1171
|
+
var obj = Object.create(null);
|
|
1172
|
+
obj.a = 'b';
|
|
1173
|
+
// st.equal(stringify(obj), 'a=b');
|
|
1174
|
+
expect(stringify(obj)).toBe('a=b');
|
|
1175
|
+
});
|
|
1176
|
+
|
|
1177
|
+
test('returns an empty string for invalid input', function () {
|
|
1178
|
+
// st.equal(stringify(undefined), '');
|
|
1179
|
+
// st.equal(stringify(false), '');
|
|
1180
|
+
// st.equal(stringify(null), '');
|
|
1181
|
+
// st.equal(stringify(''), '');
|
|
1182
|
+
expect(stringify(undefined)).toBe('');
|
|
1183
|
+
expect(stringify(false)).toBe('');
|
|
1184
|
+
expect(stringify(null)).toBe('');
|
|
1185
|
+
expect(stringify('')).toBe('');
|
|
1186
|
+
});
|
|
1187
|
+
|
|
1188
|
+
test('stringifies an object with a null object as a child', function () {
|
|
1189
|
+
var obj = { a: Object.create(null) };
|
|
1190
|
+
|
|
1191
|
+
obj.a.b = 'c';
|
|
1192
|
+
// st.equal(stringify(obj), 'a%5Bb%5D=c');
|
|
1193
|
+
expect(stringify(obj)).toBe('a%5Bb%5D=c');
|
|
1194
|
+
});
|
|
1195
|
+
|
|
1196
|
+
test('drops keys with a value of undefined', function () {
|
|
1197
|
+
// st.equal(stringify({ a: undefined }), '');
|
|
1198
|
+
expect(stringify({ a: undefined })).toBe('');
|
|
1199
|
+
|
|
1200
|
+
// st.equal(
|
|
1201
|
+
// stringify({ a: { b: undefined, c: null } }, { strictNullHandling: true }),
|
|
1202
|
+
// 'a%5Bc%5D',
|
|
1203
|
+
// );
|
|
1204
|
+
// st.equal(
|
|
1205
|
+
// stringify({ a: { b: undefined, c: null } }, { strictNullHandling: false }),
|
|
1206
|
+
// 'a%5Bc%5D=',
|
|
1207
|
+
// );
|
|
1208
|
+
// st.equal(stringify({ a: { b: undefined, c: '' } }), 'a%5Bc%5D=');
|
|
1209
|
+
expect(stringify({ a: { b: undefined, c: null } }, { strictNullHandling: true })).toBe('a%5Bc%5D');
|
|
1210
|
+
expect(stringify({ a: { b: undefined, c: null } }, { strictNullHandling: false })).toBe('a%5Bc%5D=');
|
|
1211
|
+
expect(stringify({ a: { b: undefined, c: '' } })).toBe('a%5Bc%5D=');
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
test('url encodes values', function () {
|
|
1215
|
+
// st.equal(stringify({ a: 'b c' }), 'a=b%20c');
|
|
1216
|
+
expect(stringify({ a: 'b c' })).toBe('a=b%20c');
|
|
1217
|
+
});
|
|
1218
|
+
|
|
1219
|
+
test('stringifies a date', function () {
|
|
1220
|
+
var now = new Date();
|
|
1221
|
+
var str = 'a=' + encodeURIComponent(now.toISOString());
|
|
1222
|
+
// st.equal(stringify({ a: now }), str);
|
|
1223
|
+
expect(stringify({ a: now })).toBe(str);
|
|
1224
|
+
});
|
|
1225
|
+
|
|
1226
|
+
test('stringifies the weird object from qs', function () {
|
|
1227
|
+
// st.equal(
|
|
1228
|
+
// stringify({ 'my weird field': '~q1!2"\'w$5&7/z8)?' }),
|
|
1229
|
+
// 'my%20weird%20field=~q1%212%22%27w%245%267%2Fz8%29%3F',
|
|
1230
|
+
// );
|
|
1231
|
+
expect(stringify({ 'my weird field': '~q1!2"\'w$5&7/z8)?' })).toBe(
|
|
1232
|
+
'my%20weird%20field=~q1%212%22%27w%245%267%2Fz8%29%3F',
|
|
1233
|
+
);
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
// TODO: Investigate how to to intercept in vitest
|
|
1237
|
+
// TODO(rob)
|
|
1238
|
+
test('skips properties that are part of the object prototype', function () {
|
|
1239
|
+
// st.intercept(Object.prototype, 'crash', { value: 'test' });
|
|
1240
|
+
// @ts-expect-error
|
|
1241
|
+
Object.prototype.crash = 'test';
|
|
1242
|
+
|
|
1243
|
+
// st.equal(stringify({ a: 'b' }), 'a=b');
|
|
1244
|
+
// st.equal(stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
|
|
1245
|
+
expect(stringify({ a: 'b' })).toBe('a=b');
|
|
1246
|
+
expect(stringify({ a: { b: 'c' } })).toBe('a%5Bb%5D=c');
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
test('stringifies boolean values', function () {
|
|
1250
|
+
// st.equal(stringify({ a: true }), 'a=true');
|
|
1251
|
+
// st.equal(stringify({ a: { b: true } }), 'a%5Bb%5D=true');
|
|
1252
|
+
// st.equal(stringify({ b: false }), 'b=false');
|
|
1253
|
+
// st.equal(stringify({ b: { c: false } }), 'b%5Bc%5D=false');
|
|
1254
|
+
expect(stringify({ a: true })).toBe('a=true');
|
|
1255
|
+
expect(stringify({ a: { b: true } })).toBe('a%5Bb%5D=true');
|
|
1256
|
+
expect(stringify({ b: false })).toBe('b=false');
|
|
1257
|
+
expect(stringify({ b: { c: false } })).toBe('b%5Bc%5D=false');
|
|
1258
|
+
});
|
|
1259
|
+
|
|
1260
|
+
test('stringifies buffer values', function () {
|
|
1261
|
+
// st.equal(stringify({ a: Buffer.from('test') }), 'a=test');
|
|
1262
|
+
// st.equal(stringify({ a: { b: Buffer.from('test') } }), 'a%5Bb%5D=test');
|
|
1263
|
+
});
|
|
1264
|
+
|
|
1265
|
+
test('stringifies an object using an alternative delimiter', function () {
|
|
1266
|
+
// st.equal(stringify({ a: 'b', c: 'd' }, { delimiter: ';' }), 'a=b;c=d');
|
|
1267
|
+
expect(stringify({ a: 'b', c: 'd' }, { delimiter: ';' })).toBe('a=b;c=d');
|
|
1268
|
+
});
|
|
1269
|
+
|
|
1270
|
+
// We dont target environments which dont even have Buffer
|
|
1271
|
+
// test('does not blow up when Buffer global is missing', function () {
|
|
1272
|
+
// var restore = mockProperty(global, 'Buffer', { delete: true });
|
|
1273
|
+
|
|
1274
|
+
// var result = stringify({ a: 'b', c: 'd' });
|
|
1275
|
+
|
|
1276
|
+
// restore();
|
|
1277
|
+
|
|
1278
|
+
// st.equal(result, 'a=b&c=d');
|
|
1279
|
+
// st.end();
|
|
1280
|
+
// });
|
|
1281
|
+
|
|
1282
|
+
test('does not crash when parsing circular references', function () {
|
|
1283
|
+
var a: any = {};
|
|
1284
|
+
a.b = a;
|
|
1285
|
+
|
|
1286
|
+
// st['throws'](
|
|
1287
|
+
// function () {
|
|
1288
|
+
// stringify({ 'foo[bar]': 'baz', 'foo[baz]': a });
|
|
1289
|
+
// },
|
|
1290
|
+
// /RangeError: Cyclic object value/,
|
|
1291
|
+
// 'cyclic values throw',
|
|
1292
|
+
// );
|
|
1293
|
+
expect(() => {
|
|
1294
|
+
stringify({ 'foo[bar]': 'baz', 'foo[baz]': a });
|
|
1295
|
+
}).toThrow('Cyclic object value');
|
|
1296
|
+
|
|
1297
|
+
var circular: any = {
|
|
1298
|
+
a: 'value',
|
|
1299
|
+
};
|
|
1300
|
+
circular.a = circular;
|
|
1301
|
+
// st['throws'](
|
|
1302
|
+
// function () {
|
|
1303
|
+
// stringify(circular);
|
|
1304
|
+
// },
|
|
1305
|
+
// /RangeError: Cyclic object value/,
|
|
1306
|
+
// 'cyclic values throw',
|
|
1307
|
+
// );
|
|
1308
|
+
expect(() => {
|
|
1309
|
+
stringify(circular);
|
|
1310
|
+
}).toThrow('Cyclic object value');
|
|
1311
|
+
|
|
1312
|
+
var arr = ['a'];
|
|
1313
|
+
// st.doesNotThrow(function () {
|
|
1314
|
+
// stringify({ x: arr, y: arr });
|
|
1315
|
+
// }, 'non-cyclic values do not throw');
|
|
1316
|
+
expect(() => {
|
|
1317
|
+
stringify({ x: arr, y: arr });
|
|
1318
|
+
}).not.toThrow();
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
test('non-circular duplicated references can still work', function () {
|
|
1322
|
+
var hourOfDay = {
|
|
1323
|
+
function: 'hour_of_day',
|
|
1324
|
+
};
|
|
1325
|
+
|
|
1326
|
+
var p1 = {
|
|
1327
|
+
function: 'gte',
|
|
1328
|
+
arguments: [hourOfDay, 0],
|
|
1329
|
+
};
|
|
1330
|
+
var p2 = {
|
|
1331
|
+
function: 'lte',
|
|
1332
|
+
arguments: [hourOfDay, 23],
|
|
1333
|
+
};
|
|
1334
|
+
|
|
1335
|
+
// st.equal(
|
|
1336
|
+
// stringify(
|
|
1337
|
+
// { filters: { $and: [p1, p2] } },
|
|
1338
|
+
// { encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
1339
|
+
// ),
|
|
1340
|
+
// 'filters[$and][0][function]=gte&filters[$and][0][arguments][0][function]=hour_of_day&filters[$and][0][arguments][1]=0&filters[$and][1][function]=lte&filters[$and][1][arguments][0][function]=hour_of_day&filters[$and][1][arguments][1]=23',
|
|
1341
|
+
// );
|
|
1342
|
+
// st.equal(
|
|
1343
|
+
// stringify(
|
|
1344
|
+
// { filters: { $and: [p1, p2] } },
|
|
1345
|
+
// { encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
1346
|
+
// ),
|
|
1347
|
+
// 'filters[$and][][function]=gte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=0&filters[$and][][function]=lte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=23',
|
|
1348
|
+
// );
|
|
1349
|
+
// st.equal(
|
|
1350
|
+
// stringify(
|
|
1351
|
+
// { filters: { $and: [p1, p2] } },
|
|
1352
|
+
// { encodeValuesOnly: true, arrayFormat: 'repeat' },
|
|
1353
|
+
// ),
|
|
1354
|
+
// 'filters[$and][function]=gte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=0&filters[$and][function]=lte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=23',
|
|
1355
|
+
// );
|
|
1356
|
+
expect(
|
|
1357
|
+
stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
|
|
1358
|
+
).toBe(
|
|
1359
|
+
'filters[$and][0][function]=gte&filters[$and][0][arguments][0][function]=hour_of_day&filters[$and][0][arguments][1]=0&filters[$and][1][function]=lte&filters[$and][1][arguments][0][function]=hour_of_day&filters[$and][1][arguments][1]=23',
|
|
1360
|
+
);
|
|
1361
|
+
expect(
|
|
1362
|
+
stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
1363
|
+
).toBe(
|
|
1364
|
+
'filters[$and][][function]=gte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=0&filters[$and][][function]=lte&filters[$and][][arguments][][function]=hour_of_day&filters[$and][][arguments][]=23',
|
|
1365
|
+
);
|
|
1366
|
+
expect(
|
|
1367
|
+
stringify({ filters: { $and: [p1, p2] } }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),
|
|
1368
|
+
).toBe(
|
|
1369
|
+
'filters[$and][function]=gte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=0&filters[$and][function]=lte&filters[$and][arguments][function]=hour_of_day&filters[$and][arguments]=23',
|
|
1370
|
+
);
|
|
1371
|
+
});
|
|
1372
|
+
|
|
1373
|
+
test('selects properties when filter=array', function () {
|
|
1374
|
+
// st.equal(stringify({ a: 'b' }, { filter: ['a'] }), 'a=b');
|
|
1375
|
+
// st.equal(stringify({ a: 1 }, { filter: [] }), '');
|
|
1376
|
+
expect(stringify({ a: 'b' }, { filter: ['a'] })).toBe('a=b');
|
|
1377
|
+
expect(stringify({ a: 1 }, { filter: [] })).toBe('');
|
|
1378
|
+
|
|
1379
|
+
// st.equal(
|
|
1380
|
+
// stringify(
|
|
1381
|
+
// { a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },
|
|
1382
|
+
// { filter: ['a', 'b', 0, 2], arrayFormat: 'indices' },
|
|
1383
|
+
// ),
|
|
1384
|
+
// 'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3',
|
|
1385
|
+
// 'indices => indices',
|
|
1386
|
+
// );
|
|
1387
|
+
// st.equal(
|
|
1388
|
+
// stringify(
|
|
1389
|
+
// { a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },
|
|
1390
|
+
// { filter: ['a', 'b', 0, 2], arrayFormat: 'brackets' },
|
|
1391
|
+
// ),
|
|
1392
|
+
// 'a%5Bb%5D%5B%5D=1&a%5Bb%5D%5B%5D=3',
|
|
1393
|
+
// 'brackets => brackets',
|
|
1394
|
+
// );
|
|
1395
|
+
// st.equal(
|
|
1396
|
+
// stringify({ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' }, { filter: ['a', 'b', 0, 2] }),
|
|
1397
|
+
// 'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3',
|
|
1398
|
+
// 'default => indices',
|
|
1399
|
+
// );
|
|
1400
|
+
expect(stringify({ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' }, { filter: ['a', 'b', 0, 2] })).toBe(
|
|
1401
|
+
'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3',
|
|
1402
|
+
);
|
|
1403
|
+
expect(
|
|
1404
|
+
stringify(
|
|
1405
|
+
{ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },
|
|
1406
|
+
{ filter: ['a', 'b', 0, 2], arrayFormat: 'indices' },
|
|
1407
|
+
),
|
|
1408
|
+
).toBe('a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3');
|
|
1409
|
+
expect(
|
|
1410
|
+
stringify(
|
|
1411
|
+
{ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },
|
|
1412
|
+
{ filter: ['a', 'b', 0, 2], arrayFormat: 'brackets' },
|
|
1413
|
+
),
|
|
1414
|
+
).toBe('a%5Bb%5D%5B%5D=1&a%5Bb%5D%5B%5D=3');
|
|
1415
|
+
});
|
|
1416
|
+
|
|
1417
|
+
test('supports custom representations when filter=function', function () {
|
|
1418
|
+
var calls = 0;
|
|
1419
|
+
var obj = { a: 'b', c: 'd', e: { f: new Date(1257894000000) } };
|
|
1420
|
+
var filterFunc: StringifyOptions['filter'] = function (prefix, value) {
|
|
1421
|
+
calls += 1;
|
|
1422
|
+
if (calls === 1) {
|
|
1423
|
+
// st.equal(prefix, '', 'prefix is empty');
|
|
1424
|
+
// st.equal(value, obj);
|
|
1425
|
+
expect(prefix).toBe('');
|
|
1426
|
+
expect(value).toBe(obj);
|
|
1427
|
+
} else if (prefix === 'c') {
|
|
1428
|
+
return void 0;
|
|
1429
|
+
} else if (value instanceof Date) {
|
|
1430
|
+
// st.equal(prefix, 'e[f]');
|
|
1431
|
+
expect(prefix).toBe('e[f]');
|
|
1432
|
+
return value.getTime();
|
|
1433
|
+
}
|
|
1434
|
+
return value;
|
|
1435
|
+
};
|
|
1436
|
+
|
|
1437
|
+
// st.equal(stringify(obj, { filter: filterFunc }), 'a=b&e%5Bf%5D=1257894000000');
|
|
1438
|
+
// st.equal(calls, 5);
|
|
1439
|
+
expect(stringify(obj, { filter: filterFunc })).toBe('a=b&e%5Bf%5D=1257894000000');
|
|
1440
|
+
expect(calls).toBe(5);
|
|
1441
|
+
});
|
|
1442
|
+
|
|
1443
|
+
test('can disable uri encoding', function () {
|
|
1444
|
+
// st.equal(stringify({ a: 'b' }, { encode: false }), 'a=b');
|
|
1445
|
+
// st.equal(stringify({ a: { b: 'c' } }, { encode: false }), 'a[b]=c');
|
|
1446
|
+
// st.equal(
|
|
1447
|
+
// stringify({ a: 'b', c: null }, { strictNullHandling: true, encode: false }),
|
|
1448
|
+
// 'a=b&c',
|
|
1449
|
+
// );
|
|
1450
|
+
expect(stringify({ a: 'b' }, { encode: false })).toBe('a=b');
|
|
1451
|
+
expect(stringify({ a: { b: 'c' } }, { encode: false })).toBe('a[b]=c');
|
|
1452
|
+
expect(stringify({ a: 'b', c: null }, { strictNullHandling: true, encode: false })).toBe('a=b&c');
|
|
1453
|
+
});
|
|
1454
|
+
|
|
1455
|
+
test('can sort the keys', function () {
|
|
1456
|
+
// @ts-expect-error
|
|
1457
|
+
var sort: NonNullable<StringifyOptions['sort']> = function (a: string, b: string) {
|
|
1458
|
+
return a.localeCompare(b);
|
|
1459
|
+
};
|
|
1460
|
+
// st.equal(stringify({ a: 'c', z: 'y', b: 'f' }, { sort: sort }), 'a=c&b=f&z=y');
|
|
1461
|
+
// st.equal(
|
|
1462
|
+
// stringify({ a: 'c', z: { j: 'a', i: 'b' }, b: 'f' }, { sort: sort }),
|
|
1463
|
+
// 'a=c&b=f&z%5Bi%5D=b&z%5Bj%5D=a',
|
|
1464
|
+
// );
|
|
1465
|
+
expect(stringify({ a: 'c', z: 'y', b: 'f' }, { sort: sort })).toBe('a=c&b=f&z=y');
|
|
1466
|
+
expect(stringify({ a: 'c', z: { j: 'a', i: 'b' }, b: 'f' }, { sort: sort })).toBe(
|
|
1467
|
+
'a=c&b=f&z%5Bi%5D=b&z%5Bj%5D=a',
|
|
1468
|
+
);
|
|
1469
|
+
});
|
|
1470
|
+
|
|
1471
|
+
test('can sort the keys at depth 3 or more too', function () {
|
|
1472
|
+
// @ts-expect-error
|
|
1473
|
+
var sort: NonNullable<StringifyOptions['sort']> = function (a: string, b: string) {
|
|
1474
|
+
return a.localeCompare(b);
|
|
1475
|
+
};
|
|
1476
|
+
// st.equal(
|
|
1477
|
+
// stringify(
|
|
1478
|
+
// { a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },
|
|
1479
|
+
// { sort: sort, encode: false },
|
|
1480
|
+
// ),
|
|
1481
|
+
// 'a=a&b=b&z[zi][zia]=zia&z[zi][zib]=zib&z[zj][zja]=zja&z[zj][zjb]=zjb',
|
|
1482
|
+
// );
|
|
1483
|
+
// st.equal(
|
|
1484
|
+
// stringify(
|
|
1485
|
+
// { a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },
|
|
1486
|
+
// { sort: null, encode: false },
|
|
1487
|
+
// ),
|
|
1488
|
+
// 'a=a&z[zj][zjb]=zjb&z[zj][zja]=zja&z[zi][zib]=zib&z[zi][zia]=zia&b=b',
|
|
1489
|
+
// );
|
|
1490
|
+
expect(
|
|
1491
|
+
stringify(
|
|
1492
|
+
{ a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },
|
|
1493
|
+
{ sort: sort, encode: false },
|
|
1494
|
+
),
|
|
1495
|
+
).toBe('a=a&b=b&z[zi][zia]=zia&z[zi][zib]=zib&z[zj][zja]=zja&z[zj][zjb]=zjb');
|
|
1496
|
+
expect(
|
|
1497
|
+
stringify(
|
|
1498
|
+
{ a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },
|
|
1499
|
+
{ sort: null, encode: false },
|
|
1500
|
+
),
|
|
1501
|
+
).toBe('a=a&z[zj][zjb]=zjb&z[zj][zja]=zja&z[zi][zib]=zib&z[zi][zia]=zia&b=b');
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1504
|
+
test('can stringify with custom encoding', function () {
|
|
1505
|
+
// st.equal(
|
|
1506
|
+
// stringify(
|
|
1507
|
+
// { 県: '大阪府', '': '' },
|
|
1508
|
+
// {
|
|
1509
|
+
// encoder: function (str) {
|
|
1510
|
+
// if (str.length === 0) {
|
|
1511
|
+
// return '';
|
|
1512
|
+
// }
|
|
1513
|
+
// var buf = iconv.encode(str, 'shiftjis');
|
|
1514
|
+
// var result = [];
|
|
1515
|
+
// for (var i = 0; i < buf.length; ++i) {
|
|
1516
|
+
// result.push(buf.readUInt8(i).toString(16));
|
|
1517
|
+
// }
|
|
1518
|
+
// return '%' + result.join('%');
|
|
1519
|
+
// },
|
|
1520
|
+
// },
|
|
1521
|
+
// ),
|
|
1522
|
+
// '%8c%a7=%91%e5%8d%e3%95%7b&=',
|
|
1523
|
+
// );
|
|
1524
|
+
expect(
|
|
1525
|
+
stringify(
|
|
1526
|
+
{ 県: '大阪府', '': '' },
|
|
1527
|
+
{
|
|
1528
|
+
encoder: function (str) {
|
|
1529
|
+
if (str.length === 0) {
|
|
1530
|
+
return '';
|
|
1531
|
+
}
|
|
1532
|
+
var buf = iconv.encode(str, 'shiftjis');
|
|
1533
|
+
var result = [];
|
|
1534
|
+
for (var i = 0; i < buf.length; ++i) {
|
|
1535
|
+
result.push(buf.readUInt8(i).toString(16));
|
|
1536
|
+
}
|
|
1537
|
+
return '%' + result.join('%');
|
|
1538
|
+
},
|
|
1539
|
+
},
|
|
1540
|
+
),
|
|
1541
|
+
).toBe('%8c%a7=%91%e5%8d%e3%95%7b&=');
|
|
1542
|
+
});
|
|
1543
|
+
|
|
1544
|
+
test('receives the default encoder as a second argument', function () {
|
|
1545
|
+
// stringify(
|
|
1546
|
+
// { a: 1, b: new Date(), c: true, d: [1] },
|
|
1547
|
+
// {
|
|
1548
|
+
// encoder: function (str) {
|
|
1549
|
+
// st.match(typeof str, /^(?:string|number|boolean)$/);
|
|
1550
|
+
// return '';
|
|
1551
|
+
// },
|
|
1552
|
+
// },
|
|
1553
|
+
// );
|
|
1554
|
+
|
|
1555
|
+
stringify(
|
|
1556
|
+
{ a: 1, b: new Date(), c: true, d: [1] },
|
|
1557
|
+
{
|
|
1558
|
+
encoder: function (str) {
|
|
1559
|
+
// st.match(typeof str, /^(?:string|number|boolean)$/);
|
|
1560
|
+
assert.match(typeof str, /^(?:string|number|boolean)$/);
|
|
1561
|
+
return '';
|
|
1562
|
+
},
|
|
1563
|
+
},
|
|
1564
|
+
);
|
|
1565
|
+
});
|
|
1566
|
+
|
|
1567
|
+
test('receives the default encoder as a second argument', function () {
|
|
1568
|
+
// stringify(
|
|
1569
|
+
// { a: 1 },
|
|
1570
|
+
// {
|
|
1571
|
+
// encoder: function (str, defaultEncoder) {
|
|
1572
|
+
// st.equal(defaultEncoder, utils.encode);
|
|
1573
|
+
// },
|
|
1574
|
+
// },
|
|
1575
|
+
// );
|
|
1576
|
+
|
|
1577
|
+
stringify(
|
|
1578
|
+
{ a: 1 },
|
|
1579
|
+
{
|
|
1580
|
+
// @ts-ignore
|
|
1581
|
+
encoder: function (_str, defaultEncoder) {
|
|
1582
|
+
expect(defaultEncoder).toBe(encode);
|
|
1583
|
+
},
|
|
1584
|
+
},
|
|
1585
|
+
);
|
|
1586
|
+
});
|
|
1587
|
+
|
|
1588
|
+
test('throws error with wrong encoder', function () {
|
|
1589
|
+
// st['throws'](function () {
|
|
1590
|
+
// stringify({}, { encoder: 'string' });
|
|
1591
|
+
// }, new TypeError('Encoder has to be a function.'));
|
|
1592
|
+
// st.end();
|
|
1593
|
+
expect(() => {
|
|
1594
|
+
// @ts-expect-error
|
|
1595
|
+
stringify({}, { encoder: 'string' });
|
|
1596
|
+
}).toThrow(TypeError);
|
|
1597
|
+
});
|
|
1598
|
+
|
|
1599
|
+
(typeof Buffer === 'undefined' ? test.skip : test)(
|
|
1600
|
+
'can use custom encoder for a buffer object',
|
|
1601
|
+
function () {
|
|
1602
|
+
// st.equal(
|
|
1603
|
+
// stringify(
|
|
1604
|
+
// { a: Buffer.from([1]) },
|
|
1605
|
+
// {
|
|
1606
|
+
// encoder: function (buffer) {
|
|
1607
|
+
// if (typeof buffer === 'string') {
|
|
1608
|
+
// return buffer;
|
|
1609
|
+
// }
|
|
1610
|
+
// return String.fromCharCode(buffer.readUInt8(0) + 97);
|
|
1611
|
+
// },
|
|
1612
|
+
// },
|
|
1613
|
+
// ),
|
|
1614
|
+
// 'a=b',
|
|
1615
|
+
// );
|
|
1616
|
+
expect(
|
|
1617
|
+
stringify(
|
|
1618
|
+
{ a: Buffer.from([1]) },
|
|
1619
|
+
{
|
|
1620
|
+
encoder: function (buffer) {
|
|
1621
|
+
if (typeof buffer === 'string') {
|
|
1622
|
+
return buffer;
|
|
1623
|
+
}
|
|
1624
|
+
return String.fromCharCode(buffer.readUInt8(0) + 97);
|
|
1625
|
+
},
|
|
1626
|
+
},
|
|
1627
|
+
),
|
|
1628
|
+
).toBe('a=b');
|
|
1629
|
+
|
|
1630
|
+
// st.equal(
|
|
1631
|
+
// stringify(
|
|
1632
|
+
// { a: Buffer.from('a b') },
|
|
1633
|
+
// {
|
|
1634
|
+
// encoder: function (buffer) {
|
|
1635
|
+
// return buffer;
|
|
1636
|
+
// },
|
|
1637
|
+
// },
|
|
1638
|
+
// ),
|
|
1639
|
+
// 'a=a b',
|
|
1640
|
+
// );
|
|
1641
|
+
expect(
|
|
1642
|
+
stringify(
|
|
1643
|
+
{ a: Buffer.from('a b') },
|
|
1644
|
+
{
|
|
1645
|
+
encoder: function (buffer) {
|
|
1646
|
+
return buffer;
|
|
1647
|
+
},
|
|
1648
|
+
},
|
|
1649
|
+
),
|
|
1650
|
+
).toBe('a=a b');
|
|
1651
|
+
},
|
|
1652
|
+
);
|
|
1653
|
+
|
|
1654
|
+
test('serializeDate option', function () {
|
|
1655
|
+
var date = new Date();
|
|
1656
|
+
// st.equal(
|
|
1657
|
+
// stringify({ a: date }),
|
|
1658
|
+
// 'a=' + date.toISOString().replace(/:/g, '%3A'),
|
|
1659
|
+
// 'default is toISOString',
|
|
1660
|
+
// );
|
|
1661
|
+
expect(stringify({ a: date })).toBe('a=' + date.toISOString().replace(/:/g, '%3A'));
|
|
1662
|
+
|
|
1663
|
+
var mutatedDate = new Date();
|
|
1664
|
+
mutatedDate.toISOString = function () {
|
|
1665
|
+
throw new SyntaxError();
|
|
1666
|
+
};
|
|
1667
|
+
// st['throws'](function () {
|
|
1668
|
+
// mutatedDate.toISOString();
|
|
1669
|
+
// }, SyntaxError);
|
|
1670
|
+
expect(() => {
|
|
1671
|
+
mutatedDate.toISOString();
|
|
1672
|
+
}).toThrow(SyntaxError);
|
|
1673
|
+
// st.equal(
|
|
1674
|
+
// stringify({ a: mutatedDate }),
|
|
1675
|
+
// 'a=' + Date.prototype.toISOString.call(mutatedDate).replace(/:/g, '%3A'),
|
|
1676
|
+
// 'toISOString works even when method is not locally present',
|
|
1677
|
+
// );
|
|
1678
|
+
expect(stringify({ a: mutatedDate })).toBe(
|
|
1679
|
+
'a=' + Date.prototype.toISOString.call(mutatedDate).replace(/:/g, '%3A'),
|
|
1680
|
+
);
|
|
1681
|
+
|
|
1682
|
+
var specificDate = new Date(6);
|
|
1683
|
+
// st.equal(
|
|
1684
|
+
// stringify(
|
|
1685
|
+
// { a: specificDate },
|
|
1686
|
+
// {
|
|
1687
|
+
// serializeDate: function (d) {
|
|
1688
|
+
// return d.getTime() * 7;
|
|
1689
|
+
// },
|
|
1690
|
+
// },
|
|
1691
|
+
// ),
|
|
1692
|
+
// 'a=42',
|
|
1693
|
+
// 'custom serializeDate function called',
|
|
1694
|
+
// );
|
|
1695
|
+
expect(
|
|
1696
|
+
stringify(
|
|
1697
|
+
{ a: specificDate },
|
|
1698
|
+
{
|
|
1699
|
+
// @ts-ignore
|
|
1700
|
+
serializeDate: function (d) {
|
|
1701
|
+
return d.getTime() * 7;
|
|
1702
|
+
},
|
|
1703
|
+
},
|
|
1704
|
+
),
|
|
1705
|
+
).toBe('a=42');
|
|
1706
|
+
|
|
1707
|
+
// st.equal(
|
|
1708
|
+
// stringify(
|
|
1709
|
+
// { a: [date] },
|
|
1710
|
+
// {
|
|
1711
|
+
// serializeDate: function (d) {
|
|
1712
|
+
// return d.getTime();
|
|
1713
|
+
// },
|
|
1714
|
+
// arrayFormat: 'comma',
|
|
1715
|
+
// },
|
|
1716
|
+
// ),
|
|
1717
|
+
// 'a=' + date.getTime(),
|
|
1718
|
+
// 'works with arrayFormat comma',
|
|
1719
|
+
// );
|
|
1720
|
+
// st.equal(
|
|
1721
|
+
// stringify(
|
|
1722
|
+
// { a: [date] },
|
|
1723
|
+
// {
|
|
1724
|
+
// serializeDate: function (d) {
|
|
1725
|
+
// return d.getTime();
|
|
1726
|
+
// },
|
|
1727
|
+
// arrayFormat: 'comma',
|
|
1728
|
+
// commaRoundTrip: true,
|
|
1729
|
+
// },
|
|
1730
|
+
// ),
|
|
1731
|
+
// 'a%5B%5D=' + date.getTime(),
|
|
1732
|
+
// 'works with arrayFormat comma',
|
|
1733
|
+
// );
|
|
1734
|
+
expect(
|
|
1735
|
+
stringify(
|
|
1736
|
+
{ a: [date] },
|
|
1737
|
+
{
|
|
1738
|
+
// @ts-expect-error
|
|
1739
|
+
serializeDate: function (d) {
|
|
1740
|
+
return d.getTime();
|
|
1741
|
+
},
|
|
1742
|
+
arrayFormat: 'comma',
|
|
1743
|
+
},
|
|
1744
|
+
),
|
|
1745
|
+
).toBe('a=' + date.getTime());
|
|
1746
|
+
expect(
|
|
1747
|
+
stringify(
|
|
1748
|
+
{ a: [date] },
|
|
1749
|
+
{
|
|
1750
|
+
// @ts-expect-error
|
|
1751
|
+
serializeDate: function (d) {
|
|
1752
|
+
return d.getTime();
|
|
1753
|
+
},
|
|
1754
|
+
arrayFormat: 'comma',
|
|
1755
|
+
commaRoundTrip: true,
|
|
1756
|
+
},
|
|
1757
|
+
),
|
|
1758
|
+
).toBe('a%5B%5D=' + date.getTime());
|
|
1759
|
+
});
|
|
1760
|
+
|
|
1761
|
+
test('RFC 1738 serialization', function () {
|
|
1762
|
+
// st.equal(stringify({ a: 'b c' }, { format: formats.RFC1738 }), 'a=b+c');
|
|
1763
|
+
// st.equal(stringify({ 'a b': 'c d' }, { format: formats.RFC1738 }), 'a+b=c+d');
|
|
1764
|
+
// st.equal(
|
|
1765
|
+
// stringify({ 'a b': Buffer.from('a b') }, { format: formats.RFC1738 }),
|
|
1766
|
+
// 'a+b=a+b',
|
|
1767
|
+
// );
|
|
1768
|
+
expect(stringify({ a: 'b c' }, { format: 'RFC1738' })).toBe('a=b+c');
|
|
1769
|
+
expect(stringify({ 'a b': 'c d' }, { format: 'RFC1738' })).toBe('a+b=c+d');
|
|
1770
|
+
expect(stringify({ 'a b': Buffer.from('a b') }, { format: 'RFC1738' })).toBe('a+b=a+b');
|
|
1771
|
+
|
|
1772
|
+
// st.equal(stringify({ 'foo(ref)': 'bar' }, { format: formats.RFC1738 }), 'foo(ref)=bar');
|
|
1773
|
+
expect(stringify({ 'foo(ref)': 'bar' }, { format: 'RFC1738' })).toBe('foo(ref)=bar');
|
|
1774
|
+
});
|
|
1775
|
+
|
|
1776
|
+
test('RFC 3986 spaces serialization', function () {
|
|
1777
|
+
// st.equal(stringify({ a: 'b c' }, { format: formats.RFC3986 }), 'a=b%20c');
|
|
1778
|
+
// st.equal(stringify({ 'a b': 'c d' }, { format: formats.RFC3986 }), 'a%20b=c%20d');
|
|
1779
|
+
// st.equal(
|
|
1780
|
+
// stringify({ 'a b': Buffer.from('a b') }, { format: formats.RFC3986 }),
|
|
1781
|
+
// 'a%20b=a%20b',
|
|
1782
|
+
// );
|
|
1783
|
+
expect(stringify({ a: 'b c' }, { format: 'RFC3986' })).toBe('a=b%20c');
|
|
1784
|
+
expect(stringify({ 'a b': 'c d' }, { format: 'RFC3986' })).toBe('a%20b=c%20d');
|
|
1785
|
+
expect(stringify({ 'a b': Buffer.from('a b') }, { format: 'RFC3986' })).toBe('a%20b=a%20b');
|
|
1786
|
+
});
|
|
1787
|
+
|
|
1788
|
+
test('Backward compatibility to RFC 3986', function () {
|
|
1789
|
+
// st.equal(stringify({ a: 'b c' }), 'a=b%20c');
|
|
1790
|
+
// st.equal(stringify({ 'a b': Buffer.from('a b') }), 'a%20b=a%20b');
|
|
1791
|
+
expect(stringify({ a: 'b c' })).toBe('a=b%20c');
|
|
1792
|
+
expect(stringify({ 'a b': Buffer.from('a b') })).toBe('a%20b=a%20b');
|
|
1793
|
+
});
|
|
1794
|
+
|
|
1795
|
+
test('Edge cases and unknown formats', function () {
|
|
1796
|
+
['UFO1234', false, 1234, null, {}, []].forEach(function (format) {
|
|
1797
|
+
// st['throws'](function () {
|
|
1798
|
+
// stringify({ a: 'b c' }, { format: format });
|
|
1799
|
+
// }, new TypeError('Unknown format option provided.'));
|
|
1800
|
+
expect(() => {
|
|
1801
|
+
// @ts-expect-error
|
|
1802
|
+
stringify({ a: 'b c' }, { format: format });
|
|
1803
|
+
}).toThrow(TypeError);
|
|
1804
|
+
});
|
|
1805
|
+
});
|
|
1806
|
+
|
|
1807
|
+
test('encodeValuesOnly', function () {
|
|
1808
|
+
// st.equal(
|
|
1809
|
+
// stringify(
|
|
1810
|
+
// { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
|
1811
|
+
// { encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
1812
|
+
// ),
|
|
1813
|
+
// 'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h',
|
|
1814
|
+
// 'encodeValuesOnly + indices',
|
|
1815
|
+
// );
|
|
1816
|
+
// st.equal(
|
|
1817
|
+
// stringify(
|
|
1818
|
+
// { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
|
1819
|
+
// { encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
1820
|
+
// ),
|
|
1821
|
+
// 'a=b&c[]=d&c[]=e%3Df&f[][]=g&f[][]=h',
|
|
1822
|
+
// 'encodeValuesOnly + brackets',
|
|
1823
|
+
// );
|
|
1824
|
+
// st.equal(
|
|
1825
|
+
// stringify(
|
|
1826
|
+
// { a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
|
1827
|
+
// { encodeValuesOnly: true, arrayFormat: 'repeat' },
|
|
1828
|
+
// ),
|
|
1829
|
+
// 'a=b&c=d&c=e%3Df&f=g&f=h',
|
|
1830
|
+
// 'encodeValuesOnly + repeat',
|
|
1831
|
+
// );
|
|
1832
|
+
expect(
|
|
1833
|
+
stringify(
|
|
1834
|
+
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
|
1835
|
+
{ encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
1836
|
+
),
|
|
1837
|
+
).toBe('a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h');
|
|
1838
|
+
expect(
|
|
1839
|
+
stringify(
|
|
1840
|
+
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
|
1841
|
+
{ encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
1842
|
+
),
|
|
1843
|
+
).toBe('a=b&c[]=d&c[]=e%3Df&f[][]=g&f[][]=h');
|
|
1844
|
+
expect(
|
|
1845
|
+
stringify(
|
|
1846
|
+
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
|
1847
|
+
{ encodeValuesOnly: true, arrayFormat: 'repeat' },
|
|
1848
|
+
),
|
|
1849
|
+
).toBe('a=b&c=d&c=e%3Df&f=g&f=h');
|
|
1850
|
+
|
|
1851
|
+
// st.equal(
|
|
1852
|
+
// stringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'indices' }),
|
|
1853
|
+
// 'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h',
|
|
1854
|
+
// 'no encodeValuesOnly + indices',
|
|
1855
|
+
// );
|
|
1856
|
+
// st.equal(
|
|
1857
|
+
// stringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'brackets' }),
|
|
1858
|
+
// 'a=b&c%5B%5D=d&c%5B%5D=e&f%5B%5D%5B%5D=g&f%5B%5D%5B%5D=h',
|
|
1859
|
+
// 'no encodeValuesOnly + brackets',
|
|
1860
|
+
// );
|
|
1861
|
+
// st.equal(
|
|
1862
|
+
// stringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'repeat' }),
|
|
1863
|
+
// 'a=b&c=d&c=e&f=g&f=h',
|
|
1864
|
+
// 'no encodeValuesOnly + repeat',
|
|
1865
|
+
// );
|
|
1866
|
+
expect(stringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'indices' })).toBe(
|
|
1867
|
+
'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h',
|
|
1868
|
+
);
|
|
1869
|
+
expect(stringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'brackets' })).toBe(
|
|
1870
|
+
'a=b&c%5B%5D=d&c%5B%5D=e&f%5B%5D%5B%5D=g&f%5B%5D%5B%5D=h',
|
|
1871
|
+
);
|
|
1872
|
+
expect(stringify({ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }, { arrayFormat: 'repeat' })).toBe(
|
|
1873
|
+
'a=b&c=d&c=e&f=g&f=h',
|
|
1874
|
+
);
|
|
1875
|
+
});
|
|
1876
|
+
|
|
1877
|
+
test('encodeValuesOnly - strictNullHandling', function () {
|
|
1878
|
+
// st.equal(
|
|
1879
|
+
// stringify({ a: { b: null } }, { encodeValuesOnly: true, strictNullHandling: true }),
|
|
1880
|
+
// 'a[b]',
|
|
1881
|
+
// );
|
|
1882
|
+
expect(stringify({ a: { b: null } }, { encodeValuesOnly: true, strictNullHandling: true })).toBe('a[b]');
|
|
1883
|
+
});
|
|
1884
|
+
|
|
1885
|
+
test('throws if an invalid charset is specified', function () {
|
|
1886
|
+
// st['throws'](function () {
|
|
1887
|
+
// stringify({ a: 'b' }, { charset: 'foobar' });
|
|
1888
|
+
// }, new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined'));
|
|
1889
|
+
expect(() => {
|
|
1890
|
+
// @ts-expect-error
|
|
1891
|
+
stringify({ a: 'b' }, { charset: 'foobar' });
|
|
1892
|
+
}).toThrow(TypeError);
|
|
1893
|
+
});
|
|
1894
|
+
|
|
1895
|
+
test('respects a charset of iso-8859-1', function () {
|
|
1896
|
+
// st.equal(stringify({ æ: 'æ' }, { charset: 'iso-8859-1' }), '%E6=%E6');
|
|
1897
|
+
expect(stringify({ æ: 'æ' }, { charset: 'iso-8859-1' })).toBe('%E6=%E6');
|
|
1898
|
+
});
|
|
1899
|
+
|
|
1900
|
+
test('encodes unrepresentable chars as numeric entities in iso-8859-1 mode', function () {
|
|
1901
|
+
// st.equal(stringify({ a: '☺' }, { charset: 'iso-8859-1' }), 'a=%26%239786%3B');
|
|
1902
|
+
expect(stringify({ a: '☺' }, { charset: 'iso-8859-1' })).toBe('a=%26%239786%3B');
|
|
1903
|
+
});
|
|
1904
|
+
|
|
1905
|
+
test('respects an explicit charset of utf-8 (the default)', function () {
|
|
1906
|
+
// st.equal(stringify({ a: 'æ' }, { charset: 'utf-8' }), 'a=%C3%A6');
|
|
1907
|
+
expect(stringify({ a: 'æ' }, { charset: 'utf-8' })).toBe('a=%C3%A6');
|
|
1908
|
+
});
|
|
1909
|
+
|
|
1910
|
+
test('`charsetSentinel` option', function () {
|
|
1911
|
+
// st.equal(
|
|
1912
|
+
// stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'utf-8' }),
|
|
1913
|
+
// 'utf8=%E2%9C%93&a=%C3%A6',
|
|
1914
|
+
// 'adds the right sentinel when instructed to and the charset is utf-8',
|
|
1915
|
+
// );
|
|
1916
|
+
expect(stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'utf-8' })).toBe(
|
|
1917
|
+
'utf8=%E2%9C%93&a=%C3%A6',
|
|
1918
|
+
);
|
|
1919
|
+
|
|
1920
|
+
// st.equal(
|
|
1921
|
+
// stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' }),
|
|
1922
|
+
// 'utf8=%26%2310003%3B&a=%E6',
|
|
1923
|
+
// 'adds the right sentinel when instructed to and the charset is iso-8859-1',
|
|
1924
|
+
// );
|
|
1925
|
+
expect(stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' })).toBe(
|
|
1926
|
+
'utf8=%26%2310003%3B&a=%E6',
|
|
1927
|
+
);
|
|
1928
|
+
});
|
|
1929
|
+
|
|
1930
|
+
test('does not mutate the options argument', function () {
|
|
1931
|
+
var options = {};
|
|
1932
|
+
stringify({}, options);
|
|
1933
|
+
// st.deepEqual(options, {});
|
|
1934
|
+
expect(options).toEqual({});
|
|
1935
|
+
});
|
|
1936
|
+
|
|
1937
|
+
test('strictNullHandling works with custom filter', function () {
|
|
1938
|
+
// @ts-expect-error
|
|
1939
|
+
var filter = function (_prefix, value) {
|
|
1940
|
+
return value;
|
|
1941
|
+
};
|
|
1942
|
+
|
|
1943
|
+
var options = { strictNullHandling: true, filter: filter };
|
|
1944
|
+
// st.equal(stringify({ key: null }, options), 'key');
|
|
1945
|
+
expect(stringify({ key: null }, options)).toBe('key');
|
|
1946
|
+
});
|
|
1947
|
+
|
|
1948
|
+
test('strictNullHandling works with null serializeDate', function () {
|
|
1949
|
+
var serializeDate = function () {
|
|
1950
|
+
return null;
|
|
1951
|
+
};
|
|
1952
|
+
var options = { strictNullHandling: true, serializeDate: serializeDate };
|
|
1953
|
+
var date = new Date();
|
|
1954
|
+
// st.equal(stringify({ key: date }, options), 'key');
|
|
1955
|
+
// @ts-expect-error
|
|
1956
|
+
expect(stringify({ key: date }, options)).toBe('key');
|
|
1957
|
+
});
|
|
1958
|
+
|
|
1959
|
+
test('allows for encoding keys and values differently', function () {
|
|
1960
|
+
// @ts-expect-error
|
|
1961
|
+
var encoder = function (str, defaultEncoder, charset, type) {
|
|
1962
|
+
if (type === 'key') {
|
|
1963
|
+
return defaultEncoder(str, defaultEncoder, charset, type).toLowerCase();
|
|
1964
|
+
}
|
|
1965
|
+
if (type === 'value') {
|
|
1966
|
+
return defaultEncoder(str, defaultEncoder, charset, type).toUpperCase();
|
|
1967
|
+
}
|
|
1968
|
+
throw 'this should never happen! type: ' + type;
|
|
1969
|
+
};
|
|
1970
|
+
|
|
1971
|
+
// st.deepEqual(stringify({ KeY: 'vAlUe' }, { encoder: encoder }), 'key=VALUE');
|
|
1972
|
+
expect(stringify({ KeY: 'vAlUe' }, { encoder: encoder })).toBe('key=VALUE');
|
|
1973
|
+
});
|
|
1974
|
+
|
|
1975
|
+
test('objects inside arrays', function () {
|
|
1976
|
+
var obj = { a: { b: { c: 'd', e: 'f' } } };
|
|
1977
|
+
var withArray = { a: { b: [{ c: 'd', e: 'f' }] } };
|
|
1978
|
+
|
|
1979
|
+
// st.equal(
|
|
1980
|
+
// stringify(obj, { encode: false }),
|
|
1981
|
+
// 'a[b][c]=d&a[b][e]=f',
|
|
1982
|
+
// 'no array, no arrayFormat',
|
|
1983
|
+
// );
|
|
1984
|
+
// st.equal(
|
|
1985
|
+
// stringify(obj, { encode: false, arrayFormat: 'brackets' }),
|
|
1986
|
+
// 'a[b][c]=d&a[b][e]=f',
|
|
1987
|
+
// 'no array, bracket',
|
|
1988
|
+
// );
|
|
1989
|
+
// st.equal(
|
|
1990
|
+
// stringify(obj, { encode: false, arrayFormat: 'indices' }),
|
|
1991
|
+
// 'a[b][c]=d&a[b][e]=f',
|
|
1992
|
+
// 'no array, indices',
|
|
1993
|
+
// );
|
|
1994
|
+
// st.equal(
|
|
1995
|
+
// stringify(obj, { encode: false, arrayFormat: 'repeat' }),
|
|
1996
|
+
// 'a[b][c]=d&a[b][e]=f',
|
|
1997
|
+
// 'no array, repeat',
|
|
1998
|
+
// );
|
|
1999
|
+
// st.equal(
|
|
2000
|
+
// stringify(obj, { encode: false, arrayFormat: 'comma' }),
|
|
2001
|
+
// 'a[b][c]=d&a[b][e]=f',
|
|
2002
|
+
// 'no array, comma',
|
|
2003
|
+
// );
|
|
2004
|
+
expect(stringify(obj, { encode: false })).toBe('a[b][c]=d&a[b][e]=f');
|
|
2005
|
+
expect(stringify(obj, { encode: false, arrayFormat: 'brackets' })).toBe('a[b][c]=d&a[b][e]=f');
|
|
2006
|
+
expect(stringify(obj, { encode: false, arrayFormat: 'indices' })).toBe('a[b][c]=d&a[b][e]=f');
|
|
2007
|
+
expect(stringify(obj, { encode: false, arrayFormat: 'repeat' })).toBe('a[b][c]=d&a[b][e]=f');
|
|
2008
|
+
expect(stringify(obj, { encode: false, arrayFormat: 'comma' })).toBe('a[b][c]=d&a[b][e]=f');
|
|
2009
|
+
|
|
2010
|
+
// st.equal(
|
|
2011
|
+
// stringify(withArray, { encode: false }),
|
|
2012
|
+
// 'a[b][0][c]=d&a[b][0][e]=f',
|
|
2013
|
+
// 'array, no arrayFormat',
|
|
2014
|
+
// );
|
|
2015
|
+
// st.equal(
|
|
2016
|
+
// stringify(withArray, { encode: false, arrayFormat: 'brackets' }),
|
|
2017
|
+
// 'a[b][][c]=d&a[b][][e]=f',
|
|
2018
|
+
// 'array, bracket',
|
|
2019
|
+
// );
|
|
2020
|
+
// st.equal(
|
|
2021
|
+
// stringify(withArray, { encode: false, arrayFormat: 'indices' }),
|
|
2022
|
+
// 'a[b][0][c]=d&a[b][0][e]=f',
|
|
2023
|
+
// 'array, indices',
|
|
2024
|
+
// );
|
|
2025
|
+
// st.equal(
|
|
2026
|
+
// stringify(withArray, { encode: false, arrayFormat: 'repeat' }),
|
|
2027
|
+
// 'a[b][c]=d&a[b][e]=f',
|
|
2028
|
+
// 'array, repeat',
|
|
2029
|
+
// );
|
|
2030
|
+
// st.equal(
|
|
2031
|
+
// stringify(withArray, { encode: false, arrayFormat: 'comma' }),
|
|
2032
|
+
// '???',
|
|
2033
|
+
// 'array, comma',
|
|
2034
|
+
// { skip: 'TODO: figure out what this should do' },
|
|
2035
|
+
// );
|
|
2036
|
+
expect(stringify(withArray, { encode: false })).toBe('a[b][0][c]=d&a[b][0][e]=f');
|
|
2037
|
+
expect(stringify(withArray, { encode: false, arrayFormat: 'brackets' })).toBe('a[b][][c]=d&a[b][][e]=f');
|
|
2038
|
+
expect(stringify(withArray, { encode: false, arrayFormat: 'indices' })).toBe('a[b][0][c]=d&a[b][0][e]=f');
|
|
2039
|
+
expect(stringify(withArray, { encode: false, arrayFormat: 'repeat' })).toBe('a[b][c]=d&a[b][e]=f');
|
|
2040
|
+
// !TODo: Figure out what this should do
|
|
2041
|
+
// expect(stringify(withArray, { encode: false, arrayFormat: 'comma' })).toBe(
|
|
2042
|
+
// 'a[b][c]=d&a[b][e]=f',
|
|
2043
|
+
// );
|
|
2044
|
+
});
|
|
2045
|
+
|
|
2046
|
+
test('stringifies sparse arrays', function () {
|
|
2047
|
+
// st.equal(
|
|
2048
|
+
// stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
|
|
2049
|
+
// 'a[1]=2&a[4]=1',
|
|
2050
|
+
// );
|
|
2051
|
+
// st.equal(
|
|
2052
|
+
// stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
2053
|
+
// 'a[]=2&a[]=1',
|
|
2054
|
+
// );
|
|
2055
|
+
// st.equal(
|
|
2056
|
+
// stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),
|
|
2057
|
+
// 'a=2&a=1',
|
|
2058
|
+
// );
|
|
2059
|
+
expect(stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'indices' })).toBe(
|
|
2060
|
+
'a[1]=2&a[4]=1',
|
|
2061
|
+
);
|
|
2062
|
+
expect(stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' })).toBe(
|
|
2063
|
+
'a[]=2&a[]=1',
|
|
2064
|
+
);
|
|
2065
|
+
expect(stringify({ a: [, '2', , , '1'] }, { encodeValuesOnly: true, arrayFormat: 'repeat' })).toBe(
|
|
2066
|
+
'a=2&a=1',
|
|
2067
|
+
);
|
|
2068
|
+
|
|
2069
|
+
// st.equal(
|
|
2070
|
+
// stringify(
|
|
2071
|
+
// { a: [, { b: [, , { c: '1' }] }] },
|
|
2072
|
+
// { encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
2073
|
+
// ),
|
|
2074
|
+
// 'a[1][b][2][c]=1',
|
|
2075
|
+
// );
|
|
2076
|
+
// st.equal(
|
|
2077
|
+
// stringify(
|
|
2078
|
+
// { a: [, { b: [, , { c: '1' }] }] },
|
|
2079
|
+
// { encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
2080
|
+
// ),
|
|
2081
|
+
// 'a[][b][][c]=1',
|
|
2082
|
+
// );
|
|
2083
|
+
// st.equal(
|
|
2084
|
+
// stringify(
|
|
2085
|
+
// { a: [, { b: [, , { c: '1' }] }] },
|
|
2086
|
+
// { encodeValuesOnly: true, arrayFormat: 'repeat' },
|
|
2087
|
+
// ),
|
|
2088
|
+
// 'a[b][c]=1',
|
|
2089
|
+
// );
|
|
2090
|
+
expect(
|
|
2091
|
+
stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
|
|
2092
|
+
).toBe('a[1][b][2][c]=1');
|
|
2093
|
+
expect(
|
|
2094
|
+
stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
2095
|
+
).toBe('a[][b][][c]=1');
|
|
2096
|
+
expect(
|
|
2097
|
+
stringify({ a: [, { b: [, , { c: '1' }] }] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),
|
|
2098
|
+
).toBe('a[b][c]=1');
|
|
2099
|
+
|
|
2100
|
+
// st.equal(
|
|
2101
|
+
// stringify(
|
|
2102
|
+
// { a: [, [, , [, , , { c: '1' }]]] },
|
|
2103
|
+
// { encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
2104
|
+
// ),
|
|
2105
|
+
// 'a[1][2][3][c]=1',
|
|
2106
|
+
// );
|
|
2107
|
+
// st.equal(
|
|
2108
|
+
// stringify(
|
|
2109
|
+
// { a: [, [, , [, , , { c: '1' }]]] },
|
|
2110
|
+
// { encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
2111
|
+
// ),
|
|
2112
|
+
// 'a[][][][c]=1',
|
|
2113
|
+
// );
|
|
2114
|
+
// st.equal(
|
|
2115
|
+
// stringify(
|
|
2116
|
+
// { a: [, [, , [, , , { c: '1' }]]] },
|
|
2117
|
+
// { encodeValuesOnly: true, arrayFormat: 'repeat' },
|
|
2118
|
+
// ),
|
|
2119
|
+
// 'a[c]=1',
|
|
2120
|
+
// );
|
|
2121
|
+
expect(
|
|
2122
|
+
stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
|
|
2123
|
+
).toBe('a[1][2][3][c]=1');
|
|
2124
|
+
expect(
|
|
2125
|
+
stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
2126
|
+
).toBe('a[][][][c]=1');
|
|
2127
|
+
expect(
|
|
2128
|
+
stringify({ a: [, [, , [, , , { c: '1' }]]] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),
|
|
2129
|
+
).toBe('a[c]=1');
|
|
2130
|
+
|
|
2131
|
+
// st.equal(
|
|
2132
|
+
// stringify(
|
|
2133
|
+
// { a: [, [, , [, , , { c: [, '1'] }]]] },
|
|
2134
|
+
// { encodeValuesOnly: true, arrayFormat: 'indices' },
|
|
2135
|
+
// ),
|
|
2136
|
+
// 'a[1][2][3][c][1]=1',
|
|
2137
|
+
// );
|
|
2138
|
+
// st.equal(
|
|
2139
|
+
// stringify(
|
|
2140
|
+
// { a: [, [, , [, , , { c: [, '1'] }]]] },
|
|
2141
|
+
// { encodeValuesOnly: true, arrayFormat: 'brackets' },
|
|
2142
|
+
// ),
|
|
2143
|
+
// 'a[][][][c][]=1',
|
|
2144
|
+
// );
|
|
2145
|
+
// st.equal(
|
|
2146
|
+
// stringify(
|
|
2147
|
+
// { a: [, [, , [, , , { c: [, '1'] }]]] },
|
|
2148
|
+
// { encodeValuesOnly: true, arrayFormat: 'repeat' },
|
|
2149
|
+
// ),
|
|
2150
|
+
// 'a[c]=1',
|
|
2151
|
+
// );
|
|
2152
|
+
expect(
|
|
2153
|
+
stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
|
|
2154
|
+
).toBe('a[1][2][3][c][1]=1');
|
|
2155
|
+
expect(
|
|
2156
|
+
stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
|
2157
|
+
).toBe('a[][][][c][]=1');
|
|
2158
|
+
expect(
|
|
2159
|
+
stringify({ a: [, [, , [, , , { c: [, '1'] }]]] }, { encodeValuesOnly: true, arrayFormat: 'repeat' }),
|
|
2160
|
+
).toBe('a[c]=1');
|
|
2161
|
+
});
|
|
2162
|
+
|
|
2163
|
+
test('encodes a very long string', function () {
|
|
2164
|
+
var chars = [];
|
|
2165
|
+
var expected = [];
|
|
2166
|
+
for (var i = 0; i < 5e3; i++) {
|
|
2167
|
+
chars.push(' ' + i);
|
|
2168
|
+
|
|
2169
|
+
expected.push('%20' + i);
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
var obj = {
|
|
2173
|
+
foo: chars.join(''),
|
|
2174
|
+
};
|
|
2175
|
+
|
|
2176
|
+
// st.equal(
|
|
2177
|
+
// stringify(obj, { arrayFormat: 'bracket', charset: 'utf-8' }),
|
|
2178
|
+
// 'foo=' + expected.join(''),
|
|
2179
|
+
// );
|
|
2180
|
+
// @ts-expect-error
|
|
2181
|
+
expect(stringify(obj, { arrayFormat: 'bracket', charset: 'utf-8' })).toBe('foo=' + expected.join(''));
|
|
2182
|
+
});
|
|
2183
|
+
});
|
|
2184
|
+
|
|
2185
|
+
describe('stringifies empty keys', function () {
|
|
2186
|
+
empty_test_cases.forEach(function (testCase) {
|
|
2187
|
+
test('stringifies an object with empty string key with ' + testCase.input, function () {
|
|
2188
|
+
// st.deepEqual(
|
|
2189
|
+
// stringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'indices' }),
|
|
2190
|
+
// testCase.stringifyOutput.indices,
|
|
2191
|
+
// 'test case: ' + testCase.input + ', indices',
|
|
2192
|
+
// );
|
|
2193
|
+
// st.deepEqual(
|
|
2194
|
+
// stringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'brackets' }),
|
|
2195
|
+
// testCase.stringifyOutput.brackets,
|
|
2196
|
+
// 'test case: ' + testCase.input + ', brackets',
|
|
2197
|
+
// );
|
|
2198
|
+
// st.deepEqual(
|
|
2199
|
+
// stringify(testCase.withEmptyKeys, { encode: false, arrayFormat: 'repeat' }),
|
|
2200
|
+
// testCase.stringifyOutput.repeat,
|
|
2201
|
+
// 'test case: ' + testCase.input + ', repeat',
|
|
2202
|
+
// );
|
|
2203
|
+
expect(stringify(testCase.with_empty_keys, { encode: false, arrayFormat: 'indices' })).toBe(
|
|
2204
|
+
testCase.stringify_output.indices,
|
|
2205
|
+
);
|
|
2206
|
+
expect(stringify(testCase.with_empty_keys, { encode: false, arrayFormat: 'brackets' })).toBe(
|
|
2207
|
+
testCase.stringify_output.brackets,
|
|
2208
|
+
);
|
|
2209
|
+
expect(stringify(testCase.with_empty_keys, { encode: false, arrayFormat: 'repeat' })).toBe(
|
|
2210
|
+
testCase.stringify_output.repeat,
|
|
2211
|
+
);
|
|
2212
|
+
});
|
|
2213
|
+
});
|
|
2214
|
+
|
|
2215
|
+
test('edge case with object/arrays', function () {
|
|
2216
|
+
// st.deepEqual(stringify({ '': { '': [2, 3] } }, { encode: false }), '[][0]=2&[][1]=3');
|
|
2217
|
+
// st.deepEqual(
|
|
2218
|
+
// stringify({ '': { '': [2, 3], a: 2 } }, { encode: false }),
|
|
2219
|
+
// '[][0]=2&[][1]=3&[a]=2',
|
|
2220
|
+
// );
|
|
2221
|
+
// st.deepEqual(
|
|
2222
|
+
// stringify({ '': { '': [2, 3] } }, { encode: false, arrayFormat: 'indices' }),
|
|
2223
|
+
// '[][0]=2&[][1]=3',
|
|
2224
|
+
// );
|
|
2225
|
+
// st.deepEqual(
|
|
2226
|
+
// stringify({ '': { '': [2, 3], a: 2 } }, { encode: false, arrayFormat: 'indices' }),
|
|
2227
|
+
// '[][0]=2&[][1]=3&[a]=2',
|
|
2228
|
+
// );
|
|
2229
|
+
expect(stringify({ '': { '': [2, 3] } }, { encode: false })).toBe('[][0]=2&[][1]=3');
|
|
2230
|
+
expect(stringify({ '': { '': [2, 3], a: 2 } }, { encode: false })).toBe('[][0]=2&[][1]=3&[a]=2');
|
|
2231
|
+
expect(stringify({ '': { '': [2, 3] } }, { encode: false, arrayFormat: 'indices' })).toBe(
|
|
2232
|
+
'[][0]=2&[][1]=3',
|
|
2233
|
+
);
|
|
2234
|
+
expect(stringify({ '': { '': [2, 3], a: 2 } }, { encode: false, arrayFormat: 'indices' })).toBe(
|
|
2235
|
+
'[][0]=2&[][1]=3&[a]=2',
|
|
2236
|
+
);
|
|
2237
|
+
});
|
|
2238
|
+
});
|