@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.
- 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 -6
- 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,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
exports.default = {
|
|
5
|
+
displayName: 'isomorphic-common',
|
|
6
|
+
preset: '../../jest.preset.js',
|
|
7
|
+
globals: {},
|
|
8
|
+
testEnvironment: 'node',
|
|
9
|
+
transform: {
|
|
10
|
+
'^.+\\.[tj]sx?$': [
|
|
11
|
+
'ts-jest',
|
|
12
|
+
{
|
|
13
|
+
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
|
18
|
+
coverageDirectory: '../../coverage/libs/isomorphic-common',
|
|
19
|
+
};
|
package/cjs/src/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./lib/constants/millis-per-day.constant"), exports);
|
|
18
|
+
__exportStar(require("./lib/constants/millis-per-hour.constant"), exports);
|
|
19
|
+
__exportStar(require("./lib/constants/millis-per-minute.constant"), exports);
|
|
20
|
+
__exportStar(require("./lib/functions/add-offset.function"), exports);
|
|
21
|
+
__exportStar(require("./lib/functions/camel-case.function"), exports);
|
|
22
|
+
__exportStar(require("./lib/functions/convert-object-to-literal.function"), exports);
|
|
23
|
+
__exportStar(require("./lib/functions/from-boolean-string.function"), exports);
|
|
24
|
+
__exportStar(require("./lib/functions/from-calendar-date.function"), exports);
|
|
25
|
+
__exportStar(require("./lib/functions/from-csv-string.function"), exports);
|
|
26
|
+
__exportStar(require("./lib/functions/kebab-case.function"), exports);
|
|
27
|
+
__exportStar(require("./lib/functions/parse-bool.function"), exports);
|
|
28
|
+
__exportStar(require("./lib/functions/properties-to-array.function"), exports);
|
|
29
|
+
__exportStar(require("./lib/functions/sanitize-filename.function"), exports);
|
|
30
|
+
__exportStar(require("./lib/functions/snake-case.function"), exports);
|
|
31
|
+
__exportStar(require("./lib/functions/subtract-offset.function"), exports);
|
|
32
|
+
__exportStar(require("./lib/functions/to-boolean-string.function"), exports);
|
|
33
|
+
__exportStar(require("./lib/functions/to-calendar-date.function"), exports);
|
|
34
|
+
__exportStar(require("./lib/functions/to-csv-string.function"), exports);
|
|
35
|
+
__exportStar(require("./lib/functions/to-decimal-base.function"), exports);
|
|
36
|
+
__exportStar(require("./lib/functions/to-dollars-and-cents.function"), exports);
|
|
37
|
+
__exportStar(require("./lib/functions/to-unique-array.function"), exports);
|
|
38
|
+
__exportStar(require("./lib/functions/to-words.function"), exports);
|
|
39
|
+
__exportStar(require("./lib/functions/try-parse-date.function"), exports);
|
|
40
|
+
__exportStar(require("./lib/functions/unicode-words.const"), exports);
|
|
41
|
+
__exportStar(require("./lib/functions/upper-first.function"), exports);
|
|
42
|
+
__exportStar(require("./lib/functions/words.function"), exports);
|
|
43
|
+
__exportStar(require("./lib/interfaces/axios-wrapped-nest-exception.interface"), exports);
|
|
44
|
+
__exportStar(require("./lib/interfaces/entity-provider.interface"), exports);
|
|
45
|
+
__exportStar(require("./lib/interfaces/keys-of.type"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MILLIS_PER_HOUR = void 0;
|
|
4
|
+
const millis_per_minute_constant_1 = require("./millis-per-minute.constant");
|
|
5
|
+
exports.MILLIS_PER_HOUR = millis_per_minute_constant_1.MILLIS_PER_MINUTE * 60;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addOffset = void 0;
|
|
4
|
+
const millis_per_minute_constant_1 = require("../constants/millis-per-minute.constant");
|
|
5
|
+
const try_parse_date_function_1 = require("./try-parse-date.function");
|
|
6
|
+
function addOffset(input) {
|
|
7
|
+
const parsed = (0, try_parse_date_function_1.tryParseDate)(input);
|
|
8
|
+
if (!parsed) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const offset = (parsed).getTimezoneOffset();
|
|
12
|
+
return new Date(parsed.valueOf() + offset * millis_per_minute_constant_1.MILLIS_PER_MINUTE);
|
|
13
|
+
}
|
|
14
|
+
exports.addOffset = addOffset;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const add_offset_function_1 = require("./add-offset.function");
|
|
4
|
+
describe('addOffset', () => {
|
|
5
|
+
describe('GIVEN input is partial or full ISO8601', () => {
|
|
6
|
+
it.each([
|
|
7
|
+
'2023-12-23',
|
|
8
|
+
'2023-12-23T00:00:00.000',
|
|
9
|
+
])('%j', (input) => {
|
|
10
|
+
expect((0, add_offset_function_1.addOffset)(input)).toMatchSnapshot();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// https://github.com/lodash/lodash/blob/main/src/camelCase.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.camelCase = void 0;
|
|
5
|
+
const to_string_function_1 = require("./to-string.function");
|
|
6
|
+
const upper_first_function_1 = require("./upper-first.function");
|
|
7
|
+
const words_function_1 = require("./words.function");
|
|
8
|
+
/**
|
|
9
|
+
* Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
|
|
10
|
+
*
|
|
11
|
+
* @since 3.0.0
|
|
12
|
+
* @category String
|
|
13
|
+
* @param {string} [string=''] The string to convert.
|
|
14
|
+
* @returns {string} Returns the camel cased string.
|
|
15
|
+
* @see lowerCase, kebabCase, snakeCase, startCase, upperCase, upperFirst
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* camelCase('Foo Bar')
|
|
19
|
+
* // => 'fooBar'
|
|
20
|
+
*
|
|
21
|
+
* camelCase('--foo-bar--')
|
|
22
|
+
* // => 'fooBar'
|
|
23
|
+
*
|
|
24
|
+
* camelCase('__FOO_BAR__')
|
|
25
|
+
* // => 'fooBar'
|
|
26
|
+
*/
|
|
27
|
+
const camelCase = (string) => (0, words_function_1.words)((0, to_string_function_1.toString)(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => {
|
|
28
|
+
word = word.toLowerCase();
|
|
29
|
+
return result + (index ? (0, upper_first_function_1.upperFirst)(word) : word);
|
|
30
|
+
}, '');
|
|
31
|
+
exports.camelCase = camelCase;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertObjectToLiteral = void 0;
|
|
4
|
+
function convertObjectToLiteral(literalFn, delimiter, keyValuePairs) {
|
|
5
|
+
return Object.entries(keyValuePairs)
|
|
6
|
+
.filter(([, v]) => !!v || v === 0 || v === false)
|
|
7
|
+
.map(([k, v]) => literalFn(k, v?.toString?.()))
|
|
8
|
+
.join(delimiter);
|
|
9
|
+
}
|
|
10
|
+
exports.convertObjectToLiteral = convertObjectToLiteral;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const convert_object_to_literal_function_1 = require("./convert-object-to-literal.function");
|
|
4
|
+
const qty = 337;
|
|
5
|
+
const price = 100;
|
|
6
|
+
const product = 'flux-capacitor';
|
|
7
|
+
describe(__filename, () => {
|
|
8
|
+
it.each([[(k, v) => `${k}=${v}`, ' AND ', { qty, price, product }]])('converts an object to a string', (literalFn, delimiter, obj) => {
|
|
9
|
+
expect((0, convert_object_to_literal_function_1.convertObjectToLiteral)(literalFn, delimiter, obj)).toMatchSnapshot();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromCalendarDate = void 0;
|
|
4
|
+
const add_offset_function_1 = require("./add-offset.function");
|
|
5
|
+
function fromCalendarDate(input) {
|
|
6
|
+
return (0, add_offset_function_1.addOffset)(input) || null;
|
|
7
|
+
}
|
|
8
|
+
exports.fromCalendarDate = fromCalendarDate;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const from_calendar_date_function_1 = require("./from-calendar-date.function");
|
|
4
|
+
describe('fromCalendarDate', () => {
|
|
5
|
+
describe('GIVEN input is partial or full ISO8601', () => {
|
|
6
|
+
it.each([
|
|
7
|
+
'2023-12-23',
|
|
8
|
+
])('%j', (input) => {
|
|
9
|
+
expect((0, from_calendar_date_function_1.fromCalendarDate)(input)).toMatchSnapshot();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// https://github.com/lodash/lodash/blob/main/src/.internal/getTag.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getTag = void 0;
|
|
5
|
+
const toString = Object.prototype.toString;
|
|
6
|
+
function getTag(value) {
|
|
7
|
+
if (value == null) {
|
|
8
|
+
return value === undefined ? '[object Undefined]' : '[object Null]';
|
|
9
|
+
}
|
|
10
|
+
return toString.call(value);
|
|
11
|
+
}
|
|
12
|
+
exports.getTag = getTag;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// https://github.com/lodash/lodash/blob/main/src/isSymbol.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isSymbol = void 0;
|
|
5
|
+
const get_tag_function_1 = require("./get-tag.function");
|
|
6
|
+
function isSymbol(value) {
|
|
7
|
+
const type = typeof value;
|
|
8
|
+
return (type === 'symbol' ||
|
|
9
|
+
(type === 'object' && value != null && (0, get_tag_function_1.getTag)(value) === '[object Symbol]'));
|
|
10
|
+
}
|
|
11
|
+
exports.isSymbol = isSymbol;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.kebabCase = void 0;
|
|
4
|
+
const snake_case_function_1 = require("./snake-case.function");
|
|
5
|
+
function kebabCase(string) {
|
|
6
|
+
return (0, snake_case_function_1.snakeCase)(string).replace(/_/g, '-');
|
|
7
|
+
}
|
|
8
|
+
exports.kebabCase = kebabCase;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// credit https://stackoverflow.com/questions/15690706/recursively-looping-through-an-object-to-build-a-property-list/53620876#53620876
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.propertiesToArray = void 0;
|
|
5
|
+
function propertiesToArray(obj) {
|
|
6
|
+
const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
|
|
7
|
+
const addDelimiter = (a, b) => a ? `${a}.${b}` : b;
|
|
8
|
+
const paths = (obj = {}, head = '') => {
|
|
9
|
+
return Object.entries(obj)
|
|
10
|
+
.reduce((product, [key, value]) => {
|
|
11
|
+
let fullPath = addDelimiter(head, key);
|
|
12
|
+
return isObject(value) ?
|
|
13
|
+
product.concat(paths(value, fullPath))
|
|
14
|
+
: product.concat(fullPath);
|
|
15
|
+
}, []);
|
|
16
|
+
};
|
|
17
|
+
return paths(obj);
|
|
18
|
+
}
|
|
19
|
+
exports.propertiesToArray = propertiesToArray;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-control-regex */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.sanitizeFilename = void 0;
|
|
5
|
+
const _ = '_';
|
|
6
|
+
const asciiReplacementRegX = /\/|\?|:|\\|{|\^|'|\}|%|`|]|>|\[|~|<|#|\||"|!|\*/g;
|
|
7
|
+
const unicodeReplacementRegX = /[^\u0000-\u007F]/g;
|
|
8
|
+
function sanitizeFilename(filename) {
|
|
9
|
+
return filename.replace(unicodeReplacementRegX, _).replace(asciiReplacementRegX, _).replace(/_+/g, _).trim();
|
|
10
|
+
}
|
|
11
|
+
exports.sanitizeFilename = sanitizeFilename;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// source https://github.com/lodash/lodash/blob/master/snakeCase.js
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.snakeCase = void 0;
|
|
5
|
+
const words_function_1 = require("./words.function");
|
|
6
|
+
/**
|
|
7
|
+
* Converts `string` to
|
|
8
|
+
* [snake case](https://en.wikipedia.org/wiki/Snake_case).
|
|
9
|
+
*
|
|
10
|
+
* @since 3.0.0
|
|
11
|
+
* @category String
|
|
12
|
+
* @param {string} [string=''] The string to convert.
|
|
13
|
+
* @returns {string} Returns the snake cased string.
|
|
14
|
+
* @see camelCase, lowerCase, kebabCase, startCase, upperCase, upperFirst
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* snakeCase('Foo Bar')
|
|
18
|
+
* // => 'foo_bar'
|
|
19
|
+
*
|
|
20
|
+
* snakeCase('fooBar')
|
|
21
|
+
* // => 'foo_bar'
|
|
22
|
+
*
|
|
23
|
+
* snakeCase('--FOO-BAR--')
|
|
24
|
+
* // => 'foo_bar'
|
|
25
|
+
*
|
|
26
|
+
* snakeCase('foo2bar')
|
|
27
|
+
* // => 'foo_2_bar'
|
|
28
|
+
*/
|
|
29
|
+
function snakeCase(string) {
|
|
30
|
+
return ((0, words_function_1.words)(string.replace(/['\u2019]/g, '')).reduce((result, word, index) => (result + (index ? '_' : '') + word.toLowerCase()), ''));
|
|
31
|
+
}
|
|
32
|
+
exports.snakeCase = snakeCase;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subtractOffset = void 0;
|
|
4
|
+
const millis_per_minute_constant_1 = require("../constants/millis-per-minute.constant");
|
|
5
|
+
const try_parse_date_function_1 = require("./try-parse-date.function");
|
|
6
|
+
function subtractOffset(input) {
|
|
7
|
+
const parsed = (0, try_parse_date_function_1.tryParseDate)(input);
|
|
8
|
+
if (!parsed) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const offset = (parsed).getTimezoneOffset();
|
|
12
|
+
return new Date(parsed.valueOf() - offset * millis_per_minute_constant_1.MILLIS_PER_MINUTE);
|
|
13
|
+
}
|
|
14
|
+
exports.subtractOffset = subtractOffset;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const subtract_offset_function_1 = require("./subtract-offset.function");
|
|
4
|
+
describe('subtractOffset', () => {
|
|
5
|
+
describe('GIVEN input is partial or full ISO8601', () => {
|
|
6
|
+
it.each([
|
|
7
|
+
'2023-12-23',
|
|
8
|
+
'2023-12-23T00:00:00.000',
|
|
9
|
+
])('%j', (input) => {
|
|
10
|
+
expect((0, subtract_offset_function_1.subtractOffset)(input)).toMatchSnapshot();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCalendarDate = void 0;
|
|
4
|
+
const subtract_offset_function_1 = require("./subtract-offset.function");
|
|
5
|
+
function toCalendarDate(input) {
|
|
6
|
+
const parsed = (0, subtract_offset_function_1.subtractOffset)(input);
|
|
7
|
+
if (!parsed) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return parsed?.toISOString().split('T')[0];
|
|
11
|
+
}
|
|
12
|
+
exports.toCalendarDate = toCalendarDate;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toDecimalBase = void 0;
|
|
4
|
+
function toDecimalBase(n, base = 16) {
|
|
5
|
+
const digits = n.toString().split('');
|
|
6
|
+
let answer = 0;
|
|
7
|
+
digits.reverse().forEach(function (d, i) {
|
|
8
|
+
let actualNumber = Number(d);
|
|
9
|
+
if (!actualNumber && actualNumber !== 0) {
|
|
10
|
+
const codeAt = d.charCodeAt(0);
|
|
11
|
+
if (codeAt >= 97) {
|
|
12
|
+
actualNumber = codeAt - 87;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
actualNumber = codeAt - 55;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
answer = answer + actualNumber * Math.pow(base, i);
|
|
19
|
+
});
|
|
20
|
+
return answer;
|
|
21
|
+
}
|
|
22
|
+
exports.toDecimalBase = toDecimalBase;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toDollarsAndCents = void 0;
|
|
4
|
+
const to_words_function_1 = require("./to-words.function");
|
|
5
|
+
function toDollarsAndCents(number) {
|
|
6
|
+
const num = Number(number);
|
|
7
|
+
const decimal = (Math.round((num % 1) * 100)) / 100;
|
|
8
|
+
const int = num - decimal;
|
|
9
|
+
const dollars = `${(0, to_words_function_1.toWords)(int)} dollars`;
|
|
10
|
+
if (!decimal) {
|
|
11
|
+
return dollars;
|
|
12
|
+
}
|
|
13
|
+
return `${dollars} and ${(0, to_words_function_1.toWords)(decimal * 100)} cents`;
|
|
14
|
+
}
|
|
15
|
+
exports.toDollarsAndCents = toDollarsAndCents;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const to_dollars_and_cents_function_1 = require("./to-dollars-and-cents.function");
|
|
4
|
+
describe('toDollarsAndCents', () => {
|
|
5
|
+
it('worx', () => {
|
|
6
|
+
expect((0, to_dollars_and_cents_function_1.toDollarsAndCents)(337.33)).toMatchSnapshot();
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// https://github.com/lodash/lodash/blob/main/src/toString.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.toString = void 0;
|
|
5
|
+
const is_symbol_function_1 = require("./is-symbol.function");
|
|
6
|
+
/** Used as references for various `Number` constants. */
|
|
7
|
+
const INFINITY = 1 / 0;
|
|
8
|
+
function toString(value) {
|
|
9
|
+
if (value == null) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
// Exit early for strings to avoid a performance hit in some environments.
|
|
13
|
+
if (typeof value === 'string') {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
// Recursively convert values (susceptible to call stack limits).
|
|
18
|
+
return `${value.map((other) => (other == null ? other : toString(other)))}`;
|
|
19
|
+
}
|
|
20
|
+
if ((0, is_symbol_function_1.isSymbol)(value)) {
|
|
21
|
+
return value.toString();
|
|
22
|
+
}
|
|
23
|
+
const result = `${value}`;
|
|
24
|
+
return result === '0' && 1 / value === -INFINITY ? '-0' : result;
|
|
25
|
+
}
|
|
26
|
+
exports.toString = toString;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const to_unique_array_function_1 = require("./to-unique-array.function");
|
|
4
|
+
describe('toUniqueArray', () => {
|
|
5
|
+
it.each([
|
|
6
|
+
[
|
|
7
|
+
[1, 2, 3],
|
|
8
|
+
[1, 2, 3],
|
|
9
|
+
],
|
|
10
|
+
[[1, 1, 1], [1]],
|
|
11
|
+
])('GIVEN array of numbers: %j, returns a unique array without duplicate elements', (array, expected) => {
|
|
12
|
+
expect((0, to_unique_array_function_1.toUniqueArray)(array)).toEqual(expected);
|
|
13
|
+
});
|
|
14
|
+
it.each([
|
|
15
|
+
[
|
|
16
|
+
['one', 'two', 'three'],
|
|
17
|
+
['one', 'two', 'three'],
|
|
18
|
+
],
|
|
19
|
+
[['one', 'one', 'one'], ['one']],
|
|
20
|
+
])('GIVEN array of strings: %j, returns a unique array without duplicate elements', (array, expected) => {
|
|
21
|
+
expect((0, to_unique_array_function_1.toUniqueArray)(array)).toEqual(expected);
|
|
22
|
+
});
|
|
23
|
+
it.each([
|
|
24
|
+
[
|
|
25
|
+
['one', 'two', 'three', undefined, undefined],
|
|
26
|
+
['one', 'two', 'three', undefined],
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
['one', 'one', 'one', null, null],
|
|
30
|
+
['one', null],
|
|
31
|
+
],
|
|
32
|
+
])('GIVEN array with falsey values: %j, returns a unique array without duplicate elements including falsey values', (array, expected) => {
|
|
33
|
+
expect((0, to_unique_array_function_1.toUniqueArray)(array)).toEqual(expected);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toWords = void 0;
|
|
4
|
+
const MAX_SAFE_INTEGER = 9007199254740991;
|
|
5
|
+
const TEN = 10;
|
|
6
|
+
const ONE_HUNDRED = 100;
|
|
7
|
+
const ONE_THOUSAND = 1000;
|
|
8
|
+
const ONE_MILLION = 1000000;
|
|
9
|
+
const ONE_BILLION = 1000000000;
|
|
10
|
+
const ONE_TRILLION = 1000000000000;
|
|
11
|
+
const ONE_QUADRILLION = 1000000000000000;
|
|
12
|
+
const MAX = MAX_SAFE_INTEGER + 1;
|
|
13
|
+
const LESS_THAN_TWENTY = [
|
|
14
|
+
'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten',
|
|
15
|
+
'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'
|
|
16
|
+
];
|
|
17
|
+
const TENTHS_LESS_THAN_HUNDRED = [
|
|
18
|
+
'zero', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'
|
|
19
|
+
];
|
|
20
|
+
function toWords(number) {
|
|
21
|
+
let words;
|
|
22
|
+
const num = parseInt(number, 10);
|
|
23
|
+
if (!isFinite(num)) {
|
|
24
|
+
throw new TypeError('Not a finite number: ' + number + ' (' + typeof number + ')');
|
|
25
|
+
}
|
|
26
|
+
if (!isSafeNumber(num)) {
|
|
27
|
+
throw new RangeError('Input is not a safe number, it\'s either too large or too small.');
|
|
28
|
+
}
|
|
29
|
+
words = generateWords(num);
|
|
30
|
+
return words;
|
|
31
|
+
}
|
|
32
|
+
exports.toWords = toWords;
|
|
33
|
+
function generateWords(number, words) {
|
|
34
|
+
let remainder, word;
|
|
35
|
+
if (number === 0) {
|
|
36
|
+
return !words ? 'zero' : words.join(' ').replace(/,$/, '');
|
|
37
|
+
}
|
|
38
|
+
if (!words) {
|
|
39
|
+
words = [];
|
|
40
|
+
}
|
|
41
|
+
if (number < 0) {
|
|
42
|
+
words.push('minus');
|
|
43
|
+
number = Math.abs(number);
|
|
44
|
+
}
|
|
45
|
+
if (number < 20) {
|
|
46
|
+
remainder = 0;
|
|
47
|
+
word = LESS_THAN_TWENTY[number];
|
|
48
|
+
}
|
|
49
|
+
else if (number < ONE_HUNDRED) {
|
|
50
|
+
remainder = number % TEN;
|
|
51
|
+
word = TENTHS_LESS_THAN_HUNDRED[Math.floor(number / TEN)];
|
|
52
|
+
if (remainder) {
|
|
53
|
+
word += '-' + LESS_THAN_TWENTY[remainder];
|
|
54
|
+
remainder = 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (number < ONE_THOUSAND) {
|
|
58
|
+
remainder = number % ONE_HUNDRED;
|
|
59
|
+
word = generateWords(Math.floor(number / ONE_HUNDRED)) + ' hundred';
|
|
60
|
+
}
|
|
61
|
+
else if (number < ONE_MILLION) {
|
|
62
|
+
remainder = number % ONE_THOUSAND;
|
|
63
|
+
word = generateWords(Math.floor(number / ONE_THOUSAND)) + ' thousand,';
|
|
64
|
+
}
|
|
65
|
+
else if (number < ONE_BILLION) {
|
|
66
|
+
remainder = number % ONE_MILLION;
|
|
67
|
+
word = generateWords(Math.floor(number / ONE_MILLION)) + ' million,';
|
|
68
|
+
}
|
|
69
|
+
else if (number < ONE_TRILLION) {
|
|
70
|
+
remainder = number % ONE_BILLION;
|
|
71
|
+
word = generateWords(Math.floor(number / ONE_BILLION)) + ' billion,';
|
|
72
|
+
}
|
|
73
|
+
else if (number < ONE_QUADRILLION) {
|
|
74
|
+
remainder = number % ONE_TRILLION;
|
|
75
|
+
word = generateWords(Math.floor(number / ONE_TRILLION)) + ' trillion,';
|
|
76
|
+
}
|
|
77
|
+
else if (number <= MAX) {
|
|
78
|
+
remainder = number % ONE_QUADRILLION;
|
|
79
|
+
word = generateWords(Math.floor(number / ONE_QUADRILLION)) +
|
|
80
|
+
' quadrillion,';
|
|
81
|
+
}
|
|
82
|
+
words.push(word);
|
|
83
|
+
return generateWords(remainder, words);
|
|
84
|
+
}
|
|
85
|
+
function isFinite(value) {
|
|
86
|
+
return !(typeof value !== 'number' || value !== value || value === Infinity || value === -Infinity);
|
|
87
|
+
}
|
|
88
|
+
function isSafeNumber(value) {
|
|
89
|
+
return typeof value === 'number' && Math.abs(value) <= MAX_SAFE_INTEGER;
|
|
90
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const to_words_function_1 = require("./to-words.function");
|
|
4
|
+
describe('toWords', () => {
|
|
5
|
+
it('worx', () => {
|
|
6
|
+
expect((0, to_words_function_1.toWords)(337)).toMatchSnapshot();
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryParseDate = void 0;
|
|
4
|
+
function tryParseDate(input) {
|
|
5
|
+
if (!input) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (input instanceof Date) {
|
|
9
|
+
return input;
|
|
10
|
+
}
|
|
11
|
+
const date = new Date(input);
|
|
12
|
+
if (date == 'Invalid Date') {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
return date;
|
|
16
|
+
}
|
|
17
|
+
exports.tryParseDate = tryParseDate;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const try_parse_date_function_1 = require("./try-parse-date.function");
|
|
4
|
+
describe('tryParseDate', () => {
|
|
5
|
+
describe('GIVEN input is partial or full ISO8601', () => {
|
|
6
|
+
it.each([
|
|
7
|
+
'2023-12-23',
|
|
8
|
+
'2023-12-23T00:00:00.000',
|
|
9
|
+
])('%j', (input) => {
|
|
10
|
+
expect((0, try_parse_date_function_1.tryParseDate)(input)).toMatchSnapshot();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
});
|