@fgv/ts-extras 5.1.0-1 → 5.1.0-11
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.
|
@@ -60,8 +60,41 @@ export const isoDate = new Conversion.BaseConverter((from) => {
|
|
|
60
60
|
else if (from instanceof Date) {
|
|
61
61
|
return succeed(from);
|
|
62
62
|
}
|
|
63
|
+
else if (from instanceof DateTime) {
|
|
64
|
+
if (from.isValid) {
|
|
65
|
+
return succeed(from.toJSDate());
|
|
66
|
+
}
|
|
67
|
+
return fail(`Invalid date: ${from.invalidExplanation}`);
|
|
68
|
+
}
|
|
63
69
|
return fail(`Cannot convert ${JSON.stringify(from)} to Date`);
|
|
64
70
|
});
|
|
71
|
+
/**
|
|
72
|
+
* A `Converter` which converts an iso formatted string, a number or a `Date` object to
|
|
73
|
+
* a `DateTime` object.
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
export const isoDateTime = new Conversion.BaseConverter((from) => {
|
|
77
|
+
if (typeof from === 'string') {
|
|
78
|
+
const dt = DateTime.fromISO(from);
|
|
79
|
+
if (dt.isValid) {
|
|
80
|
+
return succeed(dt);
|
|
81
|
+
}
|
|
82
|
+
return fail(`Invalid date: ${dt.invalidExplanation}`);
|
|
83
|
+
}
|
|
84
|
+
else if (typeof from === 'number') {
|
|
85
|
+
return succeed(DateTime.fromMillis(from));
|
|
86
|
+
}
|
|
87
|
+
else if (from instanceof Date) {
|
|
88
|
+
return succeed(DateTime.fromJSDate(from));
|
|
89
|
+
}
|
|
90
|
+
else if (from instanceof DateTime) {
|
|
91
|
+
if (from.isValid) {
|
|
92
|
+
return succeed(from);
|
|
93
|
+
}
|
|
94
|
+
return fail(`Invalid date: ${from.invalidExplanation}`);
|
|
95
|
+
}
|
|
96
|
+
return fail(`Cannot convert ${JSON.stringify(from)} to DateTime`);
|
|
97
|
+
});
|
|
65
98
|
/**
|
|
66
99
|
* A helper function to create a `Converter` which converts `unknown` to {@link Experimental.ExtendedArray | ExtendedArray<T>}.
|
|
67
100
|
* @remarks
|
package/dist/ts-extras.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Conversion } from '@fgv/ts-utils';
|
|
2
2
|
import { Converter } from '@fgv/ts-utils';
|
|
3
|
+
import { DateTime } from 'luxon';
|
|
3
4
|
import { FileTree } from '@fgv/ts-json-base';
|
|
4
5
|
import { Hash as Hash_2 } from '@fgv/ts-utils';
|
|
5
6
|
import { JsonValue } from '@fgv/ts-json-base';
|
|
@@ -210,7 +211,8 @@ declare namespace Converters {
|
|
|
210
211
|
extendedArrayOf,
|
|
211
212
|
rangeTypeOf,
|
|
212
213
|
rangeOf,
|
|
213
|
-
isoDate
|
|
214
|
+
isoDate,
|
|
215
|
+
isoDateTime
|
|
214
216
|
}
|
|
215
217
|
}
|
|
216
218
|
export { Converters }
|
|
@@ -1399,6 +1401,13 @@ declare function isKeyStoreFile(json: unknown): boolean;
|
|
|
1399
1401
|
*/
|
|
1400
1402
|
declare const isoDate: Converter<Date, unknown>;
|
|
1401
1403
|
|
|
1404
|
+
/**
|
|
1405
|
+
* A `Converter` which converts an iso formatted string, a number or a `Date` object to
|
|
1406
|
+
* a `DateTime` object.
|
|
1407
|
+
* @public
|
|
1408
|
+
*/
|
|
1409
|
+
declare const isoDateTime: Converter<DateTime, unknown>;
|
|
1410
|
+
|
|
1402
1411
|
/**
|
|
1403
1412
|
* Represents a variable reference extracted from a Mustache template.
|
|
1404
1413
|
* @public
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Conversion, Converter, Result } from '@fgv/ts-utils';
|
|
2
|
+
import { DateTime } from 'luxon';
|
|
2
3
|
import { ExtendedArray, RangeOf, RangeOfProperties } from '../experimental';
|
|
3
4
|
/**
|
|
4
5
|
* Helper function to create a `StringConverter` which converts
|
|
@@ -17,6 +18,12 @@ export declare function templateString(defaultContext?: unknown): Conversion.Str
|
|
|
17
18
|
* @public
|
|
18
19
|
*/
|
|
19
20
|
export declare const isoDate: Converter<Date, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* A `Converter` which converts an iso formatted string, a number or a `Date` object to
|
|
23
|
+
* a `DateTime` object.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare const isoDateTime: Converter<DateTime, unknown>;
|
|
20
27
|
/**
|
|
21
28
|
* A helper function to create a `Converter` which converts `unknown` to {@link Experimental.ExtendedArray | ExtendedArray<T>}.
|
|
22
29
|
* @remarks
|
|
@@ -24,7 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.isoDate = void 0;
|
|
27
|
+
exports.isoDateTime = exports.isoDate = void 0;
|
|
28
28
|
exports.templateString = templateString;
|
|
29
29
|
exports.extendedArrayOf = extendedArrayOf;
|
|
30
30
|
exports.rangeTypeOf = rangeTypeOf;
|
|
@@ -70,8 +70,41 @@ exports.isoDate = new ts_utils_1.Conversion.BaseConverter((from) => {
|
|
|
70
70
|
else if (from instanceof Date) {
|
|
71
71
|
return (0, ts_utils_1.succeed)(from);
|
|
72
72
|
}
|
|
73
|
+
else if (from instanceof luxon_1.DateTime) {
|
|
74
|
+
if (from.isValid) {
|
|
75
|
+
return (0, ts_utils_1.succeed)(from.toJSDate());
|
|
76
|
+
}
|
|
77
|
+
return (0, ts_utils_1.fail)(`Invalid date: ${from.invalidExplanation}`);
|
|
78
|
+
}
|
|
73
79
|
return (0, ts_utils_1.fail)(`Cannot convert ${JSON.stringify(from)} to Date`);
|
|
74
80
|
});
|
|
81
|
+
/**
|
|
82
|
+
* A `Converter` which converts an iso formatted string, a number or a `Date` object to
|
|
83
|
+
* a `DateTime` object.
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
exports.isoDateTime = new ts_utils_1.Conversion.BaseConverter((from) => {
|
|
87
|
+
if (typeof from === 'string') {
|
|
88
|
+
const dt = luxon_1.DateTime.fromISO(from);
|
|
89
|
+
if (dt.isValid) {
|
|
90
|
+
return (0, ts_utils_1.succeed)(dt);
|
|
91
|
+
}
|
|
92
|
+
return (0, ts_utils_1.fail)(`Invalid date: ${dt.invalidExplanation}`);
|
|
93
|
+
}
|
|
94
|
+
else if (typeof from === 'number') {
|
|
95
|
+
return (0, ts_utils_1.succeed)(luxon_1.DateTime.fromMillis(from));
|
|
96
|
+
}
|
|
97
|
+
else if (from instanceof Date) {
|
|
98
|
+
return (0, ts_utils_1.succeed)(luxon_1.DateTime.fromJSDate(from));
|
|
99
|
+
}
|
|
100
|
+
else if (from instanceof luxon_1.DateTime) {
|
|
101
|
+
if (from.isValid) {
|
|
102
|
+
return (0, ts_utils_1.succeed)(from);
|
|
103
|
+
}
|
|
104
|
+
return (0, ts_utils_1.fail)(`Invalid date: ${from.invalidExplanation}`);
|
|
105
|
+
}
|
|
106
|
+
return (0, ts_utils_1.fail)(`Cannot convert ${JSON.stringify(from)} to DateTime`);
|
|
107
|
+
});
|
|
75
108
|
/**
|
|
76
109
|
* A helper function to create a `Converter` which converts `unknown` to {@link Experimental.ExtendedArray | ExtendedArray<T>}.
|
|
77
110
|
* @remarks
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-extras",
|
|
3
|
-
"version": "5.1.0-
|
|
3
|
+
"version": "5.1.0-11",
|
|
4
4
|
"description": "Assorted Typescript Utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-extras.d.ts",
|
|
@@ -42,18 +42,6 @@
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"build": "heft build --clean",
|
|
47
|
-
"clean": "heft clean",
|
|
48
|
-
"test": "heft test --clean",
|
|
49
|
-
"build-docs": "typedoc --options ./config/typedoc.json",
|
|
50
|
-
"build-all": "rushx build; rushx build-docs",
|
|
51
|
-
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
52
|
-
"clean-jest": "jest --clear-cache",
|
|
53
|
-
"coverage": "jest --coverage",
|
|
54
|
-
"lint": "eslint src --ext .ts",
|
|
55
|
-
"fixlint": "eslint src --ext .ts --fix"
|
|
56
|
-
},
|
|
57
45
|
"sideEffects": false,
|
|
58
46
|
"keywords": [
|
|
59
47
|
"typescript",
|
|
@@ -66,7 +54,6 @@
|
|
|
66
54
|
},
|
|
67
55
|
"homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-extras#ts-utils",
|
|
68
56
|
"devDependencies": {
|
|
69
|
-
"@fgv/heft-dual-rig": "workspace:*",
|
|
70
57
|
"@jest/expect-utils": "^29.7.0",
|
|
71
58
|
"@microsoft/api-documenter": "^7.28.2",
|
|
72
59
|
"@microsoft/api-extractor": "^7.55.2",
|
|
@@ -90,31 +77,45 @@
|
|
|
90
77
|
"typescript": "5.9.3",
|
|
91
78
|
"eslint-plugin-n": "^17.23.1",
|
|
92
79
|
"jest-snapshot": "~29.7.0",
|
|
93
|
-
"@rushstack/heft": "1.2.
|
|
94
|
-
"@rushstack/heft-node-rig": "2.11.
|
|
80
|
+
"@rushstack/heft": "1.2.7",
|
|
81
|
+
"@rushstack/heft-node-rig": "2.11.27",
|
|
95
82
|
"@rushstack/eslint-config": "4.6.4",
|
|
96
83
|
"@types/heft-jest": "1.0.6",
|
|
97
84
|
"@rushstack/heft-jest-plugin": "1.2.6",
|
|
98
85
|
"eslint-plugin-tsdoc": "~0.5.2",
|
|
99
|
-
"@fgv/ts-utils-jest": "workspace:*",
|
|
100
|
-
"@fgv/ts-utils": "workspace:*",
|
|
101
86
|
"@types/js-yaml": "~4.0.9",
|
|
102
87
|
"typedoc": "~0.28.16",
|
|
103
|
-
"typedoc-plugin-markdown": "~4.9.0"
|
|
88
|
+
"typedoc-plugin-markdown": "~4.9.0",
|
|
89
|
+
"@fgv/heft-dual-rig": "5.1.0-11",
|
|
90
|
+
"@fgv/ts-utils-jest": "5.1.0-11",
|
|
91
|
+
"@fgv/typedoc-compact-theme": "5.1.0-11",
|
|
92
|
+
"@fgv/ts-utils": "5.1.0-11"
|
|
104
93
|
},
|
|
105
94
|
"dependencies": {
|
|
106
95
|
"luxon": "^3.7.2",
|
|
107
96
|
"mustache": "^4.2.0",
|
|
108
97
|
"papaparse": "^5.4.1",
|
|
109
98
|
"fflate": "~0.8.2",
|
|
110
|
-
"
|
|
111
|
-
"
|
|
99
|
+
"js-yaml": "~4.1.1",
|
|
100
|
+
"@fgv/ts-json-base": "5.1.0-11"
|
|
112
101
|
},
|
|
113
102
|
"peerDependencies": {
|
|
114
|
-
"@fgv/ts-utils": "
|
|
103
|
+
"@fgv/ts-utils": "5.1.0-11"
|
|
115
104
|
},
|
|
116
105
|
"repository": {
|
|
117
106
|
"type": "git",
|
|
118
107
|
"url": "https://github.com/ErikFortune/fgv.git"
|
|
108
|
+
},
|
|
109
|
+
"scripts": {
|
|
110
|
+
"build": "heft build --clean",
|
|
111
|
+
"clean": "heft clean",
|
|
112
|
+
"test": "heft test --clean",
|
|
113
|
+
"build-docs": "typedoc --options ./config/typedoc.json",
|
|
114
|
+
"build-all": "rushx build; rushx build-docs",
|
|
115
|
+
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
116
|
+
"clean-jest": "jest --clear-cache",
|
|
117
|
+
"coverage": "jest --coverage",
|
|
118
|
+
"lint": "eslint src --ext .ts",
|
|
119
|
+
"fixlint": "eslint src --ext .ts --fix"
|
|
119
120
|
}
|
|
120
|
-
}
|
|
121
|
+
}
|