@sparted/shared-library 1.0.29 → 1.1.0-rc0
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/.circleci/config.yml +40 -0
- package/.eslintignore +1 -0
- package/.eslintrc.json +25 -0
- package/.gitignore +37 -0
- package/.idea/.gitignore +8 -0
- package/.idea/codeStyles/Project.xml +35 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/jsLinters/eslint.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/shared-library.iml +11 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +100 -0
- package/.prettierrc.json +6 -0
- package/CHANGELOG.md +97 -0
- package/README.md +26 -0
- package/{_virtual → dist/_virtual}/_tslib.js +6 -1
- package/{_virtual → dist/_virtual}/_tslib.js.map +1 -1
- package/{array → dist/array}/array-to-map.d.ts +1 -1
- package/dist/business/picture-spot/index.d.ts +2 -0
- package/dist/business/picture-spot/index.js +8 -0
- package/dist/business/picture-spot/index.js.map +1 -0
- package/dist/business/types/content.d.ts +84 -0
- package/dist/business/types/index.d.ts +4 -0
- package/dist/business/types/media.d.ts +16 -0
- package/dist/business/types/multilingual.d.ts +3 -0
- package/dist/business/types/thematic.d.ts +9 -0
- package/dist/cdn/types/cdn-factory.type.d.ts +37 -0
- package/{cdn → dist/cdn}/utils/extract-info-from-url.util.d.ts +1 -1
- package/{cdn → dist/cdn}/utils/get-cdn-from-s3-url.util.d.ts +1 -1
- package/{cdn → dist/cdn}/utils/get-cdn-url.util.d.ts +1 -1
- package/{fp → dist/fp}/run-while.d.ts +2 -2
- package/{http → dist/http}/encode-search-object.d.ts +1 -1
- package/{http → dist/http}/fetch-with-timeout.d.ts +1 -1
- package/{index.d.ts → dist/index.d.ts} +0 -1
- package/{index.js → dist/index.js} +0 -2
- package/{index.js.map → dist/index.js.map} +1 -1
- package/{linked-list → dist/linked-list}/linked-list-utils.d.ts +4 -4
- package/{linked-list → dist/linked-list}/type.d.ts +7 -7
- package/{math → dist/math}/interpolate.d.ts +1 -1
- package/{math → dist/math}/number-range.d.ts +1 -1
- package/dist/package.json +65 -0
- package/{promise → dist/promise}/execute-or-resolve-default.d.ts +1 -1
- package/{string → dist/string}/replace-in-template.d.ts +1 -1
- package/{time → dist/time}/get-time-diff-as-string.d.ts +2 -2
- package/dist/types/function.d.ts +1 -0
- package/dist/types/general.d.ts +8 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/{types → dist/types}/object.d.ts +11 -11
- package/dist/types/search.d.ts +24 -0
- package/global.d.ts +2 -0
- package/package.json +2 -3
- package/rollup.config.ts +19 -0
- package/src/array/__tests__/array-to-map.test.ts +50 -0
- package/src/array/__tests__/get-values-from-keys.test.ts +14 -0
- package/src/array/__tests__/inner-join.test.ts +55 -0
- package/src/array/__tests__/left-outter-join.test.ts +55 -0
- package/src/array/array-to-map.ts +32 -0
- package/src/array/get-values-from-keys.ts +3 -0
- package/src/array/index.ts +4 -0
- package/src/array/inner-join.ts +10 -0
- package/src/array/left-outter-join.ts +10 -0
- package/src/business/picture-spot/index.ts +3 -0
- package/src/business/types/content.ts +110 -0
- package/src/business/types/index.ts +4 -0
- package/src/business/types/media.ts +18 -0
- package/src/business/types/multilingual.ts +3 -0
- package/src/business/types/thematic.ts +10 -0
- package/src/cdn/__tests__/cdn.factory.test.ts +150 -0
- package/src/cdn/__tests__/utils.test.ts +528 -0
- package/src/cdn/cdn.factory.ts +70 -0
- package/src/cdn/index.ts +2 -0
- package/src/cdn/types/cdn-factory.type.ts +49 -0
- package/src/cdn/types/index.ts +1 -0
- package/src/cdn/utils/extract-info-from-url.util.ts +25 -0
- package/src/cdn/utils/get-cdn-from-s3-url.util.ts +20 -0
- package/src/cdn/utils/get-cdn-url.util.ts +31 -0
- package/src/cdn/utils/twicpics-transformations.util.ts +9 -0
- package/src/formatting/__tests__/format-number.test.ts +11 -0
- package/src/formatting/format-number.ts +14 -0
- package/src/formatting/index.ts +1 -0
- package/src/fp/__tests__/run-while.test.ts +29 -0
- package/src/fp/index.ts +1 -0
- package/src/fp/run-while.ts +54 -0
- package/src/http/__tests__/build-search-params.test.ts +17 -0
- package/src/http/__tests__/encode-search-object.test.ts +34 -0
- package/src/http/__tests__/fetch-with-timeout.test.ts +50 -0
- package/src/http/build-search-params.ts +18 -0
- package/src/http/encode-search-object.ts +39 -0
- package/src/http/fetch-with-timeout.ts +24 -0
- package/src/http/index.ts +3 -0
- package/src/index.ts +14 -0
- package/src/linked-list/__tests__/apply-diff-linked-list.test.ts +103 -0
- package/src/linked-list/__tests__/create-linked-list.test.ts +204 -0
- package/src/linked-list/__tests__/find-linked-list.test.ts +40 -0
- package/src/linked-list/__tests__/get-linked-list.test.ts +28 -0
- package/src/linked-list/__tests__/insert-linked-list.test.ts +186 -0
- package/src/linked-list/__tests__/linked-list-utils.test.ts +252 -0
- package/src/linked-list/__tests__/reduce-linked-list.test.ts +31 -0
- package/src/linked-list/__tests__/remove-linked-list.test.ts +129 -0
- package/src/linked-list/__tests__/update-linked-list.test.ts +53 -0
- package/src/linked-list/__tests__/while-linked-list.test.ts +58 -0
- package/src/linked-list/apply-diff-linked-list.ts +35 -0
- package/src/linked-list/create-linked-list.ts +79 -0
- package/src/linked-list/find-linked-list.ts +26 -0
- package/src/linked-list/get-linked-list.ts +9 -0
- package/src/linked-list/index.ts +2 -0
- package/src/linked-list/insert-linked-list.ts +50 -0
- package/src/linked-list/linked-list-utils.ts +143 -0
- package/src/linked-list/reduce-linked-list.ts +18 -0
- package/src/linked-list/remove-linked-list.ts +36 -0
- package/src/linked-list/type.ts +38 -0
- package/src/linked-list/update-linked-list.ts +30 -0
- package/src/linked-list/while-linked-list.ts +33 -0
- package/src/math/__tests__/clamp-number.test.ts +30 -0
- package/src/math/__tests__/interpolate.test.ts +28 -0
- package/src/math/__tests__/median.test.ts +27 -0
- package/src/math/__tests__/number-range.test.ts +59 -0
- package/src/math/__tests__/random-number.test.ts +11 -0
- package/src/math/clamp-number.ts +8 -0
- package/src/math/index.ts +5 -0
- package/src/math/interpolate.ts +18 -0
- package/src/math/median.ts +21 -0
- package/src/math/number-range.ts +16 -0
- package/src/math/random-number.ts +10 -0
- package/src/object/__tests__/merge-deep.test.ts +56 -0
- package/src/object/__tests__/strip-properties-from-object.test.ts +65 -0
- package/src/object/index.ts +2 -0
- package/src/object/merge-deep.ts +26 -0
- package/src/object/strip-properties-from-object.ts +26 -0
- package/src/parsing/__tests__/parse-boolean.test.ts +15 -0
- package/src/parsing/__tests__/parse-enum.test.ts +19 -0
- package/src/parsing/__tests__/parse-number.test.ts +20 -0
- package/src/parsing/index.ts +3 -0
- package/src/parsing/parse-boolean.ts +10 -0
- package/src/parsing/parse-enum.ts +16 -0
- package/src/parsing/parse-number.ts +12 -0
- package/src/predicates/__tests__/is-function.test.ts +11 -0
- package/src/predicates/__tests__/is-null.test.ts +11 -0
- package/src/predicates/__tests__/is-object.test.ts +11 -0
- package/src/predicates/__tests__/is-primitive.test.ts +42 -0
- package/src/predicates/__tests__/is-undefined.test.ts +11 -0
- package/src/predicates/__tests__/is-uuid.test.ts +13 -0
- package/src/predicates/index.ts +5 -0
- package/src/predicates/is-function.ts +3 -0
- package/src/predicates/is-null.ts +1 -0
- package/src/predicates/is-object.ts +3 -0
- package/src/predicates/is-primitive.ts +19 -0
- package/src/predicates/is-undefined.ts +3 -0
- package/src/predicates/is-uuid.ts +3 -0
- package/src/promise/__tests__/delay.test.ts +13 -0
- package/src/promise/__tests__/execute-or-resolve-default.test.ts +25 -0
- package/src/promise/__tests__/execute-with-delay.test.ts +24 -0
- package/src/promise/delay.ts +3 -0
- package/src/promise/execute-or-resolve-default.ts +14 -0
- package/src/promise/execute-with-delay.ts +6 -0
- package/src/promise/index.ts +3 -0
- package/src/string/__tests__/is-string-length-within-range.test.ts +23 -0
- package/src/string/__tests__/replace-in-template.test.ts +52 -0
- package/src/string/index.ts +2 -0
- package/src/string/is-string-length-within-range.ts +10 -0
- package/src/string/replace-in-template.ts +45 -0
- package/src/time/__tests__/convert.test.ts +14 -0
- package/src/time/__tests__/format-minutes.test.ts +10 -0
- package/src/time/__tests__/get-time-diff-as-string.test.ts +128 -0
- package/src/time/constants.ts +4 -0
- package/src/time/convert.ts +5 -0
- package/src/time/format-minutes.ts +9 -0
- package/src/time/get-time-diff-as-string.ts +196 -0
- package/src/time/index.ts +4 -0
- package/src/types/function.ts +1 -0
- package/src/types/general.ts +15 -0
- package/src/types/index.ts +4 -0
- package/src/types/object.ts +33 -0
- package/src/types/search.ts +29 -0
- package/tsconfig.json +25 -0
- package/yarn.lock +4040 -0
- package/cdn/types/cdn-factory.type.d.ts +0 -37
- package/color/get-contrast-color.d.ts +0 -1
- package/color/get-contrast-color.js +0 -21
- package/color/get-contrast-color.js.map +0 -1
- package/color/index.d.ts +0 -1
- package/color/index.js +0 -10
- package/linked-list/index.js.map +0 -1
- package/types/function.d.ts +0 -1
- package/types/general.d.ts +0 -8
- package/types/search.d.ts +0 -24
- /package/{array → dist/array}/array-to-map.js +0 -0
- /package/{array → dist/array}/array-to-map.js.map +0 -0
- /package/{array → dist/array}/get-values-from-keys.d.ts +0 -0
- /package/{array → dist/array}/get-values-from-keys.js +0 -0
- /package/{array → dist/array}/get-values-from-keys.js.map +0 -0
- /package/{array → dist/array}/index.d.ts +0 -0
- /package/{array → dist/array}/index.js +0 -0
- /package/{array → dist/array}/index.js.map +0 -0
- /package/{array → dist/array}/inner-join.d.ts +0 -0
- /package/{array → dist/array}/inner-join.js +0 -0
- /package/{array → dist/array}/inner-join.js.map +0 -0
- /package/{array → dist/array}/left-outter-join.d.ts +0 -0
- /package/{array → dist/array}/left-outter-join.js +0 -0
- /package/{array → dist/array}/left-outter-join.js.map +0 -0
- /package/{cdn → dist/business}/types/index.js +0 -0
- /package/{cdn → dist/business}/types/index.js.map +0 -0
- /package/{cdn → dist/cdn}/cdn.factory.d.ts +0 -0
- /package/{cdn → dist/cdn}/cdn.factory.js +0 -0
- /package/{cdn → dist/cdn}/cdn.factory.js.map +0 -0
- /package/{cdn → dist/cdn}/index.d.ts +0 -0
- /package/{cdn → dist/cdn}/index.js +0 -0
- /package/{cdn → dist/cdn}/index.js.map +0 -0
- /package/{cdn → dist/cdn}/types/index.d.ts +0 -0
- /package/{types → dist/cdn/types}/index.js +0 -0
- /package/{types → dist/cdn/types}/index.js.map +0 -0
- /package/{cdn → dist/cdn}/utils/extract-info-from-url.util.js +0 -0
- /package/{cdn → dist/cdn}/utils/extract-info-from-url.util.js.map +0 -0
- /package/{cdn → dist/cdn}/utils/get-cdn-from-s3-url.util.js +0 -0
- /package/{cdn → dist/cdn}/utils/get-cdn-from-s3-url.util.js.map +0 -0
- /package/{cdn → dist/cdn}/utils/get-cdn-url.util.js +0 -0
- /package/{cdn → dist/cdn}/utils/get-cdn-url.util.js.map +0 -0
- /package/{cdn → dist/cdn}/utils/twicpics-transformations.util.d.ts +0 -0
- /package/{cdn → dist/cdn}/utils/twicpics-transformations.util.js +0 -0
- /package/{cdn → dist/cdn}/utils/twicpics-transformations.util.js.map +0 -0
- /package/{formatting → dist/formatting}/format-number.d.ts +0 -0
- /package/{formatting → dist/formatting}/format-number.js +0 -0
- /package/{formatting → dist/formatting}/format-number.js.map +0 -0
- /package/{formatting → dist/formatting}/index.d.ts +0 -0
- /package/{formatting → dist/formatting}/index.js +0 -0
- /package/{color → dist/formatting}/index.js.map +0 -0
- /package/{fp → dist/fp}/index.d.ts +0 -0
- /package/{fp → dist/fp}/index.js +0 -0
- /package/{formatting → dist/fp}/index.js.map +0 -0
- /package/{fp → dist/fp}/run-while.js +0 -0
- /package/{fp → dist/fp}/run-while.js.map +0 -0
- /package/{http → dist/http}/build-search-params.d.ts +0 -0
- /package/{http → dist/http}/build-search-params.js +0 -0
- /package/{http → dist/http}/build-search-params.js.map +0 -0
- /package/{http → dist/http}/encode-search-object.js +0 -0
- /package/{http → dist/http}/encode-search-object.js.map +0 -0
- /package/{http → dist/http}/fetch-with-timeout.js +0 -0
- /package/{http → dist/http}/fetch-with-timeout.js.map +0 -0
- /package/{http → dist/http}/index.d.ts +0 -0
- /package/{http → dist/http}/index.js +0 -0
- /package/{http → dist/http}/index.js.map +0 -0
- /package/{linked-list → dist/linked-list}/apply-diff-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/apply-diff-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/apply-diff-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/create-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/create-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/create-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/find-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/find-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/find-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/get-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/get-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/get-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/index.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/index.js +0 -0
- /package/{fp → dist/linked-list}/index.js.map +0 -0
- /package/{linked-list → dist/linked-list}/insert-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/insert-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/insert-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/linked-list-utils.js +0 -0
- /package/{linked-list → dist/linked-list}/linked-list-utils.js.map +0 -0
- /package/{linked-list → dist/linked-list}/reduce-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/reduce-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/reduce-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/remove-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/remove-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/remove-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/update-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/update-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/update-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/while-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/while-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/while-linked-list.js.map +0 -0
- /package/{math → dist/math}/clamp-number.d.ts +0 -0
- /package/{math → dist/math}/clamp-number.js +0 -0
- /package/{math → dist/math}/clamp-number.js.map +0 -0
- /package/{math → dist/math}/index.d.ts +0 -0
- /package/{math → dist/math}/index.js +0 -0
- /package/{math → dist/math}/index.js.map +0 -0
- /package/{math → dist/math}/interpolate.js +0 -0
- /package/{math → dist/math}/interpolate.js.map +0 -0
- /package/{math → dist/math}/median.d.ts +0 -0
- /package/{math → dist/math}/median.js +0 -0
- /package/{math → dist/math}/median.js.map +0 -0
- /package/{math → dist/math}/number-range.js +0 -0
- /package/{math → dist/math}/number-range.js.map +0 -0
- /package/{math → dist/math}/random-number.d.ts +0 -0
- /package/{math → dist/math}/random-number.js +0 -0
- /package/{math → dist/math}/random-number.js.map +0 -0
- /package/{object → dist/object}/index.d.ts +0 -0
- /package/{object → dist/object}/index.js +0 -0
- /package/{object → dist/object}/index.js.map +0 -0
- /package/{object → dist/object}/merge-deep.d.ts +0 -0
- /package/{object → dist/object}/merge-deep.js +0 -0
- /package/{object → dist/object}/merge-deep.js.map +0 -0
- /package/{object → dist/object}/strip-properties-from-object.d.ts +0 -0
- /package/{object → dist/object}/strip-properties-from-object.js +0 -0
- /package/{object → dist/object}/strip-properties-from-object.js.map +0 -0
- /package/{parsing → dist/parsing}/index.d.ts +0 -0
- /package/{parsing → dist/parsing}/index.js +0 -0
- /package/{parsing → dist/parsing}/index.js.map +0 -0
- /package/{parsing → dist/parsing}/parse-boolean.d.ts +0 -0
- /package/{parsing → dist/parsing}/parse-boolean.js +0 -0
- /package/{parsing → dist/parsing}/parse-boolean.js.map +0 -0
- /package/{parsing → dist/parsing}/parse-enum.d.ts +0 -0
- /package/{parsing → dist/parsing}/parse-enum.js +0 -0
- /package/{parsing → dist/parsing}/parse-enum.js.map +0 -0
- /package/{parsing → dist/parsing}/parse-number.d.ts +0 -0
- /package/{parsing → dist/parsing}/parse-number.js +0 -0
- /package/{parsing → dist/parsing}/parse-number.js.map +0 -0
- /package/{predicates → dist/predicates}/index.d.ts +0 -0
- /package/{predicates → dist/predicates}/index.js +0 -0
- /package/{predicates → dist/predicates}/index.js.map +0 -0
- /package/{predicates → dist/predicates}/is-function.d.ts +0 -0
- /package/{predicates → dist/predicates}/is-function.js +0 -0
- /package/{predicates → dist/predicates}/is-function.js.map +0 -0
- /package/{predicates → dist/predicates}/is-null.d.ts +0 -0
- /package/{predicates → dist/predicates}/is-null.js +0 -0
- /package/{predicates → dist/predicates}/is-null.js.map +0 -0
- /package/{predicates → dist/predicates}/is-object.d.ts +0 -0
- /package/{predicates → dist/predicates}/is-object.js +0 -0
- /package/{predicates → dist/predicates}/is-object.js.map +0 -0
- /package/{predicates → dist/predicates}/is-primitive.d.ts +0 -0
- /package/{predicates → dist/predicates}/is-primitive.js +0 -0
- /package/{predicates → dist/predicates}/is-primitive.js.map +0 -0
- /package/{predicates → dist/predicates}/is-undefined.d.ts +0 -0
- /package/{predicates → dist/predicates}/is-undefined.js +0 -0
- /package/{predicates → dist/predicates}/is-undefined.js.map +0 -0
- /package/{predicates → dist/predicates}/is-uuid.d.ts +0 -0
- /package/{promise → dist/promise}/delay.d.ts +0 -0
- /package/{promise → dist/promise}/delay.js +0 -0
- /package/{promise → dist/promise}/delay.js.map +0 -0
- /package/{promise → dist/promise}/execute-or-resolve-default.js +0 -0
- /package/{promise → dist/promise}/execute-or-resolve-default.js.map +0 -0
- /package/{promise → dist/promise}/execute-with-delay.d.ts +0 -0
- /package/{promise → dist/promise}/execute-with-delay.js +0 -0
- /package/{promise → dist/promise}/execute-with-delay.js.map +0 -0
- /package/{promise → dist/promise}/index.d.ts +0 -0
- /package/{promise → dist/promise}/index.js +0 -0
- /package/{promise → dist/promise}/index.js.map +0 -0
- /package/{string → dist/string}/index.d.ts +0 -0
- /package/{string → dist/string}/index.js +0 -0
- /package/{string → dist/string}/index.js.map +0 -0
- /package/{string → dist/string}/is-string-length-within-range.d.ts +0 -0
- /package/{string → dist/string}/is-string-length-within-range.js +0 -0
- /package/{string → dist/string}/is-string-length-within-range.js.map +0 -0
- /package/{string → dist/string}/replace-in-template.js +0 -0
- /package/{string → dist/string}/replace-in-template.js.map +0 -0
- /package/{time → dist/time}/constants.d.ts +0 -0
- /package/{time → dist/time}/constants.js +0 -0
- /package/{time → dist/time}/constants.js.map +0 -0
- /package/{time → dist/time}/convert.d.ts +0 -0
- /package/{time → dist/time}/convert.js +0 -0
- /package/{time → dist/time}/convert.js.map +0 -0
- /package/{time → dist/time}/format-minutes.d.ts +0 -0
- /package/{time → dist/time}/format-minutes.js +0 -0
- /package/{time → dist/time}/format-minutes.js.map +0 -0
- /package/{time → dist/time}/get-time-diff-as-string.js +0 -0
- /package/{time → dist/time}/get-time-diff-as-string.js.map +0 -0
- /package/{time → dist/time}/index.d.ts +0 -0
- /package/{time → dist/time}/index.js +0 -0
- /package/{time → dist/time}/index.js.map +0 -0
- /package/{types → dist/types}/index.d.ts +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { median } from '../median';
|
|
2
|
+
|
|
3
|
+
describe('median', () => {
|
|
4
|
+
it('should return the middle value if the array has an odd number of elements', () => {
|
|
5
|
+
expect(median([1, 2, 3])).toStrictEqual(2);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return the average of the middle two values if the array has an even number of elements', () => {
|
|
9
|
+
expect(median([1, 2, 3, 4])).toStrictEqual(2.5);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should handle an empty array', () => {
|
|
13
|
+
expect(median([])).toBeNull();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should handle array with duplicate values', () => {
|
|
17
|
+
expect(median([4, 7, 2, 4, 9])).toStrictEqual(4);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should handle array with negative values', () => {
|
|
21
|
+
expect(median([-1, -5, -3, -2, -4])).toStrictEqual(-3);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should overwrite the default value if the array is empty', () => {
|
|
25
|
+
expect(median([], 0)).toStrictEqual(0);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { assertNumberRange, isNumberInRange } from '../number-range';
|
|
2
|
+
|
|
3
|
+
describe('assertNumberRange', () => {
|
|
4
|
+
it('should throw an error if min is above max', () => {
|
|
5
|
+
expect(
|
|
6
|
+
() => assertNumberRange({
|
|
7
|
+
min: 5,
|
|
8
|
+
max: 0,
|
|
9
|
+
}),
|
|
10
|
+
).toThrowError('Invalid number range: min must be lower than or equal to max');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should not throw an error if the number range is valid', () => {
|
|
14
|
+
expect(
|
|
15
|
+
() => assertNumberRange({
|
|
16
|
+
min: 0,
|
|
17
|
+
max: 5,
|
|
18
|
+
}),
|
|
19
|
+
).not.toThrowError();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('isNumberInRange', () => {
|
|
24
|
+
it('should throw an error if range is incorrect', () => {
|
|
25
|
+
expect(
|
|
26
|
+
() => isNumberInRange(2, {
|
|
27
|
+
min: 5,
|
|
28
|
+
max: 0,
|
|
29
|
+
}),
|
|
30
|
+
).toThrowError('Invalid number range: min must be lower than or equal to max');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should return true if number is in range', () => {
|
|
34
|
+
const set = [
|
|
35
|
+
{ num: 1, range: { min: 0, max: 1 } },
|
|
36
|
+
{ num: 0, range: { min: 0, max: 1 } },
|
|
37
|
+
{ num: 0.5, range: { min: 0, max: 1 } },
|
|
38
|
+
{ num: -30, range: { min: -1000, max: 1000 } },
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
set.forEach(({ num, range }) => {
|
|
42
|
+
expect(isNumberInRange(num, range)).toBeTrue();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should return false if number is not in range', () => {
|
|
47
|
+
const set = [
|
|
48
|
+
{ num: -5, range: { min: 0, max: 1 } },
|
|
49
|
+
{ num: 1.01, range: { min: 0, max: 1 } },
|
|
50
|
+
{ num: 10, range: { min: 0, max: 1 } },
|
|
51
|
+
{ num: -2000, range: { min: -1000, max: 1000 } },
|
|
52
|
+
{ num: 2000, range: { min: -1000, max: 1000 } },
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
set.forEach(({ num, range }) => {
|
|
56
|
+
expect(isNumberInRange(num, range)).toBeFalse();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { randomNumber } from '../random-number';
|
|
2
|
+
|
|
3
|
+
describe('randomNumber', () => {
|
|
4
|
+
const satisfyInRange = (min: number, max: number) => (value: number) => value >= min && value <= max;
|
|
5
|
+
|
|
6
|
+
it('should return a random number between the range', () => {
|
|
7
|
+
expect(randomNumber({ min: 98, max: 110 })).toSatisfy(satisfyInRange(98, 110));
|
|
8
|
+
expect(randomNumber({ min: -5, max: 0 })).toSatisfy(satisfyInRange(-5, 0));
|
|
9
|
+
expect(randomNumber({ min: 0, max: 10 })).toSatisfy(satisfyInRange(0, 10));
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { assertNumberRange } from './number-range';
|
|
2
|
+
import type { NumberRange } from './number-range';
|
|
3
|
+
|
|
4
|
+
export const clampNumber = (num: number, { min, max }: NumberRange) => {
|
|
5
|
+
assertNumberRange({ min, max });
|
|
6
|
+
|
|
7
|
+
return Math.min(Math.max(num, min), max);
|
|
8
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isNumberInRange } from './number-range';
|
|
2
|
+
|
|
3
|
+
export type RangeArray = [number, number];
|
|
4
|
+
|
|
5
|
+
export const interpolate = (num: number, inputRange: RangeArray, outputRange: RangeArray) => {
|
|
6
|
+
const [x1, x2] = inputRange;
|
|
7
|
+
const [y1, y2] = outputRange;
|
|
8
|
+
|
|
9
|
+
if (x1 > x2) {
|
|
10
|
+
throw new Error('interpolate: inputRange[0] should not be superior to inputRange[1]');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!isNumberInRange(num, { min: x1, max: x2 })) {
|
|
14
|
+
throw new Error(`interpolate: input number {${num}} is not in range of {${x1}}-{${x2}}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return y1 + ((num - x1) / (x2 - x1)) * (y2 - y1);
|
|
18
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function median(arr: number[]): number | null;
|
|
2
|
+
export function median(arr: number[], defaultValueIfEmpty: number): number;
|
|
3
|
+
export function median(arr: number[], defaultValueIfEmpty?: number) {
|
|
4
|
+
if (arr.length === 0) {
|
|
5
|
+
if (typeof defaultValueIfEmpty === 'number') {
|
|
6
|
+
return defaultValueIfEmpty;
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const sorted = [...arr].sort((a, b) => a - b);
|
|
12
|
+
const mid = Math.floor(sorted.length / 2);
|
|
13
|
+
|
|
14
|
+
// If the length of the array is odd, return the middle element
|
|
15
|
+
if (sorted.length % 2 === 1) {
|
|
16
|
+
return sorted[mid];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// If the length of the array is even, return the average of the middle two elements
|
|
20
|
+
return (sorted[mid - 1] + sorted[mid]) / 2;
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type NumberRange = {
|
|
2
|
+
min: number,
|
|
3
|
+
max: number,
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const assertNumberRange = (range: NumberRange) => {
|
|
7
|
+
if (range.min > range.max) {
|
|
8
|
+
throw new Error('Invalid number range: min must be lower than or equal to max');
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const isNumberInRange = (num: number, { min, max }: NumberRange) => {
|
|
13
|
+
assertNumberRange({ min, max });
|
|
14
|
+
|
|
15
|
+
return num >= min && num <= max;
|
|
16
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { assertNumberRange } from './number-range';
|
|
2
|
+
import type { NumberRange } from './number-range';
|
|
3
|
+
|
|
4
|
+
export const randomNumber = ({ min, max }: NumberRange) => {
|
|
5
|
+
assertNumberRange({ min, max });
|
|
6
|
+
|
|
7
|
+
return Math.floor(
|
|
8
|
+
Math.random() * (max - min) + min,
|
|
9
|
+
);
|
|
10
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { mergeDeep } from '../merge-deep';
|
|
2
|
+
|
|
3
|
+
type A = {
|
|
4
|
+
a: number,
|
|
5
|
+
b: {
|
|
6
|
+
c: {
|
|
7
|
+
c1: string,
|
|
8
|
+
c2: number,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
d:ReadonlyArray<number>,
|
|
12
|
+
e: boolean,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('mergeDeep', () => {
|
|
16
|
+
it('should return same object if no update', () => {
|
|
17
|
+
const a: A = {
|
|
18
|
+
a: 0, b: { c: { c1: 'yo', c2: 0 } }, d: [], e: false,
|
|
19
|
+
};
|
|
20
|
+
const b = {};
|
|
21
|
+
|
|
22
|
+
expect(mergeDeep(a, b)).toBe(a);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should leave object unchanged if update does nothing', () => {
|
|
26
|
+
const a: A = {
|
|
27
|
+
a: 0, b: { c: { c1: 'yo', c2: 0 } }, d: [], e: false,
|
|
28
|
+
};
|
|
29
|
+
const b = { a: 0 };
|
|
30
|
+
|
|
31
|
+
expect(mergeDeep(a, b)).toBe(a);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should do an update', () => {
|
|
35
|
+
const a: A = {
|
|
36
|
+
a: 0, b: { c: { c1: 'yo', c2: 0 } }, d: [], e: false,
|
|
37
|
+
};
|
|
38
|
+
const b = { a: 1, b: { c: { c1: 'hey' } }, d: [1, 2], e: true };
|
|
39
|
+
|
|
40
|
+
expect(mergeDeep(a, b)).toStrictEqual({ a: 1, b: { c: { c1: 'hey', c2: 0 } }, d: [1, 2], e: true });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should overwrite arrays', () => {
|
|
44
|
+
const a = { a: [1, 2] };
|
|
45
|
+
const b = { a: [3, 4] };
|
|
46
|
+
|
|
47
|
+
expect(mergeDeep(a, b)).toStrictEqual(b);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should not add new keys', () => {
|
|
51
|
+
const a = { a: 0, c: 0 };
|
|
52
|
+
const b: any = { a: 0, b: 0, c: 0 };
|
|
53
|
+
|
|
54
|
+
expect(mergeDeep(a, b)).toBe(a);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { stripPropertiesFromObject } from '../strip-properties-from-object';
|
|
2
|
+
|
|
3
|
+
describe('stripPropertiesFromObject', () => {
|
|
4
|
+
const obj = {
|
|
5
|
+
a: 1,
|
|
6
|
+
b: {
|
|
7
|
+
b1: 1,
|
|
8
|
+
b2: 2,
|
|
9
|
+
b3: 3,
|
|
10
|
+
b4: {
|
|
11
|
+
b41: 1,
|
|
12
|
+
b42: 2,
|
|
13
|
+
b43: 3,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
c: 3,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
it('should remove the properties from the object', () => {
|
|
20
|
+
const result = stripPropertiesFromObject(obj, ['c', 'b.b1', 'b.b4.b41']);
|
|
21
|
+
|
|
22
|
+
expect(result).toMatchObject({
|
|
23
|
+
a: 1,
|
|
24
|
+
b: {
|
|
25
|
+
b2: 2,
|
|
26
|
+
b3: 3,
|
|
27
|
+
b4: {
|
|
28
|
+
b42: 2,
|
|
29
|
+
b43: 3,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Check if no mutation on the orignal object
|
|
35
|
+
expect(obj).toEqual({
|
|
36
|
+
a: 1,
|
|
37
|
+
b: {
|
|
38
|
+
b1: 1,
|
|
39
|
+
b2: 2,
|
|
40
|
+
b3: 3,
|
|
41
|
+
b4: {
|
|
42
|
+
b41: 1,
|
|
43
|
+
b42: 2,
|
|
44
|
+
b43: 3,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
c: 3,
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should ignore properties that do not exist', () => {
|
|
52
|
+
const result = stripPropertiesFromObject(obj, ['d', 'a.b', 'b.b1.b11']);
|
|
53
|
+
expect(result).toEqual(obj);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should not fail with empty array', () => {
|
|
57
|
+
const result = stripPropertiesFromObject(obj, []);
|
|
58
|
+
expect(result).toEqual(obj);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should handle empty property', () => {
|
|
62
|
+
const result = stripPropertiesFromObject(obj, ['']);
|
|
63
|
+
expect(result).toEqual(obj);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DeepPartial, ValueType } from '../types';
|
|
2
|
+
|
|
3
|
+
// https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript/8511350#8511350
|
|
4
|
+
const isObject = (a: any) => typeof a === 'object' && a !== null;
|
|
5
|
+
const isValueType = (a: any): a is ValueType => !isObject(a) || Array.isArray(a);
|
|
6
|
+
|
|
7
|
+
export const mergeDeep = <T>(a: T, b: DeepPartial<T>): T => {
|
|
8
|
+
if (isValueType(a) || isValueType(b)) {
|
|
9
|
+
return b as T;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return (Object.keys(b) as (keyof T)[]).reduce((acc, key) => {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
if (!(key in a)) {
|
|
15
|
+
return acc;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (b[key] === a[key]) {
|
|
19
|
+
return acc;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const merged = mergeDeep(a[key], b[key] as DeepPartial<T[keyof T]>);
|
|
23
|
+
|
|
24
|
+
return { ...acc, [key]: merged };
|
|
25
|
+
}, a);
|
|
26
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import structuredClone from '@ungap/structured-clone';
|
|
2
|
+
|
|
3
|
+
export const stripPropertiesFromObject = <Output extends Record<any, any>, Input extends Record<any, any>>(
|
|
4
|
+
obj: Input,
|
|
5
|
+
properties: string[],
|
|
6
|
+
): Output => {
|
|
7
|
+
const copy = structuredClone(obj);
|
|
8
|
+
|
|
9
|
+
properties.forEach((nestedPropertyStr) => {
|
|
10
|
+
const nestedProperties = nestedPropertyStr.split('.');
|
|
11
|
+
const propertyToRemove = nestedProperties[nestedProperties.length - 1];
|
|
12
|
+
|
|
13
|
+
const nestedObject =
|
|
14
|
+
nestedProperties.length === 1
|
|
15
|
+
? copy
|
|
16
|
+
: nestedProperties
|
|
17
|
+
.slice(0, nestedProperties.length - 1)
|
|
18
|
+
.reduce((acc, property) => acc[property], copy);
|
|
19
|
+
|
|
20
|
+
if (nestedObject) {
|
|
21
|
+
delete nestedObject[propertyToRemove];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return copy;
|
|
26
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { parseBoolean } from '../parse-boolean';
|
|
2
|
+
|
|
3
|
+
describe('parseBoolean', () => {
|
|
4
|
+
it('should return true if value is "true"', () => {
|
|
5
|
+
expect(parseBoolean('true')).toStrictEqual(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return false if value is "false"', () => {
|
|
9
|
+
expect(parseBoolean('false')).toStrictEqual(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should throw an exception if value is neither "true" nor "false"', () => {
|
|
13
|
+
expect(() => parseBoolean('value')).toThrow();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createEnumParser } from '../parse-enum';
|
|
2
|
+
|
|
3
|
+
enum TestEnum {
|
|
4
|
+
FirstValue = 'first',
|
|
5
|
+
SecondValue = 'second',
|
|
6
|
+
ThirdValue = 'third',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('createEnumParser', () => {
|
|
10
|
+
const parseTestEnum = createEnumParser(TestEnum);
|
|
11
|
+
|
|
12
|
+
it('should return a valid enum parser', () => {
|
|
13
|
+
expect(parseTestEnum('second')).toStrictEqual(TestEnum.SecondValue);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should throw an error if the parsing did not work', () => {
|
|
17
|
+
expect(() => parseTestEnum('fourth')).toThrowError();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { parseNumber } from '../parse-number';
|
|
2
|
+
|
|
3
|
+
describe('parseNumber', () => {
|
|
4
|
+
it('should return number 10 if value is "10', () => {
|
|
5
|
+
expect(parseNumber('10')).toStrictEqual(10);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return -10 if value is "-10"', () => {
|
|
9
|
+
expect(parseNumber('-10')).toStrictEqual(-10);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should return 0 if value is "0"', () => {
|
|
13
|
+
expect(parseNumber('0')).toStrictEqual(0);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should throw an exception if value is not a number', () => {
|
|
17
|
+
expect(() => parseNumber('number')).toThrow();
|
|
18
|
+
expect(() => parseNumber('false')).toThrow();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a string to a boolean. Throw error if string is neither "true" nor "false"
|
|
3
|
+
*/
|
|
4
|
+
export const parseBoolean = (value: string): boolean => {
|
|
5
|
+
if (value !== 'true' && value !== 'false') {
|
|
6
|
+
throw new Error('Cannot parse value');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return value === 'true';
|
|
10
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Primitive } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Factory to build enum to parse a string to an enum. Throw error if string is not an enum value
|
|
5
|
+
*/
|
|
6
|
+
export const createEnumParser = <E extends Record<string, Primitive>>(enumType: E) => (
|
|
7
|
+
(value: string) => {
|
|
8
|
+
const enumValues = Object.values(enumType);
|
|
9
|
+
|
|
10
|
+
if (!enumValues.includes(value as any)) {
|
|
11
|
+
throw new Error('Can\'t parse this value');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return value as unknown as E;
|
|
15
|
+
}
|
|
16
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a string to a number. Throw error if string is NaN
|
|
3
|
+
*/
|
|
4
|
+
export const parseNumber = (value: string): number => {
|
|
5
|
+
const number = parseInt(value, 10);
|
|
6
|
+
|
|
7
|
+
if (Number.isNaN(number)) {
|
|
8
|
+
throw new Error('Cannot parse value');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return number;
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isFunction } from '../is-function';
|
|
2
|
+
|
|
3
|
+
describe('isFunction', () => {
|
|
4
|
+
it('should return true if value is a function', () => {
|
|
5
|
+
expect(isFunction(() => {})).toBeTrue();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return false if value is not a function', () => {
|
|
9
|
+
expect(isFunction('')).toBeFalse();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isNull } from '../is-null';
|
|
2
|
+
|
|
3
|
+
describe('isNull', () => {
|
|
4
|
+
it('should return true if value is null', () => {
|
|
5
|
+
expect(isNull(null)).toBeTrue();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return false if value is not null', () => {
|
|
9
|
+
expect(isNull('')).toBeFalse();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isObject } from '../is-object';
|
|
2
|
+
|
|
3
|
+
describe('isObject', () => {
|
|
4
|
+
it('should return true if value is an object', () => {
|
|
5
|
+
expect(isObject({})).toBeTrue();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return false if value is not an object', () => {
|
|
9
|
+
expect(isObject('')).toBeFalse();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isPrimitive, isArrayOfPrimitive } from '../is-primitive';
|
|
2
|
+
|
|
3
|
+
describe('isPrimitive', () => {
|
|
4
|
+
it('should return true if value is a primitive', () => {
|
|
5
|
+
expect(isPrimitive('a value')).toBeTrue();
|
|
6
|
+
expect(isPrimitive(6)).toBeTrue();
|
|
7
|
+
expect(isPrimitive(true)).toBeTrue();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should return false if value is not a primitive', () => {
|
|
11
|
+
expect(isPrimitive({})).toBeFalse();
|
|
12
|
+
expect(isPrimitive(new Date())).toBeFalse();
|
|
13
|
+
expect(isPrimitive([])).toBeFalse();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('isArrayOfPrimitive', () => {
|
|
18
|
+
it('should return false if value not an array', () => {
|
|
19
|
+
expect(isArrayOfPrimitive({})).toBeFalse();
|
|
20
|
+
expect(isArrayOfPrimitive(1)).toBeFalse();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should return false if not every value in the array is primitive', () => {
|
|
24
|
+
expect(isArrayOfPrimitive([
|
|
25
|
+
1,
|
|
26
|
+
'test',
|
|
27
|
+
true,
|
|
28
|
+
false,
|
|
29
|
+
[],
|
|
30
|
+
{},
|
|
31
|
+
])).toBeFalse();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should return true if every value in the array is a primitive', () => {
|
|
35
|
+
expect(isArrayOfPrimitive([
|
|
36
|
+
1,
|
|
37
|
+
'test',
|
|
38
|
+
true,
|
|
39
|
+
false,
|
|
40
|
+
])).toBeTrue();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isUndefined } from '../is-undefined';
|
|
2
|
+
|
|
3
|
+
describe('isUndefined', () => {
|
|
4
|
+
it('should return true if value is undefined', () => {
|
|
5
|
+
expect(isUndefined(undefined)).toBeTrue();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return false if value is not undefined', () => {
|
|
9
|
+
expect(isUndefined('')).toBeFalse();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isUuidV4 } from '../is-uuid';
|
|
2
|
+
|
|
3
|
+
describe('isUuidV4', () => {
|
|
4
|
+
it('returns true if the string is uuid v4', () => {
|
|
5
|
+
expect(isUuidV4('dd819894-70f3-4629-8712-430445f93c5d')).toBeTrue();
|
|
6
|
+
});
|
|
7
|
+
it('returns false if argument is not a string', () => {
|
|
8
|
+
expect(isUuidV4(4)).toBeFalse();
|
|
9
|
+
});
|
|
10
|
+
it('returns false if argument is uuid V1', () => {
|
|
11
|
+
expect(isUuidV4('4dfde9e2-3988-11ed-a261-0242ac120002')).toBeFalse();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isNull = (value: any): value is null => value === null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Primitive } from '../types/general';
|
|
2
|
+
|
|
3
|
+
const PRIMITIVE_TYPES = [
|
|
4
|
+
'string',
|
|
5
|
+
'boolean',
|
|
6
|
+
'number',
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
export const isPrimitive = (value: any): value is Primitive => (
|
|
10
|
+
PRIMITIVE_TYPES.includes(typeof value)
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const isArrayOfPrimitive = (value: any): value is Array<Primitive> => {
|
|
14
|
+
if (!Array.isArray(value)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return value.every((arrayValue) => isPrimitive(arrayValue));
|
|
19
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { delay } from '../delay';
|
|
2
|
+
|
|
3
|
+
jest.useFakeTimers();
|
|
4
|
+
jest.spyOn(global, 'setTimeout');
|
|
5
|
+
|
|
6
|
+
describe('delay.ts', () => {
|
|
7
|
+
it('waits ', () => {
|
|
8
|
+
delay(500);
|
|
9
|
+
|
|
10
|
+
expect(setTimeout).toHaveBeenCalledOnce();
|
|
11
|
+
expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), 500);
|
|
12
|
+
});
|
|
13
|
+
});
|