@onivoro/isomorphic-common 22.0.5 → 24.0.0
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/README.md +393 -0
- package/dist/libs/isomorphic/axios/libs/isomorphic/axios/README.md +314 -0
- package/dist/libs/isomorphic/axios/libs/isomorphic/axios/package.json +10 -0
- package/dist/libs/isomorphic/common/libs/isomorphic/common/README.md +393 -0
- package/dist/libs/isomorphic/common/libs/isomorphic/common/package.json +10 -0
- package/dist/libs/server/common/libs/server/common/README.md +322 -0
- package/dist/libs/server/common/libs/server/common/package.json +12 -0
- package/jest.config.ts +11 -0
- package/package.json +8 -39
- package/project.json +23 -0
- package/{dist/cjs/index.d.ts → src/index.ts} +42 -5
- package/src/lib/constants/api-id-header.constant.ts +1 -0
- package/src/lib/constants/api-key-header.constant.ts +1 -0
- package/src/lib/constants/auth-cookie-name.constant.ts +2 -0
- package/src/lib/constants/millis-per-day.constant.ts +3 -0
- package/src/lib/constants/millis-per-hour.constant.ts +3 -0
- package/src/lib/constants/millis-per-minute.constant.ts +1 -0
- package/src/lib/constants/regexes.constant.ts +30 -0
- package/src/lib/functions/__snapshots__/chunk.function.spec.ts.snap +94 -0
- package/src/lib/functions/__snapshots__/split-date-range-into-days.function.spec.ts.snap +50 -0
- package/src/lib/functions/add-offset.function.spec.ts +12 -0
- package/src/lib/functions/add-offset.function.ts +14 -0
- package/src/lib/functions/arrange-act-assert.function.ts +23 -0
- package/src/lib/functions/camel-case.function.ts +30 -0
- package/src/lib/functions/chunk.function.spec.ts +20 -0
- package/src/lib/functions/chunk.function.ts +25 -0
- package/src/lib/functions/convert-object-to-literal.function.spec.ts +16 -0
- package/src/lib/functions/convert-object-to-literal.function.ts +10 -0
- package/src/lib/functions/format-usd.function.ts +4 -0
- package/src/lib/functions/from-boolean-string.function.ts +3 -0
- package/src/lib/functions/from-calendar-date.function.spec.ts +11 -0
- package/src/lib/functions/from-calendar-date.function.ts +5 -0
- package/src/lib/functions/from-csv-string.function.ts +3 -0
- package/src/lib/functions/get-date-last-month.function.ts +6 -0
- package/src/lib/functions/get-date-range-for-month.function copy.ts +8 -0
- package/src/lib/functions/get-date-range-for-month.function.ts +8 -0
- package/src/lib/functions/get-tag.function.ts +10 -0
- package/src/lib/functions/get-user-full-name.function.ts +5 -0
- package/src/lib/functions/is-symbol.function.ts +11 -0
- package/src/lib/functions/is-valid-date.function.ts +5 -0
- package/src/lib/functions/kebab-case.function.ts +5 -0
- package/src/lib/functions/map-entities-to-options.function.ts +11 -0
- package/src/lib/functions/map-enum-to-array-of-values.function copy.ts +3 -0
- package/src/lib/functions/map-enum-to-array-of-values.function.ts +3 -0
- package/src/lib/functions/map-enum-to-lookup-array.function.ts +6 -0
- package/src/lib/functions/map-enum-to-options.function copy.ts +7 -0
- package/src/lib/functions/map-enum-to-options.function.ts +7 -0
- package/src/lib/functions/mock-calls.function.ts +4 -0
- package/src/lib/functions/money.function.spec.ts +10 -0
- package/src/lib/functions/money.function.ts +22 -0
- package/src/lib/functions/parse-bool.function.ts +3 -0
- package/src/lib/functions/properties-to-array.function.ts +21 -0
- package/src/lib/functions/remove-alpha-chars.function.spec.ts +11 -0
- package/src/lib/functions/remove-alpha-chars.function.ts +9 -0
- package/src/lib/functions/remove-element-at-index.function copy.ts +9 -0
- package/src/lib/functions/remove-element-at-index.function.ts +9 -0
- package/src/lib/functions/round.function copy.ts +4 -0
- package/src/lib/functions/round.function.ts +4 -0
- package/src/lib/functions/sanitize-filename.function.ts +9 -0
- package/src/lib/functions/sleep.function.ts +3 -0
- package/{dist/esm/lib/functions/snake-case.function.js → src/lib/functions/snake-case.function.ts} +9 -6
- package/src/lib/functions/sort-by-created-at.function.ts +7 -0
- package/src/lib/functions/sort-by-full-name.function.ts +6 -0
- package/src/lib/functions/sort-by-id.function.ts +3 -0
- package/src/lib/functions/sort-by-name.function.ts +3 -0
- package/src/lib/functions/sort-numbers.function.ts +3 -0
- package/src/lib/functions/split-date-range-into-days.function.spec.ts +17 -0
- package/src/lib/functions/split-date-range-into-days.function.ts +26 -0
- package/src/lib/functions/subtract-offset.function.spec.ts +12 -0
- package/src/lib/functions/subtract-offset.function.ts +14 -0
- package/src/lib/functions/to-boolean-string.function.ts +3 -0
- package/src/lib/functions/to-calendar-date.function.ts +11 -0
- package/src/lib/functions/to-csv-string.function.ts +3 -0
- package/{dist/cjs/lib/functions/to-decimal-base.function.js → src/lib/functions/to-decimal-base.function.ts} +9 -7
- package/src/lib/functions/to-dollars-and-cents.function.spec.ts +7 -0
- package/src/lib/functions/to-dollars-and-cents.function.ts +17 -0
- package/{dist/cjs/lib/functions/to-string.function.js → src/lib/functions/to-string.function.ts} +6 -6
- package/src/lib/functions/to-unique-array.function.spec.ts +45 -0
- package/src/lib/functions/to-unique-array.function.ts +3 -0
- package/src/lib/functions/to-words.function.spec.ts +7 -0
- package/{dist/cjs/lib/functions/to-words.function.js → src/lib/functions/to-words.function.ts} +43 -26
- package/src/lib/functions/try-json-parse.spec.ts +37 -0
- package/src/lib/functions/try-json-parse.ts +11 -0
- package/src/lib/functions/try-json-stringify.spec.ts +44 -0
- package/src/lib/functions/try-json-stringify.ts +11 -0
- package/src/lib/functions/try-parse-date.function.spec.ts +12 -0
- package/src/lib/functions/try-parse-date.function.ts +17 -0
- package/src/lib/functions/unicode-words.const.ts +70 -0
- package/src/lib/functions/upper-first.function.spec.ts +16 -0
- package/src/lib/functions/upper-first.function.ts +10 -0
- package/src/lib/functions/use-date.function.ts +21 -0
- package/src/lib/functions/words.function.ts +38 -0
- package/src/lib/types/access-token.interface.ts +8 -0
- package/{dist/esm/lib/interfaces/axios-wrapped-nest-exception.interface.d.ts → src/lib/types/axios-wrapped-nest-exception.interface.ts} +1 -1
- package/src/lib/types/company.type.ts +18 -0
- package/src/lib/types/createable.type.ts +1 -0
- package/{dist/cjs/lib/interfaces/entity-provider.interface.d.ts → src/lib/types/entity-provider.interface.ts} +1 -1
- package/src/lib/types/keys-of.type copy.ts +1 -0
- package/src/lib/types/keys-of.type.ts +1 -0
- package/{dist/types/lib/interfaces/lookup.interface.d.ts → src/lib/types/lookup.interface copy.ts } +2 -2
- package/{dist/cjs/lib/interfaces/lookup.interface.d.ts → src/lib/types/lookup.interface.ts} +2 -2
- package/src/lib/types/nameable.type.ts +4 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +8 -0
- package/tsconfig.spec.json +14 -0
- package/dist/cjs/index.js +0 -59
- package/dist/cjs/lib/constants/decimal-regex.constant.d.ts +0 -1
- package/dist/cjs/lib/constants/decimal-regex.constant.js +0 -4
- package/dist/cjs/lib/constants/millis-per-day.constant.d.ts +0 -1
- package/dist/cjs/lib/constants/millis-per-day.constant.js +0 -5
- package/dist/cjs/lib/constants/millis-per-hour.constant.d.ts +0 -1
- package/dist/cjs/lib/constants/millis-per-hour.constant.js +0 -5
- package/dist/cjs/lib/constants/millis-per-minute.constant.d.ts +0 -1
- package/dist/cjs/lib/constants/millis-per-minute.constant.js +0 -4
- package/dist/cjs/lib/functions/add-offset.function.d.ts +0 -1
- package/dist/cjs/lib/functions/add-offset.function.js +0 -13
- package/dist/cjs/lib/functions/camel-case.function.d.ts +0 -20
- package/dist/cjs/lib/functions/camel-case.function.js +0 -31
- package/dist/cjs/lib/functions/convert-object-to-literal.function.d.ts +0 -1
- package/dist/cjs/lib/functions/convert-object-to-literal.function.js +0 -9
- package/dist/cjs/lib/functions/format-usd.function.d.ts +0 -1
- package/dist/cjs/lib/functions/format-usd.function.js +0 -7
- package/dist/cjs/lib/functions/from-boolean-string.function.d.ts +0 -1
- package/dist/cjs/lib/functions/from-boolean-string.function.js +0 -6
- package/dist/cjs/lib/functions/from-calendar-date.function.d.ts +0 -1
- package/dist/cjs/lib/functions/from-calendar-date.function.js +0 -7
- package/dist/cjs/lib/functions/from-csv-string.function.d.ts +0 -1
- package/dist/cjs/lib/functions/from-csv-string.function.js +0 -6
- package/dist/cjs/lib/functions/get-date-range-for-month.function.d.ts +0 -4
- package/dist/cjs/lib/functions/get-date-range-for-month.function.js +0 -9
- package/dist/cjs/lib/functions/get-tag.function.d.ts +0 -1
- package/dist/cjs/lib/functions/get-tag.function.js +0 -11
- package/dist/cjs/lib/functions/is-symbol.function.d.ts +0 -1
- package/dist/cjs/lib/functions/is-symbol.function.js +0 -10
- package/dist/cjs/lib/functions/is-valid-date.function.d.ts +0 -1
- package/dist/cjs/lib/functions/is-valid-date.function.js +0 -7
- package/dist/cjs/lib/functions/kebab-case.function.d.ts +0 -1
- package/dist/cjs/lib/functions/kebab-case.function.js +0 -7
- package/dist/cjs/lib/functions/map-enum-to-array-of-values.function.d.ts +0 -1
- package/dist/cjs/lib/functions/map-enum-to-array-of-values.function.js +0 -6
- package/dist/cjs/lib/functions/map-enum-to-lookup-array.function.d.ts +0 -2
- package/dist/cjs/lib/functions/map-enum-to-lookup-array.function.js +0 -7
- package/dist/cjs/lib/functions/map-enum-to-options.function.d.ts +0 -4
- package/dist/cjs/lib/functions/map-enum-to-options.function.js +0 -9
- package/dist/cjs/lib/functions/money.function.d.ts +0 -1
- package/dist/cjs/lib/functions/money.function.js +0 -19
- package/dist/cjs/lib/functions/parse-bool.function.d.ts +0 -1
- package/dist/cjs/lib/functions/parse-bool.function.js +0 -6
- package/dist/cjs/lib/functions/properties-to-array.function.d.ts +0 -1
- package/dist/cjs/lib/functions/properties-to-array.function.js +0 -18
- package/dist/cjs/lib/functions/remove-alpha-chars.function.d.ts +0 -1
- package/dist/cjs/lib/functions/remove-alpha-chars.function.js +0 -10
- package/dist/cjs/lib/functions/remove-element-at-index.function.d.ts +0 -1
- package/dist/cjs/lib/functions/remove-element-at-index.function.js +0 -12
- package/dist/cjs/lib/functions/round.function.d.ts +0 -1
- package/dist/cjs/lib/functions/round.function.js +0 -7
- package/dist/cjs/lib/functions/sanitize-filename.function.d.ts +0 -1
- package/dist/cjs/lib/functions/sanitize-filename.function.js +0 -10
- package/dist/cjs/lib/functions/sleep.function.d.ts +0 -1
- package/dist/cjs/lib/functions/sleep.function.js +0 -6
- package/dist/cjs/lib/functions/snake-case.function.d.ts +0 -24
- package/dist/cjs/lib/functions/snake-case.function.js +0 -31
- package/dist/cjs/lib/functions/subtract-offset.function.d.ts +0 -1
- package/dist/cjs/lib/functions/subtract-offset.function.js +0 -13
- package/dist/cjs/lib/functions/to-boolean-string.function.d.ts +0 -1
- package/dist/cjs/lib/functions/to-boolean-string.function.js +0 -6
- package/dist/cjs/lib/functions/to-calendar-date.function.d.ts +0 -1
- package/dist/cjs/lib/functions/to-calendar-date.function.js +0 -11
- package/dist/cjs/lib/functions/to-csv-string.function.d.ts +0 -1
- package/dist/cjs/lib/functions/to-csv-string.function.js +0 -6
- package/dist/cjs/lib/functions/to-decimal-base.function.d.ts +0 -1
- package/dist/cjs/lib/functions/to-dollars-and-cents.function.d.ts +0 -1
- package/dist/cjs/lib/functions/to-dollars-and-cents.function.js +0 -16
- package/dist/cjs/lib/functions/to-string.function.d.ts +0 -1
- package/dist/cjs/lib/functions/to-unique-array.function.d.ts +0 -1
- package/dist/cjs/lib/functions/to-unique-array.function.js +0 -6
- package/dist/cjs/lib/functions/to-words.function.d.ts +0 -1
- package/dist/cjs/lib/functions/try-json-parse.d.ts +0 -1
- package/dist/cjs/lib/functions/try-json-parse.js +0 -14
- package/dist/cjs/lib/functions/try-json-stringify.d.ts +0 -1
- package/dist/cjs/lib/functions/try-json-stringify.js +0 -14
- package/dist/cjs/lib/functions/try-parse-date.function.d.ts +0 -1
- package/dist/cjs/lib/functions/try-parse-date.function.js +0 -16
- package/dist/cjs/lib/functions/unicode-words.const.d.ts +0 -8
- package/dist/cjs/lib/functions/unicode-words.const.js +0 -68
- package/dist/cjs/lib/functions/upper-first.function.d.ts +0 -1
- package/dist/cjs/lib/functions/upper-first.function.js +0 -12
- package/dist/cjs/lib/functions/words.function.d.ts +0 -17
- package/dist/cjs/lib/functions/words.function.js +0 -34
- package/dist/cjs/lib/interfaces/axios-wrapped-nest-exception.interface.d.ts +0 -5
- package/dist/cjs/lib/interfaces/axios-wrapped-nest-exception.interface.js +0 -2
- package/dist/cjs/lib/interfaces/entity-provider.interface.js +0 -2
- package/dist/cjs/lib/interfaces/keys-of.type.d.ts +0 -3
- package/dist/cjs/lib/interfaces/keys-of.type.js +0 -2
- package/dist/cjs/lib/interfaces/lookup.interface.js +0 -2
- package/dist/esm/index.d.ts +0 -43
- package/dist/esm/index.js +0 -59
- package/dist/esm/lib/constants/decimal-regex.constant.d.ts +0 -1
- package/dist/esm/lib/constants/decimal-regex.constant.js +0 -4
- package/dist/esm/lib/constants/millis-per-day.constant.d.ts +0 -1
- package/dist/esm/lib/constants/millis-per-day.constant.js +0 -5
- package/dist/esm/lib/constants/millis-per-hour.constant.d.ts +0 -1
- package/dist/esm/lib/constants/millis-per-hour.constant.js +0 -5
- package/dist/esm/lib/constants/millis-per-minute.constant.d.ts +0 -1
- package/dist/esm/lib/constants/millis-per-minute.constant.js +0 -4
- package/dist/esm/lib/functions/add-offset.function.d.ts +0 -1
- package/dist/esm/lib/functions/add-offset.function.js +0 -13
- package/dist/esm/lib/functions/camel-case.function.d.ts +0 -20
- package/dist/esm/lib/functions/camel-case.function.js +0 -31
- package/dist/esm/lib/functions/convert-object-to-literal.function.d.ts +0 -1
- package/dist/esm/lib/functions/convert-object-to-literal.function.js +0 -9
- package/dist/esm/lib/functions/format-usd.function.d.ts +0 -1
- package/dist/esm/lib/functions/format-usd.function.js +0 -7
- package/dist/esm/lib/functions/from-boolean-string.function.d.ts +0 -1
- package/dist/esm/lib/functions/from-boolean-string.function.js +0 -6
- package/dist/esm/lib/functions/from-calendar-date.function.d.ts +0 -1
- package/dist/esm/lib/functions/from-calendar-date.function.js +0 -7
- package/dist/esm/lib/functions/from-csv-string.function.d.ts +0 -1
- package/dist/esm/lib/functions/from-csv-string.function.js +0 -6
- package/dist/esm/lib/functions/get-date-range-for-month.function.d.ts +0 -4
- package/dist/esm/lib/functions/get-date-range-for-month.function.js +0 -9
- package/dist/esm/lib/functions/get-tag.function.d.ts +0 -1
- package/dist/esm/lib/functions/get-tag.function.js +0 -11
- package/dist/esm/lib/functions/is-symbol.function.d.ts +0 -1
- package/dist/esm/lib/functions/is-symbol.function.js +0 -10
- package/dist/esm/lib/functions/is-valid-date.function.d.ts +0 -1
- package/dist/esm/lib/functions/is-valid-date.function.js +0 -7
- package/dist/esm/lib/functions/kebab-case.function.d.ts +0 -1
- package/dist/esm/lib/functions/kebab-case.function.js +0 -7
- package/dist/esm/lib/functions/map-enum-to-array-of-values.function.d.ts +0 -1
- package/dist/esm/lib/functions/map-enum-to-array-of-values.function.js +0 -6
- package/dist/esm/lib/functions/map-enum-to-lookup-array.function.d.ts +0 -2
- package/dist/esm/lib/functions/map-enum-to-lookup-array.function.js +0 -7
- package/dist/esm/lib/functions/map-enum-to-options.function.d.ts +0 -4
- package/dist/esm/lib/functions/map-enum-to-options.function.js +0 -9
- package/dist/esm/lib/functions/money.function.d.ts +0 -1
- package/dist/esm/lib/functions/money.function.js +0 -19
- package/dist/esm/lib/functions/parse-bool.function.d.ts +0 -1
- package/dist/esm/lib/functions/parse-bool.function.js +0 -6
- package/dist/esm/lib/functions/properties-to-array.function.d.ts +0 -1
- package/dist/esm/lib/functions/properties-to-array.function.js +0 -18
- package/dist/esm/lib/functions/remove-alpha-chars.function.d.ts +0 -1
- package/dist/esm/lib/functions/remove-alpha-chars.function.js +0 -10
- package/dist/esm/lib/functions/remove-element-at-index.function.d.ts +0 -1
- package/dist/esm/lib/functions/remove-element-at-index.function.js +0 -12
- package/dist/esm/lib/functions/round.function.d.ts +0 -1
- package/dist/esm/lib/functions/round.function.js +0 -7
- package/dist/esm/lib/functions/sanitize-filename.function.d.ts +0 -1
- package/dist/esm/lib/functions/sanitize-filename.function.js +0 -10
- package/dist/esm/lib/functions/sleep.function.d.ts +0 -1
- package/dist/esm/lib/functions/sleep.function.js +0 -6
- package/dist/esm/lib/functions/snake-case.function.d.ts +0 -24
- package/dist/esm/lib/functions/subtract-offset.function.d.ts +0 -1
- package/dist/esm/lib/functions/subtract-offset.function.js +0 -13
- package/dist/esm/lib/functions/to-boolean-string.function.d.ts +0 -1
- package/dist/esm/lib/functions/to-boolean-string.function.js +0 -6
- package/dist/esm/lib/functions/to-calendar-date.function.d.ts +0 -1
- package/dist/esm/lib/functions/to-calendar-date.function.js +0 -11
- package/dist/esm/lib/functions/to-csv-string.function.d.ts +0 -1
- package/dist/esm/lib/functions/to-csv-string.function.js +0 -6
- package/dist/esm/lib/functions/to-decimal-base.function.d.ts +0 -1
- package/dist/esm/lib/functions/to-decimal-base.function.js +0 -21
- package/dist/esm/lib/functions/to-dollars-and-cents.function.d.ts +0 -1
- package/dist/esm/lib/functions/to-dollars-and-cents.function.js +0 -16
- package/dist/esm/lib/functions/to-string.function.d.ts +0 -1
- package/dist/esm/lib/functions/to-string.function.js +0 -25
- package/dist/esm/lib/functions/to-unique-array.function.d.ts +0 -1
- package/dist/esm/lib/functions/to-unique-array.function.js +0 -6
- package/dist/esm/lib/functions/to-words.function.d.ts +0 -1
- package/dist/esm/lib/functions/to-words.function.js +0 -91
- package/dist/esm/lib/functions/try-json-parse.d.ts +0 -1
- package/dist/esm/lib/functions/try-json-parse.js +0 -14
- package/dist/esm/lib/functions/try-json-stringify.d.ts +0 -1
- package/dist/esm/lib/functions/try-json-stringify.js +0 -14
- package/dist/esm/lib/functions/try-parse-date.function.d.ts +0 -1
- package/dist/esm/lib/functions/try-parse-date.function.js +0 -16
- package/dist/esm/lib/functions/unicode-words.const.d.ts +0 -8
- package/dist/esm/lib/functions/unicode-words.const.js +0 -68
- package/dist/esm/lib/functions/upper-first.function.d.ts +0 -1
- package/dist/esm/lib/functions/upper-first.function.js +0 -12
- package/dist/esm/lib/functions/words.function.d.ts +0 -17
- package/dist/esm/lib/functions/words.function.js +0 -34
- package/dist/esm/lib/interfaces/axios-wrapped-nest-exception.interface.js +0 -2
- package/dist/esm/lib/interfaces/entity-provider.interface.d.ts +0 -9
- package/dist/esm/lib/interfaces/entity-provider.interface.js +0 -2
- package/dist/esm/lib/interfaces/keys-of.type.d.ts +0 -3
- package/dist/esm/lib/interfaces/keys-of.type.js +0 -2
- package/dist/esm/lib/interfaces/lookup.interface.d.ts +0 -4
- package/dist/esm/lib/interfaces/lookup.interface.js +0 -2
- package/dist/types/index.d.ts +0 -43
- package/dist/types/lib/constants/decimal-regex.constant.d.ts +0 -1
- package/dist/types/lib/constants/millis-per-day.constant.d.ts +0 -1
- package/dist/types/lib/constants/millis-per-hour.constant.d.ts +0 -1
- package/dist/types/lib/constants/millis-per-minute.constant.d.ts +0 -1
- package/dist/types/lib/functions/add-offset.function.d.ts +0 -1
- package/dist/types/lib/functions/camel-case.function.d.ts +0 -20
- package/dist/types/lib/functions/convert-object-to-literal.function.d.ts +0 -1
- package/dist/types/lib/functions/format-usd.function.d.ts +0 -1
- package/dist/types/lib/functions/from-boolean-string.function.d.ts +0 -1
- package/dist/types/lib/functions/from-calendar-date.function.d.ts +0 -1
- package/dist/types/lib/functions/from-csv-string.function.d.ts +0 -1
- package/dist/types/lib/functions/get-date-range-for-month.function.d.ts +0 -4
- package/dist/types/lib/functions/get-tag.function.d.ts +0 -1
- package/dist/types/lib/functions/is-symbol.function.d.ts +0 -1
- package/dist/types/lib/functions/is-valid-date.function.d.ts +0 -1
- package/dist/types/lib/functions/kebab-case.function.d.ts +0 -1
- package/dist/types/lib/functions/map-enum-to-array-of-values.function.d.ts +0 -1
- package/dist/types/lib/functions/map-enum-to-lookup-array.function.d.ts +0 -2
- package/dist/types/lib/functions/map-enum-to-options.function.d.ts +0 -4
- package/dist/types/lib/functions/money.function.d.ts +0 -1
- package/dist/types/lib/functions/parse-bool.function.d.ts +0 -1
- package/dist/types/lib/functions/properties-to-array.function.d.ts +0 -1
- package/dist/types/lib/functions/remove-alpha-chars.function.d.ts +0 -1
- package/dist/types/lib/functions/remove-element-at-index.function.d.ts +0 -1
- package/dist/types/lib/functions/round.function.d.ts +0 -1
- package/dist/types/lib/functions/sanitize-filename.function.d.ts +0 -1
- package/dist/types/lib/functions/sleep.function.d.ts +0 -1
- package/dist/types/lib/functions/snake-case.function.d.ts +0 -24
- package/dist/types/lib/functions/subtract-offset.function.d.ts +0 -1
- package/dist/types/lib/functions/to-boolean-string.function.d.ts +0 -1
- package/dist/types/lib/functions/to-calendar-date.function.d.ts +0 -1
- package/dist/types/lib/functions/to-csv-string.function.d.ts +0 -1
- package/dist/types/lib/functions/to-decimal-base.function.d.ts +0 -1
- package/dist/types/lib/functions/to-dollars-and-cents.function.d.ts +0 -1
- package/dist/types/lib/functions/to-string.function.d.ts +0 -1
- package/dist/types/lib/functions/to-unique-array.function.d.ts +0 -1
- package/dist/types/lib/functions/to-words.function.d.ts +0 -1
- package/dist/types/lib/functions/try-json-parse.d.ts +0 -1
- package/dist/types/lib/functions/try-json-stringify.d.ts +0 -1
- package/dist/types/lib/functions/try-parse-date.function.d.ts +0 -1
- package/dist/types/lib/functions/unicode-words.const.d.ts +0 -8
- package/dist/types/lib/functions/upper-first.function.d.ts +0 -1
- package/dist/types/lib/functions/words.function.d.ts +0 -17
- package/dist/types/lib/interfaces/axios-wrapped-nest-exception.interface.d.ts +0 -5
- package/dist/types/lib/interfaces/entity-provider.interface.d.ts +0 -9
- package/dist/types/lib/interfaces/keys-of.type.d.ts +0 -3
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ILookup } from "../types/lookup.interface";
|
|
2
|
+
|
|
3
|
+
export function mapEnumToLookupArray<TEnum extends object>(enumeration: TEnum): ILookup<string, string>[] {
|
|
4
|
+
return Object.entries(enumeration)
|
|
5
|
+
.map(([key, value]) => ({ value, display: key.replace(/_/g, ' ') }) satisfies ILookup<string, string>);
|
|
6
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function mapEnumToOptions<TEntity extends object>(enumeration: TEntity, includeBlank = true) {
|
|
2
|
+
const enumArray = Object.entries(enumeration).map(([key, value]) => ({ value, display: key.replace(/_/g, ' ') }))
|
|
3
|
+
|
|
4
|
+
return includeBlank
|
|
5
|
+
? [{ display: '', value: '' }, ...enumArray]
|
|
6
|
+
: enumArray;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function mapEnumToOptions<TEntity extends object>(enumeration: TEntity, includeBlank = true) {
|
|
2
|
+
const enumArray = Object.entries(enumeration).map(([key, value]) => ({ value, display: key.replace(/_/g, ' ') }))
|
|
3
|
+
|
|
4
|
+
return includeBlank
|
|
5
|
+
? [{ display: '', value: '' }, ...enumArray]
|
|
6
|
+
: enumArray;
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { money } from './money.function';
|
|
2
|
+
|
|
3
|
+
describe('money', () => {
|
|
4
|
+
it('worx', () => {
|
|
5
|
+
expect(money('1234.567')).toMatchSnapshot();
|
|
6
|
+
expect(money(987.65)).toMatchSnapshot();
|
|
7
|
+
expect(money('$337.65')).toMatchSnapshot();
|
|
8
|
+
expect(money('$1,234.56')).toMatchSnapshot();
|
|
9
|
+
})
|
|
10
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { removeAlphaChars } from "./remove-alpha-chars.function";
|
|
2
|
+
|
|
3
|
+
export function money(rawValue: number | string) {
|
|
4
|
+
if(!rawValue) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const scrubbed = removeAlphaChars(rawValue);
|
|
9
|
+
|
|
10
|
+
const amount = Number(scrubbed);
|
|
11
|
+
|
|
12
|
+
if(!amount && amount !== 0) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
17
|
+
style: 'currency',
|
|
18
|
+
currency: 'USD'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return formatter.format(Number(amount));
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// credit https://stackoverflow.com/questions/15690706/recursively-looping-through-an-object-to-build-a-property-list/53620876#53620876
|
|
2
|
+
|
|
3
|
+
export function propertiesToArray(obj: Record<string, any>) {
|
|
4
|
+
const isObject = (val: any) =>
|
|
5
|
+
val && typeof val === 'object' && !Array.isArray(val);
|
|
6
|
+
|
|
7
|
+
const addDelimiter = (a: any, b: any) =>
|
|
8
|
+
a ? `${a}.${b}` : b;
|
|
9
|
+
|
|
10
|
+
const paths: any = (obj = {}, head = '') => {
|
|
11
|
+
return Object.entries(obj)
|
|
12
|
+
.reduce((product, [key, value]) => {
|
|
13
|
+
let fullPath = addDelimiter(head, key)
|
|
14
|
+
return isObject(value) ?
|
|
15
|
+
product.concat(paths(value, fullPath))
|
|
16
|
+
: product.concat(fullPath)
|
|
17
|
+
}, []);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return paths(obj);
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { removeAlphaChars } from './remove-alpha-chars.function';
|
|
2
|
+
|
|
3
|
+
describe('removeAlphaChars', () => {
|
|
4
|
+
it('worx', () => {
|
|
5
|
+
expect(removeAlphaChars('1234.567')).toMatchSnapshot();
|
|
6
|
+
expect(removeAlphaChars(987.65)).toMatchSnapshot();
|
|
7
|
+
expect(removeAlphaChars('$337.65')).toMatchSnapshot();
|
|
8
|
+
expect(removeAlphaChars('$1,234.56')).toMatchSnapshot();
|
|
9
|
+
expect(removeAlphaChars('dollarzzz$1,234.5six')).toMatchSnapshot();
|
|
10
|
+
})
|
|
11
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* eslint-disable no-control-regex */
|
|
2
|
+
|
|
3
|
+
const _ = '_';
|
|
4
|
+
const asciiReplacementRegX = /\/|\?|:|\\|{|\^|'|\}|%|`|]|>|\[|~|<|#|\||"|!|\*/g;
|
|
5
|
+
const unicodeReplacementRegX = /[^\u0000-\u007F]/g;
|
|
6
|
+
|
|
7
|
+
export function sanitizeFilename(filename: string) {
|
|
8
|
+
return filename.replace(unicodeReplacementRegX, _).replace(asciiReplacementRegX, _).replace(/_+/g, _).trim();
|
|
9
|
+
}
|
package/{dist/esm/lib/functions/snake-case.function.js → src/lib/functions/snake-case.function.ts}
RENAMED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// source https://github.com/lodash/lodash/blob/master/snakeCase.js
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
|
|
3
|
+
import { words } from "./words.function";
|
|
4
|
+
|
|
6
5
|
/**
|
|
7
6
|
* Converts `string` to
|
|
8
7
|
* [snake case](https://en.wikipedia.org/wiki/Snake_case).
|
|
@@ -26,6 +25,10 @@ const words_function_1 = require("./words.function");
|
|
|
26
25
|
* snakeCase('foo2bar')
|
|
27
26
|
* // => 'foo_2_bar'
|
|
28
27
|
*/
|
|
29
|
-
function snakeCase(string) {
|
|
30
|
-
|
|
28
|
+
export function snakeCase(string: string) {
|
|
29
|
+
return (
|
|
30
|
+
(words(string.replace(/['\u2019]/g, '')) as string[]).reduce((result: string, word: string, index: number) => (
|
|
31
|
+
result + (index ? '_' : '') + word.toLowerCase()
|
|
32
|
+
), '')
|
|
33
|
+
);
|
|
31
34
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TNameable } from "../types/nameable.type";
|
|
2
|
+
import { getUserFullName } from "./get-user-full-name.function";
|
|
3
|
+
|
|
4
|
+
export function sortByFullName<TEntity extends TNameable>(a: TEntity, b: TEntity) {
|
|
5
|
+
return getUserFullName(a).localeCompare(getUserFullName(b)) || 0;
|
|
6
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { splitDateRangeIntoDays } from './split-date-range-into-days.function';
|
|
2
|
+
import { arrangeActAssert } from '../functions/arrange-act-assert.function';
|
|
3
|
+
describe('splitDateRangeIntoDays', () => {
|
|
4
|
+
it.each([
|
|
5
|
+
[{ from: '', to: '' }],
|
|
6
|
+
[{ from: 'asdf', to: '2345' }],
|
|
7
|
+
[{ from: '2024-01-01', to: '2024-01-01' }],
|
|
8
|
+
[{ from: '2024-01-01', to: '2024-02-01' }],
|
|
9
|
+
[{ from: '2025-01-01', to: '' }],
|
|
10
|
+
])('given %j, returns an array of days', async (_) => await arrangeActAssert({
|
|
11
|
+
arrange: () => ({ subject: splitDateRangeIntoDays }),
|
|
12
|
+
act: ({ subject }) => subject(_),
|
|
13
|
+
assert: ({ result }) => {
|
|
14
|
+
expect(result).toMatchSnapshot();
|
|
15
|
+
}
|
|
16
|
+
}));
|
|
17
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MILLIS_PER_DAY } from "../constants/millis-per-day.constant";
|
|
2
|
+
|
|
3
|
+
const iso8601Regex = /\d{4}-\d{2}-\d{2}/;
|
|
4
|
+
|
|
5
|
+
export function splitDateRangeIntoDays(_: { from: string, to: string }): string[] {
|
|
6
|
+
const { from = '', to = '' } = _;
|
|
7
|
+
const days: Date[] = [];
|
|
8
|
+
|
|
9
|
+
if (!from || !to || !iso8601Regex.test(from) || !iso8601Regex.test(to)) {
|
|
10
|
+
return days as any[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const _from = new Date(from);
|
|
14
|
+
const _to = new Date(to);
|
|
15
|
+
|
|
16
|
+
let current = _from;
|
|
17
|
+
|
|
18
|
+
while (current < _to) {
|
|
19
|
+
days.push(current);
|
|
20
|
+
current = new Date(+current + MILLIS_PER_DAY);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
days.push(_to);
|
|
24
|
+
|
|
25
|
+
return days.map(day => day.toISOString().split('T')[0]);
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { subtractOffset } from './subtract-offset.function';
|
|
2
|
+
|
|
3
|
+
describe('subtractOffset', () => {
|
|
4
|
+
describe('GIVEN input is partial or full ISO8601', () => {
|
|
5
|
+
it.each([
|
|
6
|
+
'2023-12-23',
|
|
7
|
+
'2023-12-23T00:00:00.000',
|
|
8
|
+
])('%j', (input) => {
|
|
9
|
+
expect(subtractOffset(input)).toMatchSnapshot();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MILLIS_PER_MINUTE } from '../constants/millis-per-minute.constant';
|
|
2
|
+
import { tryParseDate } from './try-parse-date.function';
|
|
3
|
+
|
|
4
|
+
export function subtractOffset(input: string | Date | undefined | null): Date | undefined {
|
|
5
|
+
const parsed = tryParseDate(input);
|
|
6
|
+
|
|
7
|
+
if(!parsed) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const offset = (parsed).getTimezoneOffset();
|
|
12
|
+
|
|
13
|
+
return new Date(parsed.valueOf() - offset * MILLIS_PER_MINUTE);
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { subtractOffset } from "./subtract-offset.function";
|
|
2
|
+
|
|
3
|
+
export function toCalendarDate(input: string | Date | undefined | null): string | undefined {
|
|
4
|
+
const parsed = subtractOffset(input);
|
|
5
|
+
|
|
6
|
+
if (!parsed) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return parsed?.toISOString().split('T')[0];
|
|
11
|
+
}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toDecimalBase = toDecimalBase;
|
|
4
|
-
function toDecimalBase(n, base = 16) {
|
|
1
|
+
export function toDecimalBase(n: string | number, base = 16) {
|
|
5
2
|
const digits = n.toString().split('');
|
|
3
|
+
|
|
6
4
|
let answer = 0;
|
|
5
|
+
|
|
7
6
|
digits.reverse().forEach(function (d, i) {
|
|
8
7
|
let actualNumber = Number(d);
|
|
8
|
+
|
|
9
9
|
if (!actualNumber && actualNumber !== 0) {
|
|
10
10
|
const codeAt = d.charCodeAt(0);
|
|
11
|
+
|
|
11
12
|
if (codeAt >= 97) {
|
|
12
13
|
actualNumber = codeAt - 87;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
14
|
+
} else {
|
|
15
15
|
actualNumber = codeAt - 55;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
|
|
18
19
|
answer = answer + actualNumber * Math.pow(base, i);
|
|
19
20
|
});
|
|
21
|
+
|
|
20
22
|
return answer;
|
|
21
|
-
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { removeAlphaChars } from "./remove-alpha-chars.function";
|
|
2
|
+
import { toWords } from "./to-words.function";
|
|
3
|
+
|
|
4
|
+
export function toDollarsAndCents(input: string | number): string {
|
|
5
|
+
const number = removeAlphaChars(input);
|
|
6
|
+
const num = Number(number);
|
|
7
|
+
const decimal = (Math.round((num % 1) * 100)) / 100;
|
|
8
|
+
const int = num - decimal;
|
|
9
|
+
|
|
10
|
+
const dollars = `${toWords(int)} dollars`;
|
|
11
|
+
|
|
12
|
+
if (!decimal) {
|
|
13
|
+
return dollars;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return `${dollars} and ${toWords(decimal * 100)} cents`;
|
|
17
|
+
}
|
package/{dist/cjs/lib/functions/to-string.function.js → src/lib/functions/to-string.function.ts}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// https://github.com/lodash/lodash/blob/main/src/toString.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
|
|
3
|
+
import { isSymbol } from './is-symbol.function';
|
|
4
|
+
|
|
6
5
|
/** Used as references for various `Number` constants. */
|
|
7
6
|
const INFINITY = 1 / 0;
|
|
8
|
-
|
|
7
|
+
|
|
8
|
+
export function toString(value: any): string {
|
|
9
9
|
if (value == null) {
|
|
10
10
|
return '';
|
|
11
11
|
}
|
|
@@ -17,7 +17,7 @@ function toString(value) {
|
|
|
17
17
|
// Recursively convert values (susceptible to call stack limits).
|
|
18
18
|
return `${value.map((other) => (other == null ? other : toString(other)))}`;
|
|
19
19
|
}
|
|
20
|
-
if (
|
|
20
|
+
if (isSymbol(value)) {
|
|
21
21
|
return value.toString();
|
|
22
22
|
}
|
|
23
23
|
const result = `${value}`;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { toUniqueArray } from './to-unique-array.function';
|
|
2
|
+
|
|
3
|
+
describe('toUniqueArray', () => {
|
|
4
|
+
it.each([
|
|
5
|
+
[
|
|
6
|
+
[1, 2, 3],
|
|
7
|
+
[1, 2, 3],
|
|
8
|
+
],
|
|
9
|
+
[[1, 1, 1], [1]],
|
|
10
|
+
])(
|
|
11
|
+
'GIVEN array of numbers: %j, returns a unique array without duplicate elements',
|
|
12
|
+
(array, expected) => {
|
|
13
|
+
expect(toUniqueArray(array)).toEqual(expected);
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
it.each([
|
|
18
|
+
[
|
|
19
|
+
['one', 'two', 'three'],
|
|
20
|
+
['one', 'two', 'three'],
|
|
21
|
+
],
|
|
22
|
+
[['one', 'one', 'one'], ['one']],
|
|
23
|
+
])(
|
|
24
|
+
'GIVEN array of strings: %j, returns a unique array without duplicate elements',
|
|
25
|
+
(array, expected) => {
|
|
26
|
+
expect(toUniqueArray(array)).toEqual(expected);
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
it.each([
|
|
31
|
+
[
|
|
32
|
+
['one', 'two', 'three', undefined, undefined],
|
|
33
|
+
['one', 'two', 'three', undefined],
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
['one', 'one', 'one', null, null],
|
|
37
|
+
['one', null],
|
|
38
|
+
],
|
|
39
|
+
])(
|
|
40
|
+
'GIVEN array with falsey values: %j, returns a unique array without duplicate elements including falsey values',
|
|
41
|
+
(array, expected) => {
|
|
42
|
+
expect(toUniqueArray(array)).toEqual(expected);
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
});
|
package/{dist/cjs/lib/functions/to-words.function.js → src/lib/functions/to-words.function.ts}
RENAMED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toWords = toWords;
|
|
4
|
-
const remove_alpha_chars_function_1 = require("./remove-alpha-chars.function");
|
|
1
|
+
import { removeAlphaChars } from "./remove-alpha-chars.function";
|
|
2
|
+
|
|
5
3
|
const MAX_SAFE_INTEGER = 9007199254740991;
|
|
4
|
+
|
|
6
5
|
const TEN = 10;
|
|
7
6
|
const ONE_HUNDRED = 100;
|
|
8
7
|
const ONE_THOUSAND = 1000;
|
|
@@ -18,74 +17,92 @@ const LESS_THAN_TWENTY = [
|
|
|
18
17
|
const TENTHS_LESS_THAN_HUNDRED = [
|
|
19
18
|
'zero', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'
|
|
20
19
|
];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
|
|
21
|
+
export function toWords(input: number | string): string {
|
|
22
|
+
let words: string;
|
|
23
|
+
const number = removeAlphaChars(input) || '0';
|
|
24
24
|
const num = parseInt(number, 10);
|
|
25
|
+
|
|
25
26
|
if (!isFinite(num)) {
|
|
26
|
-
throw new TypeError(
|
|
27
|
+
throw new TypeError(
|
|
28
|
+
'Not a finite number: ' + number + ' (' + typeof number + ')'
|
|
29
|
+
);
|
|
27
30
|
}
|
|
31
|
+
|
|
28
32
|
if (!isSafeNumber(num)) {
|
|
29
|
-
throw new RangeError(
|
|
33
|
+
throw new RangeError(
|
|
34
|
+
'Input is not a safe number, it\'s either too large or too small.'
|
|
35
|
+
);
|
|
30
36
|
}
|
|
37
|
+
|
|
31
38
|
words = generateWords(num);
|
|
39
|
+
|
|
32
40
|
return words;
|
|
33
41
|
}
|
|
34
|
-
|
|
42
|
+
|
|
43
|
+
function generateWords(number: any, words?: any[]): string {
|
|
35
44
|
let remainder, word;
|
|
45
|
+
|
|
36
46
|
if (number === 0) {
|
|
37
47
|
return !words ? 'zero' : words.join(' ').replace(/,$/, '');
|
|
38
48
|
}
|
|
49
|
+
|
|
39
50
|
if (!words) {
|
|
40
51
|
words = [];
|
|
41
52
|
}
|
|
53
|
+
|
|
42
54
|
if (number < 0) {
|
|
43
55
|
words.push('minus');
|
|
44
56
|
number = Math.abs(number);
|
|
45
57
|
}
|
|
58
|
+
|
|
46
59
|
if (number < 20) {
|
|
47
60
|
remainder = 0;
|
|
48
61
|
word = LESS_THAN_TWENTY[number];
|
|
49
|
-
|
|
50
|
-
else if (number < ONE_HUNDRED) {
|
|
62
|
+
|
|
63
|
+
} else if (number < ONE_HUNDRED) {
|
|
51
64
|
remainder = number % TEN;
|
|
52
65
|
word = TENTHS_LESS_THAN_HUNDRED[Math.floor(number / TEN)];
|
|
66
|
+
|
|
53
67
|
if (remainder) {
|
|
54
68
|
word += '-' + LESS_THAN_TWENTY[remainder];
|
|
55
69
|
remainder = 0;
|
|
56
70
|
}
|
|
57
|
-
|
|
58
|
-
else if (number < ONE_THOUSAND) {
|
|
71
|
+
|
|
72
|
+
} else if (number < ONE_THOUSAND) {
|
|
59
73
|
remainder = number % ONE_HUNDRED;
|
|
60
74
|
word = generateWords(Math.floor(number / ONE_HUNDRED)) + ' hundred';
|
|
61
|
-
|
|
62
|
-
else if (number < ONE_MILLION) {
|
|
75
|
+
|
|
76
|
+
} else if (number < ONE_MILLION) {
|
|
63
77
|
remainder = number % ONE_THOUSAND;
|
|
64
78
|
word = generateWords(Math.floor(number / ONE_THOUSAND)) + ' thousand,';
|
|
65
|
-
|
|
66
|
-
else if (number < ONE_BILLION) {
|
|
79
|
+
|
|
80
|
+
} else if (number < ONE_BILLION) {
|
|
67
81
|
remainder = number % ONE_MILLION;
|
|
68
82
|
word = generateWords(Math.floor(number / ONE_MILLION)) + ' million,';
|
|
69
|
-
|
|
70
|
-
else if (number < ONE_TRILLION) {
|
|
83
|
+
|
|
84
|
+
} else if (number < ONE_TRILLION) {
|
|
71
85
|
remainder = number % ONE_BILLION;
|
|
72
86
|
word = generateWords(Math.floor(number / ONE_BILLION)) + ' billion,';
|
|
73
|
-
|
|
74
|
-
else if (number < ONE_QUADRILLION) {
|
|
87
|
+
|
|
88
|
+
} else if (number < ONE_QUADRILLION) {
|
|
75
89
|
remainder = number % ONE_TRILLION;
|
|
76
90
|
word = generateWords(Math.floor(number / ONE_TRILLION)) + ' trillion,';
|
|
77
|
-
|
|
78
|
-
else if (number <= MAX) {
|
|
91
|
+
|
|
92
|
+
} else if (number <= MAX) {
|
|
79
93
|
remainder = number % ONE_QUADRILLION;
|
|
80
94
|
word = generateWords(Math.floor(number / ONE_QUADRILLION)) +
|
|
81
95
|
' quadrillion,';
|
|
82
96
|
}
|
|
97
|
+
|
|
83
98
|
words.push(word);
|
|
84
99
|
return generateWords(remainder, words);
|
|
85
100
|
}
|
|
86
|
-
|
|
101
|
+
|
|
102
|
+
function isFinite(value: any) {
|
|
87
103
|
return !(typeof value !== 'number' || value !== value || value === Infinity || value === -Infinity);
|
|
88
104
|
}
|
|
89
|
-
|
|
105
|
+
|
|
106
|
+
function isSafeNumber(value: any) {
|
|
90
107
|
return typeof value === 'number' && Math.abs(value) <= MAX_SAFE_INTEGER;
|
|
91
108
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { tryJsonParse } from './try-json-parse';
|
|
2
|
+
|
|
3
|
+
describe('tryJsonParse', () => {
|
|
4
|
+
describe('GIVEN input is parseable', () => {
|
|
5
|
+
describe.each([
|
|
6
|
+
[0, 0],
|
|
7
|
+
['0', 0],
|
|
8
|
+
[337, expect.any(Number)],
|
|
9
|
+
[`${337}`, expect.any(Number)],
|
|
10
|
+
[false, false],
|
|
11
|
+
['false', false],
|
|
12
|
+
[true, true],
|
|
13
|
+
['true', true],
|
|
14
|
+
[`{ "test": ${337} }`, expect.objectContaining({ test: expect.any(Number) })],
|
|
15
|
+
[`{ "test": "${337}" }`, expect.objectContaining({ test: expect.stringMatching(/\d/) })],
|
|
16
|
+
])('WHEN input is: %j', (input, expectedOutput) => {
|
|
17
|
+
it(`returns ${expectedOutput}`, () => {
|
|
18
|
+
expect(tryJsonParse(input as any)).toEqual(expectedOutput);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('GIVEN input is not parseable', () => {
|
|
24
|
+
describe.each([
|
|
25
|
+
['', null],
|
|
26
|
+
[null, null],
|
|
27
|
+
[undefined, null],
|
|
28
|
+
[NaN, null],
|
|
29
|
+
['randomness', null],
|
|
30
|
+
['totally random', null],
|
|
31
|
+
])('WHEN input is: %j', (input, expectedOutput) => {
|
|
32
|
+
it(`returns ${expectedOutput}`, () => {
|
|
33
|
+
expect(tryJsonParse(input as any)).toEqual(expectedOutput);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|