@sparted/shared-library 1.0.1-O → 1.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 (321) hide show
  1. package/{dist/array → array}/array-to-map.d.ts +1 -1
  2. package/{dist/array → array}/array-to-map.js +1 -1
  3. package/array/array-to-map.js.map +1 -0
  4. package/cdn/cdn-creators/imgix.cdn-creator.d.ts +3 -0
  5. package/cdn/cdn-creators/imgix.cdn-creator.js +24 -0
  6. package/cdn/cdn-creators/imgix.cdn-creator.js.map +1 -0
  7. package/cdn/cdn-creators/index.d.ts +2 -0
  8. package/cdn/cdn-creators/index.js +14 -0
  9. package/cdn/cdn-creators/twicpics.cdn-creator.d.ts +3 -0
  10. package/cdn/cdn-creators/twicpics.cdn-creator.js +30 -0
  11. package/cdn/cdn-creators/twicpics.cdn-creator.js.map +1 -0
  12. package/cdn/cdn.factory.d.ts +4 -0
  13. package/cdn/cdn.factory.js +19 -0
  14. package/cdn/cdn.factory.js.map +1 -0
  15. package/cdn/index.d.ts +2 -0
  16. package/{dist/cdn → cdn}/index.js +1 -1
  17. package/cdn/types/cdn-factory.type.d.ts +24 -0
  18. package/cdn/types/index.d.ts +2 -0
  19. package/cdn/types/transformation.type.d.ts +17 -0
  20. package/{dist/cdn → cdn}/utils/extract-info-from-url.util.d.ts +1 -1
  21. package/{dist/cdn → cdn}/utils/extract-info-from-url.util.js +1 -4
  22. package/cdn/utils/extract-info-from-url.util.js.map +1 -0
  23. package/cdn/utils/get-cdn-from-s3-url.util.d.ts +7 -0
  24. package/{dist/cdn → cdn}/utils/get-cdn-from-s3-url.util.js +5 -3
  25. package/cdn/utils/get-cdn-from-s3-url.util.js.map +1 -0
  26. package/cdn/utils/index.d.ts +2 -0
  27. package/cdn/utils/index.js +12 -0
  28. package/cdn/utils/index.js.map +1 -0
  29. package/{dist/index.js → index.js} +1 -1
  30. package/package.json +2 -2
  31. package/promise/index.js.map +1 -0
  32. package/.circleci/config.yml +0 -40
  33. package/.eslintignore +0 -1
  34. package/.eslintrc.js +0 -17
  35. package/.gitignore +0 -37
  36. package/CHANGELOG.md +0 -43
  37. package/README.md +0 -26
  38. package/dist/array/array-to-map.js.map +0 -1
  39. package/dist/cdn/cdn.factory.d.ts +0 -11
  40. package/dist/cdn/cdn.factory.js +0 -59
  41. package/dist/cdn/cdn.factory.js.map +0 -1
  42. package/dist/cdn/index.d.ts +0 -2
  43. package/dist/cdn/types/cdn-factory.type.d.ts +0 -26
  44. package/dist/cdn/types/index.d.ts +0 -1
  45. package/dist/cdn/utils/extract-info-from-url.util.js.map +0 -1
  46. package/dist/cdn/utils/get-cdn-from-s3-url.util.d.ts +0 -6
  47. package/dist/cdn/utils/get-cdn-from-s3-url.util.js.map +0 -1
  48. package/dist/cdn/utils/get-cdn-url.util.d.ts +0 -8
  49. package/dist/cdn/utils/get-cdn-url.util.js +0 -13
  50. package/dist/cdn/utils/get-cdn-url.util.js.map +0 -1
  51. package/dist/package.json +0 -61
  52. package/global.d.ts +0 -2
  53. package/rollup.config.ts +0 -15
  54. package/src/array/__tests__/array-to-map.test.ts +0 -50
  55. package/src/array/__tests__/get-values-from-keys.test.ts +0 -14
  56. package/src/array/array-to-map.ts +0 -32
  57. package/src/array/get-values-from-keys.ts +0 -3
  58. package/src/array/index.ts +0 -2
  59. package/src/cdn/__tests__/cdn.factory.test.ts +0 -126
  60. package/src/cdn/__tests__/utils.test.ts +0 -466
  61. package/src/cdn/cdn.factory.ts +0 -73
  62. package/src/cdn/index.ts +0 -2
  63. package/src/cdn/types/cdn-factory.type.ts +0 -39
  64. package/src/cdn/types/index.ts +0 -1
  65. package/src/cdn/utils/extract-info-from-url.util.ts +0 -25
  66. package/src/cdn/utils/get-cdn-from-s3-url.util.ts +0 -20
  67. package/src/cdn/utils/get-cdn-url.util.ts +0 -26
  68. package/src/formatting/__tests__/format-number.test.ts +0 -11
  69. package/src/formatting/format-number.ts +0 -14
  70. package/src/formatting/index.ts +0 -1
  71. package/src/fp/__tests__/run-while.test.ts +0 -29
  72. package/src/fp/index.ts +0 -1
  73. package/src/fp/run-while.ts +0 -54
  74. package/src/http/__tests__/build-search-params.test.ts +0 -17
  75. package/src/http/__tests__/encode-search-object.test.ts +0 -34
  76. package/src/http/__tests__/fetch-with-timeout.test.ts +0 -50
  77. package/src/http/build-search-params.ts +0 -18
  78. package/src/http/encode-search-object.ts +0 -39
  79. package/src/http/fetch-with-timeout.ts +0 -24
  80. package/src/http/index.ts +0 -3
  81. package/src/index.ts +0 -14
  82. package/src/linked-list/__tests__/apply-diff-linked-list.test.ts +0 -103
  83. package/src/linked-list/__tests__/create-linked-list.test.ts +0 -204
  84. package/src/linked-list/__tests__/find-linked-list.test.ts +0 -40
  85. package/src/linked-list/__tests__/get-linked-list.test.ts +0 -28
  86. package/src/linked-list/__tests__/insert-linked-list.test.ts +0 -186
  87. package/src/linked-list/__tests__/linked-list-utils.test.ts +0 -252
  88. package/src/linked-list/__tests__/reduce-linked-list.test.ts +0 -31
  89. package/src/linked-list/__tests__/remove-linked-list.test.ts +0 -129
  90. package/src/linked-list/__tests__/update-linked-list.test.ts +0 -53
  91. package/src/linked-list/__tests__/while-linked-list.test.ts +0 -58
  92. package/src/linked-list/apply-diff-linked-list.ts +0 -35
  93. package/src/linked-list/create-linked-list.ts +0 -79
  94. package/src/linked-list/find-linked-list.ts +0 -26
  95. package/src/linked-list/get-linked-list.ts +0 -9
  96. package/src/linked-list/index.ts +0 -2
  97. package/src/linked-list/insert-linked-list.ts +0 -50
  98. package/src/linked-list/linked-list-utils.ts +0 -143
  99. package/src/linked-list/reduce-linked-list.ts +0 -18
  100. package/src/linked-list/remove-linked-list.ts +0 -36
  101. package/src/linked-list/type.ts +0 -38
  102. package/src/linked-list/update-linked-list.ts +0 -29
  103. package/src/linked-list/while-linked-list.ts +0 -33
  104. package/src/math/__tests__/clamp-number.test.ts +0 -30
  105. package/src/math/__tests__/interpolate.test.ts +0 -28
  106. package/src/math/__tests__/number-range.test.ts +0 -59
  107. package/src/math/__tests__/random-number.test.ts +0 -11
  108. package/src/math/clamp-number.ts +0 -8
  109. package/src/math/index.ts +0 -4
  110. package/src/math/interpolate.ts +0 -18
  111. package/src/math/number-range.ts +0 -16
  112. package/src/math/random-number.ts +0 -10
  113. package/src/object/__tests__/merge-deep.test.ts +0 -56
  114. package/src/object/index.ts +0 -1
  115. package/src/object/merge-deep.ts +0 -27
  116. package/src/parsing/__tests__/parse-boolean.test.ts +0 -15
  117. package/src/parsing/__tests__/parse-enum.test.ts +0 -19
  118. package/src/parsing/__tests__/parse-number.test.ts +0 -20
  119. package/src/parsing/index.ts +0 -3
  120. package/src/parsing/parse-boolean.ts +0 -10
  121. package/src/parsing/parse-enum.ts +0 -16
  122. package/src/parsing/parse-number.ts +0 -12
  123. package/src/predicates/__tests__/is-function.test.ts +0 -11
  124. package/src/predicates/__tests__/is-null.test.ts +0 -11
  125. package/src/predicates/__tests__/is-object.test.ts +0 -11
  126. package/src/predicates/__tests__/is-primitive.test.ts +0 -42
  127. package/src/predicates/__tests__/is-undefined.test.ts +0 -11
  128. package/src/predicates/__tests__/is-uuid.test.ts +0 -13
  129. package/src/predicates/index.ts +0 -5
  130. package/src/predicates/is-function.ts +0 -3
  131. package/src/predicates/is-null.ts +0 -3
  132. package/src/predicates/is-object.ts +0 -3
  133. package/src/predicates/is-primitive.ts +0 -19
  134. package/src/predicates/is-undefined.ts +0 -3
  135. package/src/predicates/is-uuid.ts +0 -3
  136. package/src/promise/__tests__/delay.test.ts +0 -13
  137. package/src/promise/__tests__/execute-or-resolve-default.test.ts +0 -25
  138. package/src/promise/__tests__/execute-with-delay.test.ts +0 -24
  139. package/src/promise/delay.ts +0 -3
  140. package/src/promise/execute-or-resolve-default.ts +0 -14
  141. package/src/promise/execute-with-delay.ts +0 -6
  142. package/src/promise/index.ts +0 -3
  143. package/src/string/__tests__/replace-in-template.test.ts +0 -52
  144. package/src/string/index.ts +0 -1
  145. package/src/string/replace-in-template.ts +0 -45
  146. package/src/time/__tests__/convert.test.ts +0 -14
  147. package/src/time/__tests__/format-minutes.test.ts +0 -10
  148. package/src/time/__tests__/get-time-diff-as-string.test.ts +0 -128
  149. package/src/time/constants.ts +0 -4
  150. package/src/time/convert.ts +0 -5
  151. package/src/time/format-minutes.ts +0 -9
  152. package/src/time/get-time-diff-as-string.ts +0 -196
  153. package/src/time/index.ts +0 -4
  154. package/src/types/function.ts +0 -1
  155. package/src/types/general.ts +0 -10
  156. package/src/types/index.ts +0 -4
  157. package/src/types/object.ts +0 -33
  158. package/src/types/search.ts +0 -29
  159. package/tsconfig.eslint.json +0 -8
  160. package/tsconfig.json +0 -25
  161. package/yarn.lock +0 -4028
  162. /package/{dist/_virtual → _virtual}/_tslib.js +0 -0
  163. /package/{dist/_virtual → _virtual}/_tslib.js.map +0 -0
  164. /package/{dist/array → array}/get-values-from-keys.d.ts +0 -0
  165. /package/{dist/array → array}/get-values-from-keys.js +0 -0
  166. /package/{dist/array → array}/get-values-from-keys.js.map +0 -0
  167. /package/{dist/array → array}/index.d.ts +0 -0
  168. /package/{dist/array → array}/index.js +0 -0
  169. /package/{dist/array → array}/index.js.map +0 -0
  170. /package/{dist/parsing → cdn/cdn-creators}/index.js.map +0 -0
  171. /package/{dist/cdn → cdn}/index.js.map +0 -0
  172. /package/{dist/cdn → cdn}/types/index.js +0 -0
  173. /package/{dist/cdn → cdn}/types/index.js.map +0 -0
  174. /package/{dist/formatting → formatting}/format-number.d.ts +0 -0
  175. /package/{dist/formatting → formatting}/format-number.js +0 -0
  176. /package/{dist/formatting → formatting}/format-number.js.map +0 -0
  177. /package/{dist/formatting → formatting}/index.d.ts +0 -0
  178. /package/{dist/formatting → formatting}/index.js +0 -0
  179. /package/{dist/formatting → formatting}/index.js.map +0 -0
  180. /package/{dist/fp → fp}/index.d.ts +0 -0
  181. /package/{dist/fp → fp}/index.js +0 -0
  182. /package/{dist/fp → fp}/index.js.map +0 -0
  183. /package/{dist/fp → fp}/run-while.d.ts +0 -0
  184. /package/{dist/fp → fp}/run-while.js +0 -0
  185. /package/{dist/fp → fp}/run-while.js.map +0 -0
  186. /package/{dist/http → http}/encode-search-object.d.ts +0 -0
  187. /package/{dist/http → http}/encode-search-object.js +0 -0
  188. /package/{dist/http → http}/encode-search-object.js.map +0 -0
  189. /package/{dist/http → http}/fetch-with-timeout.d.ts +0 -0
  190. /package/{dist/http → http}/fetch-with-timeout.js +0 -0
  191. /package/{dist/http → http}/fetch-with-timeout.js.map +0 -0
  192. /package/{dist/http → http}/index.d.ts +0 -0
  193. /package/{dist/http → http}/index.js +0 -0
  194. /package/{dist/http → http}/index.js.map +0 -0
  195. /package/{dist/index.d.ts → index.d.ts} +0 -0
  196. /package/{dist/index.js.map → index.js.map} +0 -0
  197. /package/{dist/linked-list → linked-list}/apply-diff-linked-list.d.ts +0 -0
  198. /package/{dist/linked-list → linked-list}/apply-diff-linked-list.js +0 -0
  199. /package/{dist/linked-list → linked-list}/apply-diff-linked-list.js.map +0 -0
  200. /package/{dist/linked-list → linked-list}/create-linked-list.d.ts +0 -0
  201. /package/{dist/linked-list → linked-list}/create-linked-list.js +0 -0
  202. /package/{dist/linked-list → linked-list}/create-linked-list.js.map +0 -0
  203. /package/{dist/linked-list → linked-list}/find-linked-list.d.ts +0 -0
  204. /package/{dist/linked-list → linked-list}/find-linked-list.js +0 -0
  205. /package/{dist/linked-list → linked-list}/find-linked-list.js.map +0 -0
  206. /package/{dist/linked-list → linked-list}/get-linked-list.d.ts +0 -0
  207. /package/{dist/linked-list → linked-list}/get-linked-list.js +0 -0
  208. /package/{dist/linked-list → linked-list}/get-linked-list.js.map +0 -0
  209. /package/{dist/linked-list → linked-list}/index.d.ts +0 -0
  210. /package/{dist/linked-list → linked-list}/index.js +0 -0
  211. /package/{dist/linked-list → linked-list}/index.js.map +0 -0
  212. /package/{dist/linked-list → linked-list}/insert-linked-list.d.ts +0 -0
  213. /package/{dist/linked-list → linked-list}/insert-linked-list.js +0 -0
  214. /package/{dist/linked-list → linked-list}/insert-linked-list.js.map +0 -0
  215. /package/{dist/linked-list → linked-list}/linked-list-utils.d.ts +0 -0
  216. /package/{dist/linked-list → linked-list}/linked-list-utils.js +0 -0
  217. /package/{dist/linked-list → linked-list}/linked-list-utils.js.map +0 -0
  218. /package/{dist/linked-list → linked-list}/reduce-linked-list.d.ts +0 -0
  219. /package/{dist/linked-list → linked-list}/reduce-linked-list.js +0 -0
  220. /package/{dist/linked-list → linked-list}/reduce-linked-list.js.map +0 -0
  221. /package/{dist/linked-list → linked-list}/remove-linked-list.d.ts +0 -0
  222. /package/{dist/linked-list → linked-list}/remove-linked-list.js +0 -0
  223. /package/{dist/linked-list → linked-list}/remove-linked-list.js.map +0 -0
  224. /package/{dist/linked-list → linked-list}/type.d.ts +0 -0
  225. /package/{dist/linked-list → linked-list}/update-linked-list.d.ts +0 -0
  226. /package/{dist/linked-list → linked-list}/update-linked-list.js +0 -0
  227. /package/{dist/linked-list → linked-list}/update-linked-list.js.map +0 -0
  228. /package/{dist/linked-list → linked-list}/while-linked-list.d.ts +0 -0
  229. /package/{dist/linked-list → linked-list}/while-linked-list.js +0 -0
  230. /package/{dist/linked-list → linked-list}/while-linked-list.js.map +0 -0
  231. /package/{dist/math → math}/clamp-number.d.ts +0 -0
  232. /package/{dist/math → math}/clamp-number.js +0 -0
  233. /package/{dist/math → math}/clamp-number.js.map +0 -0
  234. /package/{dist/math → math}/index.d.ts +0 -0
  235. /package/{dist/math → math}/index.js +0 -0
  236. /package/{dist/math → math}/index.js.map +0 -0
  237. /package/{dist/math → math}/interpolate.d.ts +0 -0
  238. /package/{dist/math → math}/interpolate.js +0 -0
  239. /package/{dist/math → math}/interpolate.js.map +0 -0
  240. /package/{dist/math → math}/number-range.d.ts +0 -0
  241. /package/{dist/math → math}/number-range.js +0 -0
  242. /package/{dist/math → math}/number-range.js.map +0 -0
  243. /package/{dist/math → math}/random-number.d.ts +0 -0
  244. /package/{dist/math → math}/random-number.js +0 -0
  245. /package/{dist/math → math}/random-number.js.map +0 -0
  246. /package/{dist/object → object}/index.d.ts +0 -0
  247. /package/{dist/object → object}/index.js +0 -0
  248. /package/{dist/object → object}/index.js.map +0 -0
  249. /package/{dist/object → object}/merge-deep.d.ts +0 -0
  250. /package/{dist/object → object}/merge-deep.js +0 -0
  251. /package/{dist/object → object}/merge-deep.js.map +0 -0
  252. /package/{dist/parsing → parsing}/index.d.ts +0 -0
  253. /package/{dist/parsing → parsing}/index.js +0 -0
  254. /package/{dist/promise → parsing}/index.js.map +0 -0
  255. /package/{dist/parsing → parsing}/parse-boolean.d.ts +0 -0
  256. /package/{dist/parsing → parsing}/parse-boolean.js +0 -0
  257. /package/{dist/parsing → parsing}/parse-boolean.js.map +0 -0
  258. /package/{dist/parsing → parsing}/parse-enum.d.ts +0 -0
  259. /package/{dist/parsing → parsing}/parse-enum.js +0 -0
  260. /package/{dist/parsing → parsing}/parse-enum.js.map +0 -0
  261. /package/{dist/parsing → parsing}/parse-number.d.ts +0 -0
  262. /package/{dist/parsing → parsing}/parse-number.js +0 -0
  263. /package/{dist/parsing → parsing}/parse-number.js.map +0 -0
  264. /package/{dist/predicates → predicates}/index.d.ts +0 -0
  265. /package/{dist/predicates → predicates}/index.js +0 -0
  266. /package/{dist/predicates → predicates}/index.js.map +0 -0
  267. /package/{dist/predicates → predicates}/is-function.d.ts +0 -0
  268. /package/{dist/predicates → predicates}/is-function.js +0 -0
  269. /package/{dist/predicates → predicates}/is-function.js.map +0 -0
  270. /package/{dist/predicates → predicates}/is-null.d.ts +0 -0
  271. /package/{dist/predicates → predicates}/is-null.js +0 -0
  272. /package/{dist/predicates → predicates}/is-null.js.map +0 -0
  273. /package/{dist/predicates → predicates}/is-object.d.ts +0 -0
  274. /package/{dist/predicates → predicates}/is-object.js +0 -0
  275. /package/{dist/predicates → predicates}/is-object.js.map +0 -0
  276. /package/{dist/predicates → predicates}/is-primitive.d.ts +0 -0
  277. /package/{dist/predicates → predicates}/is-primitive.js +0 -0
  278. /package/{dist/predicates → predicates}/is-primitive.js.map +0 -0
  279. /package/{dist/predicates → predicates}/is-undefined.d.ts +0 -0
  280. /package/{dist/predicates → predicates}/is-undefined.js +0 -0
  281. /package/{dist/predicates → predicates}/is-undefined.js.map +0 -0
  282. /package/{dist/predicates → predicates}/is-uuid.d.ts +0 -0
  283. /package/{dist/promise → promise}/delay.d.ts +0 -0
  284. /package/{dist/promise → promise}/delay.js +0 -0
  285. /package/{dist/promise → promise}/delay.js.map +0 -0
  286. /package/{dist/promise → promise}/execute-or-resolve-default.d.ts +0 -0
  287. /package/{dist/promise → promise}/execute-or-resolve-default.js +0 -0
  288. /package/{dist/promise → promise}/execute-or-resolve-default.js.map +0 -0
  289. /package/{dist/promise → promise}/execute-with-delay.d.ts +0 -0
  290. /package/{dist/promise → promise}/execute-with-delay.js +0 -0
  291. /package/{dist/promise → promise}/execute-with-delay.js.map +0 -0
  292. /package/{dist/promise → promise}/index.d.ts +0 -0
  293. /package/{dist/promise → promise}/index.js +0 -0
  294. /package/{dist/string → string}/index.d.ts +0 -0
  295. /package/{dist/string → string}/index.js +0 -0
  296. /package/{dist/string → string}/index.js.map +0 -0
  297. /package/{dist/string → string}/replace-in-template.d.ts +0 -0
  298. /package/{dist/string → string}/replace-in-template.js +0 -0
  299. /package/{dist/string → string}/replace-in-template.js.map +0 -0
  300. /package/{dist/time → time}/constants.d.ts +0 -0
  301. /package/{dist/time → time}/constants.js +0 -0
  302. /package/{dist/time → time}/constants.js.map +0 -0
  303. /package/{dist/time → time}/convert.d.ts +0 -0
  304. /package/{dist/time → time}/convert.js +0 -0
  305. /package/{dist/time → time}/convert.js.map +0 -0
  306. /package/{dist/time → time}/format-minutes.d.ts +0 -0
  307. /package/{dist/time → time}/format-minutes.js +0 -0
  308. /package/{dist/time → time}/format-minutes.js.map +0 -0
  309. /package/{dist/time → time}/get-time-diff-as-string.d.ts +0 -0
  310. /package/{dist/time → time}/get-time-diff-as-string.js +0 -0
  311. /package/{dist/time → time}/get-time-diff-as-string.js.map +0 -0
  312. /package/{dist/time → time}/index.d.ts +0 -0
  313. /package/{dist/time → time}/index.js +0 -0
  314. /package/{dist/time → time}/index.js.map +0 -0
  315. /package/{dist/types → types}/function.d.ts +0 -0
  316. /package/{dist/types → types}/general.d.ts +0 -0
  317. /package/{dist/types → types}/index.d.ts +0 -0
  318. /package/{dist/types → types}/index.js +0 -0
  319. /package/{dist/types → types}/index.js.map +0 -0
  320. /package/{dist/types → types}/object.d.ts +0 -0
  321. /package/{dist/types → types}/search.d.ts +0 -0
