@onivoro/isomorphic-common 0.1.0 → 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.
- package/cjs/jest.config.js +19 -0
- package/cjs/src/index.js +45 -0
- package/cjs/src/lib/constants/millis-per-day.constant.js +5 -0
- package/cjs/src/lib/constants/millis-per-hour.constant.js +5 -0
- package/cjs/src/lib/constants/millis-per-minute.constant.js +4 -0
- package/cjs/src/lib/functions/add-offset.function.js +14 -0
- package/cjs/src/lib/functions/add-offset.function.spec.js +13 -0
- package/cjs/src/lib/functions/camel-case.function.js +31 -0
- package/cjs/src/lib/functions/convert-object-to-literal.function.js +10 -0
- package/cjs/src/lib/functions/convert-object-to-literal.function.spec.js +11 -0
- package/cjs/src/lib/functions/from-boolean-string.function.js +7 -0
- package/cjs/src/lib/functions/from-calendar-date.function.js +8 -0
- package/cjs/src/lib/functions/from-calendar-date.function.spec.js +12 -0
- package/cjs/src/lib/functions/from-csv-string.function.js +7 -0
- package/cjs/src/lib/functions/get-tag.function.js +12 -0
- package/cjs/src/lib/functions/is-symbol.function.js +11 -0
- package/cjs/src/lib/functions/kebab-case.function.js +8 -0
- package/cjs/src/lib/functions/parse-bool.function.js +7 -0
- package/cjs/src/lib/functions/properties-to-array.function.js +19 -0
- package/cjs/src/lib/functions/sanitize-filename.function.js +11 -0
- package/cjs/src/lib/functions/snake-case.function.js +32 -0
- package/cjs/src/lib/functions/subtract-offset.function.js +14 -0
- package/cjs/src/lib/functions/subtract-offset.function.spec.js +13 -0
- package/cjs/src/lib/functions/to-boolean-string.function.js +7 -0
- package/cjs/src/lib/functions/to-calendar-date.function.js +12 -0
- package/cjs/src/lib/functions/to-csv-string.function.js +7 -0
- package/cjs/src/lib/functions/to-decimal-base.function.js +22 -0
- package/cjs/src/lib/functions/to-dollars-and-cents.function.js +15 -0
- package/cjs/src/lib/functions/to-dollars-and-cents.function.spec.js +8 -0
- package/cjs/src/lib/functions/to-string.function.js +26 -0
- package/cjs/src/lib/functions/to-unique-array.function.js +7 -0
- package/cjs/src/lib/functions/to-unique-array.function.spec.js +35 -0
- package/cjs/src/lib/functions/to-words.function.js +90 -0
- package/cjs/src/lib/functions/to-words.function.spec.js +8 -0
- package/cjs/src/lib/functions/try-parse-date.function.js +17 -0
- package/cjs/src/lib/functions/try-parse-date.function.spec.js +13 -0
- package/cjs/src/lib/functions/unicode-words.const.js +69 -0
- package/cjs/src/lib/functions/upper-first.function.js +13 -0
- package/cjs/src/lib/functions/upper-first.function.spec.js +16 -0
- package/cjs/src/lib/functions/words.function.js +35 -0
- package/cjs/src/lib/interfaces/axios-wrapped-nest-exception.interface.js +2 -0
- package/cjs/src/lib/interfaces/entity-provider.interface.js +2 -0
- package/cjs/src/lib/interfaces/keys-of.type.js +2 -0
- package/dist +22 -0
- package/esm/jest.config.js +17 -0
- package/esm/package.json +1 -0
- package/esm/src/index.js +29 -0
- package/esm/src/lib/constants/millis-per-day.constant.js +2 -0
- package/esm/src/lib/constants/millis-per-hour.constant.js +2 -0
- package/esm/src/lib/constants/millis-per-minute.constant.js +1 -0
- package/esm/src/lib/functions/add-offset.function.js +10 -0
- package/esm/src/lib/functions/add-offset.function.spec.js +11 -0
- package/esm/src/lib/functions/camel-case.function.js +27 -0
- package/esm/src/lib/functions/convert-object-to-literal.function.js +6 -0
- package/esm/src/lib/functions/convert-object-to-literal.function.spec.js +9 -0
- package/esm/src/lib/functions/from-boolean-string.function.js +3 -0
- package/esm/src/lib/functions/from-calendar-date.function.js +4 -0
- package/esm/src/lib/functions/from-calendar-date.function.spec.js +10 -0
- package/esm/src/lib/functions/from-csv-string.function.js +3 -0
- package/esm/src/lib/functions/get-tag.function.js +8 -0
- package/esm/src/lib/functions/is-symbol.function.js +7 -0
- package/esm/src/lib/functions/kebab-case.function.js +4 -0
- package/esm/src/lib/functions/parse-bool.function.js +3 -0
- package/esm/src/lib/functions/properties-to-array.function.js +15 -0
- package/esm/src/lib/functions/sanitize-filename.function.js +7 -0
- package/esm/src/lib/functions/snake-case.function.js +28 -0
- package/esm/src/lib/functions/subtract-offset.function.js +10 -0
- package/esm/src/lib/functions/subtract-offset.function.spec.js +11 -0
- package/esm/src/lib/functions/to-boolean-string.function.js +3 -0
- package/esm/src/lib/functions/to-calendar-date.function.js +8 -0
- package/esm/src/lib/functions/to-csv-string.function.js +3 -0
- package/esm/src/lib/functions/to-decimal-base.function.js +18 -0
- package/esm/src/lib/functions/to-dollars-and-cents.function.js +11 -0
- package/esm/src/lib/functions/to-dollars-and-cents.function.spec.js +6 -0
- package/esm/src/lib/functions/to-string.function.js +22 -0
- package/esm/src/lib/functions/to-unique-array.function.js +3 -0
- package/esm/src/lib/functions/to-unique-array.function.spec.js +33 -0
- package/esm/src/lib/functions/to-words.function.js +86 -0
- package/esm/src/lib/functions/to-words.function.spec.js +6 -0
- package/esm/src/lib/functions/try-parse-date.function.js +13 -0
- package/esm/src/lib/functions/try-parse-date.function.spec.js +11 -0
- package/esm/src/lib/functions/unicode-words.const.js +65 -0
- package/esm/src/lib/functions/upper-first.function.js +9 -0
- package/esm/src/lib/functions/upper-first.function.spec.js +14 -0
- package/esm/src/lib/functions/words.function.js +31 -0
- package/esm/src/lib/interfaces/axios-wrapped-nest-exception.interface.js +1 -0
- package/esm/src/lib/interfaces/entity-provider.interface.js +1 -0
- package/esm/src/lib/interfaces/keys-of.type.js +1 -0
- package/jest.config.ts +17 -0
- package/package.json +16 -4
- package/src/index.ts +31 -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/functions/__snapshots__/add-offset.function.spec.ts.snap +5 -0
- package/src/lib/functions/__snapshots__/convert-object-to-literal.function.spec.ts.snap +3 -0
- package/src/lib/functions/__snapshots__/from-calendar-date.function.spec.ts.snap +3 -0
- package/src/lib/functions/__snapshots__/subtract-offset.function.spec.ts.snap +5 -0
- package/src/lib/functions/__snapshots__/to-dollars-and-cents.function.spec.ts.snap +3 -0
- package/src/lib/functions/__snapshots__/to-words.function.spec.ts.snap +3 -0
- package/src/lib/functions/__snapshots__/try-parse-date.function.spec.ts.snap +5 -0
- package/src/lib/functions/__snapshots__/upper-first.function.spec.ts.snap +13 -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/camel-case.function.ts +30 -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/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-tag.function.ts +10 -0
- package/src/lib/functions/is-symbol.function.ts +11 -0
- package/src/lib/functions/kebab-case.function.ts +5 -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/sanitize-filename.function.ts +9 -0
- package/src/lib/functions/snake-case.function.ts +34 -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/src/lib/functions/to-decimal-base.function.ts +23 -0
- package/src/lib/functions/to-dollars-and-cents.function.spec.ts +7 -0
- package/src/lib/functions/to-dollars-and-cents.function.ts +15 -0
- package/src/lib/functions/to-string.function.ts +25 -0
- 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/src/lib/functions/to-words.function.ts +105 -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/words.function.ts +38 -0
- package/src/lib/interfaces/axios-wrapped-nest-exception.interface.ts +5 -0
- package/src/lib/interfaces/entity-provider.interface.ts +9 -0
- package/src/lib/interfaces/keys-of.type.ts +1 -0
- package/tsconfig.json +16 -0
- 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;
|
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
|
+
};
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module"}
|
package/esm/src/index.js
ADDED
|
@@ -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 @@
|
|
|
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,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,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,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,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,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,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,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
|
+
});
|