es6-crawler-detect 3.1.1 → 3.3.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.
Files changed (353) hide show
  1. package/.babelrc +2 -1
  2. package/.eslintignore +6 -0
  3. package/.eslintrc.json +30 -0
  4. package/.github/ISSUE_TEMPLATE/bug_report.md +11 -8
  5. package/.github/ISSUE_TEMPLATE/feature_request.md +1 -1
  6. package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +29 -0
  7. package/.prettierrc.json +5 -0
  8. package/README.md +27 -17
  9. package/dist/main.bundle.js +1 -1
  10. package/example/node/dist/crawler.min.js +1 -1
  11. package/example/node/node_modules/.bin/mime +15 -0
  12. package/example/node/node_modules/.bin/mime.cmd +7 -0
  13. package/example/node/node_modules/.yarn-integrity +67 -0
  14. package/example/node/node_modules/accepts/HISTORY.md +236 -0
  15. package/example/node/node_modules/accepts/LICENSE +23 -0
  16. package/example/node/node_modules/accepts/README.md +142 -0
  17. package/example/node/node_modules/accepts/index.js +238 -0
  18. package/example/node/node_modules/accepts/package.json +47 -0
  19. package/example/node/node_modules/array-flatten/LICENSE +21 -0
  20. package/example/node/node_modules/array-flatten/README.md +43 -0
  21. package/example/node/node_modules/array-flatten/array-flatten.js +64 -0
  22. package/example/node/node_modules/array-flatten/package.json +39 -0
  23. package/example/node/node_modules/body-parser/HISTORY.md +624 -0
  24. package/example/node/node_modules/body-parser/LICENSE +23 -0
  25. package/example/node/node_modules/body-parser/README.md +456 -0
  26. package/example/node/node_modules/body-parser/index.js +157 -0
  27. package/example/node/node_modules/body-parser/lib/read.js +181 -0
  28. package/example/node/node_modules/body-parser/lib/types/json.js +230 -0
  29. package/example/node/node_modules/body-parser/lib/types/raw.js +101 -0
  30. package/example/node/node_modules/body-parser/lib/types/text.js +121 -0
  31. package/example/node/node_modules/body-parser/lib/types/urlencoded.js +284 -0
  32. package/example/node/node_modules/body-parser/package.json +52 -0
  33. package/example/node/node_modules/bytes/History.md +92 -0
  34. package/example/node/node_modules/bytes/LICENSE +23 -0
  35. package/example/node/node_modules/bytes/Readme.md +152 -0
  36. package/example/node/node_modules/bytes/index.js +166 -0
  37. package/example/node/node_modules/bytes/package.json +42 -0
  38. package/example/node/node_modules/content-disposition/HISTORY.md +60 -0
  39. package/example/node/node_modules/content-disposition/LICENSE +22 -0
  40. package/example/node/node_modules/content-disposition/README.md +142 -0
  41. package/example/node/node_modules/content-disposition/index.js +458 -0
  42. package/example/node/node_modules/content-disposition/package.json +44 -0
  43. package/example/node/node_modules/content-type/HISTORY.md +24 -0
  44. package/example/node/node_modules/content-type/LICENSE +22 -0
  45. package/example/node/node_modules/content-type/README.md +92 -0
  46. package/example/node/node_modules/content-type/index.js +222 -0
  47. package/example/node/node_modules/content-type/package.json +40 -0
  48. package/example/node/node_modules/cookie/HISTORY.md +128 -0
  49. package/example/node/node_modules/cookie/LICENSE +24 -0
  50. package/example/node/node_modules/cookie/README.md +257 -0
  51. package/example/node/node_modules/cookie/index.js +202 -0
  52. package/example/node/node_modules/cookie/package.json +40 -0
  53. package/example/node/node_modules/cookie-signature/History.md +38 -0
  54. package/example/node/node_modules/cookie-signature/Readme.md +42 -0
  55. package/example/node/node_modules/cookie-signature/index.js +51 -0
  56. package/example/node/node_modules/cookie-signature/package.json +18 -0
  57. package/example/node/node_modules/debug/.coveralls.yml +1 -0
  58. package/example/node/node_modules/debug/.eslintrc +11 -0
  59. package/example/node/node_modules/debug/.travis.yml +14 -0
  60. package/example/node/node_modules/debug/CHANGELOG.md +362 -0
  61. package/example/node/node_modules/debug/LICENSE +19 -0
  62. package/example/node/node_modules/debug/Makefile +50 -0
  63. package/example/node/node_modules/debug/README.md +312 -0
  64. package/example/node/node_modules/debug/component.json +19 -0
  65. package/example/node/node_modules/debug/karma.conf.js +70 -0
  66. package/example/node/node_modules/debug/node.js +1 -0
  67. package/example/node/node_modules/debug/package.json +49 -0
  68. package/example/node/node_modules/debug/src/browser.js +185 -0
  69. package/example/node/node_modules/debug/src/debug.js +202 -0
  70. package/example/node/node_modules/debug/src/index.js +10 -0
  71. package/example/node/node_modules/debug/src/inspector-log.js +15 -0
  72. package/example/node/node_modules/debug/src/node.js +248 -0
  73. package/example/node/node_modules/depd/History.md +96 -0
  74. package/example/node/node_modules/depd/LICENSE +22 -0
  75. package/example/node/node_modules/depd/Readme.md +280 -0
  76. package/example/node/node_modules/depd/index.js +522 -0
  77. package/example/node/node_modules/depd/lib/browser/index.js +77 -0
  78. package/example/node/node_modules/depd/lib/compat/callsite-tostring.js +103 -0
  79. package/example/node/node_modules/depd/lib/compat/event-listener-count.js +22 -0
  80. package/example/node/node_modules/depd/lib/compat/index.js +79 -0
  81. package/example/node/node_modules/depd/package.json +41 -0
  82. package/example/node/node_modules/destroy/LICENSE +22 -0
  83. package/example/node/node_modules/destroy/README.md +60 -0
  84. package/example/node/node_modules/destroy/index.js +75 -0
  85. package/example/node/node_modules/destroy/package.json +37 -0
  86. package/example/node/node_modules/ee-first/LICENSE +22 -0
  87. package/example/node/node_modules/ee-first/README.md +80 -0
  88. package/example/node/node_modules/ee-first/index.js +95 -0
  89. package/example/node/node_modules/ee-first/package.json +29 -0
  90. package/example/node/node_modules/encodeurl/HISTORY.md +14 -0
  91. package/example/node/node_modules/encodeurl/LICENSE +22 -0
  92. package/example/node/node_modules/encodeurl/README.md +128 -0
  93. package/example/node/node_modules/encodeurl/index.js +60 -0
  94. package/example/node/node_modules/encodeurl/package.json +40 -0
  95. package/example/node/node_modules/escape-html/LICENSE +24 -0
  96. package/example/node/node_modules/escape-html/Readme.md +43 -0
  97. package/example/node/node_modules/escape-html/index.js +78 -0
  98. package/example/node/node_modules/escape-html/package.json +24 -0
  99. package/example/node/node_modules/etag/HISTORY.md +83 -0
  100. package/example/node/node_modules/etag/LICENSE +22 -0
  101. package/example/node/node_modules/etag/README.md +159 -0
  102. package/example/node/node_modules/etag/index.js +131 -0
  103. package/example/node/node_modules/etag/package.json +47 -0
  104. package/example/node/node_modules/express/History.md +3510 -0
  105. package/example/node/node_modules/express/LICENSE +24 -0
  106. package/example/node/node_modules/express/Readme.md +158 -0
  107. package/example/node/node_modules/express/index.js +11 -0
  108. package/example/node/node_modules/express/lib/application.js +644 -0
  109. package/example/node/node_modules/express/lib/express.js +116 -0
  110. package/example/node/node_modules/express/lib/middleware/init.js +43 -0
  111. package/example/node/node_modules/express/lib/middleware/query.js +47 -0
  112. package/example/node/node_modules/express/lib/request.js +525 -0
  113. package/example/node/node_modules/express/lib/response.js +1147 -0
  114. package/example/node/node_modules/express/lib/router/index.js +668 -0
  115. package/example/node/node_modules/express/lib/router/layer.js +181 -0
  116. package/example/node/node_modules/express/lib/router/route.js +216 -0
  117. package/example/node/node_modules/express/lib/utils.js +302 -0
  118. package/example/node/node_modules/express/lib/view.js +182 -0
  119. package/example/node/node_modules/express/package.json +99 -0
  120. package/example/node/node_modules/finalhandler/HISTORY.md +187 -0
  121. package/example/node/node_modules/finalhandler/LICENSE +22 -0
  122. package/example/node/node_modules/finalhandler/README.md +148 -0
  123. package/example/node/node_modules/finalhandler/index.js +331 -0
  124. package/example/node/node_modules/finalhandler/package.json +45 -0
  125. package/example/node/node_modules/forwarded/HISTORY.md +21 -0
  126. package/example/node/node_modules/forwarded/LICENSE +22 -0
  127. package/example/node/node_modules/forwarded/README.md +57 -0
  128. package/example/node/node_modules/forwarded/index.js +90 -0
  129. package/example/node/node_modules/forwarded/package.json +45 -0
  130. package/example/node/node_modules/fresh/HISTORY.md +70 -0
  131. package/example/node/node_modules/fresh/LICENSE +23 -0
  132. package/example/node/node_modules/fresh/README.md +119 -0
  133. package/example/node/node_modules/fresh/index.js +137 -0
  134. package/example/node/node_modules/fresh/package.json +46 -0
  135. package/example/node/node_modules/http-errors/HISTORY.md +165 -0
  136. package/example/node/node_modules/http-errors/LICENSE +23 -0
  137. package/example/node/node_modules/http-errors/README.md +169 -0
  138. package/example/node/node_modules/http-errors/index.js +299 -0
  139. package/example/node/node_modules/http-errors/package.json +49 -0
  140. package/example/node/node_modules/iconv-lite/Changelog.md +162 -0
  141. package/example/node/node_modules/iconv-lite/LICENSE +21 -0
  142. package/example/node/node_modules/iconv-lite/README.md +156 -0
  143. package/example/node/node_modules/iconv-lite/encodings/dbcs-codec.js +555 -0
  144. package/example/node/node_modules/iconv-lite/encodings/dbcs-data.js +176 -0
  145. package/example/node/node_modules/iconv-lite/encodings/index.js +22 -0
  146. package/example/node/node_modules/iconv-lite/encodings/internal.js +188 -0
  147. package/example/node/node_modules/iconv-lite/encodings/sbcs-codec.js +72 -0
  148. package/example/node/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
  149. package/example/node/node_modules/iconv-lite/encodings/sbcs-data.js +174 -0
  150. package/example/node/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
  151. package/example/node/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
  152. package/example/node/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
  153. package/example/node/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
  154. package/example/node/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
  155. package/example/node/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
  156. package/example/node/node_modules/iconv-lite/encodings/tables/gbk-added.json +55 -0
  157. package/example/node/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
  158. package/example/node/node_modules/iconv-lite/encodings/utf16.js +177 -0
  159. package/example/node/node_modules/iconv-lite/encodings/utf7.js +290 -0
  160. package/example/node/node_modules/iconv-lite/lib/bom-handling.js +52 -0
  161. package/example/node/node_modules/iconv-lite/lib/extend-node.js +217 -0
  162. package/example/node/node_modules/iconv-lite/lib/index.d.ts +24 -0
  163. package/example/node/node_modules/iconv-lite/lib/index.js +153 -0
  164. package/example/node/node_modules/iconv-lite/lib/streams.js +121 -0
  165. package/example/node/node_modules/iconv-lite/package.json +46 -0
  166. package/example/node/node_modules/inherits/LICENSE +16 -0
  167. package/example/node/node_modules/inherits/README.md +42 -0
  168. package/example/node/node_modules/inherits/inherits.js +9 -0
  169. package/example/node/node_modules/inherits/inherits_browser.js +27 -0
  170. package/example/node/node_modules/inherits/package.json +29 -0
  171. package/example/node/node_modules/ipaddr.js/LICENSE +19 -0
  172. package/example/node/node_modules/ipaddr.js/README.md +233 -0
  173. package/example/node/node_modules/ipaddr.js/ipaddr.min.js +1 -0
  174. package/example/node/node_modules/ipaddr.js/lib/ipaddr.js +673 -0
  175. package/example/node/node_modules/ipaddr.js/lib/ipaddr.js.d.ts +68 -0
  176. package/example/node/node_modules/ipaddr.js/package.json +35 -0
  177. package/example/node/node_modules/media-typer/HISTORY.md +22 -0
  178. package/example/node/node_modules/media-typer/LICENSE +22 -0
  179. package/example/node/node_modules/media-typer/README.md +81 -0
  180. package/example/node/node_modules/media-typer/index.js +270 -0
  181. package/example/node/node_modules/media-typer/package.json +26 -0
  182. package/example/node/node_modules/merge-descriptors/HISTORY.md +21 -0
  183. package/example/node/node_modules/merge-descriptors/LICENSE +23 -0
  184. package/example/node/node_modules/merge-descriptors/README.md +48 -0
  185. package/example/node/node_modules/merge-descriptors/index.js +60 -0
  186. package/example/node/node_modules/merge-descriptors/package.json +32 -0
  187. package/example/node/node_modules/methods/HISTORY.md +29 -0
  188. package/example/node/node_modules/methods/LICENSE +24 -0
  189. package/example/node/node_modules/methods/README.md +51 -0
  190. package/example/node/node_modules/methods/index.js +69 -0
  191. package/example/node/node_modules/methods/package.json +36 -0
  192. package/example/node/node_modules/mime/CHANGELOG.md +164 -0
  193. package/example/node/node_modules/mime/LICENSE +21 -0
  194. package/example/node/node_modules/mime/README.md +90 -0
  195. package/example/node/node_modules/mime/cli.js +8 -0
  196. package/example/node/node_modules/mime/mime.js +108 -0
  197. package/example/node/node_modules/mime/package.json +44 -0
  198. package/example/node/node_modules/mime/src/build.js +53 -0
  199. package/example/node/node_modules/mime/src/test.js +60 -0
  200. package/example/node/node_modules/mime/types.json +1 -0
  201. package/example/node/node_modules/mime-db/HISTORY.md +499 -0
  202. package/example/node/node_modules/mime-db/LICENSE +22 -0
  203. package/example/node/node_modules/mime-db/README.md +100 -0
  204. package/example/node/node_modules/mime-db/db.json +8471 -0
  205. package/example/node/node_modules/mime-db/index.js +11 -0
  206. package/example/node/node_modules/mime-db/package.json +59 -0
  207. package/example/node/node_modules/mime-types/HISTORY.md +388 -0
  208. package/example/node/node_modules/mime-types/LICENSE +23 -0
  209. package/example/node/node_modules/mime-types/README.md +113 -0
  210. package/example/node/node_modules/mime-types/index.js +188 -0
  211. package/example/node/node_modules/mime-types/package.json +44 -0
  212. package/example/node/node_modules/ms/index.js +152 -0
  213. package/example/node/node_modules/ms/license.md +21 -0
  214. package/example/node/node_modules/ms/package.json +37 -0
  215. package/example/node/node_modules/ms/readme.md +51 -0
  216. package/example/node/node_modules/negotiator/HISTORY.md +103 -0
  217. package/example/node/node_modules/negotiator/LICENSE +24 -0
  218. package/example/node/node_modules/negotiator/README.md +203 -0
  219. package/example/node/node_modules/negotiator/index.js +124 -0
  220. package/example/node/node_modules/negotiator/lib/charset.js +169 -0
  221. package/example/node/node_modules/negotiator/lib/encoding.js +184 -0
  222. package/example/node/node_modules/negotiator/lib/language.js +179 -0
  223. package/example/node/node_modules/negotiator/lib/mediaType.js +294 -0
  224. package/example/node/node_modules/negotiator/package.json +42 -0
  225. package/example/node/node_modules/on-finished/HISTORY.md +88 -0
  226. package/example/node/node_modules/on-finished/LICENSE +23 -0
  227. package/example/node/node_modules/on-finished/README.md +154 -0
  228. package/example/node/node_modules/on-finished/index.js +196 -0
  229. package/example/node/node_modules/on-finished/package.json +31 -0
  230. package/example/node/node_modules/parseurl/HISTORY.md +58 -0
  231. package/example/node/node_modules/parseurl/LICENSE +24 -0
  232. package/example/node/node_modules/parseurl/README.md +133 -0
  233. package/example/node/node_modules/parseurl/index.js +158 -0
  234. package/example/node/node_modules/parseurl/package.json +40 -0
  235. package/example/node/node_modules/path-to-regexp/History.md +36 -0
  236. package/example/node/node_modules/path-to-regexp/LICENSE +21 -0
  237. package/example/node/node_modules/path-to-regexp/Readme.md +35 -0
  238. package/example/node/node_modules/path-to-regexp/index.js +129 -0
  239. package/example/node/node_modules/path-to-regexp/package.json +30 -0
  240. package/example/node/node_modules/proxy-addr/HISTORY.md +161 -0
  241. package/example/node/node_modules/proxy-addr/LICENSE +22 -0
  242. package/example/node/node_modules/proxy-addr/README.md +139 -0
  243. package/example/node/node_modules/proxy-addr/index.js +327 -0
  244. package/example/node/node_modules/proxy-addr/package.json +47 -0
  245. package/example/node/node_modules/qs/.editorconfig +39 -0
  246. package/example/node/node_modules/qs/.eslintignore +2 -0
  247. package/example/node/node_modules/qs/.eslintrc +35 -0
  248. package/example/node/node_modules/qs/.github/FUNDING.yml +12 -0
  249. package/example/node/node_modules/qs/.nycrc +13 -0
  250. package/example/node/node_modules/qs/CHANGELOG.md +359 -0
  251. package/example/node/node_modules/qs/LICENSE.md +29 -0
  252. package/example/node/node_modules/qs/README.md +604 -0
  253. package/example/node/node_modules/qs/dist/qs.js +832 -0
  254. package/example/node/node_modules/qs/lib/formats.js +23 -0
  255. package/example/node/node_modules/qs/lib/index.js +11 -0
  256. package/example/node/node_modules/qs/lib/parse.js +257 -0
  257. package/example/node/node_modules/qs/lib/stringify.js +278 -0
  258. package/example/node/node_modules/qs/lib/utils.js +251 -0
  259. package/example/node/node_modules/qs/package.json +69 -0
  260. package/example/node/node_modules/qs/test/parse.js +772 -0
  261. package/example/node/node_modules/qs/test/stringify.js +793 -0
  262. package/example/node/node_modules/qs/test/utils.js +136 -0
  263. package/example/node/node_modules/range-parser/HISTORY.md +56 -0
  264. package/example/node/node_modules/range-parser/LICENSE +23 -0
  265. package/example/node/node_modules/range-parser/README.md +84 -0
  266. package/example/node/node_modules/range-parser/index.js +162 -0
  267. package/example/node/node_modules/range-parser/package.json +44 -0
  268. package/example/node/node_modules/raw-body/HISTORY.md +284 -0
  269. package/example/node/node_modules/raw-body/LICENSE +22 -0
  270. package/example/node/node_modules/raw-body/README.md +217 -0
  271. package/example/node/node_modules/raw-body/index.d.ts +87 -0
  272. package/example/node/node_modules/raw-body/index.js +286 -0
  273. package/example/node/node_modules/raw-body/package.json +48 -0
  274. package/example/node/node_modules/safe-buffer/LICENSE +21 -0
  275. package/example/node/node_modules/safe-buffer/README.md +584 -0
  276. package/example/node/node_modules/safe-buffer/index.d.ts +187 -0
  277. package/example/node/node_modules/safe-buffer/index.js +65 -0
  278. package/example/node/node_modules/safe-buffer/package.json +51 -0
  279. package/example/node/node_modules/safer-buffer/LICENSE +21 -0
  280. package/example/node/node_modules/safer-buffer/Porting-Buffer.md +268 -0
  281. package/example/node/node_modules/safer-buffer/Readme.md +156 -0
  282. package/example/node/node_modules/safer-buffer/dangerous.js +58 -0
  283. package/example/node/node_modules/safer-buffer/package.json +34 -0
  284. package/example/node/node_modules/safer-buffer/safer.js +77 -0
  285. package/example/node/node_modules/safer-buffer/tests.js +406 -0
  286. package/example/node/node_modules/send/HISTORY.md +506 -0
  287. package/example/node/node_modules/send/LICENSE +23 -0
  288. package/example/node/node_modules/send/README.md +327 -0
  289. package/example/node/node_modules/send/index.js +1133 -0
  290. package/example/node/node_modules/send/node_modules/.bin/mime +15 -0
  291. package/example/node/node_modules/send/node_modules/.bin/mime.cmd +7 -0
  292. package/example/node/node_modules/send/node_modules/ms/index.js +162 -0
  293. package/example/node/node_modules/send/node_modules/ms/license.md +21 -0
  294. package/example/node/node_modules/send/node_modules/ms/package.json +38 -0
  295. package/example/node/node_modules/send/node_modules/ms/readme.md +59 -0
  296. package/example/node/node_modules/send/package.json +61 -0
  297. package/example/node/node_modules/serve-static/HISTORY.md +459 -0
  298. package/example/node/node_modules/serve-static/LICENSE +25 -0
  299. package/example/node/node_modules/serve-static/README.md +257 -0
  300. package/example/node/node_modules/serve-static/index.js +210 -0
  301. package/example/node/node_modules/serve-static/package.json +42 -0
  302. package/example/node/node_modules/setprototypeof/LICENSE +13 -0
  303. package/example/node/node_modules/setprototypeof/README.md +31 -0
  304. package/example/node/node_modules/setprototypeof/index.d.ts +2 -0
  305. package/example/node/node_modules/setprototypeof/index.js +17 -0
  306. package/example/node/node_modules/setprototypeof/package.json +38 -0
  307. package/example/node/node_modules/setprototypeof/test/index.js +24 -0
  308. package/example/node/node_modules/statuses/HISTORY.md +65 -0
  309. package/example/node/node_modules/statuses/LICENSE +23 -0
  310. package/example/node/node_modules/statuses/README.md +127 -0
  311. package/example/node/node_modules/statuses/codes.json +66 -0
  312. package/example/node/node_modules/statuses/index.js +113 -0
  313. package/example/node/node_modules/statuses/package.json +48 -0
  314. package/example/node/node_modules/toidentifier/HISTORY.md +9 -0
  315. package/example/node/node_modules/toidentifier/LICENSE +21 -0
  316. package/example/node/node_modules/toidentifier/README.md +61 -0
  317. package/example/node/node_modules/toidentifier/index.js +32 -0
  318. package/example/node/node_modules/toidentifier/package.json +38 -0
  319. package/example/node/node_modules/type-is/HISTORY.md +259 -0
  320. package/example/node/node_modules/type-is/LICENSE +23 -0
  321. package/example/node/node_modules/type-is/README.md +170 -0
  322. package/example/node/node_modules/type-is/index.js +266 -0
  323. package/example/node/node_modules/type-is/package.json +45 -0
  324. package/example/node/node_modules/unpipe/HISTORY.md +4 -0
  325. package/example/node/node_modules/unpipe/LICENSE +22 -0
  326. package/example/node/node_modules/unpipe/README.md +43 -0
  327. package/example/node/node_modules/unpipe/index.js +69 -0
  328. package/example/node/node_modules/unpipe/package.json +27 -0
  329. package/example/node/node_modules/utils-merge/LICENSE +20 -0
  330. package/example/node/node_modules/utils-merge/README.md +34 -0
  331. package/example/node/node_modules/utils-merge/index.js +23 -0
  332. package/example/node/node_modules/utils-merge/package.json +40 -0
  333. package/example/node/node_modules/vary/HISTORY.md +39 -0
  334. package/example/node/node_modules/vary/LICENSE +22 -0
  335. package/example/node/node_modules/vary/README.md +101 -0
  336. package/example/node/node_modules/vary/index.js +149 -0
  337. package/example/node/node_modules/vary/package.json +43 -0
  338. package/example/node/package.json +11 -0
  339. package/example/node/server.js +27 -15
  340. package/example/node/yarn.lock +352 -0
  341. package/package.json +29 -18
  342. package/src/index.js +16 -10
  343. package/src/lib/crawler/crawlers.js +1399 -11
  344. package/src/lib/crawler/exclusions.js +56 -9
  345. package/src/lib/crawler/headers.js +24 -15
  346. package/src/lib/crawler/provider.js +11 -13
  347. package/src/lib/crawler.js +123 -132
  348. package/test/lib/crawler.test.js +83 -24
  349. package/test/lib/database/crawlers.txt +3651 -0
  350. package/test/lib/database/devices.txt +165636 -0
  351. package/webpack.common.js +20 -20
  352. package/webpack.dev.js +7 -7
  353. package/webpack.prod.js +14 -15
@@ -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
+ });