@readme/httpsnippet 3.1.3 → 4.0.2

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 (319) hide show
  1. package/README.md +63 -62
  2. package/dist/package.json +86 -0
  3. package/dist/src/fixtures/customTarget.js +15 -0
  4. package/dist/src/fixtures/mimetypes.js +77 -0
  5. package/dist/src/fixtures/requests/application-form-encoded.js +69 -0
  6. package/dist/src/fixtures/requests/application-json.js +72 -0
  7. package/dist/src/fixtures/requests/cookies.js +51 -0
  8. package/dist/src/fixtures/requests/custom-method.js +41 -0
  9. package/dist/src/fixtures/requests/full.js +99 -0
  10. package/dist/src/fixtures/requests/headers.js +56 -0
  11. package/dist/src/fixtures/requests/http-insecure.js +45 -0
  12. package/dist/src/fixtures/requests/jsonObj-multiline.js +59 -0
  13. package/dist/src/fixtures/requests/jsonObj-null-value.js +61 -0
  14. package/dist/src/fixtures/requests/multipart-data.js +72 -0
  15. package/dist/src/fixtures/requests/multipart-file.js +65 -0
  16. package/dist/src/fixtures/requests/multipart-form-data-no-params.js +56 -0
  17. package/dist/src/fixtures/requests/multipart-form-data.js +64 -0
  18. package/dist/src/fixtures/requests/nested.js +64 -0
  19. package/dist/src/fixtures/requests/query-encoded.js +59 -0
  20. package/dist/src/fixtures/requests/query.js +64 -0
  21. package/dist/src/fixtures/requests/short.js +45 -0
  22. package/dist/src/fixtures/requests/text-plain.js +57 -0
  23. package/dist/src/fixtures/runCustomFixtures.js +77 -0
  24. package/dist/src/helpers/code-builder.js +91 -0
  25. package/dist/src/helpers/form-data.js +157 -0
  26. package/dist/src/helpers/har-validator.js +76 -0
  27. package/dist/src/helpers/headers.js +33 -0
  28. package/dist/src/helpers/reducer.js +19 -0
  29. package/dist/src/helpers/shell.js +20 -0
  30. package/dist/src/helpers/utils.js +21 -0
  31. package/dist/src/index.js +285 -0
  32. package/dist/src/targets/c/libcurl/client.js +43 -0
  33. package/dist/src/targets/c/target.js +15 -0
  34. package/dist/src/targets/clojure/clj_http/client.js +184 -0
  35. package/dist/src/targets/clojure/target.js +15 -0
  36. package/dist/src/targets/csharp/httpclient/client.js +162 -0
  37. package/dist/src/targets/csharp/restsharp/client.js +38 -0
  38. package/dist/src/targets/csharp/target.js +17 -0
  39. package/dist/src/targets/go/native/client.js +122 -0
  40. package/dist/src/targets/go/target.js +15 -0
  41. package/dist/src/targets/http/http1.1/client.js +79 -0
  42. package/dist/src/targets/http/target.js +15 -0
  43. package/dist/src/targets/java/asynchttp/client.js +53 -0
  44. package/dist/src/targets/java/nethttp/client.js +52 -0
  45. package/dist/src/targets/java/okhttp/client.js +79 -0
  46. package/dist/src/targets/java/target.js +21 -0
  47. package/dist/src/targets/java/unirest/client.js +53 -0
  48. package/dist/src/targets/javascript/axios/client.js +101 -0
  49. package/dist/src/targets/javascript/axios/fixtures/application-form-encoded.js +22 -0
  50. package/dist/src/targets/javascript/axios/fixtures/application-json.js +26 -0
  51. package/dist/src/targets/javascript/axios/fixtures/cookies.js +18 -0
  52. package/dist/src/targets/javascript/axios/fixtures/custom-method.js +14 -0
  53. package/dist/src/targets/javascript/axios/fixtures/full.js +26 -0
  54. package/dist/src/targets/javascript/axios/fixtures/headers.js +18 -0
  55. package/dist/src/targets/javascript/axios/fixtures/http-insecure.js +14 -0
  56. package/dist/src/targets/javascript/axios/fixtures/jsonObj-multiline.js +19 -0
  57. package/dist/src/targets/javascript/axios/fixtures/jsonObj-null-value.js +19 -0
  58. package/dist/src/targets/javascript/axios/fixtures/multipart-data.js +22 -0
  59. package/dist/src/targets/javascript/axios/fixtures/multipart-file.js +21 -0
  60. package/dist/src/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +18 -0
  61. package/dist/src/targets/javascript/axios/fixtures/multipart-form-data.js +21 -0
  62. package/dist/src/targets/javascript/axios/fixtures/nested.js +18 -0
  63. package/dist/src/targets/javascript/axios/fixtures/query-encoded.js +21 -0
  64. package/dist/src/targets/javascript/axios/fixtures/query.js +18 -0
  65. package/dist/src/targets/javascript/axios/fixtures/short.js +14 -0
  66. package/dist/src/targets/javascript/axios/fixtures/text-plain.js +19 -0
  67. package/dist/src/targets/javascript/fetch/client.js +115 -0
  68. package/dist/src/targets/javascript/fetch/fixtures/application-form-encoded.js +9 -0
  69. package/dist/src/targets/javascript/fetch/fixtures/application-json.js +16 -0
  70. package/dist/src/targets/javascript/fetch/fixtures/cookies.js +5 -0
  71. package/dist/src/targets/javascript/fetch/fixtures/custom-method.js +5 -0
  72. package/dist/src/targets/javascript/fetch/fixtures/full.js +13 -0
  73. package/dist/src/targets/javascript/fetch/fixtures/headers.js +8 -0
  74. package/dist/src/targets/javascript/fetch/fixtures/http-insecure.js +5 -0
  75. package/dist/src/targets/javascript/fetch/fixtures/jsonObj-multiline.js +9 -0
  76. package/dist/src/targets/javascript/fetch/fixtures/jsonObj-null-value.js +9 -0
  77. package/dist/src/targets/javascript/fetch/fixtures/multipart-data.js +9 -0
  78. package/dist/src/targets/javascript/fetch/fixtures/multipart-file.js +8 -0
  79. package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +5 -0
  80. package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data.js +8 -0
  81. package/dist/src/targets/javascript/fetch/fixtures/nested.js +5 -0
  82. package/dist/src/targets/javascript/fetch/fixtures/query-encoded.js +5 -0
  83. package/dist/src/targets/javascript/fetch/fixtures/query.js +5 -0
  84. package/dist/src/targets/javascript/fetch/fixtures/short.js +5 -0
  85. package/dist/src/targets/javascript/fetch/fixtures/text-plain.js +5 -0
  86. package/dist/src/targets/javascript/jquery/client.js +93 -0
  87. package/dist/src/targets/javascript/jquery/fixtures/application-form-encoded.js +17 -0
  88. package/dist/src/targets/javascript/jquery/fixtures/application-json.js +15 -0
  89. package/dist/src/targets/javascript/jquery/fixtures/cookies.js +13 -0
  90. package/dist/src/targets/javascript/jquery/fixtures/custom-method.js +11 -0
  91. package/dist/src/targets/javascript/jquery/fixtures/full.js +18 -0
  92. package/dist/src/targets/javascript/jquery/fixtures/headers.js +15 -0
  93. package/dist/src/targets/javascript/jquery/fixtures/http-insecure.js +11 -0
  94. package/dist/src/targets/javascript/jquery/fixtures/jsonObj-multiline.js +15 -0
  95. package/dist/src/targets/javascript/jquery/fixtures/jsonObj-null-value.js +15 -0
  96. package/dist/src/targets/javascript/jquery/fixtures/multipart-data.js +18 -0
  97. package/dist/src/targets/javascript/jquery/fixtures/multipart-file.js +17 -0
  98. package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data-no-params.js +13 -0
  99. package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data.js +17 -0
  100. package/dist/src/targets/javascript/jquery/fixtures/nested.js +11 -0
  101. package/dist/src/targets/javascript/jquery/fixtures/query-encoded.js +11 -0
  102. package/dist/src/targets/javascript/jquery/fixtures/query.js +11 -0
  103. package/dist/src/targets/javascript/jquery/fixtures/short.js +11 -0
  104. package/dist/src/targets/javascript/jquery/fixtures/text-plain.js +14 -0
  105. package/dist/src/targets/javascript/target.js +21 -0
  106. package/dist/src/targets/javascript/xhr/client.js +90 -0
  107. package/dist/src/targets/javascript/xhr/fixtures/application-form-encoded.js +12 -0
  108. package/dist/src/targets/javascript/xhr/fixtures/application-json.js +31 -0
  109. package/dist/src/targets/javascript/xhr/fixtures/cookies.js +12 -0
  110. package/dist/src/targets/javascript/xhr/fixtures/cors.js +10 -0
  111. package/dist/src/targets/javascript/xhr/fixtures/custom-method.js +11 -0
  112. package/dist/src/targets/javascript/xhr/fixtures/full.js +14 -0
  113. package/dist/src/targets/javascript/xhr/fixtures/headers.js +14 -0
  114. package/dist/src/targets/javascript/xhr/fixtures/http-insecure.js +11 -0
  115. package/dist/src/targets/javascript/xhr/fixtures/jsonObj-multiline.js +14 -0
  116. package/dist/src/targets/javascript/xhr/fixtures/jsonObj-null-value.js +14 -0
  117. package/dist/src/targets/javascript/xhr/fixtures/multipart-data.js +13 -0
  118. package/dist/src/targets/javascript/xhr/fixtures/multipart-file.js +12 -0
  119. package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data-no-params.js +11 -0
  120. package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data.js +12 -0
  121. package/dist/src/targets/javascript/xhr/fixtures/nested.js +11 -0
  122. package/dist/src/targets/javascript/xhr/fixtures/query-encoded.js +11 -0
  123. package/dist/src/targets/javascript/xhr/fixtures/query.js +11 -0
  124. package/dist/src/targets/javascript/xhr/fixtures/short.js +11 -0
  125. package/dist/src/targets/javascript/xhr/fixtures/text-plain.js +12 -0
  126. package/dist/src/targets/kotlin/okhttp/client.js +79 -0
  127. package/dist/src/targets/kotlin/target.js +15 -0
  128. package/dist/src/targets/node/axios/client.js +87 -0
  129. package/dist/src/targets/node/axios/fixtures/application-form-encoded.js +19 -0
  130. package/dist/src/targets/node/axios/fixtures/application-json.js +22 -0
  131. package/dist/src/targets/node/axios/fixtures/cookies.js +14 -0
  132. package/dist/src/targets/node/axios/fixtures/custom-method.js +10 -0
  133. package/dist/src/targets/node/axios/fixtures/full.js +22 -0
  134. package/dist/src/targets/node/axios/fixtures/headers.js +14 -0
  135. package/dist/src/targets/node/axios/fixtures/http-insecure.js +10 -0
  136. package/dist/src/targets/node/axios/fixtures/jsonObj-multiline.js +15 -0
  137. package/dist/src/targets/node/axios/fixtures/jsonObj-null-value.js +15 -0
  138. package/dist/src/targets/node/axios/fixtures/multipart-data.js +15 -0
  139. package/dist/src/targets/node/axios/fixtures/multipart-file.js +15 -0
  140. package/dist/src/targets/node/axios/fixtures/multipart-form-data-no-params.js +14 -0
  141. package/dist/src/targets/node/axios/fixtures/multipart-form-data.js +15 -0
  142. package/dist/src/targets/node/axios/fixtures/nested.js +13 -0
  143. package/dist/src/targets/node/axios/fixtures/query-encoded.js +13 -0
  144. package/dist/src/targets/node/axios/fixtures/query.js +13 -0
  145. package/dist/src/targets/node/axios/fixtures/short.js +10 -0
  146. package/dist/src/targets/node/axios/fixtures/text-plain.js +15 -0
  147. package/dist/src/targets/node/fetch/client.js +149 -0
  148. package/dist/src/targets/node/fetch/fixtures/application-form-encoded.js +15 -0
  149. package/dist/src/targets/node/fetch/fixtures/application-json.js +18 -0
  150. package/dist/src/targets/node/fetch/fixtures/cookies.js +7 -0
  151. package/dist/src/targets/node/fetch/fixtures/custom-method.js +7 -0
  152. package/dist/src/targets/node/fetch/fixtures/full.js +18 -0
  153. package/dist/src/targets/node/fetch/fixtures/headers.js +10 -0
  154. package/dist/src/targets/node/fetch/fixtures/http-insecure.js +7 -0
  155. package/dist/src/targets/node/fetch/fixtures/jsonObj-multiline.js +11 -0
  156. package/dist/src/targets/node/fetch/fixtures/jsonObj-null-value.js +11 -0
  157. package/dist/src/targets/node/fetch/fixtures/multipart-data.js +13 -0
  158. package/dist/src/targets/node/fetch/fixtures/multipart-file.js +12 -0
  159. package/dist/src/targets/node/fetch/fixtures/multipart-form-data-no-params.js +7 -0
  160. package/dist/src/targets/node/fetch/fixtures/multipart-form-data.js +11 -0
  161. package/dist/src/targets/node/fetch/fixtures/nested.js +7 -0
  162. package/dist/src/targets/node/fetch/fixtures/query-encoded.js +7 -0
  163. package/dist/src/targets/node/fetch/fixtures/query.js +7 -0
  164. package/dist/src/targets/node/fetch/fixtures/short.js +7 -0
  165. package/dist/src/targets/node/fetch/fixtures/text-plain.js +7 -0
  166. package/dist/src/targets/node/native/client.js +91 -0
  167. package/dist/src/targets/node/native/fixtures/application-form-encoded.js +24 -0
  168. package/dist/src/targets/node/native/fixtures/application-json.js +30 -0
  169. package/dist/src/targets/node/native/fixtures/cookies.js +22 -0
  170. package/dist/src/targets/node/native/fixtures/custom-method.js +20 -0
  171. package/dist/src/targets/node/native/fixtures/full.js +26 -0
  172. package/dist/src/targets/node/native/fixtures/headers.js +24 -0
  173. package/dist/src/targets/node/native/fixtures/http-insecure.js +20 -0
  174. package/dist/src/targets/node/native/fixtures/jsonObj-multiline.js +23 -0
  175. package/dist/src/targets/node/native/fixtures/jsonObj-null-value.js +23 -0
  176. package/dist/src/targets/node/native/fixtures/multipart-data.js +23 -0
  177. package/dist/src/targets/node/native/fixtures/multipart-file.js +23 -0
  178. package/dist/src/targets/node/native/fixtures/multipart-form-data-no-params.js +22 -0
  179. package/dist/src/targets/node/native/fixtures/multipart-form-data.js +23 -0
  180. package/dist/src/targets/node/native/fixtures/nested.js +20 -0
  181. package/dist/src/targets/node/native/fixtures/query-encoded.js +20 -0
  182. package/dist/src/targets/node/native/fixtures/query.js +20 -0
  183. package/dist/src/targets/node/native/fixtures/short.js +20 -0
  184. package/dist/src/targets/node/native/fixtures/text-plain.js +23 -0
  185. package/dist/src/targets/node/request/client.js +116 -0
  186. package/dist/src/targets/node/request/fixtures/application-form-encoded.js +13 -0
  187. package/dist/src/targets/node/request/fixtures/application-json.js +21 -0
  188. package/dist/src/targets/node/request/fixtures/cookies.js +11 -0
  189. package/dist/src/targets/node/request/fixtures/custom-method.js +8 -0
  190. package/dist/src/targets/node/request/fixtures/full.js +20 -0
  191. package/dist/src/targets/node/request/fixtures/headers.js +12 -0
  192. package/dist/src/targets/node/request/fixtures/http-insecure.js +8 -0
  193. package/dist/src/targets/node/request/fixtures/jsonObj-multiline.js +14 -0
  194. package/dist/src/targets/node/request/fixtures/jsonObj-null-value.js +14 -0
  195. package/dist/src/targets/node/request/fixtures/multipart-data.js +20 -0
  196. package/dist/src/targets/node/request/fixtures/multipart-file.js +19 -0
  197. package/dist/src/targets/node/request/fixtures/multipart-form-data-no-params.js +12 -0
  198. package/dist/src/targets/node/request/fixtures/multipart-form-data.js +13 -0
  199. package/dist/src/targets/node/request/fixtures/nested.js +11 -0
  200. package/dist/src/targets/node/request/fixtures/query-encoded.js +11 -0
  201. package/dist/src/targets/node/request/fixtures/query.js +11 -0
  202. package/dist/src/targets/node/request/fixtures/short.js +8 -0
  203. package/dist/src/targets/node/request/fixtures/text-plain.js +13 -0
  204. package/dist/src/targets/node/target.js +24 -0
  205. package/dist/src/targets/node/unirest/client.js +119 -0
  206. package/dist/src/targets/node/unirest/fixtures/application-form-encoded.js +15 -0
  207. package/dist/src/targets/node/unirest/fixtures/application-json.js +32 -0
  208. package/dist/src/targets/node/unirest/fixtures/cookies.js +12 -0
  209. package/dist/src/targets/node/unirest/fixtures/custom-method.js +8 -0
  210. package/dist/src/targets/node/unirest/fixtures/full.js +27 -0
  211. package/dist/src/targets/node/unirest/fixtures/headers.js +13 -0
  212. package/dist/src/targets/node/unirest/fixtures/http-insecure.js +8 -0
  213. package/dist/src/targets/node/unirest/fixtures/jsonObj-multiline.js +15 -0
  214. package/dist/src/targets/node/unirest/fixtures/jsonObj-null-value.js +15 -0
  215. package/dist/src/targets/node/unirest/fixtures/multipart-data.js +20 -0
  216. package/dist/src/targets/node/unirest/fixtures/multipart-file.js +18 -0
  217. package/dist/src/targets/node/unirest/fixtures/multipart-form-data-no-params.js +11 -0
  218. package/dist/src/targets/node/unirest/fixtures/multipart-form-data.js +16 -0
  219. package/dist/src/targets/node/unirest/fixtures/nested.js +13 -0
  220. package/dist/src/targets/node/unirest/fixtures/query-encoded.js +12 -0
  221. package/dist/src/targets/node/unirest/fixtures/query.js +16 -0
  222. package/dist/src/targets/node/unirest/fixtures/short.js +8 -0
  223. package/dist/src/targets/node/unirest/fixtures/text-plain.js +12 -0
  224. package/dist/src/targets/objc/helpers.js +59 -0
  225. package/dist/src/targets/objc/nsurlsession/client.js +151 -0
  226. package/dist/src/targets/objc/target.js +15 -0
  227. package/dist/src/targets/ocaml/cohttp/client.js +72 -0
  228. package/dist/src/targets/ocaml/target.js +15 -0
  229. package/dist/src/targets/php/curl/client.js +135 -0
  230. package/dist/src/targets/php/guzzle/client.js +126 -0
  231. package/dist/src/targets/php/helpers.js +63 -0
  232. package/dist/src/targets/php/http1/client.js +90 -0
  233. package/dist/src/targets/php/http2/client.js +128 -0
  234. package/dist/src/targets/php/target.js +22 -0
  235. package/dist/src/targets/powershell/common.js +49 -0
  236. package/dist/src/targets/powershell/restmethod/client.js +13 -0
  237. package/dist/src/targets/powershell/target.js +17 -0
  238. package/dist/src/targets/powershell/webrequest/client.js +13 -0
  239. package/dist/src/targets/python/helpers.js +70 -0
  240. package/dist/src/targets/python/requests/client.js +161 -0
  241. package/dist/src/targets/python/target.js +16 -0
  242. package/dist/src/targets/r/httr/client.js +125 -0
  243. package/dist/src/targets/r/target.js +15 -0
  244. package/dist/src/targets/ruby/native/client.js +69 -0
  245. package/dist/src/targets/ruby/target.js +15 -0
  246. package/dist/src/targets/shell/curl/client.js +171 -0
  247. package/dist/src/targets/shell/httpie/client.js +111 -0
  248. package/dist/src/targets/shell/target.js +20 -0
  249. package/dist/src/targets/shell/wget/client.js +55 -0
  250. package/dist/src/targets/swift/helpers.js +80 -0
  251. package/dist/src/targets/swift/nsurlsession/client.js +156 -0
  252. package/dist/src/targets/swift/target.js +15 -0
  253. package/dist/src/targets/targets.js +130 -0
  254. package/package.json +26 -21
  255. package/src/helpers/code-builder.js +0 -108
  256. package/src/helpers/form-data.js +0 -107
  257. package/src/helpers/headers.js +0 -48
  258. package/src/helpers/reducer.js +0 -20
  259. package/src/index.js +0 -361
  260. package/src/targets/c/index.js +0 -10
  261. package/src/targets/c/libcurl.js +0 -45
  262. package/src/targets/clojure/clj_http.js +0 -176
  263. package/src/targets/clojure/index.js +0 -10
  264. package/src/targets/csharp/httpclient.js +0 -157
  265. package/src/targets/csharp/index.js +0 -11
  266. package/src/targets/csharp/restsharp.js +0 -49
  267. package/src/targets/go/index.js +0 -10
  268. package/src/targets/go/native.js +0 -130
  269. package/src/targets/http/http1.1.js +0 -89
  270. package/src/targets/http/index.js +0 -10
  271. package/src/targets/index.js +0 -20
  272. package/src/targets/java/asynchttp.js +0 -54
  273. package/src/targets/java/index.js +0 -13
  274. package/src/targets/java/nethttp.js +0 -59
  275. package/src/targets/java/okhttp.js +0 -78
  276. package/src/targets/java/unirest.js +0 -57
  277. package/src/targets/javascript/axios.js +0 -101
  278. package/src/targets/javascript/fetch.js +0 -129
  279. package/src/targets/javascript/index.js +0 -13
  280. package/src/targets/javascript/jquery.js +0 -89
  281. package/src/targets/javascript/xhr.js +0 -86
  282. package/src/targets/kotlin/index.js +0 -10
  283. package/src/targets/kotlin/okhttp.js +0 -78
  284. package/src/targets/node/axios.js +0 -76
  285. package/src/targets/node/fetch.js +0 -145
  286. package/src/targets/node/index.js +0 -15
  287. package/src/targets/node/native.js +0 -92
  288. package/src/targets/node/request.js +0 -126
  289. package/src/targets/node/unirest.js +0 -120
  290. package/src/targets/objc/helpers.js +0 -80
  291. package/src/targets/objc/index.js +0 -10
  292. package/src/targets/objc/nsurlsession.js +0 -164
  293. package/src/targets/ocaml/cohttp.js +0 -73
  294. package/src/targets/ocaml/index.js +0 -10
  295. package/src/targets/php/curl.js +0 -142
  296. package/src/targets/php/guzzle.js +0 -135
  297. package/src/targets/php/helpers.js +0 -87
  298. package/src/targets/php/http1.js +0 -85
  299. package/src/targets/php/http2.js +0 -131
  300. package/src/targets/php/index.js +0 -14
  301. package/src/targets/powershell/common.js +0 -60
  302. package/src/targets/powershell/index.js +0 -11
  303. package/src/targets/powershell/restmethod.js +0 -8
  304. package/src/targets/powershell/webrequest.js +0 -8
  305. package/src/targets/python/helpers.js +0 -85
  306. package/src/targets/python/index.js +0 -11
  307. package/src/targets/python/requests.js +0 -163
  308. package/src/targets/r/httr.js +0 -134
  309. package/src/targets/r/index.js +0 -10
  310. package/src/targets/ruby/index.js +0 -10
  311. package/src/targets/ruby/native.js +0 -71
  312. package/src/targets/shell/curl.js +0 -157
  313. package/src/targets/shell/helpers.js +0 -23
  314. package/src/targets/shell/httpie.js +0 -129
  315. package/src/targets/shell/index.js +0 -13
  316. package/src/targets/shell/wget.js +0 -52
  317. package/src/targets/swift/helpers.js +0 -93
  318. package/src/targets/swift/index.js +0 -10
  319. package/src/targets/swift/nsurlsession.js +0 -152
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ /**
3
+ * @description
4
+ * HTTP code snippet generator for Swift using NSURLSession.
5
+ *
6
+ * @author
7
+ * @thibaultCha
8
+ *
9
+ * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
10
+ */
11
+ var __assign = (this && this.__assign) || function () {
12
+ __assign = Object.assign || function(t) {
13
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
14
+ s = arguments[i];
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
16
+ t[p] = s[p];
17
+ }
18
+ return t;
19
+ };
20
+ return __assign.apply(this, arguments);
21
+ };
22
+ var __read = (this && this.__read) || function (o, n) {
23
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
24
+ if (!m) return o;
25
+ var i = m.call(o), r, ar = [], e;
26
+ try {
27
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
28
+ }
29
+ catch (error) { e = { error: error }; }
30
+ finally {
31
+ try {
32
+ if (r && !r.done && (m = i["return"])) m.call(i);
33
+ }
34
+ finally { if (e) throw e.error; }
35
+ }
36
+ return ar;
37
+ };
38
+ exports.__esModule = true;
39
+ exports.nsurlsession = void 0;
40
+ var code_builder_1 = require("../../../helpers/code-builder");
41
+ var helpers_1 = require("../helpers");
42
+ exports.nsurlsession = {
43
+ info: {
44
+ key: 'nsurlsession',
45
+ title: 'NSURLSession',
46
+ link: 'https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSession_class/index.html',
47
+ description: "Foundation's NSURLSession request"
48
+ },
49
+ convert: function (_a, options) {
50
+ var allHeaders = _a.allHeaders, postData = _a.postData, fullUrl = _a.fullUrl, method = _a.method;
51
+ var opts = __assign({ indent: ' ', pretty: true, timeout: '10' }, options);
52
+ var _b = new code_builder_1.CodeBuilder({ indent: opts.indent }), push = _b.push, blank = _b.blank, join = _b.join;
53
+ // Markers for headers to be created as litteral objects and later be set on the NSURLRequest if exist
54
+ var req = {
55
+ hasHeaders: false,
56
+ hasBody: false
57
+ };
58
+ // We just want to make sure people understand that is the only dependency
59
+ push('import Foundation');
60
+ if (Object.keys(allHeaders).length) {
61
+ req.hasHeaders = true;
62
+ blank();
63
+ push((0, helpers_1.literalDeclaration)('headers', allHeaders, opts));
64
+ }
65
+ if (postData.text || postData.jsonObj || postData.params) {
66
+ req.hasBody = true;
67
+ switch (postData.mimeType) {
68
+ case 'application/x-www-form-urlencoded':
69
+ // By appending parameters one by one in the resulting snippet,
70
+ // we make it easier for the user to edit it according to his or her needs after pasting.
71
+ // The user can just add/remove lines adding/removing body parameters.
72
+ blank();
73
+ if (postData.params) {
74
+ var _c = __read(postData.params), head = _c[0], tail = _c.slice(1);
75
+ push("let postData = NSMutableData(data: \"".concat(head.name, "=").concat(head.value, "\".data(using: String.Encoding.utf8)!)"));
76
+ tail.forEach(function (_a) {
77
+ var name = _a.name, value = _a.value;
78
+ push("postData.append(\"&".concat(name, "=").concat(value, "\".data(using: String.Encoding.utf8)!)"));
79
+ });
80
+ }
81
+ else {
82
+ req.hasBody = false;
83
+ }
84
+ break;
85
+ case 'application/json':
86
+ if (postData.jsonObj) {
87
+ push("".concat((0, helpers_1.literalDeclaration)('parameters', postData.jsonObj, opts), " as [String : Any]"));
88
+ blank();
89
+ push('let postData = JSONSerialization.data(withJSONObject: parameters, options: [])');
90
+ }
91
+ break;
92
+ case 'multipart/form-data':
93
+ /**
94
+ * By appending multipart parameters one by one in the resulting snippet,
95
+ * we make it easier for the user to edit it according to his or her needs after pasting.
96
+ * The user can just edit the parameters NSDictionary or put this part of a snippet in a multipart builder method.
97
+ */
98
+ push((0, helpers_1.literalDeclaration)('parameters', postData.params, opts));
99
+ blank();
100
+ push("let boundary = \"".concat(postData.boundary, "\""));
101
+ blank();
102
+ push('var body = ""');
103
+ push('var error: NSError? = nil');
104
+ push('for param in parameters {');
105
+ push('let paramName = param["name"]!', 1);
106
+ push('body += "--\\(boundary)\\r\\n"', 1);
107
+ push('body += "Content-Disposition:form-data; name=\\"\\(paramName)\\""', 1);
108
+ push('if let filename = param["fileName"] {', 1);
109
+ push('let contentType = param["content-type"]!', 2);
110
+ push('let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)', 2);
111
+ push('if (error != nil) {', 2);
112
+ push('print(error as Any)', 3);
113
+ push('}', 2);
114
+ push('body += "; filename=\\"\\(filename)\\"\\r\\n"', 2);
115
+ push('body += "Content-Type: \\(contentType)\\r\\n\\r\\n"', 2);
116
+ push('body += fileContent', 2);
117
+ push('} else if let paramValue = param["value"] {', 1);
118
+ push('body += "\\r\\n\\r\\n\\(paramValue)"', 2);
119
+ push('}', 1);
120
+ push('}');
121
+ break;
122
+ default:
123
+ blank();
124
+ push("let postData = NSData(data: \"".concat(postData.text, "\".data(using: String.Encoding.utf8)!)"));
125
+ }
126
+ }
127
+ blank();
128
+ // NSURLRequestUseProtocolCachePolicy is the default policy, let's just always set it to avoid confusion.
129
+ push("let request = NSMutableURLRequest(url: NSURL(string: \"".concat(fullUrl, "\")! as URL,"));
130
+ push(' cachePolicy: .useProtocolCachePolicy,');
131
+ push(
132
+ // @ts-expect-error needs better types
133
+ " timeoutInterval: ".concat(parseInt(opts.timeout, 10).toFixed(1), ")"));
134
+ push("request.httpMethod = \"".concat(method, "\""));
135
+ if (req.hasHeaders) {
136
+ push('request.allHTTPHeaderFields = headers');
137
+ }
138
+ if (req.hasBody) {
139
+ push('request.httpBody = postData as Data');
140
+ }
141
+ blank();
142
+ // Retrieving the shared session will be less verbose than creating a new one.
143
+ push('let session = URLSession.shared');
144
+ push('let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in');
145
+ push('if (error != nil) {', 1);
146
+ push('print(error as Any)', 2);
147
+ push('} else {', 1); // Casting the NSURLResponse to NSHTTPURLResponse so the user can see the status .
148
+ push('let httpResponse = response as? HTTPURLResponse', 2);
149
+ push('print(httpResponse)', 2);
150
+ push('}', 1);
151
+ push('})');
152
+ blank();
153
+ push('dataTask.resume()');
154
+ return join();
155
+ }
156
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.swift = void 0;
4
+ var client_1 = require("./nsurlsession/client");
5
+ exports.swift = {
6
+ info: {
7
+ key: 'swift',
8
+ title: 'Swift',
9
+ extname: '.swift',
10
+ "default": 'nsurlsession'
11
+ },
12
+ clientsById: {
13
+ nsurlsession: client_1.nsurlsession
14
+ }
15
+ };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.addTargetClient = exports.isClient = exports.addTarget = exports.isTarget = exports.targets = void 0;
4
+ var target_1 = require("./c/target");
5
+ var target_2 = require("./clojure/target");
6
+ var target_3 = require("./csharp/target");
7
+ var target_4 = require("./go/target");
8
+ var target_5 = require("./http/target");
9
+ var target_6 = require("./java/target");
10
+ var target_7 = require("./javascript/target");
11
+ var target_8 = require("./kotlin/target");
12
+ var target_9 = require("./node/target");
13
+ var target_10 = require("./objc/target");
14
+ var target_11 = require("./ocaml/target");
15
+ var target_12 = require("./php/target");
16
+ var target_13 = require("./powershell/target");
17
+ var target_14 = require("./python/target");
18
+ var target_15 = require("./r/target");
19
+ var target_16 = require("./ruby/target");
20
+ var target_17 = require("./shell/target");
21
+ var target_18 = require("./swift/target");
22
+ exports.targets = {
23
+ c: target_1.c,
24
+ clojure: target_2.clojure,
25
+ csharp: target_3.csharp,
26
+ go: target_4.go,
27
+ http: target_5.http,
28
+ java: target_6.java,
29
+ javascript: target_7.javascript,
30
+ kotlin: target_8.kotlin,
31
+ node: target_9.node,
32
+ objc: target_10.objc,
33
+ ocaml: target_11.ocaml,
34
+ php: target_12.php,
35
+ powershell: target_13.powershell,
36
+ python: target_14.python,
37
+ r: target_15.r,
38
+ ruby: target_16.ruby,
39
+ shell: target_17.shell,
40
+ swift: target_18.swift
41
+ };
42
+ var isTarget = function (target) {
43
+ if (typeof target !== 'object' || target === null || Array.isArray(target)) {
44
+ var got = target === null ? 'null' : Array.isArray(target) ? 'array' : typeof target;
45
+ throw new Error("you tried to add a target which is not an object, got type: \"".concat(got, "\""));
46
+ }
47
+ if (!Object.prototype.hasOwnProperty.call(target, 'info')) {
48
+ throw new Error('targets must contain an `info` object');
49
+ }
50
+ if (!Object.prototype.hasOwnProperty.call(target.info, 'key')) {
51
+ throw new Error('targets must have an `info` object with the property `key`');
52
+ }
53
+ if (!target.info.key) {
54
+ throw new Error('target key must be a unique string');
55
+ }
56
+ if (Object.prototype.hasOwnProperty.call(exports.targets, target.info.key)) {
57
+ throw new Error("a target already exists with this key, `".concat(target.info.key, "`"));
58
+ }
59
+ if (!Object.prototype.hasOwnProperty.call(target.info, 'title')) {
60
+ throw new Error('targets must have an `info` object with the property `title`');
61
+ }
62
+ if (!target.info.title) {
63
+ throw new Error('target title must be a non-zero-length string');
64
+ }
65
+ if (!Object.prototype.hasOwnProperty.call(target.info, 'extname')) {
66
+ throw new Error('targets must have an `info` object with the property `extname`');
67
+ }
68
+ if (!Object.prototype.hasOwnProperty.call(target, 'clientsById') ||
69
+ !target.clientsById ||
70
+ Object.keys(target.clientsById).length === 0) {
71
+ throw new Error("No clients provided in target ".concat(target.info.key, ". You must provide the property `clientsById` containg your clients."));
72
+ }
73
+ if (!Object.prototype.hasOwnProperty.call(target.info, 'default')) {
74
+ throw new Error('targets must have an `info` object with the property `default`');
75
+ }
76
+ if (!Object.prototype.hasOwnProperty.call(target.clientsById, target.info["default"])) {
77
+ throw new Error("target ".concat(target.info.key, " is configured with a default client ").concat(target.info["default"], ", but no such client was found in the property `clientsById` (found ").concat(JSON.stringify(Object.keys(target.clientsById)), ")"));
78
+ }
79
+ Object.values(target.clientsById).forEach(exports.isClient);
80
+ return true;
81
+ };
82
+ exports.isTarget = isTarget;
83
+ var addTarget = function (target) {
84
+ if (!(0, exports.isTarget)(target)) {
85
+ return;
86
+ }
87
+ exports.targets[target.info.key] = target;
88
+ };
89
+ exports.addTarget = addTarget;
90
+ var isClient = function (client) {
91
+ if (!client) {
92
+ throw new Error('clients must be objects');
93
+ }
94
+ if (!Object.prototype.hasOwnProperty.call(client, 'info')) {
95
+ throw new Error('targets client must contain an `info` object');
96
+ }
97
+ if (!Object.prototype.hasOwnProperty.call(client.info, 'key')) {
98
+ throw new Error('targets client must have an `info` object with property `key`');
99
+ }
100
+ if (!client.info.key) {
101
+ throw new Error('client.info.key must contain an identifier unique to this target');
102
+ }
103
+ if (!Object.prototype.hasOwnProperty.call(client.info, 'title')) {
104
+ throw new Error('targets client must have an `info` object with property `title`');
105
+ }
106
+ if (!Object.prototype.hasOwnProperty.call(client.info, 'description')) {
107
+ throw new Error('targets client must have an `info` object with property `description`');
108
+ }
109
+ if (!Object.prototype.hasOwnProperty.call(client.info, 'link')) {
110
+ throw new Error('targets client must have an `info` object with property `link`');
111
+ }
112
+ if (!Object.prototype.hasOwnProperty.call(client, 'convert') || typeof client.convert !== 'function') {
113
+ throw new Error('targets client must have a `convert` property containing a conversion function');
114
+ }
115
+ return true;
116
+ };
117
+ exports.isClient = isClient;
118
+ var addTargetClient = function (targetId, client) {
119
+ if (!(0, exports.isClient)(client)) {
120
+ return;
121
+ }
122
+ if (!Object.prototype.hasOwnProperty.call(exports.targets, targetId)) {
123
+ throw new Error("Sorry, but no ".concat(targetId, " target exists to add clients to"));
124
+ }
125
+ if (Object.prototype.hasOwnProperty.call(exports.targets[targetId], client.info.key)) {
126
+ throw new Error("the target ".concat(targetId, " already has a client with the key ").concat(client.info.key, ", please use a different key"));
127
+ }
128
+ exports.targets[targetId].clientsById[client.info.key] = client;
129
+ };
130
+ exports.addTargetClient = addTargetClient;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
- "version": "3.1.3",
2
+ "version": "4.0.2",
3
3
  "name": "@readme/httpsnippet",
4
4
  "description": "HTTP Request snippet generator for *most* languages",
5
5
  "homepage": "https://github.com/readmeio/httpsnippet",
6
6
  "license": "MIT",
7
- "main": "src/index.js",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
8
9
  "keywords": [
9
10
  "api",
10
11
  "clojure",
@@ -36,46 +37,50 @@
36
37
  "xmlhttprequest"
37
38
  ],
38
39
  "engines": {
39
- "node": ">=10"
40
+ "node": ">=14"
40
41
  },
41
42
  "files": [
42
- "bin",
43
- "src"
43
+ "dist"
44
44
  ],
45
45
  "repository": {
46
46
  "type": "git",
47
47
  "url": "https://github.com/readmeio/httpsnippet.git"
48
48
  },
49
49
  "scripts": {
50
+ "build": "tsc --build tsconfig.build.json",
51
+ "clean": "tsc --build tsconfig.build.json --clean",
50
52
  "lint": "eslint .",
53
+ "prebuild": "npm run clean",
54
+ "prepack": "npm run build",
51
55
  "pretest": "npm run lint",
52
56
  "prettier": "prettier --list-different --write \"./**/**.js\"",
53
57
  "test": "jest --coverage"
54
58
  },
55
59
  "devDependencies": {
56
- "@readme/eslint-config": "^8.0.2",
57
- "eslint": "^8.3.0",
60
+ "@readme/eslint-config": "^8.8.3",
61
+ "@types/eslint": "^8.4.1",
62
+ "@types/event-stream": "^4.0.0",
63
+ "@types/har-format": "^1.2.8",
64
+ "@types/jest": "^27.4.1",
65
+ "@types/node": "^16.11.26",
66
+ "@types/qs": "^6.9.7",
67
+ "@types/stringify-object": "^4.0.1",
68
+ "eslint": "^8.19.0",
58
69
  "glob": "^8.0.1",
59
70
  "jest": "^28.0.3",
60
- "prettier": "^2.5.0",
61
- "require-directory": "^2.1.1"
71
+ "prettier": "^2.7.1",
72
+ "require-directory": "^2.1.1",
73
+ "ts-jest": "^28.0.5",
74
+ "type-fest": "^2.12.2",
75
+ "typescript": "^4.6.3"
62
76
  },
63
77
  "dependencies": {
78
+ "ajv": "^6.12.6",
64
79
  "event-stream": "4.0.1",
65
80
  "form-data": "^4.0.0",
66
- "har-validator": "^5.0.0",
81
+ "har-schema": "^2.0.0",
67
82
  "qs": "^6.10.1",
68
83
  "stringify-object": "^3.3.0"
69
84
  },
70
- "prettier": "@readme/eslint-config/prettier",
71
- "jest": {
72
- "coveragePathIgnorePatterns": [
73
- "<rootDir>/__tests__/(.*)/__fixtures__/",
74
- "<rootDir>/node_modules"
75
- ],
76
- "testPathIgnorePatterns": [
77
- "<rootDir>/__tests__/__fixtures__/",
78
- "<rootDir>/__tests__/targets/"
79
- ]
80
- }
85
+ "prettier": "@readme/eslint-config/prettier"
81
86
  }
