@augment-vir/common 12.14.0 → 13.1.0
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/dist/cjs/augments/common-number.d.ts +11 -0
- package/dist/cjs/augments/common-number.js +14 -1
- package/dist/cjs/augments/date/relative-date.d.ts +12 -0
- package/dist/cjs/augments/date/relative-date.js +45 -0
- package/dist/cjs/augments/object/has-key.d.ts +2 -0
- package/dist/cjs/augments/object/has-key.js +7 -0
- package/dist/cjs/augments/string/uuid.d.ts +2 -0
- package/dist/cjs/augments/string/uuid.js +8 -0
- package/dist/cjs/index.d.ts +4 -1
- package/dist/cjs/index.js +4 -1
- package/dist/esm/augments/common-number.d.ts +11 -0
- package/dist/esm/augments/common-number.js +12 -0
- package/dist/esm/augments/date/relative-date.d.ts +12 -0
- package/dist/esm/augments/date/relative-date.js +41 -0
- package/dist/esm/augments/object/has-key.d.ts +2 -0
- package/dist/esm/augments/object/has-key.js +3 -0
- package/dist/esm/augments/string/uuid.d.ts +2 -0
- package/dist/esm/augments/string/uuid.js +4 -0
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +4 -1
- package/dist/types/augments/common-number.d.ts +11 -0
- package/dist/types/augments/date/relative-date.d.ts +12 -0
- package/dist/types/augments/object/has-key.d.ts +2 -0
- package/dist/types/augments/string/uuid.d.ts +2 -0
- package/dist/types/index.d.ts +4 -1
- package/package.json +1 -1
- /package/dist/cjs/augments/{date.d.ts → date/date.d.ts} +0 -0
- /package/dist/cjs/augments/{date.js → date/date.js} +0 -0
- /package/dist/esm/augments/{date.d.ts → date/date.d.ts} +0 -0
- /package/dist/esm/augments/{date.js → date/date.js} +0 -0
- /package/dist/types/augments/{date.d.ts → date/date.d.ts} +0 -0
|
@@ -12,4 +12,15 @@ export declare function clamp(
|
|
|
12
12
|
}): number;
|
|
13
13
|
export declare function convertIntoNumber(input: unknown): number;
|
|
14
14
|
export declare function doesRequireScientificNotation(input: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
17
|
+
* that is not the case, the returned value is the given min and max values swapped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ensureMinAndMax({ min, max }: {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
}): {
|
|
23
|
+
min: number;
|
|
24
|
+
max: number;
|
|
25
|
+
};
|
|
15
26
|
//# sourceMappingURL=common-number.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.doesRequireScientificNotation = exports.convertIntoNumber = exports.clamp = exports.addCommasToNumber = exports.NaNString = void 0;
|
|
3
|
+
exports.ensureMinAndMax = exports.doesRequireScientificNotation = exports.convertIntoNumber = exports.clamp = exports.addCommasToNumber = exports.NaNString = void 0;
|
|
4
4
|
const common_string_1 = require("./common-string");
|
|
5
5
|
const regexp_1 = require("./regexp");
|
|
6
6
|
exports.NaNString = String(NaN);
|
|
@@ -43,3 +43,16 @@ function doesRequireScientificNotation(input) {
|
|
|
43
43
|
return String(input).includes('e');
|
|
44
44
|
}
|
|
45
45
|
exports.doesRequireScientificNotation = doesRequireScientificNotation;
|
|
46
|
+
/**
|
|
47
|
+
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
48
|
+
* that is not the case, the returned value is the given min and max values swapped.
|
|
49
|
+
*/
|
|
50
|
+
function ensureMinAndMax({ min, max }) {
|
|
51
|
+
if (min > max) {
|
|
52
|
+
return { min: max, max: min };
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return { min, max };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.ensureMinAndMax = ensureMinAndMax;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PartialAndUndefined } from '../..';
|
|
2
|
+
export type RelativeDateCalculation = PartialAndUndefined<{
|
|
3
|
+
milliseconds: number;
|
|
4
|
+
seconds: number;
|
|
5
|
+
minutes: number;
|
|
6
|
+
hours: number;
|
|
7
|
+
days: number;
|
|
8
|
+
months: number;
|
|
9
|
+
years: number;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function calculateRelativeDate(startingDate: Date | number | string, calculations: RelativeDateCalculation): Date;
|
|
12
|
+
//# sourceMappingURL=relative-date.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateRelativeDate = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
5
|
+
/**
|
|
6
|
+
* For the properties that don't have setters and getters named directly after them. For example, to
|
|
7
|
+
* modify "milliseconds", we can just use that string directly: getUTCMilliseconds. However, for
|
|
8
|
+
* "Months", we have to use getUTCMonth.
|
|
9
|
+
*/
|
|
10
|
+
const differentlyNamedDateSettersAndGetterKeys = {
|
|
11
|
+
days: {
|
|
12
|
+
getKey: 'getUTCDate',
|
|
13
|
+
setKey: 'setUTCDate',
|
|
14
|
+
},
|
|
15
|
+
months: {
|
|
16
|
+
getKey: 'getUTCMonth',
|
|
17
|
+
setKey: 'setUTCMonth',
|
|
18
|
+
},
|
|
19
|
+
years: {
|
|
20
|
+
getKey: 'getUTCFullYear',
|
|
21
|
+
setKey: 'setUTCFullYear',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
function calculateRelativeDate(startingDate, calculations) {
|
|
25
|
+
if (!(startingDate instanceof Date)) {
|
|
26
|
+
startingDate = new Date(startingDate);
|
|
27
|
+
}
|
|
28
|
+
let returnDate = new Date(startingDate);
|
|
29
|
+
(0, __1.getObjectTypedKeys)(calculations).forEach((calculationKey) => {
|
|
30
|
+
const calculationValue = calculations[calculationKey];
|
|
31
|
+
if (!calculationValue) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const { getKey, setKey } = (0, __1.hasKey)(differentlyNamedDateSettersAndGetterKeys, calculationKey)
|
|
35
|
+
? differentlyNamedDateSettersAndGetterKeys[calculationKey]
|
|
36
|
+
: {
|
|
37
|
+
getKey: `getUTC${(0, __1.capitalizeFirstLetter)(calculationKey)}`,
|
|
38
|
+
setKey: `setUTC${(0, __1.capitalizeFirstLetter)(calculationKey)}`,
|
|
39
|
+
};
|
|
40
|
+
const currentValue = returnDate[getKey]();
|
|
41
|
+
returnDate[setKey](currentValue + calculationValue);
|
|
42
|
+
});
|
|
43
|
+
return returnDate;
|
|
44
|
+
}
|
|
45
|
+
exports.calculateRelativeDate = calculateRelativeDate;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUuid = void 0;
|
|
4
|
+
const uuidRegExp = /[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}/;
|
|
5
|
+
function isUuid(maybeUuid) {
|
|
6
|
+
return !!maybeUuid.match(uuidRegExp);
|
|
7
|
+
}
|
|
8
|
+
exports.isUuid = isUuid;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export * from './augments/array';
|
|
|
3
3
|
export * from './augments/async';
|
|
4
4
|
export * from './augments/common-number';
|
|
5
5
|
export * from './augments/common-string';
|
|
6
|
-
export * from './augments/date';
|
|
6
|
+
export * from './augments/date/date';
|
|
7
|
+
export * from './augments/date/relative-date';
|
|
7
8
|
export * from './augments/environment';
|
|
8
9
|
export * from './augments/error';
|
|
9
10
|
export * from './augments/function';
|
|
@@ -11,6 +12,7 @@ export * from './augments/json';
|
|
|
11
12
|
export * from './augments/json-compatible';
|
|
12
13
|
export * from './augments/object/enum';
|
|
13
14
|
export * from './augments/object/filter-object';
|
|
15
|
+
export * from './augments/object/has-key';
|
|
14
16
|
export * from './augments/object/jsonify';
|
|
15
17
|
export * from './augments/object/map-object';
|
|
16
18
|
export * from './augments/object/matches-object-shape';
|
|
@@ -23,6 +25,7 @@ export * from './augments/promise';
|
|
|
23
25
|
export * from './augments/regexp';
|
|
24
26
|
export * from './augments/runtime-type-of';
|
|
25
27
|
export * from './augments/string/url';
|
|
28
|
+
export * from './augments/string/uuid';
|
|
26
29
|
export * from './augments/truncate-number';
|
|
27
30
|
export * from './augments/tuple';
|
|
28
31
|
export * from './augments/type';
|
package/dist/cjs/index.js
CHANGED
|
@@ -19,7 +19,8 @@ __exportStar(require("./augments/array"), exports);
|
|
|
19
19
|
__exportStar(require("./augments/async"), exports);
|
|
20
20
|
__exportStar(require("./augments/common-number"), exports);
|
|
21
21
|
__exportStar(require("./augments/common-string"), exports);
|
|
22
|
-
__exportStar(require("./augments/date"), exports);
|
|
22
|
+
__exportStar(require("./augments/date/date"), exports);
|
|
23
|
+
__exportStar(require("./augments/date/relative-date"), exports);
|
|
23
24
|
__exportStar(require("./augments/environment"), exports);
|
|
24
25
|
__exportStar(require("./augments/error"), exports);
|
|
25
26
|
__exportStar(require("./augments/function"), exports);
|
|
@@ -27,6 +28,7 @@ __exportStar(require("./augments/json"), exports);
|
|
|
27
28
|
__exportStar(require("./augments/json-compatible"), exports);
|
|
28
29
|
__exportStar(require("./augments/object/enum"), exports);
|
|
29
30
|
__exportStar(require("./augments/object/filter-object"), exports);
|
|
31
|
+
__exportStar(require("./augments/object/has-key"), exports);
|
|
30
32
|
__exportStar(require("./augments/object/jsonify"), exports);
|
|
31
33
|
__exportStar(require("./augments/object/map-object"), exports);
|
|
32
34
|
__exportStar(require("./augments/object/matches-object-shape"), exports);
|
|
@@ -39,6 +41,7 @@ __exportStar(require("./augments/promise"), exports);
|
|
|
39
41
|
__exportStar(require("./augments/regexp"), exports);
|
|
40
42
|
__exportStar(require("./augments/runtime-type-of"), exports);
|
|
41
43
|
__exportStar(require("./augments/string/url"), exports);
|
|
44
|
+
__exportStar(require("./augments/string/uuid"), exports);
|
|
42
45
|
__exportStar(require("./augments/truncate-number"), exports);
|
|
43
46
|
__exportStar(require("./augments/tuple"), exports);
|
|
44
47
|
__exportStar(require("./augments/type"), exports);
|
|
@@ -12,4 +12,15 @@ export declare function clamp(
|
|
|
12
12
|
}): number;
|
|
13
13
|
export declare function convertIntoNumber(input: unknown): number;
|
|
14
14
|
export declare function doesRequireScientificNotation(input: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
17
|
+
* that is not the case, the returned value is the given min and max values swapped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ensureMinAndMax({ min, max }: {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
}): {
|
|
23
|
+
min: number;
|
|
24
|
+
max: number;
|
|
25
|
+
};
|
|
15
26
|
//# sourceMappingURL=common-number.d.ts.map
|
|
@@ -36,3 +36,15 @@ export function convertIntoNumber(input) {
|
|
|
36
36
|
export function doesRequireScientificNotation(input) {
|
|
37
37
|
return String(input).includes('e');
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
41
|
+
* that is not the case, the returned value is the given min and max values swapped.
|
|
42
|
+
*/
|
|
43
|
+
export function ensureMinAndMax({ min, max }) {
|
|
44
|
+
if (min > max) {
|
|
45
|
+
return { min: max, max: min };
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return { min, max };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PartialAndUndefined } from '../..';
|
|
2
|
+
export type RelativeDateCalculation = PartialAndUndefined<{
|
|
3
|
+
milliseconds: number;
|
|
4
|
+
seconds: number;
|
|
5
|
+
minutes: number;
|
|
6
|
+
hours: number;
|
|
7
|
+
days: number;
|
|
8
|
+
months: number;
|
|
9
|
+
years: number;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function calculateRelativeDate(startingDate: Date | number | string, calculations: RelativeDateCalculation): Date;
|
|
12
|
+
//# sourceMappingURL=relative-date.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { capitalizeFirstLetter, getObjectTypedKeys, hasKey } from '../..';
|
|
2
|
+
/**
|
|
3
|
+
* For the properties that don't have setters and getters named directly after them. For example, to
|
|
4
|
+
* modify "milliseconds", we can just use that string directly: getUTCMilliseconds. However, for
|
|
5
|
+
* "Months", we have to use getUTCMonth.
|
|
6
|
+
*/
|
|
7
|
+
const differentlyNamedDateSettersAndGetterKeys = {
|
|
8
|
+
days: {
|
|
9
|
+
getKey: 'getUTCDate',
|
|
10
|
+
setKey: 'setUTCDate',
|
|
11
|
+
},
|
|
12
|
+
months: {
|
|
13
|
+
getKey: 'getUTCMonth',
|
|
14
|
+
setKey: 'setUTCMonth',
|
|
15
|
+
},
|
|
16
|
+
years: {
|
|
17
|
+
getKey: 'getUTCFullYear',
|
|
18
|
+
setKey: 'setUTCFullYear',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export function calculateRelativeDate(startingDate, calculations) {
|
|
22
|
+
if (!(startingDate instanceof Date)) {
|
|
23
|
+
startingDate = new Date(startingDate);
|
|
24
|
+
}
|
|
25
|
+
let returnDate = new Date(startingDate);
|
|
26
|
+
getObjectTypedKeys(calculations).forEach((calculationKey) => {
|
|
27
|
+
const calculationValue = calculations[calculationKey];
|
|
28
|
+
if (!calculationValue) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const { getKey, setKey } = hasKey(differentlyNamedDateSettersAndGetterKeys, calculationKey)
|
|
32
|
+
? differentlyNamedDateSettersAndGetterKeys[calculationKey]
|
|
33
|
+
: {
|
|
34
|
+
getKey: `getUTC${capitalizeFirstLetter(calculationKey)}`,
|
|
35
|
+
setKey: `setUTC${capitalizeFirstLetter(calculationKey)}`,
|
|
36
|
+
};
|
|
37
|
+
const currentValue = returnDate[getKey]();
|
|
38
|
+
returnDate[setKey](currentValue + calculationValue);
|
|
39
|
+
});
|
|
40
|
+
return returnDate;
|
|
41
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export * from './augments/array';
|
|
|
3
3
|
export * from './augments/async';
|
|
4
4
|
export * from './augments/common-number';
|
|
5
5
|
export * from './augments/common-string';
|
|
6
|
-
export * from './augments/date';
|
|
6
|
+
export * from './augments/date/date';
|
|
7
|
+
export * from './augments/date/relative-date';
|
|
7
8
|
export * from './augments/environment';
|
|
8
9
|
export * from './augments/error';
|
|
9
10
|
export * from './augments/function';
|
|
@@ -11,6 +12,7 @@ export * from './augments/json';
|
|
|
11
12
|
export * from './augments/json-compatible';
|
|
12
13
|
export * from './augments/object/enum';
|
|
13
14
|
export * from './augments/object/filter-object';
|
|
15
|
+
export * from './augments/object/has-key';
|
|
14
16
|
export * from './augments/object/jsonify';
|
|
15
17
|
export * from './augments/object/map-object';
|
|
16
18
|
export * from './augments/object/matches-object-shape';
|
|
@@ -23,6 +25,7 @@ export * from './augments/promise';
|
|
|
23
25
|
export * from './augments/regexp';
|
|
24
26
|
export * from './augments/runtime-type-of';
|
|
25
27
|
export * from './augments/string/url';
|
|
28
|
+
export * from './augments/string/uuid';
|
|
26
29
|
export * from './augments/truncate-number';
|
|
27
30
|
export * from './augments/tuple';
|
|
28
31
|
export * from './augments/type';
|
package/dist/esm/index.js
CHANGED
|
@@ -3,7 +3,8 @@ export * from './augments/array';
|
|
|
3
3
|
export * from './augments/async';
|
|
4
4
|
export * from './augments/common-number';
|
|
5
5
|
export * from './augments/common-string';
|
|
6
|
-
export * from './augments/date';
|
|
6
|
+
export * from './augments/date/date';
|
|
7
|
+
export * from './augments/date/relative-date';
|
|
7
8
|
export * from './augments/environment';
|
|
8
9
|
export * from './augments/error';
|
|
9
10
|
export * from './augments/function';
|
|
@@ -11,6 +12,7 @@ export * from './augments/json';
|
|
|
11
12
|
export * from './augments/json-compatible';
|
|
12
13
|
export * from './augments/object/enum';
|
|
13
14
|
export * from './augments/object/filter-object';
|
|
15
|
+
export * from './augments/object/has-key';
|
|
14
16
|
export * from './augments/object/jsonify';
|
|
15
17
|
export * from './augments/object/map-object';
|
|
16
18
|
export * from './augments/object/matches-object-shape';
|
|
@@ -23,6 +25,7 @@ export * from './augments/promise';
|
|
|
23
25
|
export * from './augments/regexp';
|
|
24
26
|
export * from './augments/runtime-type-of';
|
|
25
27
|
export * from './augments/string/url';
|
|
28
|
+
export * from './augments/string/uuid';
|
|
26
29
|
export * from './augments/truncate-number';
|
|
27
30
|
export * from './augments/tuple';
|
|
28
31
|
export * from './augments/type';
|
|
@@ -12,4 +12,15 @@ export declare function clamp(
|
|
|
12
12
|
}): number;
|
|
13
13
|
export declare function convertIntoNumber(input: unknown): number;
|
|
14
14
|
export declare function doesRequireScientificNotation(input: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
17
|
+
* that is not the case, the returned value is the given min and max values swapped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ensureMinAndMax({ min, max }: {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
}): {
|
|
23
|
+
min: number;
|
|
24
|
+
max: number;
|
|
25
|
+
};
|
|
15
26
|
//# sourceMappingURL=common-number.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PartialAndUndefined } from '../..';
|
|
2
|
+
export type RelativeDateCalculation = PartialAndUndefined<{
|
|
3
|
+
milliseconds: number;
|
|
4
|
+
seconds: number;
|
|
5
|
+
minutes: number;
|
|
6
|
+
hours: number;
|
|
7
|
+
days: number;
|
|
8
|
+
months: number;
|
|
9
|
+
years: number;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function calculateRelativeDate(startingDate: Date | number | string, calculations: RelativeDateCalculation): Date;
|
|
12
|
+
//# sourceMappingURL=relative-date.d.ts.map
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export * from './augments/array';
|
|
|
3
3
|
export * from './augments/async';
|
|
4
4
|
export * from './augments/common-number';
|
|
5
5
|
export * from './augments/common-string';
|
|
6
|
-
export * from './augments/date';
|
|
6
|
+
export * from './augments/date/date';
|
|
7
|
+
export * from './augments/date/relative-date';
|
|
7
8
|
export * from './augments/environment';
|
|
8
9
|
export * from './augments/error';
|
|
9
10
|
export * from './augments/function';
|
|
@@ -11,6 +12,7 @@ export * from './augments/json';
|
|
|
11
12
|
export * from './augments/json-compatible';
|
|
12
13
|
export * from './augments/object/enum';
|
|
13
14
|
export * from './augments/object/filter-object';
|
|
15
|
+
export * from './augments/object/has-key';
|
|
14
16
|
export * from './augments/object/jsonify';
|
|
15
17
|
export * from './augments/object/map-object';
|
|
16
18
|
export * from './augments/object/matches-object-shape';
|
|
@@ -23,6 +25,7 @@ export * from './augments/promise';
|
|
|
23
25
|
export * from './augments/regexp';
|
|
24
26
|
export * from './augments/runtime-type-of';
|
|
25
27
|
export * from './augments/string/url';
|
|
28
|
+
export * from './augments/string/uuid';
|
|
26
29
|
export * from './augments/truncate-number';
|
|
27
30
|
export * from './augments/tuple';
|
|
28
31
|
export * from './augments/type';
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|