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