@@ -1,466 +0,0 @@
1
- import {
2
- imgixTransformationQueries,
3
- twicpicsTransformationQueries,
4
- } from '../cdn.factory';
5
- import { extractInfoFromUrl } from '../utils/extract-info-from-url.util';
6
- import { getCdnUrlFactory } from '../utils/get-cdn-url.util';
7
- import { getCdnFromS3UrlFactory } from '../utils/get-cdn-from-s3-url.util';
8
- import type { InstanceMapper } from '../types';
9
-
10
- describe('extract-info-from-url', () => {
11
- it('should handle non-aws s3 url', () => {
12
- const info = extractInfoFromUrl('https://www.google.com');
13
-
14
- expect(info).toBeUndefined();
15
- });
16
-
17
- it('should handle all aws s3 url', () => {
18
- const { instanceId: instanceIdEW1, path: pathEW1 } = extractInfoFromUrl(
19
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
20
- ) ?? {};
21
-
22
- expect(instanceIdEW1).toBe('check');
23
- expect(pathEW1).toBe('/path/to/something');
24
-
25
- const { instanceId: instanceIdAmazonaws, path: pathAmazonaws } = extractInfoFromUrl(
26
- 'https://sparted-prod-check.s3.amazonaws.com/path/to/something',
27
- ) ?? {};
28
-
29
- expect(instanceIdAmazonaws).toBe('check');
30
- expect(pathAmazonaws).toBe('/path/to/something');
31
-
32
- const { instanceId: instanceIdCloud, path: pathCloud } = extractInfoFromUrl(
33
- 'https://sparted-prod-check.s3.fr-par.scw.cloud/path/to/something',
34
- ) ?? {};
35
-
36
- expect(instanceIdCloud).toBe('check');
37
- expect(pathCloud).toBe('/path/to/something');
38
- });
39
-
40
- it('should handle any param and not crash', () => {
41
- // @ts-ignore - Passing wrong param to fn in test
42
- expect(extractInfoFromUrl()).toBeUndefined();
43
- // @ts-ignore - Passing wrong param to fn in test
44
- expect(extractInfoFromUrl([])).toBeUndefined();
45
- // @ts-ignore - Passing wrong param to fn in test
46
- expect(extractInfoFromUrl({})).toBeUndefined();
47
- expect(extractInfoFromUrl('')).toBeUndefined();
48
- });
49
- });
50
-
51
- describe('getCdnUrlFactory', () => {
52
- it('Imgix - should generate url without params', () => {
53
- const domain = 'https://sparted.imgix.fr';
54
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
55
- const getCdnUrl = getCdnUrlFactory({
56
- domain,
57
- instanceMapper,
58
- transformationQueries: imgixTransformationQueries,
59
- });
60
-
61
- expect(getCdnUrl('test', '/path/to/something')).toBe(
62
- 'https://sparted.imgix.fr/prod/test/path/to/something?auto=compress%2Cformat',
63
- );
64
- });
65
-
66
- it('Twicpics - should generate url without params', () => {
67
- const domain = 'https://sparted.twicpics.fr';
68
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
69
- const getCdnUrl = getCdnUrlFactory({
70
- domain,
71
- instanceMapper,
72
- transformationQueries: twicpicsTransformationQueries,
73
- });
74
-
75
- expect(getCdnUrl('test', '/path/to/something')).toBe(
76
- 'https://sparted.twicpics.fr/prod/test/path/to/something',
77
- );
78
- });
79
-
80
- it('Imgix - should generate url of image as thumbnail', () => {
81
- const domain = 'https://sparted.imgix.fr';
82
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
83
- const getCdnUrl = getCdnUrlFactory({
84
- domain,
85
- instanceMapper,
86
- transformationQueries: imgixTransformationQueries,
87
- });
88
-
89
- expect(getCdnUrl('test', '/path/to/something', { asThumbnail: true })).toBe(
90
- 'https://sparted.imgix.fr/prod/test/path/to/something?auto=compress%2Cformat&h=300&w=300',
91
- );
92
- });
93
-
94
- it('Twicpics - should generate url of image as thumbnail', () => {
95
- const domain = 'https://sparted.twicpics.fr';
96
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
97
- const getCdnUrl = getCdnUrlFactory({
98
- domain,
99
- instanceMapper,
100
- transformationQueries: twicpicsTransformationQueries,
101
- });
102
-
103
- expect(getCdnUrl('test', '/path/to/something', { asThumbnail: true })).toBe(
104
- 'https://sparted.twicpics.fr/prod/test/path/to/something?twic=v1/cover=300x300',
105
- );
106
- });
107
-
108
- it('Imgix - should generate url with params', () => {
109
- const domain = 'https://sparted.imgix.fr';
110
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
111
- const getCdnUrl = getCdnUrlFactory({
112
- domain,
113
- instanceMapper,
114
- transformationQueries: imgixTransformationQueries,
115
- });
116
-
117
- expect(
118
- getCdnUrl('test', '/path/to/something', {
119
- transformation: { fit: 'crop', height: 1, width: 1 },
120
- }),
121
- ).toBe(
122
- 'https://sparted.imgix.fr/prod/test/path/to/something?auto=compress%2Cformat&fit=crop&h=1&w=1',
123
- );
124
-
125
- expect(
126
- getCdnUrl('test', '/path/to/something', {
127
- transformation: { fit: 'crop', width: 1 },
128
- }),
129
- ).toBe(
130
- 'https://sparted.imgix.fr/prod/test/path/to/something?auto=compress%2Cformat&fit=crop&w=1',
131
- );
132
-
133
- expect(
134
- getCdnUrl('test', '/path/to/something', {
135
- transformation: { fit: 'crop', height: 1 },
136
- }),
137
- ).toBe(
138
- 'https://sparted.imgix.fr/prod/test/path/to/something?auto=compress%2Cformat&fit=crop&h=1',
139
- );
140
-
141
- expect(
142
- getCdnUrl('test', '/path/to/something', { transformation: { width: 1 } }),
143
- ).toBe(
144
- 'https://sparted.imgix.fr/prod/test/path/to/something?auto=compress%2Cformat&w=1',
145
- );
146
-
147
- expect(
148
- getCdnUrl('test', '/path/to/something', { transformation: { height: 1 } }),
149
- ).toBe(
150
- 'https://sparted.imgix.fr/prod/test/path/to/something?auto=compress%2Cformat&h=1',
151
- );
152
-
153
- expect(
154
- getCdnUrl('test', '/path/to/something', {
155
- transformation: { height: 1, width: 1 },
156
- }),
157
- ).toBe(
158
- 'https://sparted.imgix.fr/prod/test/path/to/something?auto=compress%2Cformat&h=1&w=1',
159
- );
160
-
161
- expect(
162
- getCdnUrl('test', '/path/to/something', {
163
- transformation: { devicePixelRatio: 2 },
164
- }),
165
- ).toBe(
166
- 'https://sparted.imgix.fr/prod/test/path/to/something?auto=compress%2Cformat&dpr=2',
167
- );
168
-
169
- expect(
170
- getCdnUrl('test', '/path/to/something', {
171
- transformation: { quality: 75 },
172
- }),
173
- ).toBe(
174
- 'https://sparted.imgix.fr/prod/test/path/to/something?auto=compress%2Cformat&q=75',
175
- );
176
- });
177
-
178
- it('Twicpics - should generate url of image as thumbnail', () => {
179
- const domain = 'https://sparted.twicpics.fr';
180
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
181
- const getCdnUrl = getCdnUrlFactory({
182
- domain,
183
- instanceMapper,
184
- transformationQueries: twicpicsTransformationQueries,
185
- });
186
-
187
- expect(
188
- getCdnUrl('test', '/path/to/something', {
189
- transformation: { fit: 'crop', height: 1, width: 1 },
190
- }),
191
- ).toBe(
192
- 'https://sparted.twicpics.fr/prod/test/path/to/something?twic=v1/crop=1x1',
193
- );
194
-
195
- expect(
196
- getCdnUrl('test', '/path/to/something', {
197
- transformation: { fit: 'contain', height: 1, width: 1 },
198
- }),
199
- ).toBe(
200
- 'https://sparted.twicpics.fr/prod/test/path/to/something?twic=v1/contain=1x1',
201
- );
202
-
203
- expect(
204
- getCdnUrl('test', '/path/to/something', { transformation: { width: 1 } }),
205
- ).toBe(
206
- 'https://sparted.twicpics.fr/prod/test/path/to/something?twic=v1/cover=1',
207
- );
208
- });
209
- });
210
-
211
- describe('getCdnFromS3UrlFactory', () => {
212
- it('Imgix - should handle non-aws s3 url', () => {
213
- const domain = 'https://sparted.imgix.fr';
214
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
215
- const getCdnUrl = getCdnUrlFactory({
216
- domain,
217
- instanceMapper,
218
- transformationQueries: imgixTransformationQueries,
219
- });
220
-
221
- const getCdnFromS3Url = getCdnFromS3UrlFactory({
222
- getCdnUrl,
223
- });
224
-
225
- expect(getCdnFromS3Url('https://www.google.com')).toBe(
226
- 'https://www.google.com',
227
- );
228
- });
229
-
230
- it('Twicpics - should handle non-aws s3 url', () => {
231
- const domain = 'https://sparted.twicpics.fr';
232
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
233
- const getCdnUrl = getCdnUrlFactory({
234
- domain,
235
- instanceMapper,
236
- transformationQueries: twicpicsTransformationQueries,
237
- });
238
-
239
- const getCdnFromS3Url = getCdnFromS3UrlFactory({
240
- getCdnUrl,
241
- });
242
-
243
- expect(getCdnFromS3Url('https://www.google.com')).toBe(
244
- 'https://www.google.com',
245
- );
246
- });
247
-
248
- it('Imgix - should handle all aws s3 url with no params', () => {
249
- const domain = 'https://sparted.imgix.fr';
250
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
251
- const getCdnUrl = getCdnUrlFactory({
252
- domain,
253
- instanceMapper,
254
- transformationQueries: imgixTransformationQueries,
255
- });
256
-
257
- const getCdnFromS3Url = getCdnFromS3UrlFactory({
258
- getCdnUrl,
259
- });
260
-
261
- expect(
262
- getCdnFromS3Url(
263
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
264
- ),
265
- ).toBe(
266
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat',
267
- );
268
-
269
- expect(
270
- getCdnFromS3Url(
271
- 'https://sparted-prod-check.s3.amazonaws.com/path/to/something',
272
- ),
273
- ).toBe(
274
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat',
275
- );
276
-
277
- expect(
278
- getCdnFromS3Url(
279
- 'https://sparted-prod-check.s3.fr-par.scw.cloud/path/to/something',
280
- ),
281
- ).toBe(
282
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat',
283
- );
284
- });
285
-
286
- it('Twicpics - should handle all aws s3 url with no params', () => {
287
- const domain = 'https://sparted.twicpics.fr';
288
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
289
- const getCdnUrl = getCdnUrlFactory({
290
- domain,
291
- instanceMapper,
292
- transformationQueries: twicpicsTransformationQueries,
293
- });
294
-
295
- const getCdnFromS3Url = getCdnFromS3UrlFactory({
296
- getCdnUrl,
297
- });
298
-
299
- expect(
300
- getCdnFromS3Url(
301
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
302
- ),
303
- ).toBe('https://sparted.twicpics.fr/prod/check/path/to/something');
304
-
305
- expect(
306
- getCdnFromS3Url(
307
- 'https://sparted-prod-check.s3.amazonaws.com/path/to/something',
308
- ),
309
- ).toBe('https://sparted.twicpics.fr/prod/check/path/to/something');
310
-
311
- expect(
312
- getCdnFromS3Url(
313
- 'https://sparted-prod-check.s3.fr-par.scw.cloud/path/to/something',
314
- ),
315
- ).toBe('https://sparted.twicpics.fr/prod/check/path/to/something');
316
- });
317
-
318
- it('Imgix - should handle params', () => {
319
- const domain = 'https://sparted.imgix.fr';
320
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
321
- const getCdnUrl = getCdnUrlFactory({
322
- domain,
323
- instanceMapper,
324
- transformationQueries: imgixTransformationQueries,
325
- });
326
-
327
- const getCdnFromS3Url = getCdnFromS3UrlFactory({
328
- getCdnUrl,
329
- });
330
-
331
- expect(
332
- getCdnFromS3Url(
333
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
334
- {
335
- transformation: { fit: 'crop', height: 1, width: 1 },
336
- },
337
- ),
338
- ).toBe(
339
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat&fit=crop&h=1&w=1',
340
- );
341
-
342
- expect(
343
- getCdnFromS3Url(
344
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
345
- {
346
- transformation: { fit: 'crop', width: 1 },
347
- },
348
- ),
349
- ).toBe(
350
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat&fit=crop&w=1',
351
- );
352
-
353
- expect(
354
- getCdnFromS3Url(
355
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
356
- {
357
- transformation: { fit: 'crop', height: 1 },
358
- },
359
- ),
360
- ).toBe(
361
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat&fit=crop&h=1',
362
- );
363
-
364
- expect(
365
- getCdnFromS3Url(
366
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
367
- {
368
- transformation: { width: 1 },
369
- },
370
- ),
371
- ).toBe(
372
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat&w=1',
373
- );
374
-
375
- expect(
376
- getCdnFromS3Url(
377
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
378
- {
379
- transformation: { height: 1 },
380
- },
381
- ),
382
- ).toBe(
383
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat&h=1',
384
- );
385
-
386
- expect(
387
- getCdnFromS3Url(
388
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
389
- {
390
- transformation: { height: 1, width: 1 },
391
- },
392
- ),
393
- ).toBe(
394
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat&h=1&w=1',
395
- );
396
-
397
- expect(
398
- getCdnFromS3Url(
399
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
400
- {
401
- transformation: { devicePixelRatio: 2 },
402
- },
403
- ),
404
- ).toBe(
405
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat&dpr=2',
406
- );
407
-
408
- expect(
409
- getCdnFromS3Url(
410
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
411
- {
412
- transformation: { quality: 75 },
413
- },
414
- ),
415
- ).toBe(
416
- 'https://sparted.imgix.fr/prod/check/path/to/something?auto=compress%2Cformat&q=75',
417
- );
418
- });
419
-
420
- it('Twicpics - should handle params', () => {
421
- const domain = 'https://sparted.twicpics.fr';
422
- const instanceMapper: InstanceMapper = (instanceId) => `/prod/${instanceId}`;
423
- const getCdnUrl = getCdnUrlFactory({
424
- domain,
425
- instanceMapper,
426
- transformationQueries: twicpicsTransformationQueries,
427
- });
428
-
429
- const getCdnFromS3Url = getCdnFromS3UrlFactory({
430
- getCdnUrl,
431
- });
432
-
433
- expect(
434
- getCdnFromS3Url(
435
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
436
- {
437
- transformation: { fit: 'crop', height: 1, width: 1 },
438
- },
439
- ),
440
- ).toBe(
441
- 'https://sparted.twicpics.fr/prod/check/path/to/something?twic=v1/crop=1x1',
442
- );
443
-
444
- expect(
445
- getCdnFromS3Url(
446
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
447
- {
448
- transformation: { fit: 'contain', height: 1, width: 1 },
449
- },
450
- ),
451
- ).toBe(
452
- 'https://sparted.twicpics.fr/prod/check/path/to/something?twic=v1/contain=1x1',
453
- );
454
-
455
- expect(
456
- getCdnFromS3Url(
457
- 'https://sparted-prod-check.s3.eu-west-1/path/to/something',
458
- {
459
- transformation: { width: 1 },
460
- },
461
- ),
462
- ).toBe(
463
- 'https://sparted.twicpics.fr/prod/check/path/to/something?twic=v1/cover=1',
464
- );
465
- });
466
- });
@@ -1,73 +0,0 @@
1
- import { buildSearchParams } from '../http/build-search-params';
2
- import type { CreateCdn, TransformationQueries } from './types';
3
- import { getCdnFromS3UrlFactory } from './utils/get-cdn-from-s3-url.util';
4
- import { getCdnUrlFactory } from './utils/get-cdn-url.util';
5
-
6
- export const imgixTransformationQueries: TransformationQueries = ({
7
- fit,
8
- width,
9
- height,
10
- quality,
11
- compress = true,
12
- devicePixelRatio,
13
- }) => {
14
- const params = {
15
- auto: compress ? 'compress,format' : undefined,
16
- fit: fit === 'crop' ? 'crop' : undefined,
17
- dpr: Number.isFinite(devicePixelRatio) ? devicePixelRatio : undefined,
18
- h: Number.isFinite(height) ? height : undefined,
19
- w: Number.isFinite(width) ? width : undefined,
20
- q: quality !== undefined && quality >= 0 && quality <= 100 ? quality : undefined,
21
- };
22
- const searchParams = buildSearchParams(params).toString();
23
-
24
- return searchParams ? `?${searchParams}` : '';
25
- };
26
-
27
- export const twicpicsTransformationQueries: TransformationQueries = (
28
- params,
29
- ) => {
30
- if (params.fit !== undefined) {
31
- if (params.width === undefined || params.height === undefined) {
32
- // eslint-disable-next-line no-console
33
- console.error('⚠️ The Twicpics api needs a width and a height.');
34
- return '';
35
- }
36
-
37
- return `?twic=v1/${params.fit}=${params.width}x${params.height}`;
38
- }
39
- if (params.width !== undefined) {
40
- const resizeHeight = params.height !== undefined
41
- ? `x${params.height}`
42
- : '';
43
-
44
- return `?twic=v1/cover=${params.width}${resizeHeight}`;
45
- }
46
-
47
- return '';
48
- };
49
-
50
- /**
51
- *
52
- * @param type cdn provider: 'twicpics' | 'imgix'
53
- * @param domain provider domain
54
- * @param instanceMapper domain + the result of the instanceMapper will form the base path
55
- * @returns \{ getCdnUrl, transformationQueries \}
56
- */
57
- export const createCdn: CreateCdn = ({ type, domain, instanceMapper }) => {
58
- const getCdnUrl = getCdnUrlFactory({
59
- domain,
60
- instanceMapper,
61
- transformationQueries:
62
- type === 'imgix'
63
- ? imgixTransformationQueries
64
- : twicpicsTransformationQueries,
65
- });
66
-
67
- return {
68
- getCdnUrl,
69
- getCdnFromS3Url: getCdnFromS3UrlFactory({
70
- getCdnUrl,
71
- }),
72
- };
73
- };
package/src/cdn/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { createCdn } from './cdn.factory';
2
- export * from './types';
@@ -1,39 +0,0 @@
1
- export type BaseUrlMapperFunc = (instanceId: string) => string;
2
-
3
- export type Transformation = {
4
- fit?: 'crop' | 'contain';
5
- width?: number;
6
- height?: number;
7
- devicePixelRatio?: number;
8
- quality?: number;
9
- /**
10
- * Only for imgix transformations. Default is true.
11
- */
12
- compress?: boolean;
13
- };
14
-
15
- export type CdnParams = {
16
- asThumbnail?: boolean;
17
- transformation?: Transformation;
18
- };
19
-
20
- export type TransformationQueries = (params: Transformation) => string;
21
-
22
- export type GetCdnUrl = (instanceId: string, path: `/${string}`, params?: CdnParams) => string;
23
-
24
- export type GetCdnFromS3Url = (url: string, params?: CdnParams) => string;
25
-
26
- export type InstanceMapper = (instanceId: string) => string;
27
-
28
- export type CdnConfig = {
29
- type: 'twicpics' | 'imgix';
30
- domain: `https://${string}`;
31
- instanceMapper: InstanceMapper;
32
- };
33
-
34
- export type Cdn = {
35
- getCdnUrl: GetCdnUrl;
36
- getCdnFromS3Url: GetCdnFromS3Url;
37
- };
38
-
39
- export type CreateCdn = (config: CdnConfig) => Cdn;
@@ -1 +0,0 @@
1
- export * from './cdn-factory.type';
@@ -1,25 +0,0 @@
1
- type ExtractInfoFromUrl = (url: string) =>
2
- | {
3
- instanceId: string;
4
- path: `/${string}`;
5
- }
6
- | undefined;
7
-
8
- const S3_URL_RE = /https:\/\/sparted-prod-([^.]+)\.s3(\.eu-west-1)?(\.amazonaws\.com)?(\.fr-par\.scw\.cloud)?(\/[^?]+)/;
9
-
10
- export const extractInfoFromUrl: ExtractInfoFromUrl = (url) => {
11
- if (typeof url !== 'string') {
12
- return undefined;
13
- }
14
-
15
- const matchS3Url = url.match(S3_URL_RE);
16
-
17
- if (!matchS3Url) {
18
- return undefined;
19
- }
20
-
21
- const instanceId = matchS3Url[1];
22
- const path = matchS3Url[5] as `/${string}`;
23
-
24
- return { instanceId, path };
25
- };
@@ -1,20 +0,0 @@
1
- import type { GetCdnFromS3Url, GetCdnUrl } from '../types';
2
- import { extractInfoFromUrl } from './extract-info-from-url.util';
3
-
4
- type FactoryConfig = {
5
- getCdnUrl: GetCdnUrl;
6
- };
7
-
8
- export function getCdnFromS3UrlFactory(config: FactoryConfig): GetCdnFromS3Url {
9
- return (url, params) => {
10
- const { getCdnUrl } = config;
11
-
12
- const info = extractInfoFromUrl(url);
13
- if (info === undefined) {
14
- return url;
15
- }
16
- const { instanceId, path } = info;
17
-
18
- return getCdnUrl(instanceId, path, params);
19
- };
20
- }
@@ -1,26 +0,0 @@
1
- import type {
2
- GetCdnUrl,
3
- InstanceMapper,
4
- Transformation,
5
- TransformationQueries,
6
- } from '../types';
7
-
8
- const DEFAULT_THUMBNAIL_CONFIG: Transformation = { width: 300, height: 300 };
9
-
10
- type FactoryConfig = {
11
- domain: `https://${string}`;
12
- instanceMapper: InstanceMapper;
13
- transformationQueries: TransformationQueries;
14
- };
15
-
16
- export const getCdnUrlFactory = (config: FactoryConfig): GetCdnUrl => (instanceId, path, params = {}) => {
17
- const { domain, instanceMapper, transformationQueries } = config;
18
-
19
- const {
20
- transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {},
21
- } = params;
22
-
23
- return `${domain}${instanceMapper(
24
- instanceId,
25
- )}${path}${transformationQueries(transformation)}`;
26
- };
@@ -1,11 +0,0 @@
1
- import { formatNumber } from '../format-number';
2
-
3
- describe('formatNumber', () => {
4
- it('should format numbers correctly', () => {
5
- expect(formatNumber(48)).toBe('48');
6
- expect(formatNumber(999)).toBe('999');
7
- expect(formatNumber(1000)).toBe('1.0k');
8
- expect(formatNumber(42869)).toBe('42.8k');
9
- expect(formatNumber(992169)).toBe('992.1k');
10
- });
11
- });
@@ -1,14 +0,0 @@
1
- const DECIMAL_SEPARATOR = '.';
2
- const THOUSAND_UNIT = 'k';
3
-
4
- export const formatNumber = (n: number): string => {
5
- const numString = String(n);
6
- if (n < 1000) {
7
- return numString;
8
- }
9
-
10
- const decimalsMinusLast = numString.slice(0, numString.length - 3);
11
- const lastDecimal = numString.slice(numString.length - 3, numString.length - 2);
12
-
13
- return `${decimalsMinusLast}${DECIMAL_SEPARATOR}${lastDecimal}${THOUSAND_UNIT}`;
14
- };
@@ -1 +0,0 @@
1
- export * from './format-number';