@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.
Files changed (330) hide show
  1. package/README.md +289 -0
  2. package/jest.config.ts +11 -0
  3. package/package.json +8 -39
  4. package/project.json +23 -0
  5. package/{dist/cjs/index.d.ts → src/index.ts} +41 -4
  6. package/src/lib/constants/api-id-header.constant.ts +1 -0
  7. package/src/lib/constants/api-key-header.constant.ts +1 -0
  8. package/src/lib/constants/auth-cookie-name.constant.ts +2 -0
  9. package/src/lib/constants/millis-per-day.constant.ts +3 -0
  10. package/src/lib/constants/millis-per-hour.constant.ts +3 -0
  11. package/src/lib/constants/millis-per-minute.constant.ts +1 -0
  12. package/src/lib/constants/regexes.constant.ts +30 -0
  13. package/src/lib/functions/__snapshots__/chunk.function.spec.ts.snap +94 -0
  14. package/src/lib/functions/__snapshots__/split-date-range-into-days.function.spec.ts.snap +50 -0
  15. package/src/lib/functions/add-offset.function.spec.ts +12 -0
  16. package/src/lib/functions/add-offset.function.ts +14 -0
  17. package/src/lib/functions/arrange-act-assert.function.ts +23 -0
  18. package/src/lib/functions/camel-case.function.ts +30 -0
  19. package/src/lib/functions/chunk.function.spec.ts +20 -0
  20. package/src/lib/functions/chunk.function.ts +25 -0
  21. package/src/lib/functions/convert-object-to-literal.function.spec.ts +16 -0
  22. package/src/lib/functions/convert-object-to-literal.function.ts +10 -0
  23. package/src/lib/functions/format-usd.function.ts +4 -0
  24. package/src/lib/functions/from-boolean-string.function.ts +3 -0
  25. package/src/lib/functions/from-calendar-date.function.spec.ts +11 -0
  26. package/src/lib/functions/from-calendar-date.function.ts +5 -0
  27. package/src/lib/functions/from-csv-string.function.ts +3 -0
  28. package/src/lib/functions/get-date-last-month.function.ts +6 -0
  29. package/src/lib/functions/get-date-range-for-month.function copy.ts +8 -0
  30. package/src/lib/functions/get-date-range-for-month.function.ts +8 -0
  31. package/src/lib/functions/get-tag.function.ts +10 -0
  32. package/src/lib/functions/get-user-full-name.function.ts +5 -0
  33. package/src/lib/functions/is-symbol.function.ts +11 -0
  34. package/src/lib/functions/is-valid-date.function.ts +5 -0
  35. package/src/lib/functions/kebab-case.function.ts +5 -0
  36. package/src/lib/functions/map-entities-to-options.function.ts +11 -0
  37. package/src/lib/functions/map-enum-to-array-of-values.function copy.ts +3 -0
  38. package/src/lib/functions/map-enum-to-array-of-values.function.ts +3 -0
  39. package/src/lib/functions/map-enum-to-lookup-array.function.ts +6 -0
  40. package/src/lib/functions/map-enum-to-options.function copy.ts +7 -0
  41. package/src/lib/functions/map-enum-to-options.function.ts +7 -0
  42. package/src/lib/functions/mock-calls.function.ts +4 -0
  43. package/src/lib/functions/money.function.spec.ts +10 -0
  44. package/src/lib/functions/money.function.ts +22 -0
  45. package/src/lib/functions/parse-bool.function.ts +3 -0
  46. package/src/lib/functions/properties-to-array.function.ts +21 -0
  47. package/src/lib/functions/remove-alpha-chars.function.spec.ts +11 -0
  48. package/src/lib/functions/remove-alpha-chars.function.ts +9 -0
  49. package/src/lib/functions/remove-element-at-index.function copy.ts +9 -0
  50. package/src/lib/functions/remove-element-at-index.function.ts +9 -0
  51. package/src/lib/functions/round.function copy.ts +4 -0
  52. package/src/lib/functions/round.function.ts +4 -0
  53. package/src/lib/functions/sanitize-filename.function.ts +9 -0
  54. package/src/lib/functions/sleep.function.ts +3 -0
  55. package/{dist/esm/lib/functions/snake-case.function.js → src/lib/functions/snake-case.function.ts} +9 -6
  56. package/src/lib/functions/sort-by-created-at.function.ts +7 -0
  57. package/src/lib/functions/sort-by-full-name.function.ts +6 -0
  58. package/src/lib/functions/sort-by-id.function.ts +3 -0
  59. package/src/lib/functions/sort-by-name.function.ts +3 -0
  60. package/src/lib/functions/sort-numbers.function.ts +3 -0
  61. package/src/lib/functions/split-date-range-into-days.function.spec.ts +17 -0
  62. package/src/lib/functions/split-date-range-into-days.function.ts +26 -0
  63. package/src/lib/functions/subtract-offset.function.spec.ts +12 -0
  64. package/src/lib/functions/subtract-offset.function.ts +14 -0
  65. package/src/lib/functions/to-boolean-string.function.ts +3 -0
  66. package/src/lib/functions/to-calendar-date.function.ts +11 -0
  67. package/src/lib/functions/to-csv-string.function.ts +3 -0
  68. package/{dist/cjs/lib/functions/to-decimal-base.function.js → src/lib/functions/to-decimal-base.function.ts} +9 -7
  69. package/src/lib/functions/to-dollars-and-cents.function.spec.ts +7 -0
  70. package/src/lib/functions/to-dollars-and-cents.function.ts +17 -0
  71. package/{dist/cjs/lib/functions/to-string.function.js → src/lib/functions/to-string.function.ts} +6 -6
  72. package/src/lib/functions/to-unique-array.function.spec.ts +45 -0
  73. package/src/lib/functions/to-unique-array.function.ts +3 -0
  74. package/src/lib/functions/to-words.function.spec.ts +7 -0
  75. package/{dist/cjs/lib/functions/to-words.function.js → src/lib/functions/to-words.function.ts} +43 -26
  76. package/src/lib/functions/try-json-parse.spec.ts +37 -0
  77. package/src/lib/functions/try-json-parse.ts +11 -0
  78. package/src/lib/functions/try-json-stringify.spec.ts +44 -0
  79. package/src/lib/functions/try-json-stringify.ts +11 -0
  80. package/src/lib/functions/try-parse-date.function.spec.ts +12 -0
  81. package/src/lib/functions/try-parse-date.function.ts +17 -0
  82. package/src/lib/functions/unicode-words.const.ts +70 -0
  83. package/src/lib/functions/upper-first.function.spec.ts +16 -0
  84. package/src/lib/functions/upper-first.function.ts +10 -0
  85. package/src/lib/functions/use-date.function.ts +21 -0
  86. package/src/lib/functions/words.function.ts +38 -0
  87. package/src/lib/types/access-token.interface.ts +8 -0
  88. package/{dist/esm/lib/interfaces/axios-wrapped-nest-exception.interface.d.ts → src/lib/types/axios-wrapped-nest-exception.interface.ts} +1 -1
  89. package/src/lib/types/company.type.ts +18 -0
  90. package/src/lib/types/createable.type.ts +1 -0
  91. package/{dist/cjs/lib/interfaces/entity-provider.interface.d.ts → src/lib/types/entity-provider.interface.ts} +1 -1
  92. package/src/lib/types/keys-of.type copy.ts +1 -0
  93. package/src/lib/types/keys-of.type.ts +1 -0
  94. package/{dist/types/lib/interfaces/lookup.interface.d.ts → src/lib/types/lookup.interface copy.ts } +2 -2
  95. package/{dist/cjs/lib/interfaces/lookup.interface.d.ts → src/lib/types/lookup.interface.ts} +2 -2
  96. package/src/lib/types/nameable.type.ts +4 -0
  97. package/tsconfig.json +13 -0
  98. package/tsconfig.lib.json +9 -0
  99. package/tsconfig.spec.json +14 -0
  100. package/dist/cjs/index.js +0 -59
  101. package/dist/cjs/lib/constants/millis-per-day.constant.d.ts +0 -1
  102. package/dist/cjs/lib/constants/millis-per-day.constant.js +0 -5
  103. package/dist/cjs/lib/constants/millis-per-hour.constant.d.ts +0 -1
  104. package/dist/cjs/lib/constants/millis-per-hour.constant.js +0 -5
  105. package/dist/cjs/lib/constants/millis-per-minute.constant.d.ts +0 -1
  106. package/dist/cjs/lib/constants/millis-per-minute.constant.js +0 -4
  107. package/dist/cjs/lib/constants/regexes.constant.d.ts +0 -27
  108. package/dist/cjs/lib/constants/regexes.constant.js +0 -30
  109. package/dist/cjs/lib/functions/add-offset.function.d.ts +0 -1
  110. package/dist/cjs/lib/functions/add-offset.function.js +0 -13
  111. package/dist/cjs/lib/functions/camel-case.function.d.ts +0 -20
  112. package/dist/cjs/lib/functions/camel-case.function.js +0 -31
  113. package/dist/cjs/lib/functions/convert-object-to-literal.function.d.ts +0 -1
  114. package/dist/cjs/lib/functions/convert-object-to-literal.function.js +0 -9
  115. package/dist/cjs/lib/functions/format-usd.function.d.ts +0 -1
  116. package/dist/cjs/lib/functions/format-usd.function.js +0 -7
  117. package/dist/cjs/lib/functions/from-boolean-string.function.d.ts +0 -1
  118. package/dist/cjs/lib/functions/from-boolean-string.function.js +0 -6
  119. package/dist/cjs/lib/functions/from-calendar-date.function.d.ts +0 -1
  120. package/dist/cjs/lib/functions/from-calendar-date.function.js +0 -7
  121. package/dist/cjs/lib/functions/from-csv-string.function.d.ts +0 -1
  122. package/dist/cjs/lib/functions/from-csv-string.function.js +0 -6
  123. package/dist/cjs/lib/functions/get-date-range-for-month.function.d.ts +0 -4
  124. package/dist/cjs/lib/functions/get-date-range-for-month.function.js +0 -9
  125. package/dist/cjs/lib/functions/get-tag.function.d.ts +0 -1
  126. package/dist/cjs/lib/functions/get-tag.function.js +0 -11
  127. package/dist/cjs/lib/functions/is-symbol.function.d.ts +0 -1
  128. package/dist/cjs/lib/functions/is-symbol.function.js +0 -10
  129. package/dist/cjs/lib/functions/is-valid-date.function.d.ts +0 -1
  130. package/dist/cjs/lib/functions/is-valid-date.function.js +0 -7
  131. package/dist/cjs/lib/functions/kebab-case.function.d.ts +0 -1
  132. package/dist/cjs/lib/functions/kebab-case.function.js +0 -7
  133. package/dist/cjs/lib/functions/map-enum-to-array-of-values.function.d.ts +0 -1
  134. package/dist/cjs/lib/functions/map-enum-to-array-of-values.function.js +0 -6
  135. package/dist/cjs/lib/functions/map-enum-to-lookup-array.function.d.ts +0 -2
  136. package/dist/cjs/lib/functions/map-enum-to-lookup-array.function.js +0 -7
  137. package/dist/cjs/lib/functions/map-enum-to-options.function.d.ts +0 -4
  138. package/dist/cjs/lib/functions/map-enum-to-options.function.js +0 -9
  139. package/dist/cjs/lib/functions/money.function.d.ts +0 -1
  140. package/dist/cjs/lib/functions/money.function.js +0 -19
  141. package/dist/cjs/lib/functions/parse-bool.function.d.ts +0 -1
  142. package/dist/cjs/lib/functions/parse-bool.function.js +0 -6
  143. package/dist/cjs/lib/functions/properties-to-array.function.d.ts +0 -1
  144. package/dist/cjs/lib/functions/properties-to-array.function.js +0 -18
  145. package/dist/cjs/lib/functions/remove-alpha-chars.function.d.ts +0 -1
  146. package/dist/cjs/lib/functions/remove-alpha-chars.function.js +0 -10
  147. package/dist/cjs/lib/functions/remove-element-at-index.function.d.ts +0 -1
  148. package/dist/cjs/lib/functions/remove-element-at-index.function.js +0 -12
  149. package/dist/cjs/lib/functions/round.function.d.ts +0 -1
  150. package/dist/cjs/lib/functions/round.function.js +0 -7
  151. package/dist/cjs/lib/functions/sanitize-filename.function.d.ts +0 -1
  152. package/dist/cjs/lib/functions/sanitize-filename.function.js +0 -10
  153. package/dist/cjs/lib/functions/sleep.function.d.ts +0 -1
  154. package/dist/cjs/lib/functions/sleep.function.js +0 -6
  155. package/dist/cjs/lib/functions/snake-case.function.d.ts +0 -24
  156. package/dist/cjs/lib/functions/snake-case.function.js +0 -31
  157. package/dist/cjs/lib/functions/subtract-offset.function.d.ts +0 -1
  158. package/dist/cjs/lib/functions/subtract-offset.function.js +0 -13
  159. package/dist/cjs/lib/functions/to-boolean-string.function.d.ts +0 -1
  160. package/dist/cjs/lib/functions/to-boolean-string.function.js +0 -6
  161. package/dist/cjs/lib/functions/to-calendar-date.function.d.ts +0 -1
  162. package/dist/cjs/lib/functions/to-calendar-date.function.js +0 -11
  163. package/dist/cjs/lib/functions/to-csv-string.function.d.ts +0 -1
  164. package/dist/cjs/lib/functions/to-csv-string.function.js +0 -6
  165. package/dist/cjs/lib/functions/to-decimal-base.function.d.ts +0 -1
  166. package/dist/cjs/lib/functions/to-dollars-and-cents.function.d.ts +0 -1
  167. package/dist/cjs/lib/functions/to-dollars-and-cents.function.js +0 -16
  168. package/dist/cjs/lib/functions/to-string.function.d.ts +0 -1
  169. package/dist/cjs/lib/functions/to-unique-array.function.d.ts +0 -1
  170. package/dist/cjs/lib/functions/to-unique-array.function.js +0 -6
  171. package/dist/cjs/lib/functions/to-words.function.d.ts +0 -1
  172. package/dist/cjs/lib/functions/try-json-parse.d.ts +0 -1
  173. package/dist/cjs/lib/functions/try-json-parse.js +0 -14
  174. package/dist/cjs/lib/functions/try-json-stringify.d.ts +0 -1
  175. package/dist/cjs/lib/functions/try-json-stringify.js +0 -14
  176. package/dist/cjs/lib/functions/try-parse-date.function.d.ts +0 -1
  177. package/dist/cjs/lib/functions/try-parse-date.function.js +0 -16
  178. package/dist/cjs/lib/functions/unicode-words.const.d.ts +0 -8
  179. package/dist/cjs/lib/functions/unicode-words.const.js +0 -68
  180. package/dist/cjs/lib/functions/upper-first.function.d.ts +0 -1
  181. package/dist/cjs/lib/functions/upper-first.function.js +0 -12
  182. package/dist/cjs/lib/functions/words.function.d.ts +0 -17
  183. package/dist/cjs/lib/functions/words.function.js +0 -34
  184. package/dist/cjs/lib/interfaces/axios-wrapped-nest-exception.interface.d.ts +0 -5
  185. package/dist/cjs/lib/interfaces/axios-wrapped-nest-exception.interface.js +0 -2
  186. package/dist/cjs/lib/interfaces/entity-provider.interface.js +0 -2
  187. package/dist/cjs/lib/interfaces/keys-of.type.d.ts +0 -3
  188. package/dist/cjs/lib/interfaces/keys-of.type.js +0 -2
  189. package/dist/cjs/lib/interfaces/lookup.interface.js +0 -2
  190. package/dist/esm/index.d.ts +0 -43
  191. package/dist/esm/index.js +0 -59
  192. package/dist/esm/lib/constants/millis-per-day.constant.d.ts +0 -1
  193. package/dist/esm/lib/constants/millis-per-day.constant.js +0 -5
  194. package/dist/esm/lib/constants/millis-per-hour.constant.d.ts +0 -1
  195. package/dist/esm/lib/constants/millis-per-hour.constant.js +0 -5
  196. package/dist/esm/lib/constants/millis-per-minute.constant.d.ts +0 -1
  197. package/dist/esm/lib/constants/millis-per-minute.constant.js +0 -4
  198. package/dist/esm/lib/constants/regexes.constant.d.ts +0 -27
  199. package/dist/esm/lib/constants/regexes.constant.js +0 -30
  200. package/dist/esm/lib/functions/add-offset.function.d.ts +0 -1
  201. package/dist/esm/lib/functions/add-offset.function.js +0 -13
  202. package/dist/esm/lib/functions/camel-case.function.d.ts +0 -20
  203. package/dist/esm/lib/functions/camel-case.function.js +0 -31
  204. package/dist/esm/lib/functions/convert-object-to-literal.function.d.ts +0 -1
  205. package/dist/esm/lib/functions/convert-object-to-literal.function.js +0 -9
  206. package/dist/esm/lib/functions/format-usd.function.d.ts +0 -1
  207. package/dist/esm/lib/functions/format-usd.function.js +0 -7
  208. package/dist/esm/lib/functions/from-boolean-string.function.d.ts +0 -1
  209. package/dist/esm/lib/functions/from-boolean-string.function.js +0 -6
  210. package/dist/esm/lib/functions/from-calendar-date.function.d.ts +0 -1
  211. package/dist/esm/lib/functions/from-calendar-date.function.js +0 -7
  212. package/dist/esm/lib/functions/from-csv-string.function.d.ts +0 -1
  213. package/dist/esm/lib/functions/from-csv-string.function.js +0 -6
  214. package/dist/esm/lib/functions/get-date-range-for-month.function.d.ts +0 -4
  215. package/dist/esm/lib/functions/get-date-range-for-month.function.js +0 -9
  216. package/dist/esm/lib/functions/get-tag.function.d.ts +0 -1
  217. package/dist/esm/lib/functions/get-tag.function.js +0 -11
  218. package/dist/esm/lib/functions/is-symbol.function.d.ts +0 -1
  219. package/dist/esm/lib/functions/is-symbol.function.js +0 -10
  220. package/dist/esm/lib/functions/is-valid-date.function.d.ts +0 -1
  221. package/dist/esm/lib/functions/is-valid-date.function.js +0 -7
  222. package/dist/esm/lib/functions/kebab-case.function.d.ts +0 -1
  223. package/dist/esm/lib/functions/kebab-case.function.js +0 -7
  224. package/dist/esm/lib/functions/map-enum-to-array-of-values.function.d.ts +0 -1
  225. package/dist/esm/lib/functions/map-enum-to-array-of-values.function.js +0 -6
  226. package/dist/esm/lib/functions/map-enum-to-lookup-array.function.d.ts +0 -2
  227. package/dist/esm/lib/functions/map-enum-to-lookup-array.function.js +0 -7
  228. package/dist/esm/lib/functions/map-enum-to-options.function.d.ts +0 -4
  229. package/dist/esm/lib/functions/map-enum-to-options.function.js +0 -9
  230. package/dist/esm/lib/functions/money.function.d.ts +0 -1
  231. package/dist/esm/lib/functions/money.function.js +0 -19
  232. package/dist/esm/lib/functions/parse-bool.function.d.ts +0 -1
  233. package/dist/esm/lib/functions/parse-bool.function.js +0 -6
  234. package/dist/esm/lib/functions/properties-to-array.function.d.ts +0 -1
  235. package/dist/esm/lib/functions/properties-to-array.function.js +0 -18
  236. package/dist/esm/lib/functions/remove-alpha-chars.function.d.ts +0 -1
  237. package/dist/esm/lib/functions/remove-alpha-chars.function.js +0 -10
  238. package/dist/esm/lib/functions/remove-element-at-index.function.d.ts +0 -1
  239. package/dist/esm/lib/functions/remove-element-at-index.function.js +0 -12
  240. package/dist/esm/lib/functions/round.function.d.ts +0 -1
  241. package/dist/esm/lib/functions/round.function.js +0 -7
  242. package/dist/esm/lib/functions/sanitize-filename.function.d.ts +0 -1
  243. package/dist/esm/lib/functions/sanitize-filename.function.js +0 -10
  244. package/dist/esm/lib/functions/sleep.function.d.ts +0 -1
  245. package/dist/esm/lib/functions/sleep.function.js +0 -6
  246. package/dist/esm/lib/functions/snake-case.function.d.ts +0 -24
  247. package/dist/esm/lib/functions/subtract-offset.function.d.ts +0 -1
  248. package/dist/esm/lib/functions/subtract-offset.function.js +0 -13
  249. package/dist/esm/lib/functions/to-boolean-string.function.d.ts +0 -1
  250. package/dist/esm/lib/functions/to-boolean-string.function.js +0 -6
  251. package/dist/esm/lib/functions/to-calendar-date.function.d.ts +0 -1
  252. package/dist/esm/lib/functions/to-calendar-date.function.js +0 -11
  253. package/dist/esm/lib/functions/to-csv-string.function.d.ts +0 -1
  254. package/dist/esm/lib/functions/to-csv-string.function.js +0 -6
  255. package/dist/esm/lib/functions/to-decimal-base.function.d.ts +0 -1
  256. package/dist/esm/lib/functions/to-decimal-base.function.js +0 -21
  257. package/dist/esm/lib/functions/to-dollars-and-cents.function.d.ts +0 -1
  258. package/dist/esm/lib/functions/to-dollars-and-cents.function.js +0 -16
  259. package/dist/esm/lib/functions/to-string.function.d.ts +0 -1
  260. package/dist/esm/lib/functions/to-string.function.js +0 -25
  261. package/dist/esm/lib/functions/to-unique-array.function.d.ts +0 -1
  262. package/dist/esm/lib/functions/to-unique-array.function.js +0 -6
  263. package/dist/esm/lib/functions/to-words.function.d.ts +0 -1
  264. package/dist/esm/lib/functions/to-words.function.js +0 -91
  265. package/dist/esm/lib/functions/try-json-parse.d.ts +0 -1
  266. package/dist/esm/lib/functions/try-json-parse.js +0 -14
  267. package/dist/esm/lib/functions/try-json-stringify.d.ts +0 -1
  268. package/dist/esm/lib/functions/try-json-stringify.js +0 -14
  269. package/dist/esm/lib/functions/try-parse-date.function.d.ts +0 -1
  270. package/dist/esm/lib/functions/try-parse-date.function.js +0 -16
  271. package/dist/esm/lib/functions/unicode-words.const.d.ts +0 -8
  272. package/dist/esm/lib/functions/unicode-words.const.js +0 -68
  273. package/dist/esm/lib/functions/upper-first.function.d.ts +0 -1
  274. package/dist/esm/lib/functions/upper-first.function.js +0 -12
  275. package/dist/esm/lib/functions/words.function.d.ts +0 -17
  276. package/dist/esm/lib/functions/words.function.js +0 -34
  277. package/dist/esm/lib/interfaces/axios-wrapped-nest-exception.interface.js +0 -2
  278. package/dist/esm/lib/interfaces/entity-provider.interface.d.ts +0 -9
  279. package/dist/esm/lib/interfaces/entity-provider.interface.js +0 -2
  280. package/dist/esm/lib/interfaces/keys-of.type.d.ts +0 -3
  281. package/dist/esm/lib/interfaces/keys-of.type.js +0 -2
  282. package/dist/esm/lib/interfaces/lookup.interface.d.ts +0 -4
  283. package/dist/esm/lib/interfaces/lookup.interface.js +0 -2
  284. package/dist/types/index.d.ts +0 -43
  285. package/dist/types/lib/constants/millis-per-day.constant.d.ts +0 -1
  286. package/dist/types/lib/constants/millis-per-hour.constant.d.ts +0 -1
  287. package/dist/types/lib/constants/millis-per-minute.constant.d.ts +0 -1
  288. package/dist/types/lib/constants/regexes.constant.d.ts +0 -27
  289. package/dist/types/lib/functions/add-offset.function.d.ts +0 -1
  290. package/dist/types/lib/functions/camel-case.function.d.ts +0 -20
  291. package/dist/types/lib/functions/convert-object-to-literal.function.d.ts +0 -1
  292. package/dist/types/lib/functions/format-usd.function.d.ts +0 -1
  293. package/dist/types/lib/functions/from-boolean-string.function.d.ts +0 -1
  294. package/dist/types/lib/functions/from-calendar-date.function.d.ts +0 -1
  295. package/dist/types/lib/functions/from-csv-string.function.d.ts +0 -1
  296. package/dist/types/lib/functions/get-date-range-for-month.function.d.ts +0 -4
  297. package/dist/types/lib/functions/get-tag.function.d.ts +0 -1
  298. package/dist/types/lib/functions/is-symbol.function.d.ts +0 -1
  299. package/dist/types/lib/functions/is-valid-date.function.d.ts +0 -1
  300. package/dist/types/lib/functions/kebab-case.function.d.ts +0 -1
  301. package/dist/types/lib/functions/map-enum-to-array-of-values.function.d.ts +0 -1
  302. package/dist/types/lib/functions/map-enum-to-lookup-array.function.d.ts +0 -2
  303. package/dist/types/lib/functions/map-enum-to-options.function.d.ts +0 -4
  304. package/dist/types/lib/functions/money.function.d.ts +0 -1
  305. package/dist/types/lib/functions/parse-bool.function.d.ts +0 -1
  306. package/dist/types/lib/functions/properties-to-array.function.d.ts +0 -1
  307. package/dist/types/lib/functions/remove-alpha-chars.function.d.ts +0 -1
  308. package/dist/types/lib/functions/remove-element-at-index.function.d.ts +0 -1
  309. package/dist/types/lib/functions/round.function.d.ts +0 -1
  310. package/dist/types/lib/functions/sanitize-filename.function.d.ts +0 -1
  311. package/dist/types/lib/functions/sleep.function.d.ts +0 -1
  312. package/dist/types/lib/functions/snake-case.function.d.ts +0 -24
  313. package/dist/types/lib/functions/subtract-offset.function.d.ts +0 -1
  314. package/dist/types/lib/functions/to-boolean-string.function.d.ts +0 -1
  315. package/dist/types/lib/functions/to-calendar-date.function.d.ts +0 -1
  316. package/dist/types/lib/functions/to-csv-string.function.d.ts +0 -1
  317. package/dist/types/lib/functions/to-decimal-base.function.d.ts +0 -1
  318. package/dist/types/lib/functions/to-dollars-and-cents.function.d.ts +0 -1
  319. package/dist/types/lib/functions/to-string.function.d.ts +0 -1
  320. package/dist/types/lib/functions/to-unique-array.function.d.ts +0 -1
  321. package/dist/types/lib/functions/to-words.function.d.ts +0 -1
  322. package/dist/types/lib/functions/try-json-parse.d.ts +0 -1
  323. package/dist/types/lib/functions/try-json-stringify.d.ts +0 -1
  324. package/dist/types/lib/functions/try-parse-date.function.d.ts +0 -1
  325. package/dist/types/lib/functions/unicode-words.const.d.ts +0 -8
  326. package/dist/types/lib/functions/upper-first.function.d.ts +0 -1
  327. package/dist/types/lib/functions/words.function.d.ts +0 -17
  328. package/dist/types/lib/interfaces/axios-wrapped-nest-exception.interface.d.ts +0 -5
  329. package/dist/types/lib/interfaces/entity-provider.interface.d.ts +0 -9
  330. package/dist/types/lib/interfaces/keys-of.type.d.ts +0 -3
