es6-crawler-detect 3.1.3 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +18 -17
- package/.eslintignore +6 -0
- package/.eslintrc.json +30 -0
- package/.github/FUNDING.yml +12 -12
- package/.github/ISSUE_TEMPLATE/bug_report.md +41 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -20
- package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +29 -0
- package/.prettierrc.json +5 -0
- package/CODE_OF_CONDUCT.md +76 -76
- package/LICENSE +21 -21
- package/README.md +103 -93
- package/dist/main.bundle.js +1 -1
- package/example/node/dist/crawler.min.js +1 -1
- package/example/node/index.html +21 -21
- package/example/node/node_modules/.bin/mime +15 -0
- package/example/node/node_modules/.bin/mime.cmd +7 -0
- package/example/node/node_modules/.yarn-integrity +67 -0
- package/example/node/node_modules/accepts/HISTORY.md +236 -0
- package/example/node/node_modules/accepts/LICENSE +23 -0
- package/example/node/node_modules/accepts/README.md +142 -0
- package/example/node/node_modules/accepts/index.js +238 -0
- package/example/node/node_modules/accepts/package.json +47 -0
- package/example/node/node_modules/array-flatten/LICENSE +21 -0
- package/example/node/node_modules/array-flatten/README.md +43 -0
- package/example/node/node_modules/array-flatten/array-flatten.js +64 -0
- package/example/node/node_modules/array-flatten/package.json +39 -0
- package/example/node/node_modules/body-parser/HISTORY.md +624 -0
- package/example/node/node_modules/body-parser/LICENSE +23 -0
- package/example/node/node_modules/body-parser/README.md +456 -0
- package/example/node/node_modules/body-parser/index.js +157 -0
- package/example/node/node_modules/body-parser/lib/read.js +181 -0
- package/example/node/node_modules/body-parser/lib/types/json.js +230 -0
- package/example/node/node_modules/body-parser/lib/types/raw.js +101 -0
- package/example/node/node_modules/body-parser/lib/types/text.js +121 -0
- package/example/node/node_modules/body-parser/lib/types/urlencoded.js +284 -0
- package/example/node/node_modules/body-parser/package.json +52 -0
- package/example/node/node_modules/bytes/History.md +92 -0
- package/example/node/node_modules/bytes/LICENSE +23 -0
- package/example/node/node_modules/bytes/Readme.md +152 -0
- package/example/node/node_modules/bytes/index.js +166 -0
- package/example/node/node_modules/bytes/package.json +42 -0
- package/example/node/node_modules/content-disposition/HISTORY.md +60 -0
- package/example/node/node_modules/content-disposition/LICENSE +22 -0
- package/example/node/node_modules/content-disposition/README.md +142 -0
- package/example/node/node_modules/content-disposition/index.js +458 -0
- package/example/node/node_modules/content-disposition/package.json +44 -0
- package/example/node/node_modules/content-type/HISTORY.md +24 -0
- package/example/node/node_modules/content-type/LICENSE +22 -0
- package/example/node/node_modules/content-type/README.md +92 -0
- package/example/node/node_modules/content-type/index.js +222 -0
- package/example/node/node_modules/content-type/package.json +40 -0
- package/example/node/node_modules/cookie/HISTORY.md +128 -0
- package/example/node/node_modules/cookie/LICENSE +24 -0
- package/example/node/node_modules/cookie/README.md +257 -0
- package/example/node/node_modules/cookie/index.js +202 -0
- package/example/node/node_modules/cookie/package.json +40 -0
- package/example/node/node_modules/cookie-signature/History.md +38 -0
- package/example/node/node_modules/cookie-signature/Readme.md +42 -0
- package/example/node/node_modules/cookie-signature/index.js +51 -0
- package/example/node/node_modules/cookie-signature/package.json +18 -0
- package/example/node/node_modules/debug/.coveralls.yml +1 -0
- package/example/node/node_modules/debug/.eslintrc +11 -0
- package/example/node/node_modules/debug/.travis.yml +14 -0
- package/example/node/node_modules/debug/CHANGELOG.md +362 -0
- package/example/node/node_modules/debug/LICENSE +19 -0
- package/example/node/node_modules/debug/Makefile +50 -0
- package/example/node/node_modules/debug/README.md +312 -0
- package/example/node/node_modules/debug/component.json +19 -0
- package/example/node/node_modules/debug/karma.conf.js +70 -0
- package/example/node/node_modules/debug/node.js +1 -0
- package/example/node/node_modules/debug/package.json +49 -0
- package/example/node/node_modules/debug/src/browser.js +185 -0
- package/example/node/node_modules/debug/src/debug.js +202 -0
- package/example/node/node_modules/debug/src/index.js +10 -0
- package/example/node/node_modules/debug/src/inspector-log.js +15 -0
- package/example/node/node_modules/debug/src/node.js +248 -0
- package/example/node/node_modules/depd/History.md +96 -0
- package/example/node/node_modules/depd/LICENSE +22 -0
- package/example/node/node_modules/depd/Readme.md +280 -0
- package/example/node/node_modules/depd/index.js +522 -0
- package/example/node/node_modules/depd/lib/browser/index.js +77 -0
- package/example/node/node_modules/depd/lib/compat/callsite-tostring.js +103 -0
- package/example/node/node_modules/depd/lib/compat/event-listener-count.js +22 -0
- package/example/node/node_modules/depd/lib/compat/index.js +79 -0
- package/example/node/node_modules/depd/package.json +41 -0
- package/example/node/node_modules/destroy/LICENSE +22 -0
- package/example/node/node_modules/destroy/README.md +60 -0
- package/example/node/node_modules/destroy/index.js +75 -0
- package/example/node/node_modules/destroy/package.json +37 -0
- package/example/node/node_modules/ee-first/LICENSE +22 -0
- package/example/node/node_modules/ee-first/README.md +80 -0
- package/example/node/node_modules/ee-first/index.js +95 -0
- package/example/node/node_modules/ee-first/package.json +29 -0
- package/example/node/node_modules/encodeurl/HISTORY.md +14 -0
- package/example/node/node_modules/encodeurl/LICENSE +22 -0
- package/example/node/node_modules/encodeurl/README.md +128 -0
- package/example/node/node_modules/encodeurl/index.js +60 -0
- package/example/node/node_modules/encodeurl/package.json +40 -0
- package/example/node/node_modules/escape-html/LICENSE +24 -0
- package/example/node/node_modules/escape-html/Readme.md +43 -0
- package/example/node/node_modules/escape-html/index.js +78 -0
- package/example/node/node_modules/escape-html/package.json +24 -0
- package/example/node/node_modules/etag/HISTORY.md +83 -0
- package/example/node/node_modules/etag/LICENSE +22 -0
- package/example/node/node_modules/etag/README.md +159 -0
- package/example/node/node_modules/etag/index.js +131 -0
- package/example/node/node_modules/etag/package.json +47 -0
- package/example/node/node_modules/express/History.md +3510 -0
- package/example/node/node_modules/express/LICENSE +24 -0
- package/example/node/node_modules/express/Readme.md +158 -0
- package/example/node/node_modules/express/index.js +11 -0
- package/example/node/node_modules/express/lib/application.js +644 -0
- package/example/node/node_modules/express/lib/express.js +116 -0
- package/example/node/node_modules/express/lib/middleware/init.js +43 -0
- package/example/node/node_modules/express/lib/middleware/query.js +47 -0
- package/example/node/node_modules/express/lib/request.js +525 -0
- package/example/node/node_modules/express/lib/response.js +1147 -0
- package/example/node/node_modules/express/lib/router/index.js +668 -0
- package/example/node/node_modules/express/lib/router/layer.js +181 -0
- package/example/node/node_modules/express/lib/router/route.js +216 -0
- package/example/node/node_modules/express/lib/utils.js +302 -0
- package/example/node/node_modules/express/lib/view.js +182 -0
- package/example/node/node_modules/express/package.json +99 -0
- package/example/node/node_modules/finalhandler/HISTORY.md +187 -0
- package/example/node/node_modules/finalhandler/LICENSE +22 -0
- package/example/node/node_modules/finalhandler/README.md +148 -0
- package/example/node/node_modules/finalhandler/index.js +331 -0
- package/example/node/node_modules/finalhandler/package.json +45 -0
- package/example/node/node_modules/forwarded/HISTORY.md +21 -0
- package/example/node/node_modules/forwarded/LICENSE +22 -0
- package/example/node/node_modules/forwarded/README.md +57 -0
- package/example/node/node_modules/forwarded/index.js +90 -0
- package/example/node/node_modules/forwarded/package.json +45 -0
- package/example/node/node_modules/fresh/HISTORY.md +70 -0
- package/example/node/node_modules/fresh/LICENSE +23 -0
- package/example/node/node_modules/fresh/README.md +119 -0
- package/example/node/node_modules/fresh/index.js +137 -0
- package/example/node/node_modules/fresh/package.json +46 -0
- package/example/node/node_modules/http-errors/HISTORY.md +165 -0
- package/example/node/node_modules/http-errors/LICENSE +23 -0
- package/example/node/node_modules/http-errors/README.md +169 -0
- package/example/node/node_modules/http-errors/index.js +299 -0
- package/example/node/node_modules/http-errors/package.json +49 -0
- package/example/node/node_modules/iconv-lite/Changelog.md +162 -0
- package/example/node/node_modules/iconv-lite/LICENSE +21 -0
- package/example/node/node_modules/iconv-lite/README.md +156 -0
- package/example/node/node_modules/iconv-lite/encodings/dbcs-codec.js +555 -0
- package/example/node/node_modules/iconv-lite/encodings/dbcs-data.js +176 -0
- package/example/node/node_modules/iconv-lite/encodings/index.js +22 -0
- package/example/node/node_modules/iconv-lite/encodings/internal.js +188 -0
- package/example/node/node_modules/iconv-lite/encodings/sbcs-codec.js +72 -0
- package/example/node/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
- package/example/node/node_modules/iconv-lite/encodings/sbcs-data.js +174 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/gbk-added.json +55 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
- package/example/node/node_modules/iconv-lite/encodings/utf16.js +177 -0
- package/example/node/node_modules/iconv-lite/encodings/utf7.js +290 -0
- package/example/node/node_modules/iconv-lite/lib/bom-handling.js +52 -0
- package/example/node/node_modules/iconv-lite/lib/extend-node.js +217 -0
- package/example/node/node_modules/iconv-lite/lib/index.d.ts +24 -0
- package/example/node/node_modules/iconv-lite/lib/index.js +153 -0
- package/example/node/node_modules/iconv-lite/lib/streams.js +121 -0
- package/example/node/node_modules/iconv-lite/package.json +46 -0
- package/example/node/node_modules/inherits/LICENSE +16 -0
- package/example/node/node_modules/inherits/README.md +42 -0
- package/example/node/node_modules/inherits/inherits.js +9 -0
- package/example/node/node_modules/inherits/inherits_browser.js +27 -0
- package/example/node/node_modules/inherits/package.json +29 -0
- package/example/node/node_modules/ipaddr.js/LICENSE +19 -0
- package/example/node/node_modules/ipaddr.js/README.md +233 -0
- package/example/node/node_modules/ipaddr.js/ipaddr.min.js +1 -0
- package/example/node/node_modules/ipaddr.js/lib/ipaddr.js +673 -0
- package/example/node/node_modules/ipaddr.js/lib/ipaddr.js.d.ts +68 -0
- package/example/node/node_modules/ipaddr.js/package.json +35 -0
- package/example/node/node_modules/media-typer/HISTORY.md +22 -0
- package/example/node/node_modules/media-typer/LICENSE +22 -0
- package/example/node/node_modules/media-typer/README.md +81 -0
- package/example/node/node_modules/media-typer/index.js +270 -0
- package/example/node/node_modules/media-typer/package.json +26 -0
- package/example/node/node_modules/merge-descriptors/HISTORY.md +21 -0
- package/example/node/node_modules/merge-descriptors/LICENSE +23 -0
- package/example/node/node_modules/merge-descriptors/README.md +48 -0
- package/example/node/node_modules/merge-descriptors/index.js +60 -0
- package/example/node/node_modules/merge-descriptors/package.json +32 -0
- package/example/node/node_modules/methods/HISTORY.md +29 -0
- package/example/node/node_modules/methods/LICENSE +24 -0
- package/example/node/node_modules/methods/README.md +51 -0
- package/example/node/node_modules/methods/index.js +69 -0
- package/example/node/node_modules/methods/package.json +36 -0
- package/example/node/node_modules/mime/CHANGELOG.md +164 -0
- package/example/node/node_modules/mime/LICENSE +21 -0
- package/example/node/node_modules/mime/README.md +90 -0
- package/example/node/node_modules/mime/cli.js +8 -0
- package/example/node/node_modules/mime/mime.js +108 -0
- package/example/node/node_modules/mime/package.json +44 -0
- package/example/node/node_modules/mime/src/build.js +53 -0
- package/example/node/node_modules/mime/src/test.js +60 -0
- package/example/node/node_modules/mime/types.json +1 -0
- package/example/node/node_modules/mime-db/HISTORY.md +499 -0
- package/example/node/node_modules/mime-db/LICENSE +22 -0
- package/example/node/node_modules/mime-db/README.md +100 -0
- package/example/node/node_modules/mime-db/db.json +8471 -0
- package/example/node/node_modules/mime-db/index.js +11 -0
- package/example/node/node_modules/mime-db/package.json +59 -0
- package/example/node/node_modules/mime-types/HISTORY.md +388 -0
- package/example/node/node_modules/mime-types/LICENSE +23 -0
- package/example/node/node_modules/mime-types/README.md +113 -0
- package/example/node/node_modules/mime-types/index.js +188 -0
- package/example/node/node_modules/mime-types/package.json +44 -0
- package/example/node/node_modules/ms/index.js +152 -0
- package/example/node/node_modules/ms/license.md +21 -0
- package/example/node/node_modules/ms/package.json +37 -0
- package/example/node/node_modules/ms/readme.md +51 -0
- package/example/node/node_modules/negotiator/HISTORY.md +103 -0
- package/example/node/node_modules/negotiator/LICENSE +24 -0
- package/example/node/node_modules/negotiator/README.md +203 -0
- package/example/node/node_modules/negotiator/index.js +124 -0
- package/example/node/node_modules/negotiator/lib/charset.js +169 -0
- package/example/node/node_modules/negotiator/lib/encoding.js +184 -0
- package/example/node/node_modules/negotiator/lib/language.js +179 -0
- package/example/node/node_modules/negotiator/lib/mediaType.js +294 -0
- package/example/node/node_modules/negotiator/package.json +42 -0
- package/example/node/node_modules/on-finished/HISTORY.md +88 -0
- package/example/node/node_modules/on-finished/LICENSE +23 -0
- package/example/node/node_modules/on-finished/README.md +154 -0
- package/example/node/node_modules/on-finished/index.js +196 -0
- package/example/node/node_modules/on-finished/package.json +31 -0
- package/example/node/node_modules/parseurl/HISTORY.md +58 -0
- package/example/node/node_modules/parseurl/LICENSE +24 -0
- package/example/node/node_modules/parseurl/README.md +133 -0
- package/example/node/node_modules/parseurl/index.js +158 -0
- package/example/node/node_modules/parseurl/package.json +40 -0
- package/example/node/node_modules/path-to-regexp/History.md +36 -0
- package/example/node/node_modules/path-to-regexp/LICENSE +21 -0
- package/example/node/node_modules/path-to-regexp/Readme.md +35 -0
- package/example/node/node_modules/path-to-regexp/index.js +129 -0
- package/example/node/node_modules/path-to-regexp/package.json +30 -0
- package/example/node/node_modules/proxy-addr/HISTORY.md +161 -0
- package/example/node/node_modules/proxy-addr/LICENSE +22 -0
- package/example/node/node_modules/proxy-addr/README.md +139 -0
- package/example/node/node_modules/proxy-addr/index.js +327 -0
- package/example/node/node_modules/proxy-addr/package.json +47 -0
- package/example/node/node_modules/qs/.editorconfig +39 -0
- package/example/node/node_modules/qs/.eslintignore +2 -0
- package/example/node/node_modules/qs/.eslintrc +35 -0
- package/example/node/node_modules/qs/.github/FUNDING.yml +12 -0
- package/example/node/node_modules/qs/.nycrc +13 -0
- package/example/node/node_modules/qs/CHANGELOG.md +359 -0
- package/example/node/node_modules/qs/LICENSE.md +29 -0
- package/example/node/node_modules/qs/README.md +604 -0
- package/example/node/node_modules/qs/dist/qs.js +832 -0
- package/example/node/node_modules/qs/lib/formats.js +23 -0
- package/example/node/node_modules/qs/lib/index.js +11 -0
- package/example/node/node_modules/qs/lib/parse.js +257 -0
- package/example/node/node_modules/qs/lib/stringify.js +278 -0
- package/example/node/node_modules/qs/lib/utils.js +251 -0
- package/example/node/node_modules/qs/package.json +69 -0
- package/example/node/node_modules/qs/test/parse.js +772 -0
- package/example/node/node_modules/qs/test/stringify.js +793 -0
- package/example/node/node_modules/qs/test/utils.js +136 -0
- package/example/node/node_modules/range-parser/HISTORY.md +56 -0
- package/example/node/node_modules/range-parser/LICENSE +23 -0
- package/example/node/node_modules/range-parser/README.md +84 -0
- package/example/node/node_modules/range-parser/index.js +162 -0
- package/example/node/node_modules/range-parser/package.json +44 -0
- package/example/node/node_modules/raw-body/HISTORY.md +284 -0
- package/example/node/node_modules/raw-body/LICENSE +22 -0
- package/example/node/node_modules/raw-body/README.md +217 -0
- package/example/node/node_modules/raw-body/index.d.ts +87 -0
- package/example/node/node_modules/raw-body/index.js +286 -0
- package/example/node/node_modules/raw-body/package.json +48 -0
- package/example/node/node_modules/safe-buffer/LICENSE +21 -0
- package/example/node/node_modules/safe-buffer/README.md +584 -0
- package/example/node/node_modules/safe-buffer/index.d.ts +187 -0
- package/example/node/node_modules/safe-buffer/index.js +65 -0
- package/example/node/node_modules/safe-buffer/package.json +51 -0
- package/example/node/node_modules/safer-buffer/LICENSE +21 -0
- package/example/node/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/example/node/node_modules/safer-buffer/Readme.md +156 -0
- package/example/node/node_modules/safer-buffer/dangerous.js +58 -0
- package/example/node/node_modules/safer-buffer/package.json +34 -0
- package/example/node/node_modules/safer-buffer/safer.js +77 -0
- package/example/node/node_modules/safer-buffer/tests.js +406 -0
- package/example/node/node_modules/send/HISTORY.md +506 -0
- package/example/node/node_modules/send/LICENSE +23 -0
- package/example/node/node_modules/send/README.md +327 -0
- package/example/node/node_modules/send/index.js +1133 -0
- package/example/node/node_modules/send/node_modules/.bin/mime +15 -0
- package/example/node/node_modules/send/node_modules/.bin/mime.cmd +7 -0
- package/example/node/node_modules/send/node_modules/ms/index.js +162 -0
- package/example/node/node_modules/send/node_modules/ms/license.md +21 -0
- package/example/node/node_modules/send/node_modules/ms/package.json +38 -0
- package/example/node/node_modules/send/node_modules/ms/readme.md +59 -0
- package/example/node/node_modules/send/package.json +61 -0
- package/example/node/node_modules/serve-static/HISTORY.md +459 -0
- package/example/node/node_modules/serve-static/LICENSE +25 -0
- package/example/node/node_modules/serve-static/README.md +257 -0
- package/example/node/node_modules/serve-static/index.js +210 -0
- package/example/node/node_modules/serve-static/package.json +42 -0
- package/example/node/node_modules/setprototypeof/LICENSE +13 -0
- package/example/node/node_modules/setprototypeof/README.md +31 -0
- package/example/node/node_modules/setprototypeof/index.d.ts +2 -0
- package/example/node/node_modules/setprototypeof/index.js +17 -0
- package/example/node/node_modules/setprototypeof/package.json +38 -0
- package/example/node/node_modules/setprototypeof/test/index.js +24 -0
- package/example/node/node_modules/statuses/HISTORY.md +65 -0
- package/example/node/node_modules/statuses/LICENSE +23 -0
- package/example/node/node_modules/statuses/README.md +127 -0
- package/example/node/node_modules/statuses/codes.json +66 -0
- package/example/node/node_modules/statuses/index.js +113 -0
- package/example/node/node_modules/statuses/package.json +48 -0
- package/example/node/node_modules/toidentifier/HISTORY.md +9 -0
- package/example/node/node_modules/toidentifier/LICENSE +21 -0
- package/example/node/node_modules/toidentifier/README.md +61 -0
- package/example/node/node_modules/toidentifier/index.js +32 -0
- package/example/node/node_modules/toidentifier/package.json +38 -0
- package/example/node/node_modules/type-is/HISTORY.md +259 -0
- package/example/node/node_modules/type-is/LICENSE +23 -0
- package/example/node/node_modules/type-is/README.md +170 -0
- package/example/node/node_modules/type-is/index.js +266 -0
- package/example/node/node_modules/type-is/package.json +45 -0
- package/example/node/node_modules/unpipe/HISTORY.md +4 -0
- package/example/node/node_modules/unpipe/LICENSE +22 -0
- package/example/node/node_modules/unpipe/README.md +43 -0
- package/example/node/node_modules/unpipe/index.js +69 -0
- package/example/node/node_modules/unpipe/package.json +27 -0
- package/example/node/node_modules/utils-merge/LICENSE +20 -0
- package/example/node/node_modules/utils-merge/README.md +34 -0
- package/example/node/node_modules/utils-merge/index.js +23 -0
- package/example/node/node_modules/utils-merge/package.json +40 -0
- package/example/node/node_modules/vary/HISTORY.md +39 -0
- package/example/node/node_modules/vary/LICENSE +22 -0
- package/example/node/node_modules/vary/README.md +101 -0
- package/example/node/node_modules/vary/index.js +149 -0
- package/example/node/node_modules/vary/package.json +43 -0
- package/example/node/package.json +11 -0
- package/example/node/server.js +21 -15
- package/example/node/yarn.lock +352 -0
- package/package.json +59 -47
- package/src/index.js +15 -10
- package/src/lib/crawler/crawlers.js +1398 -11
- package/src/lib/crawler/exclusions.js +55 -8
- package/src/lib/crawler/headers.js +18 -9
- package/src/lib/crawler/provider.js +6 -8
- package/src/lib/crawler.js +101 -90
- package/test/lib/crawler.test.js +43 -26
- package/webpack.common.js +7 -7
- package/webpack.dev.js +4 -4
- package/webpack.prod.js +8 -9
@@ -0,0 +1,793 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var test = require('tape');
|
4
|
+
var qs = require('../');
|
5
|
+
var utils = require('../lib/utils');
|
6
|
+
var iconv = require('iconv-lite');
|
7
|
+
var SaferBuffer = require('safer-buffer').Buffer;
|
8
|
+
var hasSymbols = require('has-symbols');
|
9
|
+
var hasBigInt = typeof BigInt === 'function';
|
10
|
+
|
11
|
+
test('stringify()', function (t) {
|
12
|
+
t.test('stringifies a querystring object', function (st) {
|
13
|
+
st.equal(qs.stringify({ a: 'b' }), 'a=b');
|
14
|
+
st.equal(qs.stringify({ a: 1 }), 'a=1');
|
15
|
+
st.equal(qs.stringify({ a: 1, b: 2 }), 'a=1&b=2');
|
16
|
+
st.equal(qs.stringify({ a: 'A_Z' }), 'a=A_Z');
|
17
|
+
st.equal(qs.stringify({ a: '€' }), 'a=%E2%82%AC');
|
18
|
+
st.equal(qs.stringify({ a: '' }), 'a=%EE%80%80');
|
19
|
+
st.equal(qs.stringify({ a: 'א' }), 'a=%D7%90');
|
20
|
+
st.equal(qs.stringify({ a: '𐐷' }), 'a=%F0%90%90%B7');
|
21
|
+
st.end();
|
22
|
+
});
|
23
|
+
|
24
|
+
t.test('stringifies falsy values', function (st) {
|
25
|
+
st.equal(qs.stringify(undefined), '');
|
26
|
+
st.equal(qs.stringify(null), '');
|
27
|
+
st.equal(qs.stringify(null, { strictNullHandling: true }), '');
|
28
|
+
st.equal(qs.stringify(false), '');
|
29
|
+
st.equal(qs.stringify(0), '');
|
30
|
+
st.end();
|
31
|
+
});
|
32
|
+
|
33
|
+
t.test('stringifies symbols', { skip: !hasSymbols() }, function (st) {
|
34
|
+
st.equal(qs.stringify(Symbol.iterator), '');
|
35
|
+
st.equal(qs.stringify([Symbol.iterator]), '0=Symbol%28Symbol.iterator%29');
|
36
|
+
st.equal(qs.stringify({ a: Symbol.iterator }), 'a=Symbol%28Symbol.iterator%29');
|
37
|
+
st.equal(
|
38
|
+
qs.stringify({ a: [Symbol.iterator] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
39
|
+
'a[]=Symbol%28Symbol.iterator%29'
|
40
|
+
);
|
41
|
+
st.end();
|
42
|
+
});
|
43
|
+
|
44
|
+
t.test('stringifies bigints', { skip: !hasBigInt }, function (st) {
|
45
|
+
var three = BigInt(3);
|
46
|
+
var encodeWithN = function (value, defaultEncoder, charset) {
|
47
|
+
var result = defaultEncoder(value, defaultEncoder, charset);
|
48
|
+
return typeof value === 'bigint' ? result + 'n' : result;
|
49
|
+
};
|
50
|
+
st.equal(qs.stringify(three), '');
|
51
|
+
st.equal(qs.stringify([three]), '0=3');
|
52
|
+
st.equal(qs.stringify([three], { encoder: encodeWithN }), '0=3n');
|
53
|
+
st.equal(qs.stringify({ a: three }), 'a=3');
|
54
|
+
st.equal(qs.stringify({ a: three }, { encoder: encodeWithN }), 'a=3n');
|
55
|
+
st.equal(
|
56
|
+
qs.stringify({ a: [three] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
|
57
|
+
'a[]=3'
|
58
|
+
);
|
59
|
+
st.equal(
|
60
|
+
qs.stringify({ a: [three] }, { encodeValuesOnly: true, encoder: encodeWithN, arrayFormat: 'brackets' }),
|
61
|
+
'a[]=3n'
|
62
|
+
);
|
63
|
+
st.end();
|
64
|
+
});
|
65
|
+
|
66
|
+
t.test('adds query prefix', function (st) {
|
67
|
+
st.equal(qs.stringify({ a: 'b' }, { addQueryPrefix: true }), '?a=b');
|
68
|
+
st.end();
|
69
|
+
});
|
70
|
+
|
71
|
+
t.test('with query prefix, outputs blank string given an empty object', function (st) {
|
72
|
+
st.equal(qs.stringify({}, { addQueryPrefix: true }), '');
|
73
|
+
st.end();
|
74
|
+
});
|
75
|
+
|
76
|
+
t.test('stringifies nested falsy values', function (st) {
|
77
|
+
st.equal(qs.stringify({ a: { b: { c: null } } }), 'a%5Bb%5D%5Bc%5D=');
|
78
|
+
st.equal(qs.stringify({ a: { b: { c: null } } }, { strictNullHandling: true }), 'a%5Bb%5D%5Bc%5D');
|
79
|
+
st.equal(qs.stringify({ a: { b: { c: false } } }), 'a%5Bb%5D%5Bc%5D=false');
|
80
|
+
st.end();
|
81
|
+
});
|
82
|
+
|
83
|
+
t.test('stringifies a nested object', function (st) {
|
84
|
+
st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
|
85
|
+
st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }), 'a%5Bb%5D%5Bc%5D%5Bd%5D=e');
|
86
|
+
st.end();
|
87
|
+
});
|
88
|
+
|
89
|
+
t.test('stringifies a nested object with dots notation', function (st) {
|
90
|
+
st.equal(qs.stringify({ a: { b: 'c' } }, { allowDots: true }), 'a.b=c');
|
91
|
+
st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }, { allowDots: true }), 'a.b.c.d=e');
|
92
|
+
st.end();
|
93
|
+
});
|
94
|
+
|
95
|
+
t.test('stringifies an array value', function (st) {
|
96
|
+
st.equal(
|
97
|
+
qs.stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'indices' }),
|
98
|
+
'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',
|
99
|
+
'indices => indices'
|
100
|
+
);
|
101
|
+
st.equal(
|
102
|
+
qs.stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'brackets' }),
|
103
|
+
'a%5B%5D=b&a%5B%5D=c&a%5B%5D=d',
|
104
|
+
'brackets => brackets'
|
105
|
+
);
|
106
|
+
st.equal(
|
107
|
+
qs.stringify({ a: ['b', 'c', 'd'] }, { arrayFormat: 'comma' }),
|
108
|
+
'a=b%2Cc%2Cd',
|
109
|
+
'comma => comma'
|
110
|
+
);
|
111
|
+
st.equal(
|
112
|
+
qs.stringify({ a: ['b', 'c', 'd'] }),
|
113
|
+
'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d',
|
114
|
+
'default => indices'
|
115
|
+
);
|
116
|
+
st.end();
|
117
|
+
});
|
118
|
+
|
119
|
+
t.test('omits nulls when asked', function (st) {
|
120
|
+
st.equal(qs.stringify({ a: 'b', c: null }, { skipNulls: true }), 'a=b');
|
121
|
+
st.end();
|
122
|
+
});
|
123
|
+
|
124
|
+
t.test('omits nested nulls when asked', function (st) {
|
125
|
+
st.equal(qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true }), 'a%5Bb%5D=c');
|
126
|
+
st.end();
|
127
|
+
});
|
128
|
+
|
129
|
+
t.test('omits array indices when asked', function (st) {
|
130
|
+
st.equal(qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false }), 'a=b&a=c&a=d');
|
131
|
+
st.end();
|
132
|
+
});
|
133
|
+
|
134
|
+
t.test('stringifies a nested array value', function (st) {
|
135
|
+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { arrayFormat: 'indices' }), 'a%5Bb%5D%5B0%5D=c&a%5Bb%5D%5B1%5D=d');
|
136
|
+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { arrayFormat: 'brackets' }), 'a%5Bb%5D%5B%5D=c&a%5Bb%5D%5B%5D=d');
|
137
|
+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { arrayFormat: 'comma' }), 'a%5Bb%5D=c%2Cd'); // a[b]=c,d
|
138
|
+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }), 'a%5Bb%5D%5B0%5D=c&a%5Bb%5D%5B1%5D=d');
|
139
|
+
st.end();
|
140
|
+
});
|
141
|
+
|
142
|
+
t.test('stringifies a nested array value with dots notation', function (st) {
|
143
|
+
st.equal(
|
144
|
+
qs.stringify(
|
145
|
+
{ a: { b: ['c', 'd'] } },
|
146
|
+
{ allowDots: true, encode: false, arrayFormat: 'indices' }
|
147
|
+
),
|
148
|
+
'a.b[0]=c&a.b[1]=d',
|
149
|
+
'indices: stringifies with dots + indices'
|
150
|
+
);
|
151
|
+
st.equal(
|
152
|
+
qs.stringify(
|
153
|
+
{ a: { b: ['c', 'd'] } },
|
154
|
+
{ allowDots: true, encode: false, arrayFormat: 'brackets' }
|
155
|
+
),
|
156
|
+
'a.b[]=c&a.b[]=d',
|
157
|
+
'brackets: stringifies with dots + brackets'
|
158
|
+
);
|
159
|
+
st.equal(
|
160
|
+
qs.stringify(
|
161
|
+
{ a: { b: ['c', 'd'] } },
|
162
|
+
{ allowDots: true, encode: false, arrayFormat: 'comma' }
|
163
|
+
),
|
164
|
+
'a.b=c,d',
|
165
|
+
'comma: stringifies with dots + comma'
|
166
|
+
);
|
167
|
+
st.equal(
|
168
|
+
qs.stringify(
|
169
|
+
{ a: { b: ['c', 'd'] } },
|
170
|
+
{ allowDots: true, encode: false }
|
171
|
+
),
|
172
|
+
'a.b[0]=c&a.b[1]=d',
|
173
|
+
'default: stringifies with dots + indices'
|
174
|
+
);
|
175
|
+
st.end();
|
176
|
+
});
|
177
|
+
|
178
|
+
t.test('stringifies an object inside an array', function (st) {
|
179
|
+
st.equal(
|
180
|
+
qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'indices' }),
|
181
|
+
'a%5B0%5D%5Bb%5D=c', // a[0][b]=c
|
182
|
+
'indices => brackets'
|
183
|
+
);
|
184
|
+
st.equal(
|
185
|
+
qs.stringify({ a: [{ b: 'c' }] }, { arrayFormat: 'brackets' }),
|
186
|
+
'a%5B%5D%5Bb%5D=c', // a[][b]=c
|
187
|
+
'brackets => brackets'
|
188
|
+
);
|
189
|
+
st.equal(
|
190
|
+
qs.stringify({ a: [{ b: 'c' }] }),
|
191
|
+
'a%5B0%5D%5Bb%5D=c',
|
192
|
+
'default => indices'
|
193
|
+
);
|
194
|
+
|
195
|
+
st.equal(
|
196
|
+
qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'indices' }),
|
197
|
+
'a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1',
|
198
|
+
'indices => indices'
|
199
|
+
);
|
200
|
+
|
201
|
+
st.equal(
|
202
|
+
qs.stringify({ a: [{ b: { c: [1] } }] }, { arrayFormat: 'brackets' }),
|
203
|
+
'a%5B%5D%5Bb%5D%5Bc%5D%5B%5D=1',
|
204
|
+
'brackets => brackets'
|
205
|
+
);
|
206
|
+
|
207
|
+
st.equal(
|
208
|
+
qs.stringify({ a: [{ b: { c: [1] } }] }),
|
209
|
+
'a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1',
|
210
|
+
'default => indices'
|
211
|
+
);
|
212
|
+
|
213
|
+
st.end();
|
214
|
+
});
|
215
|
+
|
216
|
+
t.test('stringifies an array with mixed objects and primitives', function (st) {
|
217
|
+
st.equal(
|
218
|
+
qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encode: false, arrayFormat: 'indices' }),
|
219
|
+
'a[0][b]=1&a[1]=2&a[2]=3',
|
220
|
+
'indices => indices'
|
221
|
+
);
|
222
|
+
st.equal(
|
223
|
+
qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encode: false, arrayFormat: 'brackets' }),
|
224
|
+
'a[][b]=1&a[]=2&a[]=3',
|
225
|
+
'brackets => brackets'
|
226
|
+
);
|
227
|
+
st.equal(
|
228
|
+
qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encode: false }),
|
229
|
+
'a[0][b]=1&a[1]=2&a[2]=3',
|
230
|
+
'default => indices'
|
231
|
+
);
|
232
|
+
|
233
|
+
st.end();
|
234
|
+
});
|
235
|
+
|
236
|
+
t.test('stringifies an object inside an array with dots notation', function (st) {
|
237
|
+
st.equal(
|
238
|
+
qs.stringify(
|
239
|
+
{ a: [{ b: 'c' }] },
|
240
|
+
{ allowDots: true, encode: false, arrayFormat: 'indices' }
|
241
|
+
),
|
242
|
+
'a[0].b=c',
|
243
|
+
'indices => indices'
|
244
|
+
);
|
245
|
+
st.equal(
|
246
|
+
qs.stringify(
|
247
|
+
{ a: [{ b: 'c' }] },
|
248
|
+
{ allowDots: true, encode: false, arrayFormat: 'brackets' }
|
249
|
+
),
|
250
|
+
'a[].b=c',
|
251
|
+
'brackets => brackets'
|
252
|
+
);
|
253
|
+
st.equal(
|
254
|
+
qs.stringify(
|
255
|
+
{ a: [{ b: 'c' }] },
|
256
|
+
{ allowDots: true, encode: false }
|
257
|
+
),
|
258
|
+
'a[0].b=c',
|
259
|
+
'default => indices'
|
260
|
+
);
|
261
|
+
|
262
|
+
st.equal(
|
263
|
+
qs.stringify(
|
264
|
+
{ a: [{ b: { c: [1] } }] },
|
265
|
+
{ allowDots: true, encode: false, arrayFormat: 'indices' }
|
266
|
+
),
|
267
|
+
'a[0].b.c[0]=1',
|
268
|
+
'indices => indices'
|
269
|
+
);
|
270
|
+
st.equal(
|
271
|
+
qs.stringify(
|
272
|
+
{ a: [{ b: { c: [1] } }] },
|
273
|
+
{ allowDots: true, encode: false, arrayFormat: 'brackets' }
|
274
|
+
),
|
275
|
+
'a[].b.c[]=1',
|
276
|
+
'brackets => brackets'
|
277
|
+
);
|
278
|
+
st.equal(
|
279
|
+
qs.stringify(
|
280
|
+
{ a: [{ b: { c: [1] } }] },
|
281
|
+
{ allowDots: true, encode: false }
|
282
|
+
),
|
283
|
+
'a[0].b.c[0]=1',
|
284
|
+
'default => indices'
|
285
|
+
);
|
286
|
+
|
287
|
+
st.end();
|
288
|
+
});
|
289
|
+
|
290
|
+
t.test('does not omit object keys when indices = false', function (st) {
|
291
|
+
st.equal(qs.stringify({ a: [{ b: 'c' }] }, { indices: false }), 'a%5Bb%5D=c');
|
292
|
+
st.end();
|
293
|
+
});
|
294
|
+
|
295
|
+
t.test('uses indices notation for arrays when indices=true', function (st) {
|
296
|
+
st.equal(qs.stringify({ a: ['b', 'c'] }, { indices: true }), 'a%5B0%5D=b&a%5B1%5D=c');
|
297
|
+
st.end();
|
298
|
+
});
|
299
|
+
|
300
|
+
t.test('uses indices notation for arrays when no arrayFormat is specified', function (st) {
|
301
|
+
st.equal(qs.stringify({ a: ['b', 'c'] }), 'a%5B0%5D=b&a%5B1%5D=c');
|
302
|
+
st.end();
|
303
|
+
});
|
304
|
+
|
305
|
+
t.test('uses indices notation for arrays when no arrayFormat=indices', function (st) {
|
306
|
+
st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' }), 'a%5B0%5D=b&a%5B1%5D=c');
|
307
|
+
st.end();
|
308
|
+
});
|
309
|
+
|
310
|
+
t.test('uses repeat notation for arrays when no arrayFormat=repeat', function (st) {
|
311
|
+
st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' }), 'a=b&a=c');
|
312
|
+
st.end();
|
313
|
+
});
|
314
|
+
|
315
|
+
t.test('uses brackets notation for arrays when no arrayFormat=brackets', function (st) {
|
316
|
+
st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' }), 'a%5B%5D=b&a%5B%5D=c');
|
317
|
+
st.end();
|
318
|
+
});
|
319
|
+
|
320
|
+
t.test('stringifies a complicated object', function (st) {
|
321
|
+
st.equal(qs.stringify({ a: { b: 'c', d: 'e' } }), 'a%5Bb%5D=c&a%5Bd%5D=e');
|
322
|
+
st.end();
|
323
|
+
});
|
324
|
+
|
325
|
+
t.test('stringifies an empty value', function (st) {
|
326
|
+
st.equal(qs.stringify({ a: '' }), 'a=');
|
327
|
+
st.equal(qs.stringify({ a: null }, { strictNullHandling: true }), 'a');
|
328
|
+
|
329
|
+
st.equal(qs.stringify({ a: '', b: '' }), 'a=&b=');
|
330
|
+
st.equal(qs.stringify({ a: null, b: '' }, { strictNullHandling: true }), 'a&b=');
|
331
|
+
|
332
|
+
st.equal(qs.stringify({ a: { b: '' } }), 'a%5Bb%5D=');
|
333
|
+
st.equal(qs.stringify({ a: { b: null } }, { strictNullHandling: true }), 'a%5Bb%5D');
|
334
|
+
st.equal(qs.stringify({ a: { b: null } }, { strictNullHandling: false }), 'a%5Bb%5D=');
|
335
|
+
|
336
|
+
st.end();
|
337
|
+
});
|
338
|
+
|
339
|
+
t.test('stringifies an empty array in different arrayFormat', function (st) {
|
340
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false }), 'b[0]=&c=c');
|
341
|
+
// arrayFormat default
|
342
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices' }), 'b[0]=&c=c');
|
343
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets' }), 'b[]=&c=c');
|
344
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat' }), 'b=&c=c');
|
345
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma' }), 'b=&c=c');
|
346
|
+
// with strictNullHandling
|
347
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices', strictNullHandling: true }), 'b[0]&c=c');
|
348
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets', strictNullHandling: true }), 'b[]&c=c');
|
349
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat', strictNullHandling: true }), 'b&c=c');
|
350
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', strictNullHandling: true }), 'b&c=c');
|
351
|
+
// with skipNulls
|
352
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices', skipNulls: true }), 'c=c');
|
353
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets', skipNulls: true }), 'c=c');
|
354
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat', skipNulls: true }), 'c=c');
|
355
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', skipNulls: true }), 'c=c');
|
356
|
+
|
357
|
+
st.end();
|
358
|
+
});
|
359
|
+
|
360
|
+
t.test('stringifies a null object', { skip: !Object.create }, function (st) {
|
361
|
+
var obj = Object.create(null);
|
362
|
+
obj.a = 'b';
|
363
|
+
st.equal(qs.stringify(obj), 'a=b');
|
364
|
+
st.end();
|
365
|
+
});
|
366
|
+
|
367
|
+
t.test('returns an empty string for invalid input', function (st) {
|
368
|
+
st.equal(qs.stringify(undefined), '');
|
369
|
+
st.equal(qs.stringify(false), '');
|
370
|
+
st.equal(qs.stringify(null), '');
|
371
|
+
st.equal(qs.stringify(''), '');
|
372
|
+
st.end();
|
373
|
+
});
|
374
|
+
|
375
|
+
t.test('stringifies an object with a null object as a child', { skip: !Object.create }, function (st) {
|
376
|
+
var obj = { a: Object.create(null) };
|
377
|
+
|
378
|
+
obj.a.b = 'c';
|
379
|
+
st.equal(qs.stringify(obj), 'a%5Bb%5D=c');
|
380
|
+
st.end();
|
381
|
+
});
|
382
|
+
|
383
|
+
t.test('drops keys with a value of undefined', function (st) {
|
384
|
+
st.equal(qs.stringify({ a: undefined }), '');
|
385
|
+
|
386
|
+
st.equal(qs.stringify({ a: { b: undefined, c: null } }, { strictNullHandling: true }), 'a%5Bc%5D');
|
387
|
+
st.equal(qs.stringify({ a: { b: undefined, c: null } }, { strictNullHandling: false }), 'a%5Bc%5D=');
|
388
|
+
st.equal(qs.stringify({ a: { b: undefined, c: '' } }), 'a%5Bc%5D=');
|
389
|
+
st.end();
|
390
|
+
});
|
391
|
+
|
392
|
+
t.test('url encodes values', function (st) {
|
393
|
+
st.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
|
394
|
+
st.end();
|
395
|
+
});
|
396
|
+
|
397
|
+
t.test('stringifies a date', function (st) {
|
398
|
+
var now = new Date();
|
399
|
+
var str = 'a=' + encodeURIComponent(now.toISOString());
|
400
|
+
st.equal(qs.stringify({ a: now }), str);
|
401
|
+
st.end();
|
402
|
+
});
|
403
|
+
|
404
|
+
t.test('stringifies the weird object from qs', function (st) {
|
405
|
+
st.equal(qs.stringify({ 'my weird field': '~q1!2"\'w$5&7/z8)?' }), 'my%20weird%20field=~q1%212%22%27w%245%267%2Fz8%29%3F');
|
406
|
+
st.end();
|
407
|
+
});
|
408
|
+
|
409
|
+
t.test('skips properties that are part of the object prototype', function (st) {
|
410
|
+
Object.prototype.crash = 'test';
|
411
|
+
st.equal(qs.stringify({ a: 'b' }), 'a=b');
|
412
|
+
st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
|
413
|
+
delete Object.prototype.crash;
|
414
|
+
st.end();
|
415
|
+
});
|
416
|
+
|
417
|
+
t.test('stringifies boolean values', function (st) {
|
418
|
+
st.equal(qs.stringify({ a: true }), 'a=true');
|
419
|
+
st.equal(qs.stringify({ a: { b: true } }), 'a%5Bb%5D=true');
|
420
|
+
st.equal(qs.stringify({ b: false }), 'b=false');
|
421
|
+
st.equal(qs.stringify({ b: { c: false } }), 'b%5Bc%5D=false');
|
422
|
+
st.end();
|
423
|
+
});
|
424
|
+
|
425
|
+
t.test('stringifies buffer values', function (st) {
|
426
|
+
st.equal(qs.stringify({ a: SaferBuffer.from('test') }), 'a=test');
|
427
|
+
st.equal(qs.stringify({ a: { b: SaferBuffer.from('test') } }), 'a%5Bb%5D=test');
|
428
|
+
st.end();
|
429
|
+
});
|
430
|
+
|
431
|
+
t.test('stringifies an object using an alternative delimiter', function (st) {
|
432
|
+
st.equal(qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' }), 'a=b;c=d');
|
433
|
+
st.end();
|
434
|
+
});
|
435
|
+
|
436
|
+
t.test('doesn\'t blow up when Buffer global is missing', function (st) {
|
437
|
+
var tempBuffer = global.Buffer;
|
438
|
+
delete global.Buffer;
|
439
|
+
var result = qs.stringify({ a: 'b', c: 'd' });
|
440
|
+
global.Buffer = tempBuffer;
|
441
|
+
st.equal(result, 'a=b&c=d');
|
442
|
+
st.end();
|
443
|
+
});
|
444
|
+
|
445
|
+
t.test('selects properties when filter=array', function (st) {
|
446
|
+
st.equal(qs.stringify({ a: 'b' }, { filter: ['a'] }), 'a=b');
|
447
|
+
st.equal(qs.stringify({ a: 1 }, { filter: [] }), '');
|
448
|
+
|
449
|
+
st.equal(
|
450
|
+
qs.stringify(
|
451
|
+
{ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },
|
452
|
+
{ filter: ['a', 'b', 0, 2], arrayFormat: 'indices' }
|
453
|
+
),
|
454
|
+
'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3',
|
455
|
+
'indices => indices'
|
456
|
+
);
|
457
|
+
st.equal(
|
458
|
+
qs.stringify(
|
459
|
+
{ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },
|
460
|
+
{ filter: ['a', 'b', 0, 2], arrayFormat: 'brackets' }
|
461
|
+
),
|
462
|
+
'a%5Bb%5D%5B%5D=1&a%5Bb%5D%5B%5D=3',
|
463
|
+
'brackets => brackets'
|
464
|
+
);
|
465
|
+
st.equal(
|
466
|
+
qs.stringify(
|
467
|
+
{ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' },
|
468
|
+
{ filter: ['a', 'b', 0, 2] }
|
469
|
+
),
|
470
|
+
'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3',
|
471
|
+
'default => indices'
|
472
|
+
);
|
473
|
+
|
474
|
+
st.end();
|
475
|
+
});
|
476
|
+
|
477
|
+
t.test('supports custom representations when filter=function', function (st) {
|
478
|
+
var calls = 0;
|
479
|
+
var obj = { a: 'b', c: 'd', e: { f: new Date(1257894000000) } };
|
480
|
+
var filterFunc = function (prefix, value) {
|
481
|
+
calls += 1;
|
482
|
+
if (calls === 1) {
|
483
|
+
st.equal(prefix, '', 'prefix is empty');
|
484
|
+
st.equal(value, obj);
|
485
|
+
} else if (prefix === 'c') {
|
486
|
+
return void 0;
|
487
|
+
} else if (value instanceof Date) {
|
488
|
+
st.equal(prefix, 'e[f]');
|
489
|
+
return value.getTime();
|
490
|
+
}
|
491
|
+
return value;
|
492
|
+
};
|
493
|
+
|
494
|
+
st.equal(qs.stringify(obj, { filter: filterFunc }), 'a=b&e%5Bf%5D=1257894000000');
|
495
|
+
st.equal(calls, 5);
|
496
|
+
st.end();
|
497
|
+
});
|
498
|
+
|
499
|
+
t.test('can disable uri encoding', function (st) {
|
500
|
+
st.equal(qs.stringify({ a: 'b' }, { encode: false }), 'a=b');
|
501
|
+
st.equal(qs.stringify({ a: { b: 'c' } }, { encode: false }), 'a[b]=c');
|
502
|
+
st.equal(qs.stringify({ a: 'b', c: null }, { strictNullHandling: true, encode: false }), 'a=b&c');
|
503
|
+
st.end();
|
504
|
+
});
|
505
|
+
|
506
|
+
t.test('can sort the keys', function (st) {
|
507
|
+
var sort = function (a, b) {
|
508
|
+
return a.localeCompare(b);
|
509
|
+
};
|
510
|
+
st.equal(qs.stringify({ a: 'c', z: 'y', b: 'f' }, { sort: sort }), 'a=c&b=f&z=y');
|
511
|
+
st.equal(qs.stringify({ a: 'c', z: { j: 'a', i: 'b' }, b: 'f' }, { sort: sort }), 'a=c&b=f&z%5Bi%5D=b&z%5Bj%5D=a');
|
512
|
+
st.end();
|
513
|
+
});
|
514
|
+
|
515
|
+
t.test('can sort the keys at depth 3 or more too', function (st) {
|
516
|
+
var sort = function (a, b) {
|
517
|
+
return a.localeCompare(b);
|
518
|
+
};
|
519
|
+
st.equal(
|
520
|
+
qs.stringify(
|
521
|
+
{ a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },
|
522
|
+
{ sort: sort, encode: false }
|
523
|
+
),
|
524
|
+
'a=a&b=b&z[zi][zia]=zia&z[zi][zib]=zib&z[zj][zja]=zja&z[zj][zjb]=zjb'
|
525
|
+
);
|
526
|
+
st.equal(
|
527
|
+
qs.stringify(
|
528
|
+
{ a: 'a', z: { zj: { zjb: 'zjb', zja: 'zja' }, zi: { zib: 'zib', zia: 'zia' } }, b: 'b' },
|
529
|
+
{ sort: null, encode: false }
|
530
|
+
),
|
531
|
+
'a=a&z[zj][zjb]=zjb&z[zj][zja]=zja&z[zi][zib]=zib&z[zi][zia]=zia&b=b'
|
532
|
+
);
|
533
|
+
st.end();
|
534
|
+
});
|
535
|
+
|
536
|
+
t.test('can stringify with custom encoding', function (st) {
|
537
|
+
st.equal(qs.stringify({ 県: '大阪府', '': '' }, {
|
538
|
+
encoder: function (str) {
|
539
|
+
if (str.length === 0) {
|
540
|
+
return '';
|
541
|
+
}
|
542
|
+
var buf = iconv.encode(str, 'shiftjis');
|
543
|
+
var result = [];
|
544
|
+
for (var i = 0; i < buf.length; ++i) {
|
545
|
+
result.push(buf.readUInt8(i).toString(16));
|
546
|
+
}
|
547
|
+
return '%' + result.join('%');
|
548
|
+
}
|
549
|
+
}), '%8c%a7=%91%e5%8d%e3%95%7b&=');
|
550
|
+
st.end();
|
551
|
+
});
|
552
|
+
|
553
|
+
t.test('receives the default encoder as a second argument', function (st) {
|
554
|
+
st.plan(2);
|
555
|
+
qs.stringify({ a: 1 }, {
|
556
|
+
encoder: function (str, defaultEncoder) {
|
557
|
+
st.equal(defaultEncoder, utils.encode);
|
558
|
+
}
|
559
|
+
});
|
560
|
+
st.end();
|
561
|
+
});
|
562
|
+
|
563
|
+
t.test('throws error with wrong encoder', function (st) {
|
564
|
+
st['throws'](function () {
|
565
|
+
qs.stringify({}, { encoder: 'string' });
|
566
|
+
}, new TypeError('Encoder has to be a function.'));
|
567
|
+
st.end();
|
568
|
+
});
|
569
|
+
|
570
|
+
t.test('can use custom encoder for a buffer object', { skip: typeof Buffer === 'undefined' }, function (st) {
|
571
|
+
st.equal(qs.stringify({ a: SaferBuffer.from([1]) }, {
|
572
|
+
encoder: function (buffer) {
|
573
|
+
if (typeof buffer === 'string') {
|
574
|
+
return buffer;
|
575
|
+
}
|
576
|
+
return String.fromCharCode(buffer.readUInt8(0) + 97);
|
577
|
+
}
|
578
|
+
}), 'a=b');
|
579
|
+
|
580
|
+
st.equal(qs.stringify({ a: SaferBuffer.from('a b') }, {
|
581
|
+
encoder: function (buffer) {
|
582
|
+
return buffer;
|
583
|
+
}
|
584
|
+
}), 'a=a b');
|
585
|
+
st.end();
|
586
|
+
});
|
587
|
+
|
588
|
+
t.test('serializeDate option', function (st) {
|
589
|
+
var date = new Date();
|
590
|
+
st.equal(
|
591
|
+
qs.stringify({ a: date }),
|
592
|
+
'a=' + date.toISOString().replace(/:/g, '%3A'),
|
593
|
+
'default is toISOString'
|
594
|
+
);
|
595
|
+
|
596
|
+
var mutatedDate = new Date();
|
597
|
+
mutatedDate.toISOString = function () {
|
598
|
+
throw new SyntaxError();
|
599
|
+
};
|
600
|
+
st['throws'](function () {
|
601
|
+
mutatedDate.toISOString();
|
602
|
+
}, SyntaxError);
|
603
|
+
st.equal(
|
604
|
+
qs.stringify({ a: mutatedDate }),
|
605
|
+
'a=' + Date.prototype.toISOString.call(mutatedDate).replace(/:/g, '%3A'),
|
606
|
+
'toISOString works even when method is not locally present'
|
607
|
+
);
|
608
|
+
|
609
|
+
var specificDate = new Date(6);
|
610
|
+
st.equal(
|
611
|
+
qs.stringify(
|
612
|
+
{ a: specificDate },
|
613
|
+
{ serializeDate: function (d) { return d.getTime() * 7; } }
|
614
|
+
),
|
615
|
+
'a=42',
|
616
|
+
'custom serializeDate function called'
|
617
|
+
);
|
618
|
+
|
619
|
+
st.equal(
|
620
|
+
qs.stringify(
|
621
|
+
{ a: [date] },
|
622
|
+
{
|
623
|
+
serializeDate: function (d) { return d.getTime(); },
|
624
|
+
arrayFormat: 'comma'
|
625
|
+
}
|
626
|
+
),
|
627
|
+
'a=' + date.getTime(),
|
628
|
+
'works with arrayFormat comma'
|
629
|
+
);
|
630
|
+
|
631
|
+
st.end();
|
632
|
+
});
|
633
|
+
|
634
|
+
t.test('RFC 1738 serialization', function (st) {
|
635
|
+
st.equal(qs.stringify({ a: 'b c' }, { format: qs.formats.RFC1738 }), 'a=b+c');
|
636
|
+
st.equal(qs.stringify({ 'a b': 'c d' }, { format: qs.formats.RFC1738 }), 'a+b=c+d');
|
637
|
+
st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }, { format: qs.formats.RFC1738 }), 'a+b=a+b');
|
638
|
+
|
639
|
+
st.equal(qs.stringify({ 'foo(ref)': 'bar' }, { format: qs.formats.RFC1738 }), 'foo(ref)=bar');
|
640
|
+
|
641
|
+
st.end();
|
642
|
+
});
|
643
|
+
|
644
|
+
t.test('RFC 3986 spaces serialization', function (st) {
|
645
|
+
st.equal(qs.stringify({ a: 'b c' }, { format: qs.formats.RFC3986 }), 'a=b%20c');
|
646
|
+
st.equal(qs.stringify({ 'a b': 'c d' }, { format: qs.formats.RFC3986 }), 'a%20b=c%20d');
|
647
|
+
st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }, { format: qs.formats.RFC3986 }), 'a%20b=a%20b');
|
648
|
+
|
649
|
+
st.end();
|
650
|
+
});
|
651
|
+
|
652
|
+
t.test('Backward compatibility to RFC 3986', function (st) {
|
653
|
+
st.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
|
654
|
+
st.equal(qs.stringify({ 'a b': SaferBuffer.from('a b') }), 'a%20b=a%20b');
|
655
|
+
|
656
|
+
st.end();
|
657
|
+
});
|
658
|
+
|
659
|
+
t.test('Edge cases and unknown formats', function (st) {
|
660
|
+
['UFO1234', false, 1234, null, {}, []].forEach(
|
661
|
+
function (format) {
|
662
|
+
st['throws'](
|
663
|
+
function () {
|
664
|
+
qs.stringify({ a: 'b c' }, { format: format });
|
665
|
+
},
|
666
|
+
new TypeError('Unknown format option provided.')
|
667
|
+
);
|
668
|
+
}
|
669
|
+
);
|
670
|
+
st.end();
|
671
|
+
});
|
672
|
+
|
673
|
+
t.test('encodeValuesOnly', function (st) {
|
674
|
+
st.equal(
|
675
|
+
qs.stringify(
|
676
|
+
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
677
|
+
{ encodeValuesOnly: true }
|
678
|
+
),
|
679
|
+
'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h'
|
680
|
+
);
|
681
|
+
st.equal(
|
682
|
+
qs.stringify(
|
683
|
+
{ a: 'b', c: ['d', 'e'], f: [['g'], ['h']] }
|
684
|
+
),
|
685
|
+
'a=b&c%5B0%5D=d&c%5B1%5D=e&f%5B0%5D%5B0%5D=g&f%5B1%5D%5B0%5D=h'
|
686
|
+
);
|
687
|
+
st.end();
|
688
|
+
});
|
689
|
+
|
690
|
+
t.test('encodeValuesOnly - strictNullHandling', function (st) {
|
691
|
+
st.equal(
|
692
|
+
qs.stringify(
|
693
|
+
{ a: { b: null } },
|
694
|
+
{ encodeValuesOnly: true, strictNullHandling: true }
|
695
|
+
),
|
696
|
+
'a[b]'
|
697
|
+
);
|
698
|
+
st.end();
|
699
|
+
});
|
700
|
+
|
701
|
+
t.test('throws if an invalid charset is specified', function (st) {
|
702
|
+
st['throws'](function () {
|
703
|
+
qs.stringify({ a: 'b' }, { charset: 'foobar' });
|
704
|
+
}, new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined'));
|
705
|
+
st.end();
|
706
|
+
});
|
707
|
+
|
708
|
+
t.test('respects a charset of iso-8859-1', function (st) {
|
709
|
+
st.equal(qs.stringify({ æ: 'æ' }, { charset: 'iso-8859-1' }), '%E6=%E6');
|
710
|
+
st.end();
|
711
|
+
});
|
712
|
+
|
713
|
+
t.test('encodes unrepresentable chars as numeric entities in iso-8859-1 mode', function (st) {
|
714
|
+
st.equal(qs.stringify({ a: '☺' }, { charset: 'iso-8859-1' }), 'a=%26%239786%3B');
|
715
|
+
st.end();
|
716
|
+
});
|
717
|
+
|
718
|
+
t.test('respects an explicit charset of utf-8 (the default)', function (st) {
|
719
|
+
st.equal(qs.stringify({ a: 'æ' }, { charset: 'utf-8' }), 'a=%C3%A6');
|
720
|
+
st.end();
|
721
|
+
});
|
722
|
+
|
723
|
+
t.test('adds the right sentinel when instructed to and the charset is utf-8', function (st) {
|
724
|
+
st.equal(qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'utf-8' }), 'utf8=%E2%9C%93&a=%C3%A6');
|
725
|
+
st.end();
|
726
|
+
});
|
727
|
+
|
728
|
+
t.test('adds the right sentinel when instructed to and the charset is iso-8859-1', function (st) {
|
729
|
+
st.equal(qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' }), 'utf8=%26%2310003%3B&a=%E6');
|
730
|
+
st.end();
|
731
|
+
});
|
732
|
+
|
733
|
+
t.test('does not mutate the options argument', function (st) {
|
734
|
+
var options = {};
|
735
|
+
qs.stringify({}, options);
|
736
|
+
st.deepEqual(options, {});
|
737
|
+
st.end();
|
738
|
+
});
|
739
|
+
|
740
|
+
t.test('strictNullHandling works with custom filter', function (st) {
|
741
|
+
var filter = function (prefix, value) {
|
742
|
+
return value;
|
743
|
+
};
|
744
|
+
|
745
|
+
var options = { strictNullHandling: true, filter: filter };
|
746
|
+
st.equal(qs.stringify({ key: null }, options), 'key');
|
747
|
+
st.end();
|
748
|
+
});
|
749
|
+
|
750
|
+
t.test('strictNullHandling works with null serializeDate', function (st) {
|
751
|
+
var serializeDate = function () {
|
752
|
+
return null;
|
753
|
+
};
|
754
|
+
var options = { strictNullHandling: true, serializeDate: serializeDate };
|
755
|
+
var date = new Date();
|
756
|
+
st.equal(qs.stringify({ key: date }, options), 'key');
|
757
|
+
st.end();
|
758
|
+
});
|
759
|
+
|
760
|
+
t.test('allows for encoding keys and values differently', function (st) {
|
761
|
+
var encoder = function (str, defaultEncoder, charset, type) {
|
762
|
+
if (type === 'key') {
|
763
|
+
return defaultEncoder(str, defaultEncoder, charset, type).toLowerCase();
|
764
|
+
}
|
765
|
+
if (type === 'value') {
|
766
|
+
return defaultEncoder(str, defaultEncoder, charset, type).toUpperCase();
|
767
|
+
}
|
768
|
+
throw 'this should never happen! type: ' + type;
|
769
|
+
};
|
770
|
+
|
771
|
+
st.deepEqual(qs.stringify({ KeY: 'vAlUe' }, { encoder: encoder }), 'key=VALUE');
|
772
|
+
st.end();
|
773
|
+
});
|
774
|
+
|
775
|
+
t.test('objects inside arrays', function (st) {
|
776
|
+
var obj = { a: { b: { c: 'd', e: 'f' } } };
|
777
|
+
var withArray = { a: { b: [{ c: 'd', e: 'f' }] } };
|
778
|
+
|
779
|
+
st.equal(qs.stringify(obj, { encode: false }), 'a[b][c]=d&a[b][e]=f', 'no array, no arrayFormat');
|
780
|
+
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'bracket' }), 'a[b][c]=d&a[b][e]=f', 'no array, bracket');
|
781
|
+
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'indices' }), 'a[b][c]=d&a[b][e]=f', 'no array, indices');
|
782
|
+
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'comma' }), 'a[b][c]=d&a[b][e]=f', 'no array, comma');
|
783
|
+
|
784
|
+
st.equal(qs.stringify(withArray, { encode: false }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, no arrayFormat');
|
785
|
+
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'bracket' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, bracket');
|
786
|
+
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'indices' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, indices');
|
787
|
+
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'comma' }), '???', 'array, comma (pending issue #378)', { skip: true });
|
788
|
+
|
789
|
+
st.end();
|
790
|
+
});
|
791
|
+
|
792
|
+
t.end();
|
793
|
+
});
|