es6-crawler-detect 3.2.0 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +1 -1
- package/.mocharc.json +5 -0
- package/README.md +1 -0
- package/dist/main.bundle.js +1 -1
- package/eslint.config.mjs +62 -0
- package/example/node/package.json +1 -1
- package/example/node/server.js +38 -32
- package/example/node/yarn.lock +222 -99
- package/package.json +30 -25
- package/src/index.js +20 -14
- package/src/index.ts +18 -0
- package/src/lib/crawler/crawlers.js +9 -12
- package/src/lib/crawler/crawlers.ts +1397 -0
- package/src/lib/crawler/exclusions.js +7 -11
- package/src/lib/crawler/exclusions.ts +56 -0
- package/src/lib/crawler/headers.js +6 -10
- package/src/lib/crawler/headers.ts +18 -0
- package/src/lib/crawler/provider.js +1 -10
- package/src/lib/crawler/provider.ts +3 -0
- package/src/lib/crawler.js +61 -98
- package/src/lib/crawler.ts +128 -0
- package/src/types.js +2 -0
- package/src/types.ts +15 -0
- package/test/lib/crawler.spec.js +149 -0
- package/test/lib/crawler.spec.ts +116 -0
- package/test/lib/database/crawlers.txt +3651 -0
- package/test/lib/database/devices.txt +165636 -0
- package/tsconfig.json +16 -0
- package/webpack.common.js +20 -20
- package/webpack.dev.js +7 -7
- package/webpack.prod.js +14 -14
- package/.eslintignore +0 -6
- package/.eslintrc.json +0 -30
- package/example/node/node_modules/.bin/mime +0 -15
- package/example/node/node_modules/.bin/mime.cmd +0 -7
- package/example/node/node_modules/.yarn-integrity +0 -67
- package/example/node/node_modules/accepts/HISTORY.md +0 -236
- package/example/node/node_modules/accepts/LICENSE +0 -23
- package/example/node/node_modules/accepts/README.md +0 -142
- package/example/node/node_modules/accepts/index.js +0 -238
- package/example/node/node_modules/accepts/package.json +0 -47
- package/example/node/node_modules/array-flatten/LICENSE +0 -21
- package/example/node/node_modules/array-flatten/README.md +0 -43
- package/example/node/node_modules/array-flatten/array-flatten.js +0 -64
- package/example/node/node_modules/array-flatten/package.json +0 -39
- package/example/node/node_modules/body-parser/HISTORY.md +0 -624
- package/example/node/node_modules/body-parser/LICENSE +0 -23
- package/example/node/node_modules/body-parser/README.md +0 -456
- package/example/node/node_modules/body-parser/index.js +0 -157
- package/example/node/node_modules/body-parser/lib/read.js +0 -181
- package/example/node/node_modules/body-parser/lib/types/json.js +0 -230
- package/example/node/node_modules/body-parser/lib/types/raw.js +0 -101
- package/example/node/node_modules/body-parser/lib/types/text.js +0 -121
- package/example/node/node_modules/body-parser/lib/types/urlencoded.js +0 -284
- package/example/node/node_modules/body-parser/package.json +0 -52
- package/example/node/node_modules/bytes/History.md +0 -92
- package/example/node/node_modules/bytes/LICENSE +0 -23
- package/example/node/node_modules/bytes/Readme.md +0 -152
- package/example/node/node_modules/bytes/index.js +0 -166
- package/example/node/node_modules/bytes/package.json +0 -42
- package/example/node/node_modules/content-disposition/HISTORY.md +0 -60
- package/example/node/node_modules/content-disposition/LICENSE +0 -22
- package/example/node/node_modules/content-disposition/README.md +0 -142
- package/example/node/node_modules/content-disposition/index.js +0 -458
- package/example/node/node_modules/content-disposition/package.json +0 -44
- package/example/node/node_modules/content-type/HISTORY.md +0 -24
- package/example/node/node_modules/content-type/LICENSE +0 -22
- package/example/node/node_modules/content-type/README.md +0 -92
- package/example/node/node_modules/content-type/index.js +0 -222
- package/example/node/node_modules/content-type/package.json +0 -40
- package/example/node/node_modules/cookie/HISTORY.md +0 -128
- package/example/node/node_modules/cookie/LICENSE +0 -24
- package/example/node/node_modules/cookie/README.md +0 -257
- package/example/node/node_modules/cookie/index.js +0 -202
- package/example/node/node_modules/cookie/package.json +0 -40
- package/example/node/node_modules/cookie-signature/History.md +0 -38
- package/example/node/node_modules/cookie-signature/Readme.md +0 -42
- package/example/node/node_modules/cookie-signature/index.js +0 -51
- package/example/node/node_modules/cookie-signature/package.json +0 -18
- package/example/node/node_modules/debug/.coveralls.yml +0 -1
- package/example/node/node_modules/debug/.eslintrc +0 -11
- package/example/node/node_modules/debug/.travis.yml +0 -14
- package/example/node/node_modules/debug/CHANGELOG.md +0 -362
- package/example/node/node_modules/debug/LICENSE +0 -19
- package/example/node/node_modules/debug/Makefile +0 -50
- package/example/node/node_modules/debug/README.md +0 -312
- package/example/node/node_modules/debug/component.json +0 -19
- package/example/node/node_modules/debug/karma.conf.js +0 -70
- package/example/node/node_modules/debug/node.js +0 -1
- package/example/node/node_modules/debug/package.json +0 -49
- package/example/node/node_modules/debug/src/browser.js +0 -185
- package/example/node/node_modules/debug/src/debug.js +0 -202
- package/example/node/node_modules/debug/src/index.js +0 -10
- package/example/node/node_modules/debug/src/inspector-log.js +0 -15
- package/example/node/node_modules/debug/src/node.js +0 -248
- package/example/node/node_modules/depd/History.md +0 -96
- package/example/node/node_modules/depd/LICENSE +0 -22
- package/example/node/node_modules/depd/Readme.md +0 -280
- package/example/node/node_modules/depd/index.js +0 -522
- package/example/node/node_modules/depd/lib/browser/index.js +0 -77
- package/example/node/node_modules/depd/lib/compat/callsite-tostring.js +0 -103
- package/example/node/node_modules/depd/lib/compat/event-listener-count.js +0 -22
- package/example/node/node_modules/depd/lib/compat/index.js +0 -79
- package/example/node/node_modules/depd/package.json +0 -41
- package/example/node/node_modules/destroy/LICENSE +0 -22
- package/example/node/node_modules/destroy/README.md +0 -60
- package/example/node/node_modules/destroy/index.js +0 -75
- package/example/node/node_modules/destroy/package.json +0 -37
- package/example/node/node_modules/ee-first/LICENSE +0 -22
- package/example/node/node_modules/ee-first/README.md +0 -80
- package/example/node/node_modules/ee-first/index.js +0 -95
- package/example/node/node_modules/ee-first/package.json +0 -29
- package/example/node/node_modules/encodeurl/HISTORY.md +0 -14
- package/example/node/node_modules/encodeurl/LICENSE +0 -22
- package/example/node/node_modules/encodeurl/README.md +0 -128
- package/example/node/node_modules/encodeurl/index.js +0 -60
- package/example/node/node_modules/encodeurl/package.json +0 -40
- package/example/node/node_modules/escape-html/LICENSE +0 -24
- package/example/node/node_modules/escape-html/Readme.md +0 -43
- package/example/node/node_modules/escape-html/index.js +0 -78
- package/example/node/node_modules/escape-html/package.json +0 -24
- package/example/node/node_modules/etag/HISTORY.md +0 -83
- package/example/node/node_modules/etag/LICENSE +0 -22
- package/example/node/node_modules/etag/README.md +0 -159
- package/example/node/node_modules/etag/index.js +0 -131
- package/example/node/node_modules/etag/package.json +0 -47
- package/example/node/node_modules/express/History.md +0 -3510
- package/example/node/node_modules/express/LICENSE +0 -24
- package/example/node/node_modules/express/Readme.md +0 -158
- package/example/node/node_modules/express/index.js +0 -11
- package/example/node/node_modules/express/lib/application.js +0 -644
- package/example/node/node_modules/express/lib/express.js +0 -116
- package/example/node/node_modules/express/lib/middleware/init.js +0 -43
- package/example/node/node_modules/express/lib/middleware/query.js +0 -47
- package/example/node/node_modules/express/lib/request.js +0 -525
- package/example/node/node_modules/express/lib/response.js +0 -1147
- package/example/node/node_modules/express/lib/router/index.js +0 -668
- package/example/node/node_modules/express/lib/router/layer.js +0 -181
- package/example/node/node_modules/express/lib/router/route.js +0 -216
- package/example/node/node_modules/express/lib/utils.js +0 -302
- package/example/node/node_modules/express/lib/view.js +0 -182
- package/example/node/node_modules/express/package.json +0 -99
- package/example/node/node_modules/finalhandler/HISTORY.md +0 -187
- package/example/node/node_modules/finalhandler/LICENSE +0 -22
- package/example/node/node_modules/finalhandler/README.md +0 -148
- package/example/node/node_modules/finalhandler/index.js +0 -331
- package/example/node/node_modules/finalhandler/package.json +0 -45
- package/example/node/node_modules/forwarded/HISTORY.md +0 -21
- package/example/node/node_modules/forwarded/LICENSE +0 -22
- package/example/node/node_modules/forwarded/README.md +0 -57
- package/example/node/node_modules/forwarded/index.js +0 -90
- package/example/node/node_modules/forwarded/package.json +0 -45
- package/example/node/node_modules/fresh/HISTORY.md +0 -70
- package/example/node/node_modules/fresh/LICENSE +0 -23
- package/example/node/node_modules/fresh/README.md +0 -119
- package/example/node/node_modules/fresh/index.js +0 -137
- package/example/node/node_modules/fresh/package.json +0 -46
- package/example/node/node_modules/http-errors/HISTORY.md +0 -165
- package/example/node/node_modules/http-errors/LICENSE +0 -23
- package/example/node/node_modules/http-errors/README.md +0 -169
- package/example/node/node_modules/http-errors/index.js +0 -299
- package/example/node/node_modules/http-errors/package.json +0 -49
- package/example/node/node_modules/iconv-lite/Changelog.md +0 -162
- package/example/node/node_modules/iconv-lite/LICENSE +0 -21
- package/example/node/node_modules/iconv-lite/README.md +0 -156
- package/example/node/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -555
- package/example/node/node_modules/iconv-lite/encodings/dbcs-data.js +0 -176
- package/example/node/node_modules/iconv-lite/encodings/index.js +0 -22
- package/example/node/node_modules/iconv-lite/encodings/internal.js +0 -188
- package/example/node/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -72
- package/example/node/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -451
- package/example/node/node_modules/iconv-lite/encodings/sbcs-data.js +0 -174
- package/example/node/node_modules/iconv-lite/encodings/tables/big5-added.json +0 -122
- package/example/node/node_modules/iconv-lite/encodings/tables/cp936.json +0 -264
- package/example/node/node_modules/iconv-lite/encodings/tables/cp949.json +0 -273
- package/example/node/node_modules/iconv-lite/encodings/tables/cp950.json +0 -177
- package/example/node/node_modules/iconv-lite/encodings/tables/eucjp.json +0 -182
- package/example/node/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +0 -1
- package/example/node/node_modules/iconv-lite/encodings/tables/gbk-added.json +0 -55
- package/example/node/node_modules/iconv-lite/encodings/tables/shiftjis.json +0 -125
- package/example/node/node_modules/iconv-lite/encodings/utf16.js +0 -177
- package/example/node/node_modules/iconv-lite/encodings/utf7.js +0 -290
- package/example/node/node_modules/iconv-lite/lib/bom-handling.js +0 -52
- package/example/node/node_modules/iconv-lite/lib/extend-node.js +0 -217
- package/example/node/node_modules/iconv-lite/lib/index.d.ts +0 -24
- package/example/node/node_modules/iconv-lite/lib/index.js +0 -153
- package/example/node/node_modules/iconv-lite/lib/streams.js +0 -121
- package/example/node/node_modules/iconv-lite/package.json +0 -46
- package/example/node/node_modules/inherits/LICENSE +0 -16
- package/example/node/node_modules/inherits/README.md +0 -42
- package/example/node/node_modules/inherits/inherits.js +0 -9
- package/example/node/node_modules/inherits/inherits_browser.js +0 -27
- package/example/node/node_modules/inherits/package.json +0 -29
- package/example/node/node_modules/ipaddr.js/LICENSE +0 -19
- package/example/node/node_modules/ipaddr.js/README.md +0 -233
- package/example/node/node_modules/ipaddr.js/ipaddr.min.js +0 -1
- package/example/node/node_modules/ipaddr.js/lib/ipaddr.js +0 -673
- package/example/node/node_modules/ipaddr.js/lib/ipaddr.js.d.ts +0 -68
- package/example/node/node_modules/ipaddr.js/package.json +0 -35
- package/example/node/node_modules/media-typer/HISTORY.md +0 -22
- package/example/node/node_modules/media-typer/LICENSE +0 -22
- package/example/node/node_modules/media-typer/README.md +0 -81
- package/example/node/node_modules/media-typer/index.js +0 -270
- package/example/node/node_modules/media-typer/package.json +0 -26
- package/example/node/node_modules/merge-descriptors/HISTORY.md +0 -21
- package/example/node/node_modules/merge-descriptors/LICENSE +0 -23
- package/example/node/node_modules/merge-descriptors/README.md +0 -48
- package/example/node/node_modules/merge-descriptors/index.js +0 -60
- package/example/node/node_modules/merge-descriptors/package.json +0 -32
- package/example/node/node_modules/methods/HISTORY.md +0 -29
- package/example/node/node_modules/methods/LICENSE +0 -24
- package/example/node/node_modules/methods/README.md +0 -51
- package/example/node/node_modules/methods/index.js +0 -69
- package/example/node/node_modules/methods/package.json +0 -36
- package/example/node/node_modules/mime/CHANGELOG.md +0 -164
- package/example/node/node_modules/mime/LICENSE +0 -21
- package/example/node/node_modules/mime/README.md +0 -90
- package/example/node/node_modules/mime/cli.js +0 -8
- package/example/node/node_modules/mime/mime.js +0 -108
- package/example/node/node_modules/mime/package.json +0 -44
- package/example/node/node_modules/mime/src/build.js +0 -53
- package/example/node/node_modules/mime/src/test.js +0 -60
- package/example/node/node_modules/mime/types.json +0 -1
- package/example/node/node_modules/mime-db/HISTORY.md +0 -499
- package/example/node/node_modules/mime-db/LICENSE +0 -22
- package/example/node/node_modules/mime-db/README.md +0 -100
- package/example/node/node_modules/mime-db/db.json +0 -8471
- package/example/node/node_modules/mime-db/index.js +0 -11
- package/example/node/node_modules/mime-db/package.json +0 -59
- package/example/node/node_modules/mime-types/HISTORY.md +0 -388
- package/example/node/node_modules/mime-types/LICENSE +0 -23
- package/example/node/node_modules/mime-types/README.md +0 -113
- package/example/node/node_modules/mime-types/index.js +0 -188
- package/example/node/node_modules/mime-types/package.json +0 -44
- package/example/node/node_modules/ms/index.js +0 -152
- package/example/node/node_modules/ms/license.md +0 -21
- package/example/node/node_modules/ms/package.json +0 -37
- package/example/node/node_modules/ms/readme.md +0 -51
- package/example/node/node_modules/negotiator/HISTORY.md +0 -103
- package/example/node/node_modules/negotiator/LICENSE +0 -24
- package/example/node/node_modules/negotiator/README.md +0 -203
- package/example/node/node_modules/negotiator/index.js +0 -124
- package/example/node/node_modules/negotiator/lib/charset.js +0 -169
- package/example/node/node_modules/negotiator/lib/encoding.js +0 -184
- package/example/node/node_modules/negotiator/lib/language.js +0 -179
- package/example/node/node_modules/negotiator/lib/mediaType.js +0 -294
- package/example/node/node_modules/negotiator/package.json +0 -42
- package/example/node/node_modules/on-finished/HISTORY.md +0 -88
- package/example/node/node_modules/on-finished/LICENSE +0 -23
- package/example/node/node_modules/on-finished/README.md +0 -154
- package/example/node/node_modules/on-finished/index.js +0 -196
- package/example/node/node_modules/on-finished/package.json +0 -31
- package/example/node/node_modules/parseurl/HISTORY.md +0 -58
- package/example/node/node_modules/parseurl/LICENSE +0 -24
- package/example/node/node_modules/parseurl/README.md +0 -133
- package/example/node/node_modules/parseurl/index.js +0 -158
- package/example/node/node_modules/parseurl/package.json +0 -40
- package/example/node/node_modules/path-to-regexp/History.md +0 -36
- package/example/node/node_modules/path-to-regexp/LICENSE +0 -21
- package/example/node/node_modules/path-to-regexp/Readme.md +0 -35
- package/example/node/node_modules/path-to-regexp/index.js +0 -129
- package/example/node/node_modules/path-to-regexp/package.json +0 -30
- package/example/node/node_modules/proxy-addr/HISTORY.md +0 -161
- package/example/node/node_modules/proxy-addr/LICENSE +0 -22
- package/example/node/node_modules/proxy-addr/README.md +0 -139
- package/example/node/node_modules/proxy-addr/index.js +0 -327
- package/example/node/node_modules/proxy-addr/package.json +0 -47
- package/example/node/node_modules/qs/.editorconfig +0 -39
- package/example/node/node_modules/qs/.eslintignore +0 -2
- package/example/node/node_modules/qs/.eslintrc +0 -35
- package/example/node/node_modules/qs/.github/FUNDING.yml +0 -12
- package/example/node/node_modules/qs/.nycrc +0 -13
- package/example/node/node_modules/qs/CHANGELOG.md +0 -359
- package/example/node/node_modules/qs/LICENSE.md +0 -29
- package/example/node/node_modules/qs/README.md +0 -604
- package/example/node/node_modules/qs/dist/qs.js +0 -832
- package/example/node/node_modules/qs/lib/formats.js +0 -23
- package/example/node/node_modules/qs/lib/index.js +0 -11
- package/example/node/node_modules/qs/lib/parse.js +0 -257
- package/example/node/node_modules/qs/lib/stringify.js +0 -278
- package/example/node/node_modules/qs/lib/utils.js +0 -251
- package/example/node/node_modules/qs/package.json +0 -69
- package/example/node/node_modules/qs/test/parse.js +0 -772
- package/example/node/node_modules/qs/test/stringify.js +0 -793
- package/example/node/node_modules/qs/test/utils.js +0 -136
- package/example/node/node_modules/range-parser/HISTORY.md +0 -56
- package/example/node/node_modules/range-parser/LICENSE +0 -23
- package/example/node/node_modules/range-parser/README.md +0 -84
- package/example/node/node_modules/range-parser/index.js +0 -162
- package/example/node/node_modules/range-parser/package.json +0 -44
- package/example/node/node_modules/raw-body/HISTORY.md +0 -284
- package/example/node/node_modules/raw-body/LICENSE +0 -22
- package/example/node/node_modules/raw-body/README.md +0 -217
- package/example/node/node_modules/raw-body/index.d.ts +0 -87
- package/example/node/node_modules/raw-body/index.js +0 -286
- package/example/node/node_modules/raw-body/package.json +0 -48
- package/example/node/node_modules/safe-buffer/LICENSE +0 -21
- package/example/node/node_modules/safe-buffer/README.md +0 -584
- package/example/node/node_modules/safe-buffer/index.d.ts +0 -187
- package/example/node/node_modules/safe-buffer/index.js +0 -65
- package/example/node/node_modules/safe-buffer/package.json +0 -51
- package/example/node/node_modules/safer-buffer/LICENSE +0 -21
- package/example/node/node_modules/safer-buffer/Porting-Buffer.md +0 -268
- package/example/node/node_modules/safer-buffer/Readme.md +0 -156
- package/example/node/node_modules/safer-buffer/dangerous.js +0 -58
- package/example/node/node_modules/safer-buffer/package.json +0 -34
- package/example/node/node_modules/safer-buffer/safer.js +0 -77
- package/example/node/node_modules/safer-buffer/tests.js +0 -406
- package/example/node/node_modules/send/HISTORY.md +0 -506
- package/example/node/node_modules/send/LICENSE +0 -23
- package/example/node/node_modules/send/README.md +0 -327
- package/example/node/node_modules/send/index.js +0 -1133
- package/example/node/node_modules/send/node_modules/.bin/mime +0 -15
- package/example/node/node_modules/send/node_modules/.bin/mime.cmd +0 -7
- package/example/node/node_modules/send/node_modules/ms/index.js +0 -162
- package/example/node/node_modules/send/node_modules/ms/license.md +0 -21
- package/example/node/node_modules/send/node_modules/ms/package.json +0 -38
- package/example/node/node_modules/send/node_modules/ms/readme.md +0 -59
- package/example/node/node_modules/send/package.json +0 -61
- package/example/node/node_modules/serve-static/HISTORY.md +0 -459
- package/example/node/node_modules/serve-static/LICENSE +0 -25
- package/example/node/node_modules/serve-static/README.md +0 -257
- package/example/node/node_modules/serve-static/index.js +0 -210
- package/example/node/node_modules/serve-static/package.json +0 -42
- package/example/node/node_modules/setprototypeof/LICENSE +0 -13
- package/example/node/node_modules/setprototypeof/README.md +0 -31
- package/example/node/node_modules/setprototypeof/index.d.ts +0 -2
- package/example/node/node_modules/setprototypeof/index.js +0 -17
- package/example/node/node_modules/setprototypeof/package.json +0 -38
- package/example/node/node_modules/setprototypeof/test/index.js +0 -24
- package/example/node/node_modules/statuses/HISTORY.md +0 -65
- package/example/node/node_modules/statuses/LICENSE +0 -23
- package/example/node/node_modules/statuses/README.md +0 -127
- package/example/node/node_modules/statuses/codes.json +0 -66
- package/example/node/node_modules/statuses/index.js +0 -113
- package/example/node/node_modules/statuses/package.json +0 -48
- package/example/node/node_modules/toidentifier/HISTORY.md +0 -9
- package/example/node/node_modules/toidentifier/LICENSE +0 -21
- package/example/node/node_modules/toidentifier/README.md +0 -61
- package/example/node/node_modules/toidentifier/index.js +0 -32
- package/example/node/node_modules/toidentifier/package.json +0 -38
- package/example/node/node_modules/type-is/HISTORY.md +0 -259
- package/example/node/node_modules/type-is/LICENSE +0 -23
- package/example/node/node_modules/type-is/README.md +0 -170
- package/example/node/node_modules/type-is/index.js +0 -266
- package/example/node/node_modules/type-is/package.json +0 -45
- package/example/node/node_modules/unpipe/HISTORY.md +0 -4
- package/example/node/node_modules/unpipe/LICENSE +0 -22
- package/example/node/node_modules/unpipe/README.md +0 -43
- package/example/node/node_modules/unpipe/index.js +0 -69
- package/example/node/node_modules/unpipe/package.json +0 -27
- package/example/node/node_modules/utils-merge/LICENSE +0 -20
- package/example/node/node_modules/utils-merge/README.md +0 -34
- package/example/node/node_modules/utils-merge/index.js +0 -23
- package/example/node/node_modules/utils-merge/package.json +0 -40
- package/example/node/node_modules/vary/HISTORY.md +0 -39
- package/example/node/node_modules/vary/LICENSE +0 -22
- package/example/node/node_modules/vary/README.md +0 -101
- package/example/node/node_modules/vary/index.js +0 -149
- package/example/node/node_modules/vary/package.json +0 -43
- package/test/lib/crawler.test.js +0 -52
@@ -1,793 +0,0 @@
|
|
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
|
-
});
|