@onivoro/isomorphic-common 22.0.7 → 24.0.1
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 +289 -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} +41 -4
- 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 +9 -0
- package/tsconfig.spec.json +14 -0
- package/dist/cjs/index.js +0 -59
- 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/constants/regexes.constant.d.ts +0 -27
- package/dist/cjs/lib/constants/regexes.constant.js +0 -30
- 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/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/constants/regexes.constant.d.ts +0 -27
- package/dist/esm/lib/constants/regexes.constant.js +0 -30
- 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/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/constants/regexes.constant.d.ts +0 -27
- 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
package/README.md
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# @onivoro/isomorphic-common
|
|
2
|
+
|
|
3
|
+
Common utilities, functions, types, and constants shared between browser and server environments in the Onivoro monorepo. This library provides essential building blocks for TypeScript applications with a focus on type safety and consistent behavior across different runtime environments.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @onivoro/isomorphic-common
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Isomorphic Design**: Works identically in browser and Node.js environments
|
|
14
|
+
- **String Manipulation**: Case conversion, formatting, and validation utilities
|
|
15
|
+
- **Array Operations**: Chunking, sorting, deduplication, and transformation functions
|
|
16
|
+
- **Date/Time Utilities**: Calendar operations, offset calculations, and time constants
|
|
17
|
+
- **Financial Functions**: Currency formatting and money calculations
|
|
18
|
+
- **Type Utilities**: TypeScript type helpers and interfaces
|
|
19
|
+
- **Validation Functions**: Data validation and parsing utilities
|
|
20
|
+
- **Testing Helpers**: Mock functions and test arrangement utilities
|
|
21
|
+
- **Constants**: Authentication headers, regex patterns, and time constants
|
|
22
|
+
|
|
23
|
+
## Constants
|
|
24
|
+
|
|
25
|
+
### Authentication Headers
|
|
26
|
+
```typescript
|
|
27
|
+
import { apiKeyHeader } from '@onivoro/isomorphic-common';
|
|
28
|
+
|
|
29
|
+
// Use in HTTP requests
|
|
30
|
+
const headers = {
|
|
31
|
+
[apiKeyHeader]: 'your-api-key' // 'x-api-key'
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Time Constants
|
|
36
|
+
```typescript
|
|
37
|
+
import { MILLIS_PER_DAY, MILLIS_PER_HOUR, MILLIS_PER_MINUTE } from '@onivoro/isomorphic-common';
|
|
38
|
+
|
|
39
|
+
// Time constants (calculated from MILLIS_PER_MINUTE base)
|
|
40
|
+
const hoursInDay = MILLIS_PER_DAY / MILLIS_PER_HOUR; // 24
|
|
41
|
+
const minutesInHour = MILLIS_PER_HOUR / MILLIS_PER_MINUTE; // 60
|
|
42
|
+
|
|
43
|
+
// Set timeouts
|
|
44
|
+
setTimeout(() => {}, MILLIS_PER_MINUTE); // 1 minute timeout
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Regular Expressions
|
|
48
|
+
```typescript
|
|
49
|
+
import {
|
|
50
|
+
email,
|
|
51
|
+
phone,
|
|
52
|
+
zip,
|
|
53
|
+
v4,
|
|
54
|
+
dateIso8601,
|
|
55
|
+
numeric,
|
|
56
|
+
ssn,
|
|
57
|
+
ein
|
|
58
|
+
} from '@onivoro/isomorphic-common';
|
|
59
|
+
|
|
60
|
+
// Validate email
|
|
61
|
+
const isValidEmail = email.test('user@example.com'); // true
|
|
62
|
+
|
|
63
|
+
// Validate phone number (format: 123-456-7890)
|
|
64
|
+
const isValidPhone = phone.test('123-456-7890'); // true
|
|
65
|
+
|
|
66
|
+
// Validate ZIP code (5 digits)
|
|
67
|
+
const isValidZip = zip.test('12345'); // true
|
|
68
|
+
|
|
69
|
+
// Validate UUID v4
|
|
70
|
+
const isValidUuid = v4.test('550e8400-e29b-41d4-a716-446655440000'); // true
|
|
71
|
+
|
|
72
|
+
// Validate ISO date (YYYY-MM-DD)
|
|
73
|
+
const isValidDate = dateIso8601.test('2023-12-31'); // true
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## String Functions
|
|
77
|
+
|
|
78
|
+
### Case Conversion
|
|
79
|
+
```typescript
|
|
80
|
+
import { camelCase, kebabCase, snakeCase } from '@onivoro/isomorphic-common';
|
|
81
|
+
|
|
82
|
+
// camelCase(string: string): string
|
|
83
|
+
camelCase('hello world'); // 'helloWorld'
|
|
84
|
+
camelCase('--foo-bar--'); // 'fooBar'
|
|
85
|
+
camelCase('__FOO_BAR__'); // 'fooBar'
|
|
86
|
+
|
|
87
|
+
// kebabCase(string: string): string
|
|
88
|
+
kebabCase('Hello World'); // 'hello-world'
|
|
89
|
+
kebabCase('fooBar'); // 'foo-bar'
|
|
90
|
+
|
|
91
|
+
// snakeCase(string: string): string
|
|
92
|
+
snakeCase('Hello World'); // 'hello_world'
|
|
93
|
+
snakeCase('fooBar'); // 'foo_bar'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Array Functions
|
|
97
|
+
|
|
98
|
+
### Array Manipulation
|
|
99
|
+
```typescript
|
|
100
|
+
import {
|
|
101
|
+
chunk,
|
|
102
|
+
removeElementAtIndex,
|
|
103
|
+
toUniqueArray
|
|
104
|
+
} from '@onivoro/isomorphic-common';
|
|
105
|
+
|
|
106
|
+
// chunk<T>(array: T[], numDivisions: number): T[][]
|
|
107
|
+
// Divides array into N divisions (NOT chunks of size N)
|
|
108
|
+
chunk([1, 2, 3, 4, 5, 6], 3); // [[1, 2], [3, 4], [5, 6]] - 3 divisions
|
|
109
|
+
chunk([1, 2, 3, 4, 5], 2); // [[1, 2, 3], [4, 5]] - 2 divisions
|
|
110
|
+
|
|
111
|
+
// removeElementAtIndex<T>(array: T[], indexToRemove: number): T[]
|
|
112
|
+
removeElementAtIndex(['a', 'b', 'c'], 1); // ['a', 'c']
|
|
113
|
+
|
|
114
|
+
// toUniqueArray<TElement>(elements: TElement[]): TElement[]
|
|
115
|
+
toUniqueArray([1, 2, 2, 3, 3, 4]); // [1, 2, 3, 4]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Sorting Functions
|
|
119
|
+
```typescript
|
|
120
|
+
import {
|
|
121
|
+
sortByName,
|
|
122
|
+
sortById,
|
|
123
|
+
sortNumbers
|
|
124
|
+
} from '@onivoro/isomorphic-common';
|
|
125
|
+
|
|
126
|
+
// sortByName<TEntity extends { name: string }>(a: TEntity, b: TEntity): number
|
|
127
|
+
const users = [{ name: 'Bob' }, { name: 'Alice' }];
|
|
128
|
+
users.sort(sortByName); // [{ name: 'Alice' }, { name: 'Bob' }]
|
|
129
|
+
|
|
130
|
+
// sortById<TEntity extends { id: string }>(a: TEntity, b: TEntity): number
|
|
131
|
+
const items = [{ id: '3' }, { id: '1' }, { id: '2' }];
|
|
132
|
+
items.sort(sortById); // [{ id: '1' }, { id: '2' }, { id: '3' }]
|
|
133
|
+
|
|
134
|
+
// sortNumbers(a: number, b: number): number
|
|
135
|
+
const numbers = [3, 1, 4, 1, 5];
|
|
136
|
+
numbers.sort(sortNumbers); // [1, 1, 3, 4, 5]
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Date/Time Functions
|
|
140
|
+
|
|
141
|
+
### Date Operations
|
|
142
|
+
```typescript
|
|
143
|
+
import {
|
|
144
|
+
addOffset,
|
|
145
|
+
subtractOffset,
|
|
146
|
+
getDateRangeForMonth
|
|
147
|
+
} from '@onivoro/isomorphic-common';
|
|
148
|
+
|
|
149
|
+
// addOffset(input: string | Date | undefined | null): Date | undefined
|
|
150
|
+
const date = new Date('2023-01-15');
|
|
151
|
+
const withOffset = addOffset(date); // Adds timezone offset
|
|
152
|
+
|
|
153
|
+
// subtractOffset(input: string | Date | undefined | null): Date | undefined
|
|
154
|
+
const withoutOffset = subtractOffset(date); // Subtracts timezone offset
|
|
155
|
+
|
|
156
|
+
// getDateRangeForMonth(year: number, month: number): {startDate: Date, endDate: Date}
|
|
157
|
+
const { startDate, endDate } = getDateRangeForMonth(2023, 0); // January 2023 (month 0-indexed)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Date Utilities
|
|
161
|
+
```typescript
|
|
162
|
+
import {
|
|
163
|
+
isValidDate,
|
|
164
|
+
parseBool
|
|
165
|
+
} from '@onivoro/isomorphic-common';
|
|
166
|
+
|
|
167
|
+
// isValidDate(dateString: string | Date): Date | undefined
|
|
168
|
+
const validDate = isValidDate('2023-01-15'); // Date object
|
|
169
|
+
const invalidDate = isValidDate('invalid'); // undefined
|
|
170
|
+
|
|
171
|
+
// parseBool(asc: string | boolean | null | undefined): boolean
|
|
172
|
+
parseBool('true'); // true
|
|
173
|
+
parseBool('false'); // false
|
|
174
|
+
parseBool(true); // true
|
|
175
|
+
parseBool(null); // false
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Financial Functions
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import {
|
|
182
|
+
formatUsd,
|
|
183
|
+
money,
|
|
184
|
+
toDollarsAndCents,
|
|
185
|
+
round
|
|
186
|
+
} from '@onivoro/isomorphic-common';
|
|
187
|
+
|
|
188
|
+
// formatUsd(rawAmount?: number | string): string
|
|
189
|
+
formatUsd(1234.56); // '$1,234.56'
|
|
190
|
+
formatUsd('1234.56'); // '$1,234.56'
|
|
191
|
+
formatUsd(); // '$0.00'
|
|
192
|
+
|
|
193
|
+
// money(rawValue: number | string): string | undefined
|
|
194
|
+
money(19.99); // '$19.99'
|
|
195
|
+
money('abc'); // undefined
|
|
196
|
+
|
|
197
|
+
// toDollarsAndCents(input: string | number): string
|
|
198
|
+
toDollarsAndCents(19.99); // 'nineteen dollars and ninety-nine cents'
|
|
199
|
+
toDollarsAndCents(20); // 'twenty dollars'
|
|
200
|
+
|
|
201
|
+
// round(numberToRound: number, scalingFactor: number): number
|
|
202
|
+
round(19.999, 100); // 20.00 (rounds to nearest cent)
|
|
203
|
+
round(19.994, 100); // 19.99
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Data Transformation
|
|
207
|
+
|
|
208
|
+
### Enum Utilities
|
|
209
|
+
```typescript
|
|
210
|
+
import {
|
|
211
|
+
mapEnumToOptions
|
|
212
|
+
} from '@onivoro/isomorphic-common';
|
|
213
|
+
|
|
214
|
+
enum Status {
|
|
215
|
+
ACTIVE = 'active',
|
|
216
|
+
INACTIVE = 'inactive',
|
|
217
|
+
PENDING = 'pending'
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// mapEnumToOptions<TEntity extends object>(enumeration: TEntity, includeBlank = true)
|
|
221
|
+
const options = mapEnumToOptions(Status);
|
|
222
|
+
// [{ display: '', value: '' }, { display: 'ACTIVE', value: 'active' }, ...]
|
|
223
|
+
|
|
224
|
+
const optionsNoBlank = mapEnumToOptions(Status, false);
|
|
225
|
+
// [{ display: 'ACTIVE', value: 'active' }, ...]
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Entity Utilities
|
|
229
|
+
```typescript
|
|
230
|
+
import { getUserFullName } from '@onivoro/isomorphic-common';
|
|
231
|
+
|
|
232
|
+
// getUserFullName(user: TNameable | undefined): string
|
|
233
|
+
const user = { firstName: 'John', lastName: 'Doe' };
|
|
234
|
+
getUserFullName(user); // 'John Doe'
|
|
235
|
+
getUserFullName(undefined); // 'undefined undefined'
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## JSON Utilities
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import {
|
|
242
|
+
tryJsonParse,
|
|
243
|
+
tryJsonStringify
|
|
244
|
+
} from '@onivoro/isomorphic-common';
|
|
245
|
+
|
|
246
|
+
// tryJsonParse<T>(parseable: string | null | undefined): T | null
|
|
247
|
+
const parsed = tryJsonParse<{name: string}>('{"name":"John"}'); // {name: 'John'}
|
|
248
|
+
const failed = tryJsonParse('invalid json'); // null
|
|
249
|
+
|
|
250
|
+
// tryJsonStringify<T>(object: T | null | undefined, fmtr?: any, spaces?: number): string | null
|
|
251
|
+
const json = tryJsonStringify({name: 'John'}); // '{"name":"John"}'
|
|
252
|
+
const formatted = tryJsonStringify({name: 'John'}, null, 2); // Pretty formatted JSON
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Utility Functions
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
import { sleep } from '@onivoro/isomorphic-common';
|
|
259
|
+
|
|
260
|
+
// sleep(milliseconds = 0): Promise<void>
|
|
261
|
+
await sleep(1000); // Wait 1 second
|
|
262
|
+
await sleep(); // Wait 0 milliseconds (next tick)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Type Definitions
|
|
266
|
+
|
|
267
|
+
### Interfaces
|
|
268
|
+
```typescript
|
|
269
|
+
import {
|
|
270
|
+
ILookup,
|
|
271
|
+
TNameable
|
|
272
|
+
} from '@onivoro/isomorphic-common';
|
|
273
|
+
|
|
274
|
+
// Lookup interface for key-value pairs
|
|
275
|
+
const lookup: ILookup<string, number> = {
|
|
276
|
+
display: 'Option 1',
|
|
277
|
+
value: 1
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// Nameable type
|
|
281
|
+
const user: TNameable = {
|
|
282
|
+
firstName: 'John',
|
|
283
|
+
lastName: 'Doe'
|
|
284
|
+
};
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## License
|
|
288
|
+
|
|
289
|
+
MIT
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
export default {
|
|
3
|
+
displayName: 'lib-isomorphic-common',
|
|
4
|
+
preset: '../../../jest.preset.js',
|
|
5
|
+
testEnvironment: 'node',
|
|
6
|
+
transform: {
|
|
7
|
+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
|
8
|
+
},
|
|
9
|
+
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
10
|
+
coverageDirectory: '../../../coverage/libs/isomorphic/common',
|
|
11
|
+
};
|
package/package.json
CHANGED
|
@@ -1,41 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"files": [
|
|
11
|
-
"dist/*"
|
|
12
|
-
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"onx": "onx",
|
|
15
|
-
"build": "onx Build",
|
|
16
|
-
"deploy": "onx Publish",
|
|
17
|
-
"test": "onx Test",
|
|
18
|
-
"update": "onx Update"
|
|
19
|
-
},
|
|
20
|
-
"exports": {
|
|
21
|
-
".": {
|
|
22
|
-
"types": "./dist/types/index.d.ts",
|
|
23
|
-
"require": "./dist/cjs/index.js",
|
|
24
|
-
"import": "./dist/esm/index.js",
|
|
25
|
-
"default": "./dist/esm/lib.js"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
"onx": {
|
|
29
|
-
"platform": "isomorphic",
|
|
30
|
-
"module": "commonjs"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@onivoro/cli": "^22.0.8",
|
|
34
|
-
"@types/jest": "*",
|
|
35
|
-
"typescript": "*"
|
|
36
|
-
},
|
|
37
|
-
"engines": {
|
|
38
|
-
"node": "22.10.0",
|
|
39
|
-
"npm": "10.9.0"
|
|
40
|
-
}
|
|
2
|
+
"name": "@onivoro/isomorphic-common",
|
|
3
|
+
"version": "24.0.1",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"tslib": "^2.3.0"
|
|
9
|
+
}
|
|
41
10
|
}
|
package/project.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lib-isomorphic-common",
|
|
3
|
+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "libs/isomorphic/common/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"targets": {
|
|
7
|
+
"build": {
|
|
8
|
+
"executor": "@nx/js:tsc",
|
|
9
|
+
"outputs": ["{options.outputPath}"],
|
|
10
|
+
"options": {
|
|
11
|
+
"outputPath": "dist/libs/isomorphic/common",
|
|
12
|
+
"main": "libs/isomorphic/common/src/index.ts",
|
|
13
|
+
"tsConfig": "libs/isomorphic/common/tsconfig.lib.json",
|
|
14
|
+
"assets": [
|
|
15
|
+
"libs/isomorphic/common/README.md",
|
|
16
|
+
"libs/isomorphic/common/package.json"
|
|
17
|
+
],
|
|
18
|
+
"declaration": true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"tags": []
|
|
23
|
+
}
|
|
@@ -1,7 +1,43 @@
|
|
|
1
|
+
export * from './lib/constants/api-id-header.constant';
|
|
2
|
+
export * from './lib/constants/api-key-header.constant';
|
|
3
|
+
export * from './lib/constants/auth-cookie-name.constant';
|
|
4
|
+
export * from './lib/constants/regexes.constant';
|
|
5
|
+
|
|
6
|
+
export * from './lib/functions/arrange-act-assert.function';
|
|
7
|
+
export * from './lib/functions/mock-calls.function';
|
|
8
|
+
|
|
9
|
+
export * from './lib/functions/chunk.function';
|
|
10
|
+
export * from './lib/functions/format-usd.function';
|
|
11
|
+
export * from './lib/functions/get-date-last-month.function';
|
|
12
|
+
export * from './lib/functions/get-date-range-for-month.function';
|
|
13
|
+
export * from './lib/functions/get-user-full-name.function';
|
|
14
|
+
export * from './lib/functions/is-valid-date.function';
|
|
15
|
+
export * from './lib/functions/map-entities-to-options.function';
|
|
16
|
+
export * from './lib/functions/map-enum-to-array-of-values.function';
|
|
17
|
+
export * from './lib/functions/map-enum-to-lookup-array.function';
|
|
18
|
+
export * from './lib/functions/map-enum-to-options.function';
|
|
19
|
+
export * from './lib/functions/remove-element-at-index.function';
|
|
20
|
+
export * from './lib/functions/round.function';
|
|
21
|
+
export * from './lib/functions/sort-by-created-at.function';
|
|
22
|
+
export * from './lib/functions/sort-by-full-name.function';
|
|
23
|
+
export * from './lib/functions/sort-by-id.function';
|
|
24
|
+
export * from './lib/functions/sort-by-name.function';
|
|
25
|
+
export * from './lib/functions/sort-numbers.function';
|
|
26
|
+
export * from './lib/functions/split-date-range-into-days.function';
|
|
27
|
+
export * from './lib/functions/use-date.function';
|
|
28
|
+
|
|
29
|
+
export * from './lib/types/access-token.interface';
|
|
30
|
+
export * from './lib/types/company.type';
|
|
31
|
+
export * from './lib/types/createable.type';
|
|
32
|
+
export * from './lib/types/keys-of.type';
|
|
33
|
+
export * from './lib/types/lookup.interface';
|
|
34
|
+
export * from './lib/types/nameable.type';
|
|
35
|
+
|
|
1
36
|
export * from './lib/constants/millis-per-day.constant';
|
|
2
37
|
export * from './lib/constants/millis-per-hour.constant';
|
|
3
38
|
export * from './lib/constants/millis-per-minute.constant';
|
|
4
39
|
export * from './lib/constants/regexes.constant';
|
|
40
|
+
|
|
5
41
|
export * from './lib/functions/add-offset.function';
|
|
6
42
|
export * from './lib/functions/camel-case.function';
|
|
7
43
|
export * from './lib/functions/convert-object-to-literal.function';
|
|
@@ -37,7 +73,8 @@ export * from './lib/functions/try-parse-date.function';
|
|
|
37
73
|
export * from './lib/functions/unicode-words.const';
|
|
38
74
|
export * from './lib/functions/upper-first.function';
|
|
39
75
|
export * from './lib/functions/words.function';
|
|
40
|
-
|
|
41
|
-
export * from './lib/
|
|
42
|
-
export * from './lib/
|
|
43
|
-
export * from './lib/
|
|
76
|
+
|
|
77
|
+
export * from './lib/types/axios-wrapped-nest-exception.interface';
|
|
78
|
+
export * from './lib/types/entity-provider.interface';
|
|
79
|
+
export * from './lib/types/keys-of.type';
|
|
80
|
+
export * from './lib/types/lookup.interface';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const apiIdHeader = 'x-api-id';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const apiKeyHeader = 'x-api-key';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const MILLIS_PER_MINUTE = 1000 * 60;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const oneOrMoreSpaces = /\s{1,}/g;
|
|
2
|
+
export const multipleSpaces = /\s{2,}/g;
|
|
3
|
+
export const comma = /,/g;
|
|
4
|
+
export const dashesLettersNumbers = /^([a-z]|-|\d)*$/i;
|
|
5
|
+
export const dashesLettersNumbersSpaces = /^([a-z]|-|\s|\d)*$/i;
|
|
6
|
+
export const zip = /^\d{5}$/;
|
|
7
|
+
export const phone = /^\d{3}-\d{3}-\d{4}$/;
|
|
8
|
+
export const phonePlusOne = /^\+1\d{10}$/;
|
|
9
|
+
export const code = /^\d{6}$/;
|
|
10
|
+
export const url = /(https?:\/\/|https?:\/\/).*\..+/;
|
|
11
|
+
export const protocol = /https?:\/\/|https?:\/\//;
|
|
12
|
+
export const firstSpaceLast = /[a-z]+\s[a-z]+([a-z]|')+[a-z]+/i;
|
|
13
|
+
export const passwordNumber = /\d/;
|
|
14
|
+
export const passwordUpper = /[A-Z]/;
|
|
15
|
+
export const passwordLower = /[a-z]/;
|
|
16
|
+
export const passwordSpecial = /\^|\$|\*|\.|\?|-|!|@|#|%|>|<|:|;|_|~|\+|=/;
|
|
17
|
+
export const ssn = /^\d{3}-\d{2}-\d{4}$/;
|
|
18
|
+
export const numeric = /^(\d|\.)*$/;
|
|
19
|
+
export const duns = /^\d{9}$/;
|
|
20
|
+
export const lastFourSocial = /^\d{4}$/;
|
|
21
|
+
export const ein = /^\d{2}-\d{7}$/;
|
|
22
|
+
export const stateShort = /^[A-Z]{2}$/;
|
|
23
|
+
export const email = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
24
|
+
export const domain = /^(?!:\/\/)([a-zA-Z0-9-_]{1,63}\.)+[a-zA-Z]{2,63}$/;
|
|
25
|
+
export const emailDomain = /^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
26
|
+
export const v4 = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
|
|
27
|
+
export const dateIso8601 = /^\d{4}-\d{1,2}-\d{1,2}$/;
|
|
28
|
+
export const dateIso8601WithTime = /^\d{4}-\d{1,2}-\d{1,2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
29
|
+
export const decimalRegex = /(\d|\.)/g;
|
|
30
|
+
export const slashR = /\r/g;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`chunk given 1, returns an array of arrays 1`] = `
|
|
4
|
+
[
|
|
5
|
+
[
|
|
6
|
+
"one",
|
|
7
|
+
"two",
|
|
8
|
+
"three",
|
|
9
|
+
"four",
|
|
10
|
+
"five",
|
|
11
|
+
"six",
|
|
12
|
+
"seven",
|
|
13
|
+
"eight",
|
|
14
|
+
],
|
|
15
|
+
]
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
exports[`chunk given 2, returns an array of arrays 1`] = `
|
|
19
|
+
[
|
|
20
|
+
[
|
|
21
|
+
"one",
|
|
22
|
+
"two",
|
|
23
|
+
"three",
|
|
24
|
+
"four",
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
"five",
|
|
28
|
+
"six",
|
|
29
|
+
"seven",
|
|
30
|
+
"eight",
|
|
31
|
+
],
|
|
32
|
+
]
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
exports[`chunk given 3, returns an array of arrays 1`] = `
|
|
36
|
+
[
|
|
37
|
+
[
|
|
38
|
+
"one",
|
|
39
|
+
"two",
|
|
40
|
+
"three",
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
"four",
|
|
44
|
+
"five",
|
|
45
|
+
"six",
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
"seven",
|
|
49
|
+
"eight",
|
|
50
|
+
],
|
|
51
|
+
]
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
exports[`chunk given 4, returns an array of arrays 1`] = `
|
|
55
|
+
[
|
|
56
|
+
[
|
|
57
|
+
"one",
|
|
58
|
+
"two",
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
"three",
|
|
62
|
+
"four",
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
"five",
|
|
66
|
+
"six",
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
"seven",
|
|
70
|
+
"eight",
|
|
71
|
+
],
|
|
72
|
+
]
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
exports[`chunk given 5, returns an array of arrays 1`] = `
|
|
76
|
+
[
|
|
77
|
+
[
|
|
78
|
+
"one",
|
|
79
|
+
"two",
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
"three",
|
|
83
|
+
"four",
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
"five",
|
|
87
|
+
"six",
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
"seven",
|
|
91
|
+
"eight",
|
|
92
|
+
],
|
|
93
|
+
]
|
|
94
|
+
`;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`splitDateRangeIntoDays given {"from":"","to":""}, returns an array of days 1`] = `[]`;
|
|
4
|
+
|
|
5
|
+
exports[`splitDateRangeIntoDays given {"from":"2024-01-01","to":"2024-01-01"}, returns an array of days 1`] = `
|
|
6
|
+
[
|
|
7
|
+
"2024-01-01",
|
|
8
|
+
]
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
exports[`splitDateRangeIntoDays given {"from":"2024-01-01","to":"2024-02-01"}, returns an array of days 1`] = `
|
|
12
|
+
[
|
|
13
|
+
"2024-01-01",
|
|
14
|
+
"2024-01-02",
|
|
15
|
+
"2024-01-03",
|
|
16
|
+
"2024-01-04",
|
|
17
|
+
"2024-01-05",
|
|
18
|
+
"2024-01-06",
|
|
19
|
+
"2024-01-07",
|
|
20
|
+
"2024-01-08",
|
|
21
|
+
"2024-01-09",
|
|
22
|
+
"2024-01-10",
|
|
23
|
+
"2024-01-11",
|
|
24
|
+
"2024-01-12",
|
|
25
|
+
"2024-01-13",
|
|
26
|
+
"2024-01-14",
|
|
27
|
+
"2024-01-15",
|
|
28
|
+
"2024-01-16",
|
|
29
|
+
"2024-01-17",
|
|
30
|
+
"2024-01-18",
|
|
31
|
+
"2024-01-19",
|
|
32
|
+
"2024-01-20",
|
|
33
|
+
"2024-01-21",
|
|
34
|
+
"2024-01-22",
|
|
35
|
+
"2024-01-23",
|
|
36
|
+
"2024-01-24",
|
|
37
|
+
"2024-01-25",
|
|
38
|
+
"2024-01-26",
|
|
39
|
+
"2024-01-27",
|
|
40
|
+
"2024-01-28",
|
|
41
|
+
"2024-01-29",
|
|
42
|
+
"2024-01-30",
|
|
43
|
+
"2024-01-31",
|
|
44
|
+
"2024-02-01",
|
|
45
|
+
]
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
exports[`splitDateRangeIntoDays given {"from":"2025-01-01","to":""}, returns an array of days 1`] = `[]`;
|
|
49
|
+
|
|
50
|
+
exports[`splitDateRangeIntoDays given {"from":"asdf","to":"2345"}, returns an array of days 1`] = `[]`;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { addOffset } from './add-offset.function';
|
|
2
|
+
|
|
3
|
+
describe('addOffset', () => {
|
|
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(addOffset(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 addOffset(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,23 @@
|
|
|
1
|
+
// YOU MUST AWAIT THIS FUNCTION WHEN INVOKING IT!!!
|
|
2
|
+
|
|
3
|
+
// TODO: PUT THIS IN A TEST-ONLY LIBRARY => LIBS/ISO/JEST
|
|
4
|
+
|
|
5
|
+
export async function arrangeActAssert<TArrangeOutput, TActOutput>({ arrange, act, assert }: { arrange: () => TArrangeOutput, act: (_: TArrangeOutput) => TActOutput, assert: (_: TArrangeOutput & { result: TActOutput }) => any }) {
|
|
6
|
+
const arrangeOutput = arrange();
|
|
7
|
+
|
|
8
|
+
const actInput = isPromise(arrangeOutput) ? await arrangeOutput : arrangeOutput;
|
|
9
|
+
|
|
10
|
+
const actOutput = act(actInput);
|
|
11
|
+
|
|
12
|
+
const assertInput = isPromise(actOutput) ? await actOutput : actOutput;
|
|
13
|
+
|
|
14
|
+
const assertOutput = assert({ ...actInput, result: assertInput });
|
|
15
|
+
|
|
16
|
+
const returnValue = isPromise(assertOutput) ? await assertOutput : assertOutput;
|
|
17
|
+
|
|
18
|
+
return returnValue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isPromise(value: any) {
|
|
22
|
+
return (typeof value?.then) === 'function';
|
|
23
|
+
}
|