@@ -1,108 +0,0 @@
1
- /* eslint-disable no-param-reassign */
2
- const { format } = require('util');
3
-
4
- /**
5
- * Helper object to format and aggragate lines of code.
6
- * Lines are aggregated in a `code` array, and need to be joined to obtain a proper code snippet.
7
- *
8
- * @class
9
- *
10
- * @param {string} indentation Desired indentation character for aggregated lines of code
11
- * @param {string} join Desired character to join each line of code
12
- */
13
- class CodeBuilder {
14
- constructor(indentation, join) {
15
- this.code = [];
16
- this.indentation = indentation;
17
- this.lineJoin = join || '\n';
18
- }
19
-
20
- /**
21
- * Add given indentation level to given string and format the string (variadic)
22
- * @param {number} [indentationLevel=0] - Desired level of indentation for this line
23
- * @param {string} line - Line of code. Can contain formatting placeholders
24
- * @param {...anyobject} - Parameter to bind to `line`'s formatting placeholders
25
- * @return {string}
26
- *
27
- * @example
28
- * var builder = CodeBuilder('\t')
29
- *
30
- * builder.buildLine('console.log("hello world")')
31
- * // returns: 'console.log("hello world")'
32
- *
33
- * builder.buildLine(2, 'console.log("hello world")')
34
- * // returns: 'console.log("\t\thello world")'
35
- *
36
- * builder.buildLine(2, 'console.log("%s %s")', 'hello', 'world')
37
- * // returns: 'console.log("\t\thello world")'
38
- */
39
- buildLine(indentationLevel, line) {
40
- let lineIndentation = '';
41
- let slice = 2;
42
- if (Object.prototype.toString.call(indentationLevel) === '[object String]') {
43
- slice = 1;
44
- line = indentationLevel;
45
- indentationLevel = 0;
46
- } else if (indentationLevel === null) {
47
- return null;
48
- }
49
-
50
- while (indentationLevel) {
51
- lineIndentation += this.indentation;
52
- // eslint-disable-next-line no-plusplus
53
- indentationLevel--;
54
- }
55
-
56
- // eslint-disable-next-line prefer-rest-params
57
- const data = Array.prototype.slice.call(arguments, slice, arguments.length);
58
- data.unshift(lineIndentation + line);
59
-
60
- return format.apply(this, data);
61
- }
62
-
63
- /**
64
- * Invoke buildLine() and add the line at the top of current lines
65
- * @param {number} [indentationLevel=0] Desired level of indentation for this line
66
- * @param {string} line Line of code
67
- * @return {this}
68
- */
69
- unshift(...args) {
70
- // eslint-disable-next-line prefer-spread
71
- this.code.unshift(this.buildLine.apply(this, args));
72
-
73
- return this;
74
- }
75
-
76
- /**
77
- * Invoke buildLine() and add the line at the bottom of current lines
78
- * @param {number} [indentationLevel=0] Desired level of indentation for this line
79
- * @param {string} line Line of code
80
- * @return {this}
81
- */
82
- push(...args) {
83
- // eslint-disable-next-line prefer-spread
84
- this.code.push(this.buildLine.apply(this, args));
85
-
86
- return this;
87
- }
88
-
89
- /**
90
- * Add an empty line at the end of current lines
91
- * @return {this}
92
- */
93
- blank() {
94
- this.code.push(null);
95
-
96
- return this;
97
- }
98
-
99
- /**
100
- * Concatenate all current lines using the given lineJoin
101
- * @return {string}
102
- */
103
- join() {
104
- return this.code.join(this.lineJoin);
105
- }
106
- }
107
-
108
- module.exports = CodeBuilder;
@@ -1,107 +0,0 @@
1
- /**
2
- * @license https://raw.githubusercontent.com/node-fetch/node-fetch/master/LICENSE.md
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2016 - 2020 Node Fetch Team
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * Extracted from https://github.com/node-fetch/node-fetch/blob/64c5c296a0250b852010746c76144cb9e14698d9/src/utils/form-data.js
27
- */
28
-
29
- const carriage = '\r\n';
30
- const dashes = '-'.repeat(2);
31
-
32
- const NAME = Symbol.toStringTag;
33
-
34
- const isBlob = object => {
35
- return (
36
- typeof object === 'object' &&
37
- typeof object.arrayBuffer === 'function' &&
38
- typeof object.type === 'string' &&
39
- typeof object.stream === 'function' &&
40
- typeof object.constructor === 'function' &&
41
- /^(Blob|File)$/.test(object[NAME])
42
- );
43
- };
44
-
45
- /**
46
- * @param {string} boundary
47
- */
48
- const getFooter = boundary => `${dashes}${boundary}${dashes}${carriage.repeat(2)}`;
49
-
50
- /**
51
- * @param {string} boundary
52
- * @param {string} name
53
- * @param {*} field
54
- *
55
- * @return {string}
56
- */
57
- function getHeader(boundary, name, field) {
58
- let header = '';
59
-
60
- header += `${dashes}${boundary}${carriage}`;
61
- header += `Content-Disposition: form-data; name="${name}"`;
62
-
63
- if (isBlob(field)) {
64
- header += `; filename="${field.name}"${carriage}`;
65
- header += `Content-Type: ${field.type || 'application/octet-stream'}`;
66
- }
67
-
68
- return `${header}${carriage.repeat(2)}`;
69
- }
70
-
71
- /**
72
- * @return {string}
73
- */
74
- module.exports.getBoundary = () => {
75
- // This generates a 50 character boundary similar to those used by Firefox.
76
- // They are optimized for boyer-moore parsing.
77
- let boundary = '--------------------------';
78
- // eslint-disable-next-line no-plusplus
79
- for (let i = 0; i < 24; i++) {
80
- boundary += Math.floor(Math.random() * 10).toString(16);
81
- }
82
-
83
- return boundary;
84
- };
85
-
86
- /**
87
- * @param {FormData} form
88
- * @param {string} boundary
89
- */
90
- module.exports.formDataIterator = function* (form, boundary) {
91
- // eslint-disable-next-line no-restricted-syntax
92
- for (const [name, value] of form) {
93
- yield getHeader(boundary, name, value);
94
-
95
- if (isBlob(value)) {
96
- yield* value.stream();
97
- } else {
98
- yield value;
99
- }
100
-
101
- yield carriage;
102
- }
103
-
104
- yield getFooter(boundary);
105
- };
106
-
107
- module.exports.isBlob = isBlob;
@@ -1,48 +0,0 @@
1
- module.exports = {
2
- /**
3
- * Given a headers object retrieve the contents of a header out of it via a case-insensitive key.
4
- *
5
- * @param {object} headers
6
- * @param {string} name
7
- * @return {string}
8
- */
9
- getHeader: (headers, name) => {
10
- return headers[Object.keys(headers).find(k => k.toLowerCase() === name.toLowerCase())];
11
- },
12
-
13
- /**
14
- * Given a headers object retrieve a specific header out of it via a case-insensitive key.
15
- *
16
- * @param {object} headers
17
- * @param {string} name
18
- * @return {string}
19
- */
20
- getHeaderName: (headers, name) => {
21
- return Object.keys(headers).find(k => {
22
- return k.toLowerCase() === name.toLowerCase();
23
- });
24
- },
25
-
26
- /**
27
- * Determine if a given case-insensitive header exists within a header object.
28
- *
29
- * @param {object} headers
30
- * @param {string} name
31
- * @return {(integer|boolean)}
32
- */
33
- hasHeader: (headers, name) => {
34
- return Boolean(Object.keys(headers).find(k => k.toLowerCase() === name.toLowerCase()));
35
- },
36
-
37
- /**
38
- * Determines if a given mimetype is JSON, or a variant of such.
39
- *
40
- * @param {string}} mimeType
41
- * @returns {boolean}
42
- */
43
- isMimeTypeJson: mimeType => {
44
- return ['application/json', 'application/x-json', 'text/json', 'text/x-json', '+json'].some(function (type) {
45
- return mimeType.indexOf(type) > -1;
46
- });
47
- },
48
- };
@@ -1,20 +0,0 @@
1
- /* eslint-disable no-param-reassign */
2
- module.exports = function (obj, pair) {
3
- if (obj[pair.name] === undefined) {
4
- obj[pair.name] = pair.value;
5
- return obj;
6
- }
7
-
8
- // If we already have it as array just push the value
9
- if (Array.isArray(obj[pair.name])) {
10
- obj[pair.name].push(pair.value);
11
- return obj;
12
- }
13
-
14
- // convert to array
15
- const arr = [obj[pair.name], pair.value];
16
-
17
- obj[pair.name] = arr;
18
-
19
- return obj;
20
- };