@aneuhold/core-ts-lib 1.1.52 → 2.0.6
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/LICENSE +21 -0
- package/lib/helperFunctions/sleep.d.ts.map +1 -1
- package/lib/helperFunctions/sleep.js +2 -4
- package/lib/helperFunctions/sleep.js.map +1 -0
- package/lib/helperFunctions/sleep.ts +8 -0
- package/lib/index.d.ts +12 -12
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -26
- package/lib/index.js.map +1 -0
- package/lib/index.ts +29 -0
- package/lib/services/ArrayService.d.ts +8 -0
- package/lib/services/ArrayService.d.ts.map +1 -1
- package/lib/services/ArrayService.js +10 -4
- package/lib/services/ArrayService.js.map +1 -0
- package/lib/services/ArrayService.ts +26 -0
- package/lib/services/DateService/DateService.d.ts +8 -0
- package/lib/services/DateService/DateService.d.ts.map +1 -1
- package/lib/services/DateService/DateService.js +14 -4
- package/lib/services/DateService/DateService.js.map +1 -0
- package/lib/services/DateService/DateService.spec.ts +98 -0
- package/lib/services/DateService/DateService.ts +209 -0
- package/lib/services/DependencyService.d.ts +19 -3
- package/lib/services/DependencyService.d.ts.map +1 -1
- package/lib/services/DependencyService.js +66 -17
- package/lib/services/DependencyService.js.map +1 -0
- package/lib/services/DependencyService.ts +156 -0
- package/lib/services/FileSystemService/FileSystemService.d.ts +7 -0
- package/lib/services/FileSystemService/FileSystemService.d.ts.map +1 -1
- package/lib/services/FileSystemService/FileSystemService.js +49 -34
- package/lib/services/FileSystemService/FileSystemService.js.map +1 -0
- package/lib/services/FileSystemService/FileSystemService.spec.ts +117 -0
- package/lib/services/FileSystemService/FileSystemService.ts +185 -0
- package/lib/services/PackageService.d.ts +28 -0
- package/lib/services/PackageService.d.ts.map +1 -0
- package/lib/services/PackageService.js +131 -0
- package/lib/services/PackageService.js.map +1 -0
- package/lib/services/PackageService.ts +148 -0
- package/lib/services/StringService.d.ts.map +1 -1
- package/lib/services/StringService.js +2 -4
- package/lib/services/StringService.js.map +1 -0
- package/lib/services/StringService.ts +15 -0
- package/lib/utils/ErrorUtils.d.ts +7 -0
- package/lib/utils/ErrorUtils.d.ts.map +1 -1
- package/lib/utils/ErrorUtils.js +19 -4
- package/lib/utils/ErrorUtils.js.map +1 -0
- package/lib/utils/ErrorUtils.ts +37 -0
- package/lib/utils/Logger.d.ts +3 -0
- package/lib/utils/Logger.d.ts.map +1 -1
- package/lib/utils/Logger.js +5 -4
- package/lib/utils/Logger.js.map +1 -0
- package/lib/utils/Logger.ts +122 -0
- package/lib/utils/TestUtils.d.ts +3 -0
- package/lib/utils/TestUtils.d.ts.map +1 -1
- package/lib/utils/TestUtils.js +9 -8
- package/lib/utils/TestUtils.js.map +1 -0
- package/lib/utils/TestUtils.ts +33 -0
- package/package.json +29 -21
- package/readme.md +61 -2
- package/lib/helperFunctions/dateFunctions.d.ts +0 -10
- package/lib/helperFunctions/dateFunctions.d.ts.map +0 -1
- package/lib/helperFunctions/dateFunctions.js +0 -15
- package/lib/services/DateService/DateService.spec.d.ts +0 -2
- package/lib/services/DateService/DateService.spec.d.ts.map +0 -1
- package/lib/services/DateService/DateService.spec.js +0 -62
- package/lib/services/FileSystemService/FileSystemService.spec.d.ts +0 -2
- package/lib/services/FileSystemService/FileSystemService.spec.d.ts.map +0 -1
- package/lib/services/FileSystemService/FileSystemService.spec.js +0 -88
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2024] [Anton G Neuhold Jr]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","sourceRoot":"./src/","sources":["helperFunctions/sleep.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvD"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = sleep;
|
|
4
1
|
/**
|
|
5
2
|
* Sleeps for the given amount of milliseconds, and resolves once finished.
|
|
6
3
|
*
|
|
7
4
|
* @param ms the number of milliseconds to sleep
|
|
8
5
|
*/
|
|
9
|
-
function sleep(ms) {
|
|
6
|
+
export default function sleep(ms) {
|
|
10
7
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
8
|
}
|
|
9
|
+
//# sourceMappingURL=sleep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep.js","sourceRoot":"./src/","sources":["helperFunctions/sleep.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAU;IACtC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import StringService from './services/StringService';
|
|
8
|
-
import ErrorUtils from './utils/ErrorUtils';
|
|
9
|
-
import Logger from './utils/Logger';
|
|
10
|
-
import TestUtils from './utils/TestUtils';
|
|
11
|
-
export {
|
|
12
|
-
export type {};
|
|
1
|
+
import sleep from './helperFunctions/sleep.js';
|
|
2
|
+
import ArrayService from './services/ArrayService.js';
|
|
3
|
+
import DateService from './services/DateService/DateService.js';
|
|
4
|
+
import DependencyService, { VersionType } from './services/DependencyService.js';
|
|
5
|
+
import FileSystemService from './services/FileSystemService/FileSystemService.js';
|
|
6
|
+
import PackageService from './services/PackageService.js';
|
|
7
|
+
import StringService from './services/StringService.js';
|
|
8
|
+
import ErrorUtils from './utils/ErrorUtils.js';
|
|
9
|
+
import Logger from './utils/Logger.js';
|
|
10
|
+
import TestUtils from './utils/TestUtils.js';
|
|
11
|
+
export { ArrayService, DateService, DependencyService, ErrorUtils, FileSystemService, Logger, PackageService, sleep, StringService, TestUtils };
|
|
12
|
+
export type { VersionType };
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"./src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,4BAA4B,CAAC;AAC/C,OAAO,YAAY,MAAM,4BAA4B,CAAC;AACtD,OAAO,WAAW,MAAM,uCAAuC,CAAC;AAChE,OAAO,iBAAiB,EAAE,EACxB,WAAW,EACZ,MAAM,iCAAiC,CAAC;AACzC,OAAO,iBAAiB,MAAM,mDAAmD,CAAC;AAClF,OAAO,cAAc,MAAM,8BAA8B,CAAC;AAC1D,OAAO,aAAa,MAAM,6BAA6B,CAAC;AACxD,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAG7C,OAAO,EACL,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,cAAc,EACd,KAAK,EACL,aAAa,EACb,SAAS,EACV,CAAC;AAGF,YAAY,EAAE,WAAW,EAAE,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
exports.DateService = DateService_1.default;
|
|
15
|
-
const DependencyService_1 = __importDefault(require("./services/DependencyService"));
|
|
16
|
-
exports.DependencyService = DependencyService_1.default;
|
|
17
|
-
const FileSystemService_1 = __importDefault(require("./services/FileSystemService/FileSystemService"));
|
|
18
|
-
exports.FileSystemService = FileSystemService_1.default;
|
|
19
|
-
const StringService_1 = __importDefault(require("./services/StringService"));
|
|
20
|
-
exports.StringService = StringService_1.default;
|
|
21
|
-
const ErrorUtils_1 = __importDefault(require("./utils/ErrorUtils"));
|
|
22
|
-
exports.ErrorUtils = ErrorUtils_1.default;
|
|
23
|
-
const Logger_1 = __importDefault(require("./utils/Logger"));
|
|
24
|
-
exports.Logger = Logger_1.default;
|
|
25
|
-
const TestUtils_1 = __importDefault(require("./utils/TestUtils"));
|
|
26
|
-
exports.TestUtils = TestUtils_1.default;
|
|
1
|
+
import sleep from './helperFunctions/sleep.js';
|
|
2
|
+
import ArrayService from './services/ArrayService.js';
|
|
3
|
+
import DateService from './services/DateService/DateService.js';
|
|
4
|
+
import DependencyService from './services/DependencyService.js';
|
|
5
|
+
import FileSystemService from './services/FileSystemService/FileSystemService.js';
|
|
6
|
+
import PackageService from './services/PackageService.js';
|
|
7
|
+
import StringService from './services/StringService.js';
|
|
8
|
+
import ErrorUtils from './utils/ErrorUtils.js';
|
|
9
|
+
import Logger from './utils/Logger.js';
|
|
10
|
+
import TestUtils from './utils/TestUtils.js';
|
|
11
|
+
// Export all the functions and classes from this library
|
|
12
|
+
export { ArrayService, DateService, DependencyService, ErrorUtils, FileSystemService, Logger, PackageService, sleep, StringService, TestUtils };
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"./src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,4BAA4B,CAAC;AAC/C,OAAO,YAAY,MAAM,4BAA4B,CAAC;AACtD,OAAO,WAAW,MAAM,uCAAuC,CAAC;AAChE,OAAO,iBAEN,MAAM,iCAAiC,CAAC;AACzC,OAAO,iBAAiB,MAAM,mDAAmD,CAAC;AAClF,OAAO,cAAc,MAAM,8BAA8B,CAAC;AAC1D,OAAO,aAAa,MAAM,6BAA6B,CAAC;AACxD,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAE7C,yDAAyD;AACzD,OAAO,EACL,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,cAAc,EACd,KAAK,EACL,aAAa,EACb,SAAS,EACV,CAAC"}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import sleep from './helperFunctions/sleep.js';
|
|
2
|
+
import ArrayService from './services/ArrayService.js';
|
|
3
|
+
import DateService from './services/DateService/DateService.js';
|
|
4
|
+
import DependencyService, {
|
|
5
|
+
VersionType
|
|
6
|
+
} from './services/DependencyService.js';
|
|
7
|
+
import FileSystemService from './services/FileSystemService/FileSystemService.js';
|
|
8
|
+
import PackageService from './services/PackageService.js';
|
|
9
|
+
import StringService from './services/StringService.js';
|
|
10
|
+
import ErrorUtils from './utils/ErrorUtils.js';
|
|
11
|
+
import Logger from './utils/Logger.js';
|
|
12
|
+
import TestUtils from './utils/TestUtils.js';
|
|
13
|
+
|
|
14
|
+
// Export all the functions and classes from this library
|
|
15
|
+
export {
|
|
16
|
+
ArrayService,
|
|
17
|
+
DateService,
|
|
18
|
+
DependencyService,
|
|
19
|
+
ErrorUtils,
|
|
20
|
+
FileSystemService,
|
|
21
|
+
Logger,
|
|
22
|
+
PackageService,
|
|
23
|
+
sleep,
|
|
24
|
+
StringService,
|
|
25
|
+
TestUtils
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Export TypeScript types where needed
|
|
29
|
+
export type { VersionType };
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A service which can be used to work with arrays in various ways.
|
|
3
|
+
*/
|
|
1
4
|
export default class ArrayService {
|
|
5
|
+
/**
|
|
6
|
+
* Determines if two arrays have the same primitive values.
|
|
7
|
+
*
|
|
8
|
+
* @returns true if the arrays have the same primitive values, false otherwise.
|
|
9
|
+
*/
|
|
2
10
|
static arraysHaveSamePrimitiveValues(array1: Array<unknown>, array2: Array<unknown>): boolean;
|
|
3
11
|
}
|
|
4
12
|
//# sourceMappingURL=ArrayService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArrayService.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"ArrayService.d.ts","sourceRoot":"./src/","sources":["services/ArrayService.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B;;;;OAIG;IACH,MAAM,CAAC,6BAA6B,CAClC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,EACtB,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,GACrB,OAAO;CAaX"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A service which can be used to work with arrays in various ways.
|
|
3
|
+
*/
|
|
4
|
+
export default class ArrayService {
|
|
5
|
+
/**
|
|
6
|
+
* Determines if two arrays have the same primitive values.
|
|
7
|
+
*
|
|
8
|
+
* @returns true if the arrays have the same primitive values, false otherwise.
|
|
9
|
+
*/
|
|
4
10
|
static arraysHaveSamePrimitiveValues(array1, array2) {
|
|
5
11
|
if (array1.length !== array2.length) {
|
|
6
12
|
return false;
|
|
@@ -12,4 +18,4 @@ class ArrayService {
|
|
|
12
18
|
return array1Copy.every((value, index) => value === array2Copy[index]);
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
|
-
|
|
21
|
+
//# sourceMappingURL=ArrayService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArrayService.js","sourceRoot":"./src/","sources":["services/ArrayService.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B;;;;OAIG;IACH,MAAM,CAAC,6BAA6B,CAClC,MAAsB,EACtB,MAAsB;QAEtB,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,UAAU,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;QAC/B,MAAM,UAAU,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;QAE/B,UAAU,CAAC,IAAI,EAAE,CAAC;QAClB,UAAU,CAAC,IAAI,EAAE,CAAC;QAElB,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACzE,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A service which can be used to work with arrays in various ways.
|
|
3
|
+
*/
|
|
4
|
+
export default class ArrayService {
|
|
5
|
+
/**
|
|
6
|
+
* Determines if two arrays have the same primitive values.
|
|
7
|
+
*
|
|
8
|
+
* @returns true if the arrays have the same primitive values, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
static arraysHaveSamePrimitiveValues(
|
|
11
|
+
array1: Array<unknown>,
|
|
12
|
+
array2: Array<unknown>
|
|
13
|
+
): boolean {
|
|
14
|
+
if (array1.length !== array2.length) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const array1Copy = [...array1];
|
|
19
|
+
const array2Copy = [...array2];
|
|
20
|
+
|
|
21
|
+
array1Copy.sort();
|
|
22
|
+
array2Copy.sort();
|
|
23
|
+
|
|
24
|
+
return array1Copy.every((value, index) => value === array2Copy[index]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -56,5 +56,13 @@ export default class DateService {
|
|
|
56
56
|
* It acts as a border between two dates.
|
|
57
57
|
*/
|
|
58
58
|
static dateIsMidnight(date: Date): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Determines if the dates are on the same day.
|
|
61
|
+
*
|
|
62
|
+
* @param first the first date
|
|
63
|
+
* @param second the second date
|
|
64
|
+
* @returns true if they are on the same day
|
|
65
|
+
*/
|
|
66
|
+
static datesAreOnSameDay(first: Date, second: Date): boolean;
|
|
59
67
|
}
|
|
60
68
|
//# sourceMappingURL=DateService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateService.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"DateService.d.ts","sourceRoot":"./src/","sources":["services/DateService/DateService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B,OAAO,CAAC,MAAM,CAAC,aAAa,CAIzB;IAEH,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAM7B;IAEH;;;OAGG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IAO5C;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAIvC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IAIxC,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IAI5C;;OAEG;IACH,MAAM,CAAC,aAAa,CAClB,KAAK,EAAE,IAAI,GAAG,SAAS,GAAG,IAAI,EAC9B,KAAK,EAAE,IAAI,GAAG,SAAS,GAAG,IAAI,GAC7B,OAAO;IAUV;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAS/C;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IAmBzC,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IAK7C,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAQ3D;;;;;;OAMG;IACH,MAAM,CAAC,wBAAwB,CAC7B,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GAAG,MAAM,GACpB,IAAI,GAAG,IAAI;IAiCd;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAM9C,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAMlD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIhD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAMhD;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAO1C;;;;;;OAMG;IACH,MAAM,CAAC,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,OAAO;CAO7D"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* A class that supports converting dates across various personal projects.
|
|
5
3
|
*
|
|
6
4
|
* All of the things in this class should be able to be used in Node and the
|
|
7
5
|
* browser.
|
|
8
6
|
*/
|
|
9
|
-
class DateService {
|
|
7
|
+
export default class DateService {
|
|
10
8
|
static dateFormatter = new Intl.DateTimeFormat('en-US', {
|
|
11
9
|
year: 'numeric',
|
|
12
10
|
month: 'short',
|
|
@@ -159,5 +157,17 @@ class DateService {
|
|
|
159
157
|
return ((date.getHours() === 0 && date.getMinutes() === 0) ||
|
|
160
158
|
(date.getHours() === 23 && date.getMinutes() === 59));
|
|
161
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Determines if the dates are on the same day.
|
|
162
|
+
*
|
|
163
|
+
* @param first the first date
|
|
164
|
+
* @param second the second date
|
|
165
|
+
* @returns true if they are on the same day
|
|
166
|
+
*/
|
|
167
|
+
static datesAreOnSameDay(first, second) {
|
|
168
|
+
return (first.getFullYear() === second.getFullYear() &&
|
|
169
|
+
first.getMonth() === second.getMonth() &&
|
|
170
|
+
first.getDate() === second.getDate());
|
|
171
|
+
}
|
|
162
172
|
}
|
|
163
|
-
|
|
173
|
+
//# sourceMappingURL=DateService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateService.js","sourceRoot":"./src/","sources":["services/DateService/DateService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IACtB,MAAM,CAAC,aAAa,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;QAC9D,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,OAAO;QACd,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IAEK,MAAM,CAAC,iBAAiB,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;QAClE,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,OAAO;QACd,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;KAClB,CAAC,CAAC;IAEH;;;OAGG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAU;QACjC,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,IAAU;QAC3B,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,IAAU;QAC7B,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,IAAU;QACjC,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAClB,KAA8B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C,WAAW,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,CAAC;QACnD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,IAAU;QAC9B,OAAO,CACL,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;YAClD,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CACrD,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,iBAAiB,CAAC,KAAW,EAAE,MAAY;QAChD,OAAO,CACL,KAAK,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,WAAW,EAAE;YAC5C,KAAK,CAAC,QAAQ,EAAE,KAAK,MAAM,CAAC,QAAQ,EAAE;YACtC,KAAK,CAAC,OAAO,EAAE,KAAK,MAAM,CAAC,OAAO,EAAE,CACrC,CAAC;IACJ,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import DateService from './DateService.js';
|
|
2
|
+
|
|
3
|
+
describe('DateService', () => {
|
|
4
|
+
describe('addWeeks', () => {
|
|
5
|
+
it('should successfully add weeks to a date', () => {
|
|
6
|
+
const result = DateService.addWeeks(new Date(2024, 0, 1), 1);
|
|
7
|
+
expect(result).toEqual(new Date(2024, 0, 8));
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should successfully add weeks to a date that crosses months', () => {
|
|
11
|
+
const result = DateService.addWeeks(new Date(2024, 0, 23), 2);
|
|
12
|
+
expect(result).toEqual(new Date(2024, 1, 6));
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should successfully add weeks to a date that crosses years', () => {
|
|
16
|
+
const result = DateService.addWeeks(new Date(2024, 11, 25), 1);
|
|
17
|
+
expect(result).toEqual(new Date(2025, 0, 1));
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('getWeekOfMonth', () => {
|
|
22
|
+
it('should successfully get the week of month for a date', () => {
|
|
23
|
+
const result = DateService.getWeekOfMonth(new Date(2024, 0, 14));
|
|
24
|
+
expect(result).toEqual(3);
|
|
25
|
+
|
|
26
|
+
const result2 = DateService.getWeekOfMonth(new Date(2024, 0, 1));
|
|
27
|
+
expect(result2).toEqual(1);
|
|
28
|
+
|
|
29
|
+
const result3 = DateService.getWeekOfMonth(new Date(2024, 0, 31));
|
|
30
|
+
expect(result3).toEqual(5);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('getWeekDayOfXWeekOfMonth', () => {
|
|
35
|
+
it('should successfully get the 2nd monday of January 2024', () => {
|
|
36
|
+
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
37
|
+
new Date(2024, 0, 1),
|
|
38
|
+
1,
|
|
39
|
+
2
|
|
40
|
+
);
|
|
41
|
+
expect(result).toEqual(new Date(2024, 0, 8));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should successfully get the 3rd monday of January 2024', () => {
|
|
45
|
+
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
46
|
+
new Date(2024, 0, 1),
|
|
47
|
+
1,
|
|
48
|
+
3
|
|
49
|
+
);
|
|
50
|
+
expect(result).toEqual(new Date(2024, 0, 15));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should successfully get the 3rd tuesday of January 2024', () => {
|
|
54
|
+
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
55
|
+
new Date(2024, 0, 1),
|
|
56
|
+
2,
|
|
57
|
+
3
|
|
58
|
+
);
|
|
59
|
+
expect(result).toEqual(new Date(2024, 0, 16));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should successfully get the 1st Saturday of January 2024', () => {
|
|
63
|
+
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
64
|
+
new Date(2024, 0, 1),
|
|
65
|
+
6,
|
|
66
|
+
1
|
|
67
|
+
);
|
|
68
|
+
expect(result).toEqual(new Date(2024, 0, 6));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should successfully get the 1st sunday of January 2024', () => {
|
|
72
|
+
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
73
|
+
new Date(2024, 0, 1),
|
|
74
|
+
0,
|
|
75
|
+
1
|
|
76
|
+
);
|
|
77
|
+
expect(result).toEqual(new Date(2024, 0, 7));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should successfully get the last sunday of January 2024', () => {
|
|
81
|
+
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
82
|
+
new Date(2024, 0, 1),
|
|
83
|
+
0,
|
|
84
|
+
'last'
|
|
85
|
+
);
|
|
86
|
+
expect(result).toEqual(new Date(2024, 0, 28));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should return null if the week and day do not exist', () => {
|
|
90
|
+
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
91
|
+
new Date(2024, 0, 1),
|
|
92
|
+
0,
|
|
93
|
+
5
|
|
94
|
+
);
|
|
95
|
+
expect(result).toEqual(null);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class that supports converting dates across various personal projects.
|
|
3
|
+
*
|
|
4
|
+
* All of the things in this class should be able to be used in Node and the
|
|
5
|
+
* browser.
|
|
6
|
+
*/
|
|
7
|
+
export default class DateService {
|
|
8
|
+
private static dateFormatter = new Intl.DateTimeFormat('en-US', {
|
|
9
|
+
year: 'numeric',
|
|
10
|
+
month: 'short',
|
|
11
|
+
day: 'numeric'
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
private static dateTimeFormatter = new Intl.DateTimeFormat('en-US', {
|
|
15
|
+
year: 'numeric',
|
|
16
|
+
month: 'short',
|
|
17
|
+
day: 'numeric',
|
|
18
|
+
hour: 'numeric',
|
|
19
|
+
minute: 'numeric'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Gets the date in date format if it is set to midnight, otherwise gets the
|
|
24
|
+
* date in date time format.
|
|
25
|
+
*/
|
|
26
|
+
static getAutoDateString(date: Date): string {
|
|
27
|
+
if (this.dateHasTime(date)) {
|
|
28
|
+
return this.getDateTimeString(date);
|
|
29
|
+
}
|
|
30
|
+
return this.getDateString(date);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Determines if a date has a user-specified time component to it, meaning
|
|
35
|
+
* that it isn't midnight.
|
|
36
|
+
*/
|
|
37
|
+
static dateHasTime(date: Date): boolean {
|
|
38
|
+
return !this.dateIsMidnight(date);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static getDateString(date: Date): string {
|
|
42
|
+
return this.dateFormatter.format(date);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static getDateTimeString(date: Date): string {
|
|
46
|
+
return this.dateTimeFormatter.format(date);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Determines if two dates are equal. This is strict, down to the ms.
|
|
51
|
+
*/
|
|
52
|
+
static datesAreEqual(
|
|
53
|
+
date1: Date | undefined | null,
|
|
54
|
+
date2: Date | undefined | null
|
|
55
|
+
): boolean {
|
|
56
|
+
if (!date1 && !date2) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (!date1 || !date2) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return date1.getTime() === date2.getTime();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Gets the last day of the month for the provided date. This will retain the
|
|
67
|
+
* time that was provided in the date.
|
|
68
|
+
*/
|
|
69
|
+
static getLastDayOfGivenMonth(date: Date): Date {
|
|
70
|
+
// Setting the day to 0, makes the date move to the last day of the
|
|
71
|
+
// previous month.
|
|
72
|
+
const newDate = new Date(date);
|
|
73
|
+
newDate.setMonth(newDate.getMonth() + 1);
|
|
74
|
+
newDate.setDate(0);
|
|
75
|
+
return newDate;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Gets the week of the month for the provided date. This starts at 1.
|
|
80
|
+
*/
|
|
81
|
+
static getWeekOfMonth(date: Date): number {
|
|
82
|
+
const firstDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1);
|
|
83
|
+
const firstDayOfMonthWeekday = firstDayOfMonth.getDay();
|
|
84
|
+
const firstDayOfSecondWeek = new Date(firstDayOfMonth);
|
|
85
|
+
const daysUntilSecondWeek = 7 - firstDayOfMonthWeekday;
|
|
86
|
+
firstDayOfSecondWeek.setDate(
|
|
87
|
+
firstDayOfSecondWeek.getDate() + daysUntilSecondWeek
|
|
88
|
+
);
|
|
89
|
+
if (date < firstDayOfSecondWeek) {
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
const daysSinceFirstDayOfSecondWeek =
|
|
93
|
+
date.getDate() - firstDayOfSecondWeek.getDate();
|
|
94
|
+
const weeksSinceFirstDayOfSecondWeek = Math.floor(
|
|
95
|
+
daysSinceFirstDayOfSecondWeek / 7
|
|
96
|
+
);
|
|
97
|
+
return weeksSinceFirstDayOfSecondWeek + 2;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static getLastWeekOfMonth(date: Date): number {
|
|
101
|
+
const lastDayOfMonth = this.getLastDayOfGivenMonth(date);
|
|
102
|
+
return this.getWeekOfMonth(lastDayOfMonth);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static getDaysUntilWeekDay(date: Date, day: number): number {
|
|
106
|
+
const daysUntilWeekDay = day - date.getDay();
|
|
107
|
+
if (daysUntilWeekDay < 0) {
|
|
108
|
+
return daysUntilWeekDay + 7;
|
|
109
|
+
}
|
|
110
|
+
return daysUntilWeekDay;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Gets the date of the provided weekday in the provided week of the month.
|
|
115
|
+
* Retains the time that was provided in the date.
|
|
116
|
+
*
|
|
117
|
+
* For example, the 2nd Monday of the month, or the last Saturday of the
|
|
118
|
+
* month.
|
|
119
|
+
*/
|
|
120
|
+
static getWeekDayOfXWeekOfMonth(
|
|
121
|
+
date: Date,
|
|
122
|
+
day: number,
|
|
123
|
+
week: number | 'last'
|
|
124
|
+
): Date | null {
|
|
125
|
+
if (
|
|
126
|
+
(typeof week === 'number' && (week < 1 || week > 5)) ||
|
|
127
|
+
day < 0 ||
|
|
128
|
+
day > 6
|
|
129
|
+
) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
if (week === 'last') {
|
|
133
|
+
let resultDate = this.getLastDayOfGivenMonth(date);
|
|
134
|
+
while (resultDate.getDay() !== day) {
|
|
135
|
+
resultDate = this.addDays(resultDate, -1);
|
|
136
|
+
}
|
|
137
|
+
return resultDate;
|
|
138
|
+
}
|
|
139
|
+
const firstDayOfMonth = new Date(date);
|
|
140
|
+
firstDayOfMonth.setDate(1);
|
|
141
|
+
let resultDate = new Date(firstDayOfMonth);
|
|
142
|
+
resultDate.setDate(
|
|
143
|
+
resultDate.getDate() + this.getDaysUntilWeekDay(firstDayOfMonth, day)
|
|
144
|
+
);
|
|
145
|
+
// The number of times the day has shown up so far.
|
|
146
|
+
let instanceOfDay = 1;
|
|
147
|
+
while (instanceOfDay < week) {
|
|
148
|
+
resultDate = this.addWeeks(resultDate, 1);
|
|
149
|
+
instanceOfDay += 1;
|
|
150
|
+
if (resultDate.getMonth() !== date.getMonth()) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return resultDate;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Adds the provided number of days to the provided date. If the days are
|
|
159
|
+
* over or under the number of days in the month, then the month will be
|
|
160
|
+
* adjusted accordingly.
|
|
161
|
+
*/
|
|
162
|
+
static addDays(date: Date, days: number): Date {
|
|
163
|
+
const newDate = new Date(date);
|
|
164
|
+
newDate.setDate(newDate.getDate() + days);
|
|
165
|
+
return newDate;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static addMonths(date: Date, months: number): Date {
|
|
169
|
+
const newDate = new Date(date);
|
|
170
|
+
newDate.setMonth(newDate.getMonth() + months);
|
|
171
|
+
return newDate;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static addWeeks(date: Date, weeks: number): Date {
|
|
175
|
+
return this.addDays(date, weeks * 7);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static addYears(date: Date, years: number): Date {
|
|
179
|
+
const newDate = new Date(date);
|
|
180
|
+
newDate.setFullYear(newDate.getFullYear() + years);
|
|
181
|
+
return newDate;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* For personal projects, midnight can mean exactly midnight, or 11:59pm.
|
|
186
|
+
* It acts as a border between two dates.
|
|
187
|
+
*/
|
|
188
|
+
static dateIsMidnight(date: Date): boolean {
|
|
189
|
+
return (
|
|
190
|
+
(date.getHours() === 0 && date.getMinutes() === 0) ||
|
|
191
|
+
(date.getHours() === 23 && date.getMinutes() === 59)
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Determines if the dates are on the same day.
|
|
197
|
+
*
|
|
198
|
+
* @param first the first date
|
|
199
|
+
* @param second the second date
|
|
200
|
+
* @returns true if they are on the same day
|
|
201
|
+
*/
|
|
202
|
+
static datesAreOnSameDay(first: Date, second: Date): boolean {
|
|
203
|
+
return (
|
|
204
|
+
first.getFullYear() === second.getFullYear() &&
|
|
205
|
+
first.getMonth() === second.getMonth() &&
|
|
206
|
+
first.getDate() === second.getDate()
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface PackageJson extends JsonWithVersionProperty {
|
|
2
2
|
name: string;
|
|
3
|
-
version: string;
|
|
4
3
|
dependencies?: Record<string, string>;
|
|
5
4
|
devDependencies?: Record<string, string>;
|
|
6
5
|
peerDependencies?: Record<string, string>;
|
|
7
6
|
optionalDependencies?: Record<string, string>;
|
|
8
|
-
}
|
|
7
|
+
}
|
|
8
|
+
export interface JsonWithVersionProperty {
|
|
9
|
+
version: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Standard Semantic Versioning bump types.
|
|
13
|
+
*/
|
|
14
|
+
export declare enum VersionType {
|
|
15
|
+
Patch = "patch",
|
|
16
|
+
Minor = "minor",
|
|
17
|
+
Major = "major"
|
|
18
|
+
}
|
|
9
19
|
/**
|
|
10
20
|
* A service which can be used to manage dependencies in the current project
|
|
11
21
|
* in various ways.
|
|
@@ -17,5 +27,11 @@ export default class DependencyService {
|
|
|
17
27
|
* sub-directories to the version in the root package.json file.
|
|
18
28
|
*/
|
|
19
29
|
static updateChildPackageJsons(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Bumps the version of the package.json and jsr.json files in the current
|
|
32
|
+
* working directory.
|
|
33
|
+
* @param versionType The type of version bump (patch, minor, major).
|
|
34
|
+
*/
|
|
35
|
+
static bumpVersion(versionType?: VersionType): Promise<void>;
|
|
20
36
|
}
|
|
21
37
|
//# sourceMappingURL=DependencyService.d.ts.map
|