@sparted/shared-library 1.2.0 → 1.2.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.
- package/business/picture-spot/index.d.ts +37 -0
- package/business/types/campaign.d.ts +12 -0
- package/{dist/business → business}/types/content.d.ts +7 -8
- package/business/types/content.js.map +1 -0
- package/{src/business/types/index.ts → business/types/index.d.ts} +5 -5
- package/package.json +1 -1
- package/.circleci/config.yml +0 -40
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -25
- package/.gitignore +0 -37
- package/.idea/.gitignore +0 -8
- package/.idea/codeStyles/Project.xml +0 -35
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/shared-library.iml +0 -11
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -108
- package/.prettierrc.json +0 -6
- package/CHANGELOG.md +0 -130
- package/README.md +0 -26
- package/dist/business/picture-spot/index.d.ts +0 -2
- package/dist/business/types/content.js.map +0 -1
- package/dist/business/types/index.d.ts +0 -4
- package/dist/package.json +0 -66
- package/global.d.ts +0 -2
- package/rollup.config.ts +0 -19
- package/src/array/__tests__/array-to-map.test.ts +0 -50
- package/src/array/__tests__/get-values-from-keys.test.ts +0 -14
- package/src/array/__tests__/inner-join.test.ts +0 -55
- package/src/array/__tests__/left-outter-join.test.ts +0 -55
- package/src/array/array-to-map.ts +0 -32
- package/src/array/get-values-from-keys.ts +0 -3
- package/src/array/index.ts +0 -4
- package/src/array/inner-join.ts +0 -10
- package/src/array/left-outter-join.ts +0 -10
- package/src/business/picture-spot/index.ts +0 -3
- package/src/business/types/campaign.ts +0 -14
- package/src/business/types/content.ts +0 -155
- package/src/business/types/media.ts +0 -18
- package/src/business/types/multilingual.ts +0 -46
- package/src/business/types/thematic.ts +0 -10
- package/src/cdn/__tests__/cdn.factory.test.ts +0 -150
- package/src/cdn/__tests__/utils.test.ts +0 -528
- package/src/cdn/cdn.factory.ts +0 -70
- package/src/cdn/index.ts +0 -2
- package/src/cdn/types/cdn-factory.type.ts +0 -49
- package/src/cdn/types/index.ts +0 -1
- package/src/cdn/utils/extract-info-from-url.util.ts +0 -25
- package/src/cdn/utils/get-cdn-from-s3-url.util.ts +0 -20
- package/src/cdn/utils/get-cdn-url.util.ts +0 -31
- package/src/cdn/utils/twicpics-transformations.util.ts +0 -9
- package/src/color/__tests__/get-contrast-color.test.ts +0 -22
- package/src/color/get-contrast-color.ts +0 -18
- package/src/color/index.ts +0 -1
- package/src/formatting/__tests__/format-number.test.ts +0 -11
- package/src/formatting/format-number.ts +0 -14
- package/src/formatting/index.ts +0 -1
- package/src/fp/__tests__/run-while.test.ts +0 -29
- package/src/fp/index.ts +0 -1
- package/src/fp/run-while.ts +0 -54
- package/src/http/__tests__/build-search-params.test.ts +0 -17
- package/src/http/__tests__/encode-search-object.test.ts +0 -34
- package/src/http/__tests__/fetch-with-timeout.test.ts +0 -50
- package/src/http/build-search-params.ts +0 -18
- package/src/http/encode-search-object.ts +0 -39
- package/src/http/fetch-with-timeout.ts +0 -24
- package/src/http/index.ts +0 -3
- package/src/index.ts +0 -15
- package/src/linked-list/__tests__/apply-diff-linked-list.test.ts +0 -103
- package/src/linked-list/__tests__/create-linked-list.test.ts +0 -204
- package/src/linked-list/__tests__/find-linked-list.test.ts +0 -40
- package/src/linked-list/__tests__/get-linked-list.test.ts +0 -28
- package/src/linked-list/__tests__/insert-linked-list.test.ts +0 -186
- package/src/linked-list/__tests__/linked-list-utils.test.ts +0 -252
- package/src/linked-list/__tests__/reduce-linked-list.test.ts +0 -31
- package/src/linked-list/__tests__/remove-linked-list.test.ts +0 -129
- package/src/linked-list/__tests__/update-linked-list.test.ts +0 -53
- package/src/linked-list/__tests__/while-linked-list.test.ts +0 -58
- package/src/linked-list/apply-diff-linked-list.ts +0 -35
- package/src/linked-list/create-linked-list.ts +0 -79
- package/src/linked-list/find-linked-list.ts +0 -26
- package/src/linked-list/get-linked-list.ts +0 -9
- package/src/linked-list/index.ts +0 -2
- package/src/linked-list/insert-linked-list.ts +0 -50
- package/src/linked-list/linked-list-utils.ts +0 -143
- package/src/linked-list/reduce-linked-list.ts +0 -18
- package/src/linked-list/remove-linked-list.ts +0 -36
- package/src/linked-list/type.ts +0 -38
- package/src/linked-list/update-linked-list.ts +0 -30
- package/src/linked-list/while-linked-list.ts +0 -33
- package/src/math/__tests__/clamp-number.test.ts +0 -30
- package/src/math/__tests__/interpolate.test.ts +0 -28
- package/src/math/__tests__/median.test.ts +0 -27
- package/src/math/__tests__/number-range.test.ts +0 -59
- package/src/math/__tests__/random-number.test.ts +0 -11
- package/src/math/clamp-number.ts +0 -8
- package/src/math/index.ts +0 -5
- package/src/math/interpolate.ts +0 -18
- package/src/math/median.ts +0 -21
- package/src/math/number-range.ts +0 -16
- package/src/math/random-number.ts +0 -10
- package/src/object/__tests__/merge-deep.test.ts +0 -56
- package/src/object/__tests__/strip-properties-from-object.test.ts +0 -65
- package/src/object/index.ts +0 -2
- package/src/object/merge-deep.ts +0 -26
- package/src/object/strip-properties-from-object.ts +0 -26
- package/src/parsing/__tests__/parse-boolean.test.ts +0 -15
- package/src/parsing/__tests__/parse-enum.test.ts +0 -19
- package/src/parsing/__tests__/parse-number.test.ts +0 -20
- package/src/parsing/index.ts +0 -3
- package/src/parsing/parse-boolean.ts +0 -10
- package/src/parsing/parse-enum.ts +0 -16
- package/src/parsing/parse-number.ts +0 -12
- package/src/predicates/__tests__/is-function.test.ts +0 -11
- package/src/predicates/__tests__/is-null.test.ts +0 -11
- package/src/predicates/__tests__/is-object.test.ts +0 -11
- package/src/predicates/__tests__/is-primitive.test.ts +0 -42
- package/src/predicates/__tests__/is-undefined.test.ts +0 -11
- package/src/predicates/__tests__/is-uuid.test.ts +0 -13
- package/src/predicates/index.ts +0 -5
- package/src/predicates/is-function.ts +0 -3
- package/src/predicates/is-null.ts +0 -1
- package/src/predicates/is-object.ts +0 -3
- package/src/predicates/is-primitive.ts +0 -19
- package/src/predicates/is-undefined.ts +0 -3
- package/src/predicates/is-uuid.ts +0 -3
- package/src/promise/__tests__/delay.test.ts +0 -13
- package/src/promise/__tests__/execute-or-resolve-default.test.ts +0 -25
- package/src/promise/__tests__/execute-with-delay.test.ts +0 -24
- package/src/promise/delay.ts +0 -3
- package/src/promise/execute-or-resolve-default.ts +0 -14
- package/src/promise/execute-with-delay.ts +0 -6
- package/src/promise/index.ts +0 -3
- package/src/string/__tests__/is-string-length-within-range.test.ts +0 -23
- package/src/string/__tests__/replace-in-template.test.ts +0 -52
- package/src/string/index.ts +0 -2
- package/src/string/is-string-length-within-range.ts +0 -10
- package/src/string/replace-in-template.ts +0 -45
- package/src/time/__tests__/convert.test.ts +0 -14
- package/src/time/__tests__/format-minutes.test.ts +0 -10
- package/src/time/__tests__/get-time-diff-as-string.test.ts +0 -128
- package/src/time/constants.ts +0 -4
- package/src/time/convert.ts +0 -5
- package/src/time/format-minutes.ts +0 -9
- package/src/time/get-time-diff-as-string.ts +0 -196
- package/src/time/index.ts +0 -4
- package/src/types/function.ts +0 -1
- package/src/types/general.ts +0 -15
- package/src/types/index.ts +0 -4
- package/src/types/object.ts +0 -33
- package/src/types/search.ts +0 -29
- package/tsconfig.json +0 -25
- package/yarn-error.log +0 -4133
- package/yarn.lock +0 -4045
- /package/{dist/_virtual → _virtual}/_tslib.js +0 -0
- /package/{dist/_virtual → _virtual}/_tslib.js.map +0 -0
- /package/{dist/array → array}/array-to-map.d.ts +0 -0
- /package/{dist/array → array}/array-to-map.js +0 -0
- /package/{dist/array → array}/array-to-map.js.map +0 -0
- /package/{dist/array → array}/get-values-from-keys.d.ts +0 -0
- /package/{dist/array → array}/get-values-from-keys.js +0 -0
- /package/{dist/array → array}/get-values-from-keys.js.map +0 -0
- /package/{dist/array → array}/index.d.ts +0 -0
- /package/{dist/array → array}/index.js +0 -0
- /package/{dist/array → array}/index.js.map +0 -0
- /package/{dist/array → array}/inner-join.d.ts +0 -0
- /package/{dist/array → array}/inner-join.js +0 -0
- /package/{dist/array → array}/inner-join.js.map +0 -0
- /package/{dist/array → array}/left-outter-join.d.ts +0 -0
- /package/{dist/array → array}/left-outter-join.js +0 -0
- /package/{dist/array → array}/left-outter-join.js.map +0 -0
- /package/{dist/business → business}/picture-spot/index.js +0 -0
- /package/{dist/business → business}/picture-spot/index.js.map +0 -0
- /package/{dist/business → business}/types/content.js +0 -0
- /package/{dist/business → business}/types/index.js +0 -0
- /package/{dist/business → business}/types/index.js.map +0 -0
- /package/{dist/business → business}/types/media.d.ts +0 -0
- /package/{dist/business → business}/types/multilingual.d.ts +0 -0
- /package/{dist/business → business}/types/multilingual.js +0 -0
- /package/{dist/business → business}/types/multilingual.js.map +0 -0
- /package/{dist/business → business}/types/thematic.d.ts +0 -0
- /package/{dist/cdn → cdn}/cdn.factory.d.ts +0 -0
- /package/{dist/cdn → cdn}/cdn.factory.js +0 -0
- /package/{dist/cdn → cdn}/cdn.factory.js.map +0 -0
- /package/{dist/cdn → cdn}/index.d.ts +0 -0
- /package/{dist/cdn → cdn}/index.js +0 -0
- /package/{dist/cdn → cdn}/index.js.map +0 -0
- /package/{dist/cdn → cdn}/types/cdn-factory.type.d.ts +0 -0
- /package/{dist/cdn → cdn}/types/index.d.ts +0 -0
- /package/{dist/cdn → cdn}/types/index.js +0 -0
- /package/{dist/cdn → cdn}/types/index.js.map +0 -0
- /package/{dist/cdn → cdn}/utils/extract-info-from-url.util.d.ts +0 -0
- /package/{dist/cdn → cdn}/utils/extract-info-from-url.util.js +0 -0
- /package/{dist/cdn → cdn}/utils/extract-info-from-url.util.js.map +0 -0
- /package/{dist/cdn → cdn}/utils/get-cdn-from-s3-url.util.d.ts +0 -0
- /package/{dist/cdn → cdn}/utils/get-cdn-from-s3-url.util.js +0 -0
- /package/{dist/cdn → cdn}/utils/get-cdn-from-s3-url.util.js.map +0 -0
- /package/{dist/cdn → cdn}/utils/get-cdn-url.util.d.ts +0 -0
- /package/{dist/cdn → cdn}/utils/get-cdn-url.util.js +0 -0
- /package/{dist/cdn → cdn}/utils/get-cdn-url.util.js.map +0 -0
- /package/{dist/cdn → cdn}/utils/twicpics-transformations.util.d.ts +0 -0
- /package/{dist/cdn → cdn}/utils/twicpics-transformations.util.js +0 -0
- /package/{dist/cdn → cdn}/utils/twicpics-transformations.util.js.map +0 -0
- /package/{dist/color → color}/get-contrast-color.d.ts +0 -0
- /package/{dist/color → color}/get-contrast-color.js +0 -0
- /package/{dist/color → color}/get-contrast-color.js.map +0 -0
- /package/{dist/color → color}/index.d.ts +0 -0
- /package/{dist/color → color}/index.js +0 -0
- /package/{dist/color → color}/index.js.map +0 -0
- /package/{dist/formatting → formatting}/format-number.d.ts +0 -0
- /package/{dist/formatting → formatting}/format-number.js +0 -0
- /package/{dist/formatting → formatting}/format-number.js.map +0 -0
- /package/{dist/formatting → formatting}/index.d.ts +0 -0
- /package/{dist/formatting → formatting}/index.js +0 -0
- /package/{dist/formatting → formatting}/index.js.map +0 -0
- /package/{dist/fp → fp}/index.d.ts +0 -0
- /package/{dist/fp → fp}/index.js +0 -0
- /package/{dist/fp → fp}/index.js.map +0 -0
- /package/{dist/fp → fp}/run-while.d.ts +0 -0
- /package/{dist/fp → fp}/run-while.js +0 -0
- /package/{dist/fp → fp}/run-while.js.map +0 -0
- /package/{dist/http → http}/build-search-params.d.ts +0 -0
- /package/{dist/http → http}/build-search-params.js +0 -0
- /package/{dist/http → http}/build-search-params.js.map +0 -0
- /package/{dist/http → http}/encode-search-object.d.ts +0 -0
- /package/{dist/http → http}/encode-search-object.js +0 -0
- /package/{dist/http → http}/encode-search-object.js.map +0 -0
- /package/{dist/http → http}/fetch-with-timeout.d.ts +0 -0
- /package/{dist/http → http}/fetch-with-timeout.js +0 -0
- /package/{dist/http → http}/fetch-with-timeout.js.map +0 -0
- /package/{dist/http → http}/index.d.ts +0 -0
- /package/{dist/http → http}/index.js +0 -0
- /package/{dist/http → http}/index.js.map +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/index.js.map → index.js.map} +0 -0
- /package/{dist/linked-list → linked-list}/apply-diff-linked-list.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/apply-diff-linked-list.js +0 -0
- /package/{dist/linked-list → linked-list}/apply-diff-linked-list.js.map +0 -0
- /package/{dist/linked-list → linked-list}/create-linked-list.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/create-linked-list.js +0 -0
- /package/{dist/linked-list → linked-list}/create-linked-list.js.map +0 -0
- /package/{dist/linked-list → linked-list}/find-linked-list.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/find-linked-list.js +0 -0
- /package/{dist/linked-list → linked-list}/find-linked-list.js.map +0 -0
- /package/{dist/linked-list → linked-list}/get-linked-list.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/get-linked-list.js +0 -0
- /package/{dist/linked-list → linked-list}/get-linked-list.js.map +0 -0
- /package/{dist/linked-list → linked-list}/index.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/index.js +0 -0
- /package/{dist/linked-list → linked-list}/index.js.map +0 -0
- /package/{dist/linked-list → linked-list}/insert-linked-list.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/insert-linked-list.js +0 -0
- /package/{dist/linked-list → linked-list}/insert-linked-list.js.map +0 -0
- /package/{dist/linked-list → linked-list}/linked-list-utils.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/linked-list-utils.js +0 -0
- /package/{dist/linked-list → linked-list}/linked-list-utils.js.map +0 -0
- /package/{dist/linked-list → linked-list}/reduce-linked-list.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/reduce-linked-list.js +0 -0
- /package/{dist/linked-list → linked-list}/reduce-linked-list.js.map +0 -0
- /package/{dist/linked-list → linked-list}/remove-linked-list.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/remove-linked-list.js +0 -0
- /package/{dist/linked-list → linked-list}/remove-linked-list.js.map +0 -0
- /package/{dist/linked-list → linked-list}/type.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/update-linked-list.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/update-linked-list.js +0 -0
- /package/{dist/linked-list → linked-list}/update-linked-list.js.map +0 -0
- /package/{dist/linked-list → linked-list}/while-linked-list.d.ts +0 -0
- /package/{dist/linked-list → linked-list}/while-linked-list.js +0 -0
- /package/{dist/linked-list → linked-list}/while-linked-list.js.map +0 -0
- /package/{dist/math → math}/clamp-number.d.ts +0 -0
- /package/{dist/math → math}/clamp-number.js +0 -0
- /package/{dist/math → math}/clamp-number.js.map +0 -0
- /package/{dist/math → math}/index.d.ts +0 -0
- /package/{dist/math → math}/index.js +0 -0
- /package/{dist/math → math}/index.js.map +0 -0
- /package/{dist/math → math}/interpolate.d.ts +0 -0
- /package/{dist/math → math}/interpolate.js +0 -0
- /package/{dist/math → math}/interpolate.js.map +0 -0
- /package/{dist/math → math}/median.d.ts +0 -0
- /package/{dist/math → math}/median.js +0 -0
- /package/{dist/math → math}/median.js.map +0 -0
- /package/{dist/math → math}/number-range.d.ts +0 -0
- /package/{dist/math → math}/number-range.js +0 -0
- /package/{dist/math → math}/number-range.js.map +0 -0
- /package/{dist/math → math}/random-number.d.ts +0 -0
- /package/{dist/math → math}/random-number.js +0 -0
- /package/{dist/math → math}/random-number.js.map +0 -0
- /package/{dist/object → object}/index.d.ts +0 -0
- /package/{dist/object → object}/index.js +0 -0
- /package/{dist/object → object}/index.js.map +0 -0
- /package/{dist/object → object}/merge-deep.d.ts +0 -0
- /package/{dist/object → object}/merge-deep.js +0 -0
- /package/{dist/object → object}/merge-deep.js.map +0 -0
- /package/{dist/object → object}/strip-properties-from-object.d.ts +0 -0
- /package/{dist/object → object}/strip-properties-from-object.js +0 -0
- /package/{dist/object → object}/strip-properties-from-object.js.map +0 -0
- /package/{dist/parsing → parsing}/index.d.ts +0 -0
- /package/{dist/parsing → parsing}/index.js +0 -0
- /package/{dist/parsing → parsing}/index.js.map +0 -0
- /package/{dist/parsing → parsing}/parse-boolean.d.ts +0 -0
- /package/{dist/parsing → parsing}/parse-boolean.js +0 -0
- /package/{dist/parsing → parsing}/parse-boolean.js.map +0 -0
- /package/{dist/parsing → parsing}/parse-enum.d.ts +0 -0
- /package/{dist/parsing → parsing}/parse-enum.js +0 -0
- /package/{dist/parsing → parsing}/parse-enum.js.map +0 -0
- /package/{dist/parsing → parsing}/parse-number.d.ts +0 -0
- /package/{dist/parsing → parsing}/parse-number.js +0 -0
- /package/{dist/parsing → parsing}/parse-number.js.map +0 -0
- /package/{dist/predicates → predicates}/index.d.ts +0 -0
- /package/{dist/predicates → predicates}/index.js +0 -0
- /package/{dist/predicates → predicates}/index.js.map +0 -0
- /package/{dist/predicates → predicates}/is-function.d.ts +0 -0
- /package/{dist/predicates → predicates}/is-function.js +0 -0
- /package/{dist/predicates → predicates}/is-function.js.map +0 -0
- /package/{dist/predicates → predicates}/is-null.d.ts +0 -0
- /package/{dist/predicates → predicates}/is-null.js +0 -0
- /package/{dist/predicates → predicates}/is-null.js.map +0 -0
- /package/{dist/predicates → predicates}/is-object.d.ts +0 -0
- /package/{dist/predicates → predicates}/is-object.js +0 -0
- /package/{dist/predicates → predicates}/is-object.js.map +0 -0
- /package/{dist/predicates → predicates}/is-primitive.d.ts +0 -0
- /package/{dist/predicates → predicates}/is-primitive.js +0 -0
- /package/{dist/predicates → predicates}/is-primitive.js.map +0 -0
- /package/{dist/predicates → predicates}/is-undefined.d.ts +0 -0
- /package/{dist/predicates → predicates}/is-undefined.js +0 -0
- /package/{dist/predicates → predicates}/is-undefined.js.map +0 -0
- /package/{dist/predicates → predicates}/is-uuid.d.ts +0 -0
- /package/{dist/promise → promise}/delay.d.ts +0 -0
- /package/{dist/promise → promise}/delay.js +0 -0
- /package/{dist/promise → promise}/delay.js.map +0 -0
- /package/{dist/promise → promise}/execute-or-resolve-default.d.ts +0 -0
- /package/{dist/promise → promise}/execute-or-resolve-default.js +0 -0
- /package/{dist/promise → promise}/execute-or-resolve-default.js.map +0 -0
- /package/{dist/promise → promise}/execute-with-delay.d.ts +0 -0
- /package/{dist/promise → promise}/execute-with-delay.js +0 -0
- /package/{dist/promise → promise}/execute-with-delay.js.map +0 -0
- /package/{dist/promise → promise}/index.d.ts +0 -0
- /package/{dist/promise → promise}/index.js +0 -0
- /package/{dist/promise → promise}/index.js.map +0 -0
- /package/{dist/string → string}/index.d.ts +0 -0
- /package/{dist/string → string}/index.js +0 -0
- /package/{dist/string → string}/index.js.map +0 -0
- /package/{dist/string → string}/is-string-length-within-range.d.ts +0 -0
- /package/{dist/string → string}/is-string-length-within-range.js +0 -0
- /package/{dist/string → string}/is-string-length-within-range.js.map +0 -0
- /package/{dist/string → string}/replace-in-template.d.ts +0 -0
- /package/{dist/string → string}/replace-in-template.js +0 -0
- /package/{dist/string → string}/replace-in-template.js.map +0 -0
- /package/{dist/time → time}/constants.d.ts +0 -0
- /package/{dist/time → time}/constants.js +0 -0
- /package/{dist/time → time}/constants.js.map +0 -0
- /package/{dist/time → time}/convert.d.ts +0 -0
- /package/{dist/time → time}/convert.js +0 -0
- /package/{dist/time → time}/convert.js.map +0 -0
- /package/{dist/time → time}/format-minutes.d.ts +0 -0
- /package/{dist/time → time}/format-minutes.js +0 -0
- /package/{dist/time → time}/format-minutes.js.map +0 -0
- /package/{dist/time → time}/get-time-diff-as-string.d.ts +0 -0
- /package/{dist/time → time}/get-time-diff-as-string.js +0 -0
- /package/{dist/time → time}/get-time-diff-as-string.js.map +0 -0
- /package/{dist/time → time}/index.d.ts +0 -0
- /package/{dist/time → time}/index.js +0 -0
- /package/{dist/time → time}/index.js.map +0 -0
- /package/{dist/types → types}/function.d.ts +0 -0
- /package/{dist/types → types}/general.d.ts +0 -0
- /package/{dist/types → types}/index.d.ts +0 -0
- /package/{dist/types → types}/index.js +0 -0
- /package/{dist/types → types}/index.js.map +0 -0
- /package/{dist/types → types}/object.d.ts +0 -0
- /package/{dist/types → types}/search.d.ts +0 -0
package/src/cdn/cdn.factory.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { buildSearchParams } from '../http/build-search-params';
|
|
2
|
-
import type { CdnConfig, CdnType, TransformationQueries, TwicpicsTransformationChain } from './types';
|
|
3
|
-
import { getCdnFromS3UrlFactory } from './utils/get-cdn-from-s3-url.util';
|
|
4
|
-
import { getCdnUrlFactory } from './utils/get-cdn-url.util';
|
|
5
|
-
import { twicpicsTransformationChainToString } from './utils/twicpics-transformations.util';
|
|
6
|
-
|
|
7
|
-
export const imgixTransformationQueries: TransformationQueries = ({
|
|
8
|
-
fit,
|
|
9
|
-
width,
|
|
10
|
-
height,
|
|
11
|
-
quality,
|
|
12
|
-
compress = true,
|
|
13
|
-
devicePixelRatio,
|
|
14
|
-
}) => {
|
|
15
|
-
const params = {
|
|
16
|
-
auto: compress ? 'compress,format' : undefined,
|
|
17
|
-
fit: fit === 'crop' ? 'crop' : undefined,
|
|
18
|
-
dpr: Number.isFinite(devicePixelRatio) ? devicePixelRatio : undefined,
|
|
19
|
-
h: Number.isFinite(height) ? height : undefined,
|
|
20
|
-
w: Number.isFinite(width) ? width : undefined,
|
|
21
|
-
q: quality !== undefined && quality >= 0 && quality <= 100 ? quality : undefined,
|
|
22
|
-
};
|
|
23
|
-
const searchParams = buildSearchParams(params).toString();
|
|
24
|
-
|
|
25
|
-
return searchParams ? `${searchParams}` : '';
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const twicpicsTransformationQueries: TransformationQueries = (params) => {
|
|
29
|
-
const quality = params.quality || 70;
|
|
30
|
-
const transformations: TwicpicsTransformationChain = [['quality', quality]];
|
|
31
|
-
const dpr = params.devicePixelRatio || 1;
|
|
32
|
-
|
|
33
|
-
const width = params.width ? Math.round(params.width * dpr) : '-';
|
|
34
|
-
const height = params.height ? Math.round(params.height * dpr) : '-';
|
|
35
|
-
const fit = params.fit || 'cover';
|
|
36
|
-
|
|
37
|
-
if (params.width !== undefined || params.height !== undefined) {
|
|
38
|
-
transformations.push([fit, `${width}x${height}`]);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (params.output !== undefined) {
|
|
42
|
-
transformations.push(['output', params.output]);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return twicpicsTransformationChainToString(transformations);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
* @param type cdn provider: 'twicpics' | 'imgix'
|
|
51
|
-
* @param domain provider domain
|
|
52
|
-
* @param instanceMapper domain + the result of the instanceMapper will form the base path
|
|
53
|
-
* @param cacheVersion
|
|
54
|
-
* @returns \{ getCdnUrl, transformationQueries \}
|
|
55
|
-
*/
|
|
56
|
-
export const createCdn = <T extends CdnType>({ type, domain, instanceMapper, cacheVersion }: CdnConfig<T>) => {
|
|
57
|
-
const getCdnUrl = getCdnUrlFactory({
|
|
58
|
-
domain,
|
|
59
|
-
instanceMapper,
|
|
60
|
-
transformationQueries: type === 'imgix' ? imgixTransformationQueries : twicpicsTransformationQueries,
|
|
61
|
-
cacheVersion,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
getCdnUrl,
|
|
66
|
-
getCdnFromS3Url: getCdnFromS3UrlFactory({
|
|
67
|
-
getCdnUrl,
|
|
68
|
-
}),
|
|
69
|
-
};
|
|
70
|
-
};
|
package/src/cdn/index.ts
DELETED
|
@@ -1,49 +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
|
-
output?: 'jpeg' | 'png' | 'webp' | 'image';
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type CdnParams = {
|
|
17
|
-
asThumbnail?: boolean;
|
|
18
|
-
transformation?: Transformation;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type TransformationQueries = (params: Transformation) => string;
|
|
22
|
-
|
|
23
|
-
type TwicpicsOutputTransformation = ['output', Transformation['output']];
|
|
24
|
-
|
|
25
|
-
type TwicpicsFitTransformation = ['cover' | 'crop' | 'contain', string] | ['quality', number];
|
|
26
|
-
|
|
27
|
-
export type TwicpicsTransformation = TwicpicsOutputTransformation | TwicpicsFitTransformation;
|
|
28
|
-
|
|
29
|
-
export type TwicpicsTransformationChain = TwicpicsTransformation[];
|
|
30
|
-
|
|
31
|
-
export type GetCdnUrl = (instanceId: string, path: `/${string}`, params?: CdnParams) => string;
|
|
32
|
-
|
|
33
|
-
export type GetCdnFromS3Url = (url: string, params?: CdnParams) => string;
|
|
34
|
-
|
|
35
|
-
export type InstanceMapper = (instanceId: string) => string;
|
|
36
|
-
|
|
37
|
-
export type CdnType = 'twicpics' | 'imgix';
|
|
38
|
-
|
|
39
|
-
export type CdnConfig<T extends CdnType> = {
|
|
40
|
-
type: T;
|
|
41
|
-
domain: `https://${string}`;
|
|
42
|
-
instanceMapper: InstanceMapper;
|
|
43
|
-
cacheVersion?: T extends 'twicpics' ? number : undefined;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type Cdn = {
|
|
47
|
-
getCdnUrl: GetCdnUrl;
|
|
48
|
-
getCdnFromS3Url: GetCdnFromS3Url;
|
|
49
|
-
};
|
package/src/cdn/types/index.ts
DELETED
|
@@ -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,31 +0,0 @@
|
|
|
1
|
-
import type { GetCdnUrl, InstanceMapper, Transformation, TransformationQueries } from '../types';
|
|
2
|
-
|
|
3
|
-
const DEFAULT_THUMBNAIL_CONFIG: Transformation = {
|
|
4
|
-
width: 300,
|
|
5
|
-
height: 300,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
type FactoryConfig = {
|
|
9
|
-
domain: `https://${string}`;
|
|
10
|
-
instanceMapper: InstanceMapper;
|
|
11
|
-
transformationQueries: TransformationQueries;
|
|
12
|
-
cacheVersion?: number;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const genCacheVersionQuery = (cacheVersion?: number) => (cacheVersion ? `v=${cacheVersion}` : '');
|
|
16
|
-
|
|
17
|
-
export const getCdnUrlFactory =
|
|
18
|
-
(config: FactoryConfig): GetCdnUrl =>
|
|
19
|
-
(instanceId, path, params = {}) => {
|
|
20
|
-
const { domain, instanceMapper, transformationQueries, cacheVersion } = config;
|
|
21
|
-
|
|
22
|
-
const { transformation = params.asThumbnail ? DEFAULT_THUMBNAIL_CONFIG : {} } = params;
|
|
23
|
-
|
|
24
|
-
const transformationQuery: string = transformationQueries(transformation);
|
|
25
|
-
const cacheVersionQuery = genCacheVersionQuery(cacheVersion);
|
|
26
|
-
const hasQueryParams = [transformationQuery, cacheVersionQuery].some((query) => query !== '');
|
|
27
|
-
|
|
28
|
-
return `${domain}${instanceMapper(instanceId)}${path}${hasQueryParams ? '?' : ''}${transformationQuery}${
|
|
29
|
-
cacheVersionQuery ? `&${cacheVersionQuery}` : ''
|
|
30
|
-
}`;
|
|
31
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { TwicpicsTransformationChain } from '../types';
|
|
2
|
-
|
|
3
|
-
export const twicpicsTransformationChainToString = (transformationChain: TwicpicsTransformationChain): string => {
|
|
4
|
-
if (transformationChain.length === 0) return '';
|
|
5
|
-
|
|
6
|
-
const transformations = transformationChain.map(([key, value]) => `${key}=${value}`).join('/');
|
|
7
|
-
|
|
8
|
-
return `twic=v1/${transformations}`;
|
|
9
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getContrastColor } from '../get-contrast-color';
|
|
2
|
-
|
|
3
|
-
describe('getContrastColor', () => {
|
|
4
|
-
const customLight = '#f18888';
|
|
5
|
-
const customDark = '#051831';
|
|
6
|
-
|
|
7
|
-
it('should return the default light color', () => {
|
|
8
|
-
expect(getContrastColor('#000000')).toBe('#FFFFFF');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should return the default dark color', () => {
|
|
12
|
-
expect(getContrastColor('#FFFFFF')).toBe('#000000');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should return a specified light color', () => {
|
|
16
|
-
expect(getContrastColor('#000000', customLight, customDark)).toBe(customLight);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should return a specified dark color', () => {
|
|
20
|
-
expect(getContrastColor('#FFFFFF', customLight, customDark)).toBe(customDark);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const DEFAULT_LIGHT_COLOR = '#FFFFFF';
|
|
2
|
-
const DEFAULT_DARK_COLOR = '#000000';
|
|
3
|
-
|
|
4
|
-
// Based on https://stackoverflow.com/questions/11867545/change-text-color-based-on-brightness-of-the-covered-background-area
|
|
5
|
-
export const getContrastColor = (bgColor: string, lightColor: string = DEFAULT_LIGHT_COLOR, darkColor: string = DEFAULT_DARK_COLOR): string => {
|
|
6
|
-
const color = bgColor.charAt(0) === '#' ? bgColor.substring(1, 7) : bgColor;
|
|
7
|
-
|
|
8
|
-
if (color.length !== 6) {
|
|
9
|
-
throw new Error(`Invalid HEX color "${bgColor}" in sparted mail manager.`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const r = parseInt(color.substring(0, 2), 16); // hexToR
|
|
13
|
-
const g = parseInt(color.substring(2, 4), 16); // hexToG
|
|
14
|
-
const b = parseInt(color.substring(4, 6), 16); // hexToB
|
|
15
|
-
|
|
16
|
-
// Values from https://www.w3.org/TR/AERT/#color-contrast
|
|
17
|
-
return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? darkColor : lightColor;
|
|
18
|
-
};
|
package/src/color/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './get-contrast-color';
|
|
@@ -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
|
-
};
|
package/src/formatting/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './format-number';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { runWhile } from '../run-while';
|
|
2
|
-
|
|
3
|
-
describe('runWhile', () => {
|
|
4
|
-
it('should run while the predicate is true and return the right interation count', () => {
|
|
5
|
-
const { result, iterationCount } = runWhile({
|
|
6
|
-
predicate: (counter) => counter <= 9,
|
|
7
|
-
callback: (counter) => counter + 1,
|
|
8
|
-
initialValue: 0,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
expect(result).toStrictEqual(10);
|
|
12
|
-
expect(iterationCount).toStrictEqual(10);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should throw an error when the iteration limit is reached', () => {
|
|
16
|
-
const predicateMock = jest.fn().mockReturnValue(true);
|
|
17
|
-
|
|
18
|
-
const { iterationCount } = runWhile({
|
|
19
|
-
predicate: predicateMock,
|
|
20
|
-
callback: (counter) => counter + 1,
|
|
21
|
-
initialValue: 0,
|
|
22
|
-
iterationLimit: 89,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// Called once outside the while loop
|
|
26
|
-
expect(predicateMock).toHaveBeenCalledTimes(90);
|
|
27
|
-
expect(iterationCount).toStrictEqual(89);
|
|
28
|
-
});
|
|
29
|
-
});
|
package/src/fp/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './run-while';
|
package/src/fp/run-while.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export type RunWhileConfig<T> = {
|
|
2
|
-
/**
|
|
3
|
-
* Return a boolean to keep running the callback or not.
|
|
4
|
-
*/
|
|
5
|
-
predicate: (current: T) => boolean,
|
|
6
|
-
/**
|
|
7
|
-
* The function to run while `predicate` returns `true`
|
|
8
|
-
*/
|
|
9
|
-
callback: (current: T, iteractionCount: number) => T,
|
|
10
|
-
/**
|
|
11
|
-
* `callback` will not be run again if `iterationCount` exceeds this value.
|
|
12
|
-
* Default to `Infinity`
|
|
13
|
-
*/
|
|
14
|
-
iterationLimit?: number,
|
|
15
|
-
/**
|
|
16
|
-
* The first value passed to the callback.
|
|
17
|
-
*/
|
|
18
|
-
initialValue: T,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type RunWhileFn = <T>(config: RunWhileConfig<T>) => {
|
|
22
|
-
/**
|
|
23
|
-
* The callback last result.
|
|
24
|
-
*/
|
|
25
|
-
result: T,
|
|
26
|
-
iterationCount: number,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Run the callback while the predicate return true. Throws an
|
|
31
|
-
* error if the iteration count exceeds the iteration limit.
|
|
32
|
-
*/
|
|
33
|
-
export const runWhile: RunWhileFn = ({ predicate, callback, initialValue, iterationLimit = Infinity }) => {
|
|
34
|
-
let counter = 0;
|
|
35
|
-
let currentValue = initialValue;
|
|
36
|
-
let shouldRun = predicate(currentValue);
|
|
37
|
-
|
|
38
|
-
while (shouldRun) {
|
|
39
|
-
if (counter >= iterationLimit) {
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const nextValue = callback(currentValue, counter);
|
|
44
|
-
|
|
45
|
-
counter += 1;
|
|
46
|
-
shouldRun = predicate(nextValue);
|
|
47
|
-
currentValue = nextValue;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
result: currentValue,
|
|
52
|
-
iterationCount: counter,
|
|
53
|
-
};
|
|
54
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { buildSearchParams } from '../build-search-params';
|
|
2
|
-
|
|
3
|
-
describe('buildSearchParams', () => {
|
|
4
|
-
it('should remove undefined values', () => {
|
|
5
|
-
const params = {
|
|
6
|
-
param1: 'value1',
|
|
7
|
-
param2: undefined,
|
|
8
|
-
param3: 'value3',
|
|
9
|
-
};
|
|
10
|
-
const searchParams = buildSearchParams(params);
|
|
11
|
-
|
|
12
|
-
expect(searchParams.toString()).toStrictEqual('param1=value1¶m3=value3');
|
|
13
|
-
expect(searchParams.get('param1')).toStrictEqual('value1');
|
|
14
|
-
expect(searchParams.get('param2')).toStrictEqual(null);
|
|
15
|
-
expect(searchParams.get('param3')).toStrictEqual('value3');
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { encodeSearchObject } from '../encode-search-object';
|
|
2
|
-
|
|
3
|
-
describe('encodeSearchObject', () => {
|
|
4
|
-
it('should not encode sort and query if undefined', () => {
|
|
5
|
-
const url = encodeSearchObject({
|
|
6
|
-
limit: 10,
|
|
7
|
-
offset: 15,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
expect(url).toStrictEqual('offset=15&limit=10');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should encode sort and query twice', () => {
|
|
14
|
-
const url = encodeSearchObject({
|
|
15
|
-
limit: 10,
|
|
16
|
-
offset: 0,
|
|
17
|
-
sort: {
|
|
18
|
-
name: 'asc',
|
|
19
|
-
editionDate: 'desc',
|
|
20
|
-
},
|
|
21
|
-
query: {
|
|
22
|
-
name: 'The name of something',
|
|
23
|
-
status: 'published',
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
expect(url).toStrictEqual([
|
|
28
|
-
'offset=0',
|
|
29
|
-
'limit=10',
|
|
30
|
-
'sort=name%3Aasc%2BeditionDate%3Adesc',
|
|
31
|
-
'query=name%3AThe%2520name%2520of%2520something%2Bstatus%3Apublished',
|
|
32
|
-
].join('&'));
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/first -- https://github.com/jefflau/jest-fetch-mock#to-setup-for-an-individual-test */
|
|
2
|
-
|
|
3
|
-
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
|
|
4
|
-
|
|
5
|
-
// must appear before any other imports
|
|
6
|
-
enableFetchMocks();
|
|
7
|
-
|
|
8
|
-
import { fetchWithTimeout } from '../fetch-with-timeout';
|
|
9
|
-
|
|
10
|
-
describe('fetchWithTimeout', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
fetchMock.resetMocks();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should call fetch with the same parameters', async () => {
|
|
16
|
-
const url = 'http://some/url';
|
|
17
|
-
const init = {
|
|
18
|
-
headers: {
|
|
19
|
-
some: 'header',
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
fetchMock.mockResponseOnce('mock response');
|
|
24
|
-
const response = await fetchWithTimeout(url, init);
|
|
25
|
-
|
|
26
|
-
expect(fetch as any).toHaveBeenNthCalledWith(1, url, expect.objectContaining(init));
|
|
27
|
-
expect(await response.text()).toBe('mock response');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should abort the request if timeout has elapsed', async () => {
|
|
31
|
-
jest.useFakeTimers();
|
|
32
|
-
const TIMEOUT = 3000;
|
|
33
|
-
const REQUEST_TIMEOUT = TIMEOUT * 2;
|
|
34
|
-
|
|
35
|
-
// This request will take too long
|
|
36
|
-
fetchMock.mockResponseOnce(async () => {
|
|
37
|
-
jest.advanceTimersByTime(REQUEST_TIMEOUT);
|
|
38
|
-
return 'mock response';
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// https://github.com/jefflau/jest-fetch-mock/issues/159
|
|
42
|
-
(global as any).DOMException = Error;
|
|
43
|
-
|
|
44
|
-
const responsePromise = fetchWithTimeout('http://some/url', { timeout: TIMEOUT });
|
|
45
|
-
|
|
46
|
-
jest.advanceTimersByTime(TIMEOUT + 100);
|
|
47
|
-
|
|
48
|
-
await expect(responsePromise).rejects.toThrow('The operation was aborted. ');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Primitive } from '../types';
|
|
2
|
-
|
|
3
|
-
export const buildSearchParams = (params: Record<string, Primitive | undefined>): URLSearchParams => {
|
|
4
|
-
const definedParams = Object
|
|
5
|
-
.entries(params)
|
|
6
|
-
.reduce((acc, [key, value]) => {
|
|
7
|
-
if (value !== undefined) {
|
|
8
|
-
return {
|
|
9
|
-
...acc,
|
|
10
|
-
[key]: String(value),
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return acc;
|
|
15
|
-
}, {} as Record<string, string>);
|
|
16
|
-
|
|
17
|
-
return new URLSearchParams(definedParams);
|
|
18
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { SearchObject } from '../types';
|
|
2
|
-
|
|
3
|
-
export type EncodingConfig = {
|
|
4
|
-
keyValueDelimiter: string,
|
|
5
|
-
pairDelimiter: string,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const defaultEncodingConfig: EncodingConfig = {
|
|
9
|
-
keyValueDelimiter: ':',
|
|
10
|
-
pairDelimiter: '+',
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const encodeSearchValue = <T extends Record<string, string>>(
|
|
14
|
-
searchValue: T,
|
|
15
|
-
config: EncodingConfig = defaultEncodingConfig,
|
|
16
|
-
) => {
|
|
17
|
-
const { pairDelimiter, keyValueDelimiter } = config;
|
|
18
|
-
|
|
19
|
-
return Object.entries(searchValue)
|
|
20
|
-
.map(([key, value]) => `${key}${keyValueDelimiter}${encodeURI(value)}`)
|
|
21
|
-
.join(pairDelimiter);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const encodeSearchObject = (searchObject: SearchObject): string => {
|
|
25
|
-
const { sort, query, offset, limit } = searchObject;
|
|
26
|
-
|
|
27
|
-
const sortEncoded = sort ? encodeSearchValue(sort) : null;
|
|
28
|
-
const queryEncoded = query ? encodeSearchValue(query) : null;
|
|
29
|
-
|
|
30
|
-
const urlParams = new URLSearchParams({
|
|
31
|
-
offset: offset.toString(),
|
|
32
|
-
limit: limit.toString(),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (sortEncoded) urlParams.append('sort', sortEncoded);
|
|
36
|
-
if (queryEncoded) urlParams.append('query', queryEncoded);
|
|
37
|
-
|
|
38
|
-
return urlParams.toString();
|
|
39
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export type RequestInitWithTimeout = RequestInit & {
|
|
2
|
-
timeout?: number
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Use fetch to perform an HTTP request
|
|
7
|
-
* Add an optional timeout, that will abort the request if it has not returned before
|
|
8
|
-
*/
|
|
9
|
-
export const fetchWithTimeout = (input: RequestInfo, init?: Omit<RequestInitWithTimeout, 'signal'> | undefined): Promise<Response> => {
|
|
10
|
-
const abortController = new AbortController();
|
|
11
|
-
|
|
12
|
-
const { timeout, ...rest } = init || {};
|
|
13
|
-
|
|
14
|
-
const params = {
|
|
15
|
-
...rest,
|
|
16
|
-
signal: abortController.signal,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
if (timeout !== undefined) {
|
|
20
|
-
setTimeout(() => abortController.abort(), timeout);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return fetch(input, params);
|
|
24
|
-
};
|
package/src/http/index.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from './array';
|
|
2
|
-
export * from './cdn';
|
|
3
|
-
export * from './time';
|
|
4
|
-
export * from './formatting';
|
|
5
|
-
export * from './fp';
|
|
6
|
-
export * from './http';
|
|
7
|
-
export * from './linked-list';
|
|
8
|
-
export * from './math';
|
|
9
|
-
export * from './object';
|
|
10
|
-
export * from './parsing';
|
|
11
|
-
export * from './predicates';
|
|
12
|
-
export * from './promise';
|
|
13
|
-
export * from './string';
|
|
14
|
-
export * from './types';
|
|
15
|
-
export * from './color';
|