@onivoro/isomorphic-common 0.1.1 → 0.2.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 (142) hide show
  1. package/cjs/jest.config.js +19 -0
  2. package/cjs/src/index.js +45 -0
  3. package/cjs/src/lib/constants/millis-per-day.constant.js +5 -0
  4. package/cjs/src/lib/constants/millis-per-hour.constant.js +5 -0
  5. package/cjs/src/lib/constants/millis-per-minute.constant.js +4 -0
  6. package/cjs/src/lib/functions/add-offset.function.js +14 -0
  7. package/cjs/src/lib/functions/add-offset.function.spec.js +13 -0
  8. package/cjs/src/lib/functions/camel-case.function.js +31 -0
  9. package/cjs/src/lib/functions/convert-object-to-literal.function.js +10 -0
  10. package/cjs/src/lib/functions/convert-object-to-literal.function.spec.js +11 -0
  11. package/cjs/src/lib/functions/from-boolean-string.function.js +7 -0
  12. package/cjs/src/lib/functions/from-calendar-date.function.js +8 -0
  13. package/cjs/src/lib/functions/from-calendar-date.function.spec.js +12 -0
  14. package/cjs/src/lib/functions/from-csv-string.function.js +7 -0
  15. package/cjs/src/lib/functions/get-tag.function.js +12 -0
  16. package/cjs/src/lib/functions/is-symbol.function.js +11 -0
  17. package/cjs/src/lib/functions/kebab-case.function.js +8 -0
  18. package/cjs/src/lib/functions/parse-bool.function.js +7 -0
  19. package/cjs/src/lib/functions/properties-to-array.function.js +19 -0
  20. package/cjs/src/lib/functions/sanitize-filename.function.js +11 -0
  21. package/cjs/src/lib/functions/snake-case.function.js +32 -0
  22. package/cjs/src/lib/functions/subtract-offset.function.js +14 -0
  23. package/cjs/src/lib/functions/subtract-offset.function.spec.js +13 -0
  24. package/cjs/src/lib/functions/to-boolean-string.function.js +7 -0
  25. package/cjs/src/lib/functions/to-calendar-date.function.js +12 -0
  26. package/cjs/src/lib/functions/to-csv-string.function.js +7 -0
  27. package/cjs/src/lib/functions/to-decimal-base.function.js +22 -0
  28. package/cjs/src/lib/functions/to-dollars-and-cents.function.js +15 -0
  29. package/cjs/src/lib/functions/to-dollars-and-cents.function.spec.js +8 -0
  30. package/cjs/src/lib/functions/to-string.function.js +26 -0
  31. package/cjs/src/lib/functions/to-unique-array.function.js +7 -0
  32. package/cjs/src/lib/functions/to-unique-array.function.spec.js +35 -0
  33. package/cjs/src/lib/functions/to-words.function.js +90 -0
  34. package/cjs/src/lib/functions/to-words.function.spec.js +8 -0
  35. package/cjs/src/lib/functions/try-parse-date.function.js +17 -0
  36. package/cjs/src/lib/functions/try-parse-date.function.spec.js +13 -0
  37. package/cjs/src/lib/functions/unicode-words.const.js +69 -0
  38. package/cjs/src/lib/functions/upper-first.function.js +13 -0
  39. package/cjs/src/lib/functions/upper-first.function.spec.js +16 -0
  40. package/cjs/src/lib/functions/words.function.js +35 -0
  41. package/cjs/src/lib/interfaces/axios-wrapped-nest-exception.interface.js +2 -0
  42. package/cjs/src/lib/interfaces/entity-provider.interface.js +2 -0
  43. package/cjs/src/lib/interfaces/keys-of.type.js +2 -0
  44. package/dist +22 -0
  45. package/esm/jest.config.js +17 -0
  46. package/esm/package.json +1 -0
  47. package/esm/src/index.js +29 -0
  48. package/esm/src/lib/constants/millis-per-day.constant.js +2 -0
  49. package/esm/src/lib/constants/millis-per-hour.constant.js +2 -0
  50. package/esm/src/lib/constants/millis-per-minute.constant.js +1 -0
  51. package/esm/src/lib/functions/add-offset.function.js +10 -0
  52. package/esm/src/lib/functions/add-offset.function.spec.js +11 -0
  53. package/esm/src/lib/functions/camel-case.function.js +27 -0
  54. package/esm/src/lib/functions/convert-object-to-literal.function.js +6 -0
  55. package/esm/src/lib/functions/convert-object-to-literal.function.spec.js +9 -0
  56. package/esm/src/lib/functions/from-boolean-string.function.js +3 -0
  57. package/esm/src/lib/functions/from-calendar-date.function.js +4 -0
  58. package/esm/src/lib/functions/from-calendar-date.function.spec.js +10 -0
  59. package/esm/src/lib/functions/from-csv-string.function.js +3 -0
  60. package/esm/src/lib/functions/get-tag.function.js +8 -0
  61. package/esm/src/lib/functions/is-symbol.function.js +7 -0
  62. package/esm/src/lib/functions/kebab-case.function.js +4 -0
  63. package/esm/src/lib/functions/parse-bool.function.js +3 -0
  64. package/esm/src/lib/functions/properties-to-array.function.js +15 -0
  65. package/esm/src/lib/functions/sanitize-filename.function.js +7 -0
  66. package/esm/src/lib/functions/snake-case.function.js +28 -0
  67. package/esm/src/lib/functions/subtract-offset.function.js +10 -0
  68. package/esm/src/lib/functions/subtract-offset.function.spec.js +11 -0
  69. package/esm/src/lib/functions/to-boolean-string.function.js +3 -0
  70. package/esm/src/lib/functions/to-calendar-date.function.js +8 -0
  71. package/esm/src/lib/functions/to-csv-string.function.js +3 -0
  72. package/esm/src/lib/functions/to-decimal-base.function.js +18 -0
  73. package/esm/src/lib/functions/to-dollars-and-cents.function.js +11 -0
  74. package/esm/src/lib/functions/to-dollars-and-cents.function.spec.js +6 -0
  75. package/esm/src/lib/functions/to-string.function.js +22 -0
  76. package/esm/src/lib/functions/to-unique-array.function.js +3 -0
  77. package/esm/src/lib/functions/to-unique-array.function.spec.js +33 -0
  78. package/esm/src/lib/functions/to-words.function.js +86 -0
  79. package/esm/src/lib/functions/to-words.function.spec.js +6 -0
  80. package/esm/src/lib/functions/try-parse-date.function.js +13 -0
  81. package/esm/src/lib/functions/try-parse-date.function.spec.js +11 -0
  82. package/esm/src/lib/functions/unicode-words.const.js +65 -0
  83. package/esm/src/lib/functions/upper-first.function.js +9 -0
  84. package/esm/src/lib/functions/upper-first.function.spec.js +14 -0
  85. package/esm/src/lib/functions/words.function.js +31 -0
  86. package/esm/src/lib/interfaces/axios-wrapped-nest-exception.interface.js +1 -0
  87. package/esm/src/lib/interfaces/entity-provider.interface.js +1 -0
  88. package/esm/src/lib/interfaces/keys-of.type.js +1 -0
  89. package/jest.config.ts +17 -0
  90. package/package.json +16 -6
  91. package/src/index.ts +31 -0
  92. package/src/lib/constants/millis-per-day.constant.ts +3 -0
  93. package/src/lib/constants/millis-per-hour.constant.ts +3 -0
  94. package/src/lib/constants/millis-per-minute.constant.ts +1 -0
  95. package/src/lib/functions/__snapshots__/add-offset.function.spec.ts.snap +5 -0
  96. package/src/lib/functions/__snapshots__/convert-object-to-literal.function.spec.ts.snap +3 -0
  97. package/src/lib/functions/__snapshots__/from-calendar-date.function.spec.ts.snap +3 -0
  98. package/src/lib/functions/__snapshots__/subtract-offset.function.spec.ts.snap +5 -0
  99. package/src/lib/functions/__snapshots__/to-dollars-and-cents.function.spec.ts.snap +3 -0
  100. package/src/lib/functions/__snapshots__/to-words.function.spec.ts.snap +3 -0
  101. package/src/lib/functions/__snapshots__/try-parse-date.function.spec.ts.snap +5 -0
  102. package/src/lib/functions/__snapshots__/upper-first.function.spec.ts.snap +13 -0
  103. package/src/lib/functions/add-offset.function.spec.ts +12 -0
  104. package/src/lib/functions/add-offset.function.ts +14 -0
  105. package/src/lib/functions/camel-case.function.ts +30 -0
  106. package/src/lib/functions/convert-object-to-literal.function.spec.ts +16 -0
  107. package/src/lib/functions/convert-object-to-literal.function.ts +10 -0
  108. package/src/lib/functions/from-boolean-string.function.ts +3 -0
  109. package/src/lib/functions/from-calendar-date.function.spec.ts +11 -0
  110. package/src/lib/functions/from-calendar-date.function.ts +5 -0
  111. package/src/lib/functions/from-csv-string.function.ts +3 -0
  112. package/src/lib/functions/get-tag.function.ts +10 -0
  113. package/src/lib/functions/is-symbol.function.ts +11 -0
  114. package/src/lib/functions/kebab-case.function.ts +5 -0
  115. package/src/lib/functions/parse-bool.function.ts +3 -0
  116. package/src/lib/functions/properties-to-array.function.ts +21 -0
  117. package/src/lib/functions/sanitize-filename.function.ts +9 -0
  118. package/src/lib/functions/snake-case.function.ts +34 -0
  119. package/src/lib/functions/subtract-offset.function.spec.ts +12 -0
  120. package/src/lib/functions/subtract-offset.function.ts +14 -0
  121. package/src/lib/functions/to-boolean-string.function.ts +3 -0
  122. package/src/lib/functions/to-calendar-date.function.ts +11 -0
  123. package/src/lib/functions/to-csv-string.function.ts +3 -0
  124. package/src/lib/functions/to-decimal-base.function.ts +23 -0
  125. package/src/lib/functions/to-dollars-and-cents.function.spec.ts +7 -0
  126. package/src/lib/functions/to-dollars-and-cents.function.ts +15 -0
  127. package/src/lib/functions/to-string.function.ts +25 -0
  128. package/src/lib/functions/to-unique-array.function.spec.ts +45 -0
  129. package/src/lib/functions/to-unique-array.function.ts +3 -0
  130. package/src/lib/functions/to-words.function.spec.ts +7 -0
  131. package/src/lib/functions/to-words.function.ts +105 -0
  132. package/src/lib/functions/try-parse-date.function.spec.ts +12 -0
  133. package/src/lib/functions/try-parse-date.function.ts +17 -0
  134. package/src/lib/functions/unicode-words.const.ts +70 -0
  135. package/src/lib/functions/upper-first.function.spec.ts +16 -0
  136. package/src/lib/functions/upper-first.function.ts +10 -0
  137. package/src/lib/functions/words.function.ts +38 -0
  138. package/src/lib/interfaces/axios-wrapped-nest-exception.interface.ts +5 -0
  139. package/src/lib/interfaces/entity-provider.interface.ts +9 -0
  140. package/src/lib/interfaces/keys-of.type.ts +1 -0
  141. package/tsconfig.json +16 -0
  142. package/index.cjs.js +0 -465
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ // source https://github.com/lodash/lodash/blob/master/.internal/unicodeWords.js
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.unicodeWords = void 0;
5
+ /** Used to compose unicode character classes. */
6
+ const rsAstralRange = '\\ud800-\\udfff';
7
+ const rsComboMarksRange = '\\u0300-\\u036f';
8
+ const reComboHalfMarksRange = '\\ufe20-\\ufe2f';
9
+ const rsComboSymbolsRange = '\\u20d0-\\u20ff';
10
+ const rsComboMarksExtendedRange = '\\u1ab0-\\u1aff';
11
+ const rsComboMarksSupplementRange = '\\u1dc0-\\u1dff';
12
+ const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange + rsComboMarksExtendedRange + rsComboMarksSupplementRange;
13
+ const rsDingbatRange = '\\u2700-\\u27bf';
14
+ const rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff';
15
+ const rsMathOpRange = '\\xac\\xb1\\xd7\\xf7';
16
+ const rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf';
17
+ const rsPunctuationRange = '\\u2000-\\u206f';
18
+ const rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000';
19
+ const rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde';
20
+ const rsVarRange = '\\ufe0e\\ufe0f';
21
+ const rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
22
+ /** Used to compose unicode capture groups. */
23
+ const rsApos = "['\u2019]";
24
+ const rsBreak = `[${rsBreakRange}]`;
25
+ const rsCombo = `[${rsComboRange}]`;
26
+ const rsDigit = '\\d';
27
+ const rsDingbat = `[${rsDingbatRange}]`;
28
+ const rsLower = `[${rsLowerRange}]`;
29
+ const rsMisc = `[^${rsAstralRange}${rsBreakRange + rsDigit + rsDingbatRange + rsLowerRange + rsUpperRange}]`;
30
+ const rsFitz = '\\ud83c[\\udffb-\\udfff]';
31
+ const rsModifier = `(?:${rsCombo}|${rsFitz})`;
32
+ const rsNonAstral = `[^${rsAstralRange}]`;
33
+ const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}';
34
+ const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]';
35
+ const rsUpper = `[${rsUpperRange}]`;
36
+ const rsZWJ = '\\u200d';
37
+ /** Used to compose unicode regexes. */
38
+ const rsMiscLower = `(?:${rsLower}|${rsMisc})`;
39
+ const rsMiscUpper = `(?:${rsUpper}|${rsMisc})`;
40
+ const rsOptContrLower = `(?:${rsApos}(?:d|ll|m|re|s|t|ve))?`;
41
+ const rsOptContrUpper = `(?:${rsApos}(?:D|LL|M|RE|S|T|VE))?`;
42
+ const reOptMod = `${rsModifier}?`;
43
+ const rsOptVar = `[${rsVarRange}]?`;
44
+ const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*`;
45
+ const rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])';
46
+ const rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])';
47
+ const rsSeq = rsOptVar + reOptMod + rsOptJoin;
48
+ const rsEmoji = `(?:${[rsDingbat, rsRegional, rsSurrPair].join('|')})${rsSeq}`;
49
+ const reUnicodeWords = RegExp([
50
+ `${rsUpper}?${rsLower}+${rsOptContrLower}(?=${[rsBreak, rsUpper, '$'].join('|')})`,
51
+ `${rsMiscUpper}+${rsOptContrUpper}(?=${[rsBreak, rsUpper + rsMiscLower, '$'].join('|')})`,
52
+ `${rsUpper}?${rsMiscLower}+${rsOptContrLower}`,
53
+ `${rsUpper}+${rsOptContrUpper}`,
54
+ rsOrdUpper,
55
+ rsOrdLower,
56
+ `${rsDigit}+`,
57
+ rsEmoji
58
+ ].join('|'), 'g');
59
+ /**
60
+ * Splits a Unicode `string` into an array of its words.
61
+ *
62
+ * @private
63
+ * @param {string} The string to inspect.
64
+ * @returns {Array} Returns the words of `string`.
65
+ */
66
+ function unicodeWords(string) {
67
+ return string.match(reUnicodeWords);
68
+ }
69
+ exports.unicodeWords = unicodeWords;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.upperFirst = void 0;
4
+ function upperFirst(string) {
5
+ if (!string) {
6
+ return string;
7
+ }
8
+ return string
9
+ .split('')
10
+ .map((curr, i) => curr[!i ? 'toUpperCase' : 'toLowerCase']())
11
+ .join('');
12
+ }
13
+ exports.upperFirst = upperFirst;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const upper_first_function_1 = require("./upper-first.function");
4
+ describe('upperFirst', () => {
5
+ it.each([
6
+ 'asdf',
7
+ 'XCVB'
8
+ ])('GIVEN %j, does what u expect', (input) => {
9
+ expect((0, upper_first_function_1.upperFirst)(input)).toMatchSnapshot();
10
+ });
11
+ it.each([
12
+ null, undefined, 0, false
13
+ ])('GIVEN falsey input %j, does what u expect', (input) => {
14
+ expect((0, upper_first_function_1.upperFirst)(input)).toMatchSnapshot();
15
+ });
16
+ });
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ // source https://github.com/lodash/lodash/blob/master/words.js
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.words = void 0;
5
+ const unicode_words_const_1 = require("./unicode-words.const");
6
+ const hasUnicodeWord = RegExp.prototype.test.bind(/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/);
7
+ /** Used to match words composed of alphanumeric characters. */
8
+ const reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
9
+ function asciiWords(string) {
10
+ return string.match(reAsciiWord);
11
+ }
12
+ /**
13
+ * Splits `string` into an array of its words.
14
+ *
15
+ * @since 3.0.0
16
+ * @category String
17
+ * @param {string} [string=''] The string to inspect.
18
+ * @param {RegExp|string} [pattern] The pattern to match words.
19
+ * @returns {Array} Returns the words of `string`.
20
+ * @example
21
+ *
22
+ * words('fred, barney, & pebbles')
23
+ * // => ['fred', 'barney', 'pebbles']
24
+ *
25
+ * words('fred, barney, & pebbles', /[^, ]+/g)
26
+ * // => ['fred', 'barney', '&', 'pebbles']
27
+ */
28
+ function words(string, pattern) {
29
+ if (pattern === undefined) {
30
+ const result = hasUnicodeWord(string) ? (0, unicode_words_const_1.unicodeWords)(string) : asciiWords(string);
31
+ return result || [];
32
+ }
33
+ return string.match(pattern) || [];
34
+ }
35
+ exports.words = words;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@onivoro/isomorphic-common",
3
+ "version": "0.2.1",
4
+ "module": "esm/index.js",
5
+ "type": "module",
6
+ "main": "cjs/index.js",
7
+ "scripts": {
8
+ "esb": "npx esbuild src/index.ts --bundle --platform=node --target=node16.20.2 > dist/index.cjs.js",
9
+ "ts": "npx tsc --module es2022 --outDir esm/ && echo '{\"type\": \"module\"}' > esm/package.json",
10
+ "push": "npm run ts && cp package.json dist && npm publish --access public"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "require": "./cjs/index.js",
15
+ "import": "./esm/index.js"
16
+ }
17
+ },
18
+ "devDependencies": {
19
+ "@types/jest": "^29.5.12",
20
+ "typescript": "^5.3.3"
21
+ }
22
+ }
@@ -0,0 +1,17 @@
1
+ /* eslint-disable */
2
+ export default {
3
+ displayName: 'isomorphic-common',
4
+ preset: '../../jest.preset.js',
5
+ globals: {},
6
+ testEnvironment: 'node',
7
+ transform: {
8
+ '^.+\\.[tj]sx?$': [
9
+ 'ts-jest',
10
+ {
11
+ tsconfig: '<rootDir>/tsconfig.spec.json',
12
+ },
13
+ ],
14
+ },
15
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
16
+ coverageDirectory: '../../coverage/libs/isomorphic-common',
17
+ };
@@ -0,0 +1 @@
1
+ {"type": "module"}
@@ -0,0 +1,29 @@
1
+ export * from './lib/constants/millis-per-day.constant';
2
+ export * from './lib/constants/millis-per-hour.constant';
3
+ export * from './lib/constants/millis-per-minute.constant';
4
+ export * from './lib/functions/add-offset.function';
5
+ export * from './lib/functions/camel-case.function';
6
+ export * from './lib/functions/convert-object-to-literal.function';
7
+ export * from './lib/functions/from-boolean-string.function';
8
+ export * from './lib/functions/from-calendar-date.function';
9
+ export * from './lib/functions/from-csv-string.function';
10
+ export * from './lib/functions/kebab-case.function';
11
+ export * from './lib/functions/parse-bool.function';
12
+ export * from './lib/functions/properties-to-array.function';
13
+ export * from './lib/functions/sanitize-filename.function';
14
+ export * from './lib/functions/snake-case.function';
15
+ export * from './lib/functions/subtract-offset.function';
16
+ export * from './lib/functions/to-boolean-string.function';
17
+ export * from './lib/functions/to-calendar-date.function';
18
+ export * from './lib/functions/to-csv-string.function';
19
+ export * from './lib/functions/to-decimal-base.function';
20
+ export * from './lib/functions/to-dollars-and-cents.function';
21
+ export * from './lib/functions/to-unique-array.function';
22
+ export * from './lib/functions/to-words.function';
23
+ export * from './lib/functions/try-parse-date.function';
24
+ export * from './lib/functions/unicode-words.const';
25
+ export * from './lib/functions/upper-first.function';
26
+ export * from './lib/functions/words.function';
27
+ export * from './lib/interfaces/axios-wrapped-nest-exception.interface';
28
+ export * from './lib/interfaces/entity-provider.interface';
29
+ export * from './lib/interfaces/keys-of.type';
@@ -0,0 +1,2 @@
1
+ import { MILLIS_PER_HOUR } from "./millis-per-hour.constant";
2
+ export const MILLIS_PER_DAY = MILLIS_PER_HOUR * 24;
@@ -0,0 +1,2 @@
1
+ import { MILLIS_PER_MINUTE } from "./millis-per-minute.constant";
2
+ export const MILLIS_PER_HOUR = MILLIS_PER_MINUTE * 60;
@@ -0,0 +1 @@
1
+ export const MILLIS_PER_MINUTE = 1000 * 60;
@@ -0,0 +1,10 @@
1
+ import { MILLIS_PER_MINUTE } from '../constants/millis-per-minute.constant';
2
+ import { tryParseDate } from './try-parse-date.function';
3
+ export function addOffset(input) {
4
+ const parsed = tryParseDate(input);
5
+ if (!parsed) {
6
+ return;
7
+ }
8
+ const offset = (parsed).getTimezoneOffset();
9
+ return new Date(parsed.valueOf() + offset * MILLIS_PER_MINUTE);
10
+ }
@@ -0,0 +1,11 @@
1
+ import { addOffset } from './add-offset.function';
2
+ describe('addOffset', () => {
3
+ describe('GIVEN input is partial or full ISO8601', () => {
4
+ it.each([
5
+ '2023-12-23',
6
+ '2023-12-23T00:00:00.000',
7
+ ])('%j', (input) => {
8
+ expect(addOffset(input)).toMatchSnapshot();
9
+ });
10
+ });
11
+ });
@@ -0,0 +1,27 @@
1
+ // https://github.com/lodash/lodash/blob/main/src/camelCase.ts
2
+ import { toString } from './to-string.function';
3
+ import { upperFirst } from './upper-first.function';
4
+ import { words } from './words.function';
5
+ /**
6
+ * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
7
+ *
8
+ * @since 3.0.0
9
+ * @category String
10
+ * @param {string} [string=''] The string to convert.
11
+ * @returns {string} Returns the camel cased string.
12
+ * @see lowerCase, kebabCase, snakeCase, startCase, upperCase, upperFirst
13
+ * @example
14
+ *
15
+ * camelCase('Foo Bar')
16
+ * // => 'fooBar'
17
+ *
18
+ * camelCase('--foo-bar--')
19
+ * // => 'fooBar'
20
+ *
21
+ * camelCase('__FOO_BAR__')
22
+ * // => 'fooBar'
23
+ */
24
+ export const camelCase = (string) => words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => {
25
+ word = word.toLowerCase();
26
+ return result + (index ? upperFirst(word) : word);
27
+ }, '');
@@ -0,0 +1,6 @@
1
+ export function convertObjectToLiteral(literalFn, delimiter, keyValuePairs) {
2
+ return Object.entries(keyValuePairs)
3
+ .filter(([, v]) => !!v || v === 0 || v === false)
4
+ .map(([k, v]) => literalFn(k, v?.toString?.()))
5
+ .join(delimiter);
6
+ }
@@ -0,0 +1,9 @@
1
+ import { convertObjectToLiteral } from './convert-object-to-literal.function';
2
+ const qty = 337;
3
+ const price = 100;
4
+ const product = 'flux-capacitor';
5
+ describe(__filename, () => {
6
+ it.each([[(k, v) => `${k}=${v}`, ' AND ', { qty, price, product }]])('converts an object to a string', (literalFn, delimiter, obj) => {
7
+ expect(convertObjectToLiteral(literalFn, delimiter, obj)).toMatchSnapshot();
8
+ });
9
+ });
@@ -0,0 +1,3 @@
1
+ export function fromBooleanString(value) {
2
+ return value === 'true';
3
+ }
@@ -0,0 +1,4 @@
1
+ import { addOffset } from "./add-offset.function";
2
+ export function fromCalendarDate(input) {
3
+ return addOffset(input) || null;
4
+ }
@@ -0,0 +1,10 @@
1
+ import { fromCalendarDate } from './from-calendar-date.function';
2
+ describe('fromCalendarDate', () => {
3
+ describe('GIVEN input is partial or full ISO8601', () => {
4
+ it.each([
5
+ '2023-12-23',
6
+ ])('%j', (input) => {
7
+ expect(fromCalendarDate(input)).toMatchSnapshot();
8
+ });
9
+ });
10
+ });
@@ -0,0 +1,3 @@
1
+ export function fromCsvString(value) {
2
+ return value ? value.split(',').map((v) => v.trim()) : [];
3
+ }
@@ -0,0 +1,8 @@
1
+ // https://github.com/lodash/lodash/blob/main/src/.internal/getTag.ts
2
+ const toString = Object.prototype.toString;
3
+ export function getTag(value) {
4
+ if (value == null) {
5
+ return value === undefined ? '[object Undefined]' : '[object Null]';
6
+ }
7
+ return toString.call(value);
8
+ }
@@ -0,0 +1,7 @@
1
+ // https://github.com/lodash/lodash/blob/main/src/isSymbol.ts
2
+ import { getTag } from './get-tag.function';
3
+ export function isSymbol(value) {
4
+ const type = typeof value;
5
+ return (type === 'symbol' ||
6
+ (type === 'object' && value != null && getTag(value) === '[object Symbol]'));
7
+ }
@@ -0,0 +1,4 @@
1
+ import { snakeCase } from "./snake-case.function";
2
+ export function kebabCase(string) {
3
+ return snakeCase(string).replace(/_/g, '-');
4
+ }
@@ -0,0 +1,3 @@
1
+ export function parseBool(asc) {
2
+ return asc ? asc === true || asc === 'true' : false;
3
+ }
@@ -0,0 +1,15 @@
1
+ // credit https://stackoverflow.com/questions/15690706/recursively-looping-through-an-object-to-build-a-property-list/53620876#53620876
2
+ export function propertiesToArray(obj) {
3
+ const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
4
+ const addDelimiter = (a, b) => a ? `${a}.${b}` : b;
5
+ const paths = (obj = {}, head = '') => {
6
+ return Object.entries(obj)
7
+ .reduce((product, [key, value]) => {
8
+ let fullPath = addDelimiter(head, key);
9
+ return isObject(value) ?
10
+ product.concat(paths(value, fullPath))
11
+ : product.concat(fullPath);
12
+ }, []);
13
+ };
14
+ return paths(obj);
15
+ }
@@ -0,0 +1,7 @@
1
+ /* eslint-disable no-control-regex */
2
+ const _ = '_';
3
+ const asciiReplacementRegX = /\/|\?|:|\\|{|\^|'|\}|%|`|]|>|\[|~|<|#|\||"|!|\*/g;
4
+ const unicodeReplacementRegX = /[^\u0000-\u007F]/g;
5
+ export function sanitizeFilename(filename) {
6
+ return filename.replace(unicodeReplacementRegX, _).replace(asciiReplacementRegX, _).replace(/_+/g, _).trim();
7
+ }
@@ -0,0 +1,28 @@
1
+ // source https://github.com/lodash/lodash/blob/master/snakeCase.js
2
+ import { words } from "./words.function";
3
+ /**
4
+ * Converts `string` to
5
+ * [snake case](https://en.wikipedia.org/wiki/Snake_case).
6
+ *
7
+ * @since 3.0.0
8
+ * @category String
9
+ * @param {string} [string=''] The string to convert.
10
+ * @returns {string} Returns the snake cased string.
11
+ * @see camelCase, lowerCase, kebabCase, startCase, upperCase, upperFirst
12
+ * @example
13
+ *
14
+ * snakeCase('Foo Bar')
15
+ * // => 'foo_bar'
16
+ *
17
+ * snakeCase('fooBar')
18
+ * // => 'foo_bar'
19
+ *
20
+ * snakeCase('--FOO-BAR--')
21
+ * // => 'foo_bar'
22
+ *
23
+ * snakeCase('foo2bar')
24
+ * // => 'foo_2_bar'
25
+ */
26
+ export function snakeCase(string) {
27
+ return (words(string.replace(/['\u2019]/g, '')).reduce((result, word, index) => (result + (index ? '_' : '') + word.toLowerCase()), ''));
28
+ }
@@ -0,0 +1,10 @@
1
+ import { MILLIS_PER_MINUTE } from '../constants/millis-per-minute.constant';
2
+ import { tryParseDate } from './try-parse-date.function';
3
+ export function subtractOffset(input) {
4
+ const parsed = tryParseDate(input);
5
+ if (!parsed) {
6
+ return;
7
+ }
8
+ const offset = (parsed).getTimezoneOffset();
9
+ return new Date(parsed.valueOf() - offset * MILLIS_PER_MINUTE);
10
+ }
@@ -0,0 +1,11 @@
1
+ import { subtractOffset } from './subtract-offset.function';
2
+ describe('subtractOffset', () => {
3
+ describe('GIVEN input is partial or full ISO8601', () => {
4
+ it.each([
5
+ '2023-12-23',
6
+ '2023-12-23T00:00:00.000',
7
+ ])('%j', (input) => {
8
+ expect(subtractOffset(input)).toMatchSnapshot();
9
+ });
10
+ });
11
+ });
@@ -0,0 +1,3 @@
1
+ export function toBooleanString(val) {
2
+ return (!!(val || false)).toString();
3
+ }
@@ -0,0 +1,8 @@
1
+ import { subtractOffset } from "./subtract-offset.function";
2
+ export function toCalendarDate(input) {
3
+ const parsed = subtractOffset(input);
4
+ if (!parsed) {
5
+ return;
6
+ }
7
+ return parsed?.toISOString().split('T')[0];
8
+ }
@@ -0,0 +1,3 @@
1
+ export function toCsvString(val) {
2
+ return (val || []).join(',');
3
+ }
@@ -0,0 +1,18 @@
1
+ export function toDecimalBase(n, base = 16) {
2
+ const digits = n.toString().split('');
3
+ let answer = 0;
4
+ digits.reverse().forEach(function (d, i) {
5
+ let actualNumber = Number(d);
6
+ if (!actualNumber && actualNumber !== 0) {
7
+ const codeAt = d.charCodeAt(0);
8
+ if (codeAt >= 97) {
9
+ actualNumber = codeAt - 87;
10
+ }
11
+ else {
12
+ actualNumber = codeAt - 55;
13
+ }
14
+ }
15
+ answer = answer + actualNumber * Math.pow(base, i);
16
+ });
17
+ return answer;
18
+ }
@@ -0,0 +1,11 @@
1
+ import { toWords } from "./to-words.function";
2
+ export function toDollarsAndCents(number) {
3
+ const num = Number(number);
4
+ const decimal = (Math.round((num % 1) * 100)) / 100;
5
+ const int = num - decimal;
6
+ const dollars = `${toWords(int)} dollars`;
7
+ if (!decimal) {
8
+ return dollars;
9
+ }
10
+ return `${dollars} and ${toWords(decimal * 100)} cents`;
11
+ }
@@ -0,0 +1,6 @@
1
+ import { toDollarsAndCents } from './to-dollars-and-cents.function';
2
+ describe('toDollarsAndCents', () => {
3
+ it('worx', () => {
4
+ expect(toDollarsAndCents(337.33)).toMatchSnapshot();
5
+ });
6
+ });
@@ -0,0 +1,22 @@
1
+ // https://github.com/lodash/lodash/blob/main/src/toString.ts
2
+ import { isSymbol } from './is-symbol.function';
3
+ /** Used as references for various `Number` constants. */
4
+ const INFINITY = 1 / 0;
5
+ export function toString(value) {
6
+ if (value == null) {
7
+ return '';
8
+ }
9
+ // Exit early for strings to avoid a performance hit in some environments.
10
+ if (typeof value === 'string') {
11
+ return value;
12
+ }
13
+ if (Array.isArray(value)) {
14
+ // Recursively convert values (susceptible to call stack limits).
15
+ return `${value.map((other) => (other == null ? other : toString(other)))}`;
16
+ }
17
+ if (isSymbol(value)) {
18
+ return value.toString();
19
+ }
20
+ const result = `${value}`;
21
+ return result === '0' && 1 / value === -INFINITY ? '-0' : result;
22
+ }
@@ -0,0 +1,3 @@
1
+ export function toUniqueArray(elements) {
2
+ return Array.from(new Set(elements));
3
+ }
@@ -0,0 +1,33 @@
1
+ import { toUniqueArray } from './to-unique-array.function';
2
+ describe('toUniqueArray', () => {
3
+ it.each([
4
+ [
5
+ [1, 2, 3],
6
+ [1, 2, 3],
7
+ ],
8
+ [[1, 1, 1], [1]],
9
+ ])('GIVEN array of numbers: %j, returns a unique array without duplicate elements', (array, expected) => {
10
+ expect(toUniqueArray(array)).toEqual(expected);
11
+ });
12
+ it.each([
13
+ [
14
+ ['one', 'two', 'three'],
15
+ ['one', 'two', 'three'],
16
+ ],
17
+ [['one', 'one', 'one'], ['one']],
18
+ ])('GIVEN array of strings: %j, returns a unique array without duplicate elements', (array, expected) => {
19
+ expect(toUniqueArray(array)).toEqual(expected);
20
+ });
21
+ it.each([
22
+ [
23
+ ['one', 'two', 'three', undefined, undefined],
24
+ ['one', 'two', 'three', undefined],
25
+ ],
26
+ [
27
+ ['one', 'one', 'one', null, null],
28
+ ['one', null],
29
+ ],
30
+ ])('GIVEN array with falsey values: %j, returns a unique array without duplicate elements including falsey values', (array, expected) => {
31
+ expect(toUniqueArray(array)).toEqual(expected);
32
+ });
33
+ });