@@ -0,0 +1,30 @@
1
+ // https://github.com/lodash/lodash/blob/main/src/camelCase.ts
2
+
3
+ import { toString } from './to-string.function';
4
+ import { upperFirst } from './upper-first.function';
5
+ import { words } from './words.function';
6
+
7
+ /**
8
+ * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
9
+ *
10
+ * @since 3.0.0
11
+ * @category String
12
+ * @param {string} [string=''] The string to convert.
13
+ * @returns {string} Returns the camel cased string.
14
+ * @see lowerCase, kebabCase, snakeCase, startCase, upperCase, upperFirst
15
+ * @example
16
+ *
17
+ * camelCase('Foo Bar')
18
+ * // => 'fooBar'
19
+ *
20
+ * camelCase('--foo-bar--')
21
+ * // => 'fooBar'
22
+ *
23
+ * camelCase('__FOO_BAR__')
24
+ * // => 'fooBar'
25
+ */
26
+ export const camelCase = (string: string): string =>
27
+ (words(toString(string).replace(/['\u2019]/g, '')) as string[]).reduce((result: string, word: string, index: number) => {
28
+ word = word.toLowerCase();
29
+ return result + (index ? upperFirst(word) : word);
30
+ }, '');
@@ -0,0 +1,20 @@
1
+ import { chunk } from './chunk.function';
2
+ import { arrangeActAssert } from '../functions/arrange-act-assert.function';
3
+
4
+ const array = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'];
5
+
6
+ describe('chunk', () => {
7
+ it.each([
8
+ [1],
9
+ [2],
10
+ [3],
11
+ [4],
12
+ [5],
13
+ ])('given %j, returns an array of arrays', async (_) => await arrangeActAssert({
14
+ arrange: () => ({ subject: chunk }),
15
+ act: ({ subject }) => subject(array, _),
16
+ assert: ({ result }) => {
17
+ expect(result).toMatchSnapshot();
18
+ }
19
+ }));
20
+ });
@@ -0,0 +1,25 @@
1
+ export function chunk<T>(array: T[], numDivisions: number): T[][] {
2
+ if (numDivisions <= 0) {
3
+ throw new Error('Number of divisions must be greater than or equal to 0');
4
+ }
5
+
6
+ if (array.length === 0) {
7
+ return [];
8
+ }
9
+
10
+ const result: T[][] = [];
11
+ const chunkSize = Math.ceil(array.length / numDivisions);
12
+
13
+ for (let i = 0; i < array.length; i += chunkSize) {
14
+ result.push(array.slice(i, i + chunkSize));
15
+ }
16
+
17
+ while (result.length > numDivisions) {
18
+ const lastChunk = result.pop();
19
+ if (lastChunk) {
20
+ result[result.length - 1].push(...lastChunk);
21
+ }
22
+ }
23
+
24
+ return result;
25
+ }
@@ -0,0 +1,16 @@
1
+ import { convertObjectToLiteral } from './convert-object-to-literal.function';
2
+
3
+ const qty = 337;
4
+ const price = 100;
5
+ const product = 'flux-capacitor';
6
+
7
+ describe('convertObjectToLiteral', () => {
8
+ it.each([[(k, v) => `${k}=${v}`, ' AND ', { qty, price, product }]])(
9
+ 'converts an object to a string',
10
+ (literalFn, delimiter, obj) => {
11
+ expect(
12
+ convertObjectToLiteral(literalFn, delimiter, obj)
13
+ ).toMatchSnapshot();
14
+ }
15
+ );
16
+ });
@@ -0,0 +1,10 @@
1
+ export function convertObjectToLiteral(
2
+ literalFn: (k: string, v: any) => string,
3
+ delimiter: string,
4
+ keyValuePairs: Record<string, any>
5
+ ) {
6
+ return Object.entries(keyValuePairs)
7
+ .filter(([, v]) => !!v || v === 0 || v === false)
8
+ .map(([k, v]) => literalFn(k, v?.toString?.()))
9
+ .join(delimiter);
10
+ }
@@ -0,0 +1,4 @@
1
+ export function formatUsd(rawAmount?: number | string) {
2
+ const amount = Number(rawAmount) || 0;
3
+ return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(amount);
4
+ }
@@ -0,0 +1,3 @@
1
+ export function fromBooleanString(value?: string) {
2
+ return value === 'true';
3
+ }
@@ -0,0 +1,11 @@
1
+ import { fromCalendarDate } from './from-calendar-date.function';
2
+
3
+ describe('fromCalendarDate', () => {
4
+ describe('GIVEN input is partial or full ISO8601', () => {
5
+ it.each([
6
+ '2023-12-23',
7
+ ])('%j', (input) => {
8
+ expect(fromCalendarDate(input)).toMatchSnapshot();
9
+ });
10
+ });
11
+ });
@@ -0,0 +1,5 @@
1
+ import { addOffset } from "./add-offset.function";
2
+
3
+ export function fromCalendarDate(input: string | Date | undefined | null): Date | null {
4
+ return addOffset(input) || null;
5
+ }
@@ -0,0 +1,3 @@
1
+ export function fromCsvString(value?: string) {
2
+ return value ? value.split(',').map((v) => v.trim()) : [];
3
+ }
@@ -0,0 +1,6 @@
1
+ import { MILLIS_PER_DAY } from "../constants/millis-per-day.constant";
2
+
3
+ export function getDateLastMonth() {
4
+ const days = new Date().getUTCDate() + 1;
5
+ return new Date(Date.now() - (MILLIS_PER_DAY * days));
6
+ }
@@ -0,0 +1,8 @@
1
+ import { MILLIS_PER_DAY } from "../constants/millis-per-day.constant";
2
+
3
+ export function getDateRangeForMonth(year: number, month: number) {
4
+ const startDate = new Date(+Date.UTC(year, month + -1, 0) + MILLIS_PER_DAY);
5
+ const endDate = new Date(+Date.UTC(year, month + 0, 0) + MILLIS_PER_DAY);
6
+
7
+ return { startDate, endDate };
8
+ }
@@ -0,0 +1,8 @@
1
+ import { MILLIS_PER_DAY } from "../constants/millis-per-day.constant";
2
+
3
+ export function getDateRangeForMonth(year: number, month: number) {
4
+ const startDate = new Date(+Date.UTC(year, month + -1, 0) + MILLIS_PER_DAY);
5
+ const endDate = new Date(+Date.UTC(year, month + 0, 0) + MILLIS_PER_DAY);
6
+
7
+ return { startDate, endDate };
8
+ }
@@ -0,0 +1,10 @@
1
+ // https://github.com/lodash/lodash/blob/main/src/.internal/getTag.ts
2
+
3
+ const toString = Object.prototype.toString
4
+
5
+ export function getTag(value: any): string {
6
+ if (value == null) {
7
+ return value === undefined ? '[object Undefined]' : '[object Null]'
8
+ }
9
+ return toString.call(value)
10
+ }
@@ -0,0 +1,5 @@
1
+ import { TNameable } from "../types/nameable.type";
2
+
3
+ export function getUserFullName(user: TNameable | undefined): string {
4
+ return `${user?.firstName} ${user?.lastName}`;
5
+ }
@@ -0,0 +1,11 @@
1
+ // https://github.com/lodash/lodash/blob/main/src/isSymbol.ts
2
+
3
+ import { getTag } from './get-tag.function';
4
+
5
+ export function isSymbol(value: any): boolean {
6
+ const type = typeof value;
7
+ return (
8
+ type === 'symbol' ||
9
+ (type === 'object' && value != null && getTag(value) === '[object Symbol]')
10
+ );
11
+ }
@@ -0,0 +1,5 @@
1
+ export function isValidDate(dateString: string | Date) {
2
+ const date = new Date(dateString);
3
+
4
+ return (date instanceof Date && !isNaN(date.getTime())) ? date : undefined;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { snakeCase } from "./snake-case.function";
2
+
3
+ export function kebabCase(string: string) {
4
+ return snakeCase(string).replace(/_/g, '-');
5
+ }
@@ -0,0 +1,11 @@
1
+ export function mapEntitiesToOptions<TEntity extends { name?: string, id: string }>(
2
+ entities: Record<string, TEntity>,
3
+ ids: string[],
4
+ includeBlank = true,
5
+ ) {
6
+ const entityArray = ids?.length ? (ids?.map((value => ({ value, display: entities[value].name || entities[value].id })))) : [];
7
+
8
+ return includeBlank
9
+ ? [{ display: '', value: '' }, ...entityArray]
10
+ : entityArray;
11
+ }
@@ -0,0 +1,3 @@
1
+ export function mapEnumToArrayOfValues(enumeration: any): any {
2
+ return Object.entries(enumeration).map(([key, value]) => value) as string[];
3
+ }
@@ -0,0 +1,3 @@
1
+ export function mapEnumToArrayOfValues(enumeration: any): any {
2
+ return Object.entries(enumeration).map(([key, value]) => value) as string[];
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,4 @@
1
+ export function mockCalls(jestFn: any, label = 'mock-calls') {
2
+ const calls = jestFn?.mock?.calls || [];
3
+ return { [`${label} -->> ${calls.length} invocation(s)`]: calls };
4
+ }
@@ -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,3 @@
1
+ export function parseBool(asc: string | boolean | null | undefined) {
2
+ return asc ? asc === true || asc === 'true' : false;
3
+ }
@@ -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
+ import { decimalRegex } from "../constants/regexes.constant";
2
+
3
+ export function removeAlphaChars(input?: string | number) {
4
+ if (!input) {
5
+ return;
6
+ }
7
+
8
+ return input.toString().match(decimalRegex)?.join?.('');
9
+ }
@@ -0,0 +1,9 @@
1
+ export function removeElementAtIndex<T>(array: T[], indexToRemove: number): T[] {
2
+ const newArray: T[] = [];
3
+ (array || []).forEach((element, index) => {
4
+ if(index !== indexToRemove) {
5
+ newArray.push(element);
6
+ }
7
+ });
8
+ return newArray;
9
+ }
@@ -0,0 +1,9 @@
1
+ export function removeElementAtIndex<T>(array: T[], indexToRemove: number): T[] {
2
+ const newArray: T[] = [];
3
+ (array || []).forEach((element, index) => {
4
+ if(index !== indexToRemove) {
5
+ newArray.push(element);
6
+ }
7
+ });
8
+ return newArray;
9
+ }
@@ -0,0 +1,4 @@
1
+ export function round(numberToRound: number, scalingFactor: number) {
2
+ const scaledServingDose = numberToRound * scalingFactor;
3
+ return Math.round(scaledServingDose) / scalingFactor;
4
+ }
@@ -0,0 +1,4 @@
1
+ export function round(numberToRound: number, scalingFactor: number) {
2
+ const scaledServingDose = numberToRound * scalingFactor;
3
+ return Math.round(scaledServingDose) / scalingFactor;
4
+ }
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ export async function sleep(milliseconds = 0) {
2
+ return await new Promise(resolve => setTimeout(resolve, milliseconds));
3
+ }
@@ -1,8 +1,7 @@
1
- "use strict";
2
1
  // source https://github.com/lodash/lodash/blob/master/snakeCase.js
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.snakeCase = snakeCase;
5
- const words_function_1 = require("./words.function");
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
- return ((0, words_function_1.words)(string.replace(/['\u2019]/g, '')).reduce((result, word, index) => (result + (index ? '_' : '') + word.toLowerCase()), ''));
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,7 @@
1
+ import { TCreateable } from "../types/createable.type";
2
+
3
+ export function sortByCreatedAt<TEntity extends TCreateable>(a: TEntity, b: TEntity) {
4
+ const isLessThan = a.createdAt < b.createdAt;
5
+
6
+ return isLessThan ? -1 : 1;
7
+ }
@@ -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,3 @@
1
+ export function sortById<TEntity extends { id: string }>(a: TEntity, b: TEntity) {
2
+ return a?.id?.localeCompare(b?.id || '') || 0;
3
+ }
@@ -0,0 +1,3 @@
1
+ export function sortByName<TEntity extends { name: string }>(a: TEntity, b: TEntity) {
2
+ return a?.name?.localeCompare(b?.name || '') || 0;
3
+ }
@@ -0,0 +1,3 @@
1
+ export const sortNumbers = (a: number, b: number) => {
2
+ return Number(a) < Number(b) ? -1 : 1;
3
+ };
@@ -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,3 @@
1
+ export function toBooleanString(val?: boolean) {
2
+ return (!!(val || false)).toString() as 'true' | 'false';
3
+ }
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ export function toCsvString(val?: string[]) {
2
+ return (val || []).join(',');
3
+ }
@@ -1,21 +1,23 @@
1
- "use strict";
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,7 @@
1
+ import { toDollarsAndCents } from './to-dollars-and-cents.function';
2
+
3
+ describe('toDollarsAndCents', () => {
4
+ it('worx', () => {
5
+ expect(toDollarsAndCents(337.33)).toMatchSnapshot();
6
+ });
7
+ });
@@ -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
+ }