@augment-vir/common 13.0.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.
@@ -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,2 @@
1
+ export declare function hasKey<ParentType>(parent: ParentType, property: PropertyKey): property is keyof ParentType;
2
+ //# sourceMappingURL=has-key.d.ts.map
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasKey = void 0;
4
+ function hasKey(parent, property) {
5
+ return property in parent;
6
+ }
7
+ exports.hasKey = hasKey;
@@ -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';
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);
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ export declare function hasKey<ParentType>(parent: ParentType, property: PropertyKey): property is keyof ParentType;
2
+ //# sourceMappingURL=has-key.d.ts.map
@@ -0,0 +1,3 @@
1
+ export function hasKey(parent, property) {
2
+ return property in parent;
3
+ }
@@ -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';
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';
@@ -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,2 @@
1
+ export declare function hasKey<ParentType>(parent: ParentType, property: PropertyKey): property is keyof ParentType;
2
+ //# sourceMappingURL=has-key.d.ts.map
@@ -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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "13.0.0",
3
+ "version": "13.1.0",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"
File without changes
File without changes
File without changes
File without changes