@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"./src/","sources":["utils/Logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAClB,MAAM,CAAC,qBAAqB,GAAG,KAAK,CAAC;IAE5C;;;OAGG;IACK,gBAAgB,GAAG,KAAK,CAAC;IAEjC,YAAY,gBAA0B;QACpC,IAAI,gBAAgB,EAAE,CAAC;YACrB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QAC3C,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,MAAM,KAAK,OAAO;QAChB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,GAAW,EAAE,WAAqB;QACrC,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;YACrB,MAAM,YAAY,GAAG,OAAO,GAAG,EAAE,CAAC;YAClC,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YACrC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,GAAW,EAAE,WAAqB;QAC5C,IAAI,MAAM,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,GAAW;QACjB,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;YACrB,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAW;QACxB,IAAI,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,GAAW;QACjB,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;YACrB,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAW;QACxB,IAAI,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAW;QACf,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;YACrB,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,GAAW;QACtB,IAAI,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAEO,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,gBAAgB,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;YAC3D,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A standard logger that can be used to log messages to the console.
|
|
3
|
+
*/
|
|
4
|
+
export default class Logger {
|
|
5
|
+
public static verboseLoggingEnabled = false;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Private variable that sets if any logging on this instance of the Log
|
|
9
|
+
* should only log if the `verboseLoggingEnabled` is set to true.
|
|
10
|
+
*/
|
|
11
|
+
private logOnlyIfVerbose = false;
|
|
12
|
+
|
|
13
|
+
constructor(logOnlyIfVerbose?: boolean) {
|
|
14
|
+
if (logOnlyIfVerbose) {
|
|
15
|
+
this.logOnlyIfVerbose = logOnlyIfVerbose;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Sets the logging of the next chained function to only be activated
|
|
21
|
+
* if verbose logging is turned on.
|
|
22
|
+
*/
|
|
23
|
+
static get verbose(): Logger {
|
|
24
|
+
return new Logger(true);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Logs info to the console. Prepends `ℹ️` to each message.
|
|
29
|
+
*/
|
|
30
|
+
info(msg: string, skipNewline?: boolean): void {
|
|
31
|
+
if (this.shouldLog()) {
|
|
32
|
+
const printMessage = `ℹ️ ${msg}`;
|
|
33
|
+
if (skipNewline) {
|
|
34
|
+
process.stdout.write(printMessage);
|
|
35
|
+
} else {
|
|
36
|
+
console.log(printMessage);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Static version of {@link Logger.prototype.info}.
|
|
43
|
+
*
|
|
44
|
+
* @see Logger.prototype.info
|
|
45
|
+
*/
|
|
46
|
+
static info(msg: string, skipNewline?: boolean): void {
|
|
47
|
+
new Logger().info(msg, skipNewline);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Logs a success message to the console. Prepends `✅` to each message.
|
|
52
|
+
*
|
|
53
|
+
* @param msg
|
|
54
|
+
*/
|
|
55
|
+
success(msg: string): void {
|
|
56
|
+
if (this.shouldLog()) {
|
|
57
|
+
console.log(`✅ ${msg}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Static version of {@link Logger.prototype.success}.
|
|
63
|
+
*
|
|
64
|
+
* @see Logger.prototype.success
|
|
65
|
+
*/
|
|
66
|
+
static success(msg: string): void {
|
|
67
|
+
new Logger().success(msg);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Logs a failure message to the console. Prepends `🔴` to each message.
|
|
72
|
+
*
|
|
73
|
+
* See {@link error} for logging errors.
|
|
74
|
+
*
|
|
75
|
+
* This doesn't use a `console.error` entry. Just a `console.log` entry.
|
|
76
|
+
* @param msg
|
|
77
|
+
*/
|
|
78
|
+
failure(msg: string): void {
|
|
79
|
+
if (this.shouldLog()) {
|
|
80
|
+
console.log(`🔴 ${msg}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Static version of {@link Logger.prototype.failure}.
|
|
86
|
+
*
|
|
87
|
+
* @see Logger.prototype.failure
|
|
88
|
+
*/
|
|
89
|
+
static failure(msg: string): void {
|
|
90
|
+
new Logger().failure(msg);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Logs an error message to the console. Only use this for errors that will
|
|
95
|
+
* likely stop execution. Prepends `💀` to each message and uses `console.error`.
|
|
96
|
+
*
|
|
97
|
+
* See {@link failure} for logging simple failures.
|
|
98
|
+
*
|
|
99
|
+
* @param msg
|
|
100
|
+
*/
|
|
101
|
+
error(msg: string): void {
|
|
102
|
+
if (this.shouldLog()) {
|
|
103
|
+
console.error(`💀 ${msg}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Static version of {@link Logger.prototype.error}.
|
|
109
|
+
*
|
|
110
|
+
* @see Logger.prototype.error
|
|
111
|
+
*/
|
|
112
|
+
static error(msg: string): void {
|
|
113
|
+
new Logger().error(msg);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private shouldLog(): boolean {
|
|
117
|
+
if (!this.logOnlyIfVerbose || Logger.verboseLoggingEnabled) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
package/lib/utils/TestUtils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestUtils.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"TestUtils.d.ts","sourceRoot":"./src/","sources":["utils/TestUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAC,cAAc,CAK3B;IAEF;;;OAGG;WACW,eAAe;IAO7B;;;OAGG;WACW,cAAc;CAM7B"}
|
package/lib/utils/TestUtils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Utility class used for testing purposes.
|
|
3
|
+
*/
|
|
4
|
+
export default class TestUtils {
|
|
4
5
|
static consoleLoggers = {
|
|
5
6
|
error: console.error,
|
|
6
7
|
log: console.log,
|
|
@@ -12,10 +13,10 @@ class TestUtils {
|
|
|
12
13
|
* Use `restoreConsole` when the test is finished to restore the console.
|
|
13
14
|
*/
|
|
14
15
|
static suppressConsole() {
|
|
15
|
-
console.error =
|
|
16
|
-
console.log =
|
|
17
|
-
console.info =
|
|
18
|
-
console.warn =
|
|
16
|
+
console.error = () => { };
|
|
17
|
+
console.log = () => { };
|
|
18
|
+
console.info = () => { };
|
|
19
|
+
console.warn = () => { };
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* Restores the normal console output functionality of all console loggers
|
|
@@ -28,4 +29,4 @@ class TestUtils {
|
|
|
28
29
|
console.warn = TestUtils.consoleLoggers.warn;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
//# sourceMappingURL=TestUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestUtils.js","sourceRoot":"./src/","sources":["utils/TestUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IACpB,MAAM,CAAC,cAAc,GAAG;QAC9B,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC;IAEF;;;OAGG;IACI,MAAM,CAAC,eAAe;QAC3B,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QACzB,OAAO,CAAC,GAAG,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QACvB,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QACxB,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,cAAc;QAC1B,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC;QAC/C,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC;QAC3C,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC;QAC7C,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC;IAC/C,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class used for testing purposes.
|
|
3
|
+
*/
|
|
4
|
+
export default class TestUtils {
|
|
5
|
+
private static consoleLoggers = {
|
|
6
|
+
error: console.error,
|
|
7
|
+
log: console.log,
|
|
8
|
+
info: console.info,
|
|
9
|
+
warn: console.warn
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Suppresses the console output of all console loggers (error, log, info, etc.).
|
|
14
|
+
* Use `restoreConsole` when the test is finished to restore the console.
|
|
15
|
+
*/
|
|
16
|
+
public static suppressConsole() {
|
|
17
|
+
console.error = () => {};
|
|
18
|
+
console.log = () => {};
|
|
19
|
+
console.info = () => {};
|
|
20
|
+
console.warn = () => {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Restores the normal console output functionality of all console loggers
|
|
25
|
+
* (error, log, info, etc.).
|
|
26
|
+
*/
|
|
27
|
+
public static restoreConsole() {
|
|
28
|
+
console.error = TestUtils.consoleLoggers.error;
|
|
29
|
+
console.log = TestUtils.consoleLoggers.log;
|
|
30
|
+
console.info = TestUtils.consoleLoggers.info;
|
|
31
|
+
console.warn = TestUtils.consoleLoggers.warn;
|
|
32
|
+
}
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,47 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aneuhold/core-ts-lib",
|
|
3
|
-
"
|
|
3
|
+
"author": "Anton G. Neuhold Jr.",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"version": "2.0.6",
|
|
4
6
|
"description": "A core library for all of my TypeScript projects",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"types": "lib/index.d.ts",
|
|
7
7
|
"packageManager": "yarn@4.5.1",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"scripts": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"watch": "tsc -w",
|
|
12
|
-
"link:local": "cd lib && yarn link",
|
|
13
|
-
"unlink:local": "cd lib && yarn unlink",
|
|
14
|
-
"upgrade:all": "yarn up",
|
|
10
|
+
"build": "rimraf lib && tsc --project tsconfig.build.json && tsx ./scripts/copyTsFiles.ts",
|
|
11
|
+
"lint": "eslint",
|
|
15
12
|
"test": "jest",
|
|
16
|
-
"
|
|
13
|
+
"jsr:validate": "tsx ./scripts/validateJsrPublish.ts",
|
|
14
|
+
"checkAll": "yarn build && yarn lint && yarn test && yarn jsr:validate",
|
|
15
|
+
"jsr:publish": "tsx ./scripts/publishJsr.ts",
|
|
16
|
+
"upgrade:all": "yarn up"
|
|
17
|
+
},
|
|
18
|
+
"main": "lib/index.js",
|
|
19
|
+
"module": "lib/index.js",
|
|
20
|
+
"types": "lib/index.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"lib/**/*"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./lib/index.d.ts",
|
|
27
|
+
"import": "./lib/index.js"
|
|
28
|
+
}
|
|
17
29
|
},
|
|
18
|
-
"type": "commonjs",
|
|
19
30
|
"repository": {
|
|
20
31
|
"type": "git",
|
|
21
32
|
"url": "git+https://github.com/aneuhold/core-ts-lib.git"
|
|
22
33
|
},
|
|
23
|
-
"keywords": [
|
|
24
|
-
"Scripting",
|
|
25
|
-
"Node.js"
|
|
26
|
-
],
|
|
27
|
-
"author": "Anton G. Neuhold Jr.",
|
|
28
|
-
"license": "MIT",
|
|
29
34
|
"bugs": {
|
|
30
35
|
"url": "https://github.com/aneuhold/core-ts-lib/issues"
|
|
31
36
|
},
|
|
32
37
|
"homepage": "https://github.com/aneuhold/core-ts-lib#readme",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
38
|
+
"keywords": [
|
|
39
|
+
"Scripting",
|
|
40
|
+
"Node.js"
|
|
35
41
|
],
|
|
36
42
|
"devDependencies": {
|
|
37
|
-
"@aneuhold/eslint-config": "^1.0.
|
|
43
|
+
"@aneuhold/eslint-config": "^1.0.37",
|
|
38
44
|
"@types/jest": "^29.5.13",
|
|
39
45
|
"@types/node": "^20.16.13",
|
|
40
46
|
"eslint": "^9.13.0",
|
|
41
47
|
"jest": "^29.7.0",
|
|
48
|
+
"jsr": "*",
|
|
42
49
|
"prettier": "^3.3.3",
|
|
50
|
+
"rimraf": "^6.0.1",
|
|
43
51
|
"ts-jest": "^29.2.5",
|
|
44
|
-
"
|
|
52
|
+
"tsx": "^4.19.1",
|
|
45
53
|
"typescript": "^5.6.3"
|
|
46
54
|
}
|
|
47
55
|
}
|
package/readme.md
CHANGED
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
# core-ts-lib
|
|
2
2
|
|
|
3
|
-
](https://jsr.io/@aneuhold/core-ts-lib)
|
|
4
|
+
[](https://www.npmjs.com/package/@aneuhold/core-ts-lib)
|
|
5
|
+
[](https://github.com/aneuhold/core-ts-lib/blob/main/LICENSE)
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
A library containing TypeScript that I am sharing among most TypeScript-based projects. This package is published using ES Modules only.
|
|
8
|
+
|
|
9
|
+
## 📦 Installation
|
|
10
|
+
|
|
11
|
+
To add to a repo, follow the instructions below for your environment:
|
|
12
|
+
|
|
13
|
+
### For Node using NPM
|
|
14
|
+
|
|
15
|
+
Run `yarn add @aneuhold/core-ts-lib`
|
|
16
|
+
|
|
17
|
+
### For Node using JSR
|
|
18
|
+
|
|
19
|
+
The below instructions still allow for things like Renovate to work, and normal commands with yarn such as `yarn up`.
|
|
20
|
+
|
|
21
|
+
1. Add the required JSR configuration to a `.yarnrc.yml` file if not there already:
|
|
22
|
+
```yml
|
|
23
|
+
npmScopes:
|
|
24
|
+
jsr:
|
|
25
|
+
npmRegistryServer: 'https://npm.jsr.io'
|
|
26
|
+
```
|
|
27
|
+
1. Add the package with `yarn add @jsr/aneuhold__core-ts-lib`
|
|
28
|
+
|
|
29
|
+
### For Deno
|
|
30
|
+
|
|
31
|
+
Run `deno add jsr:@aneuhold/core-ts-lib`
|
|
32
|
+
|
|
33
|
+
## 🟢 Usage
|
|
34
|
+
|
|
35
|
+
Pull in one of the services and use it like so:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { Logger } from '@aneuhold/core-ts-lib';
|
|
39
|
+
// If using Node with JSR
|
|
40
|
+
// import { Logger } from '@jsr/aneuhold__core-ts-lib';
|
|
41
|
+
|
|
42
|
+
export default function logSomething() {
|
|
43
|
+
Logger.info('Something');
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
[See full documentation on usage at JSR!](https://jsr.io/@aneuhold/core-ts-lib/doc)
|
|
48
|
+
|
|
49
|
+
## 🛠️ Development
|
|
50
|
+
|
|
51
|
+
### Updating via PR
|
|
52
|
+
|
|
53
|
+
1. Create a new branch locally
|
|
54
|
+
1. Make some changes locally
|
|
55
|
+
1. Run `yarn version patch`
|
|
56
|
+
1. Push the branch up to a PR to make sure it passes checks
|
|
57
|
+
1. Once it passes checks, merge the PR and it will automatically get deployed.
|
|
58
|
+
|
|
59
|
+
### Updating via Push to Main
|
|
60
|
+
|
|
61
|
+
1. Make changes locally
|
|
62
|
+
2. Run `yarn version patch`
|
|
63
|
+
3. Run `yarn checkAll`
|
|
64
|
+
4. Push it up to main. This will get automatically deployed.
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Determines if the dates are on the same day.
|
|
3
|
-
*
|
|
4
|
-
* @param first the first date
|
|
5
|
-
* @param second the second date
|
|
6
|
-
* @returns true if they are on the same day
|
|
7
|
-
*/
|
|
8
|
-
declare function datesAreOnSameDay(first: Date, second: Date): boolean;
|
|
9
|
-
export default datesAreOnSameDay;
|
|
10
|
-
//# sourceMappingURL=dateFunctions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dateFunctions.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/dateFunctions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,iBAAS,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,OAAO,CAM7D;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Determines if the dates are on the same day.
|
|
5
|
-
*
|
|
6
|
-
* @param first the first date
|
|
7
|
-
* @param second the second date
|
|
8
|
-
* @returns true if they are on the same day
|
|
9
|
-
*/
|
|
10
|
-
function datesAreOnSameDay(first, second) {
|
|
11
|
-
return (first.getFullYear() === second.getFullYear() &&
|
|
12
|
-
first.getMonth() === second.getMonth() &&
|
|
13
|
-
first.getDate() === second.getDate());
|
|
14
|
-
}
|
|
15
|
-
exports.default = datesAreOnSameDay;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DateService.spec.d.ts","sourceRoot":"","sources":["../../../src/services/DateService/DateService.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const DateService_1 = __importDefault(require("./DateService"));
|
|
7
|
-
describe('DateService', () => {
|
|
8
|
-
describe('addWeeks', () => {
|
|
9
|
-
it('should successfully add weeks to a date', () => {
|
|
10
|
-
const result = DateService_1.default.addWeeks(new Date(2024, 0, 1), 1);
|
|
11
|
-
expect(result).toEqual(new Date(2024, 0, 8));
|
|
12
|
-
});
|
|
13
|
-
it('should successfully add weeks to a date that crosses months', () => {
|
|
14
|
-
const result = DateService_1.default.addWeeks(new Date(2024, 0, 23), 2);
|
|
15
|
-
expect(result).toEqual(new Date(2024, 1, 6));
|
|
16
|
-
});
|
|
17
|
-
it('should successfully add weeks to a date that crosses years', () => {
|
|
18
|
-
const result = DateService_1.default.addWeeks(new Date(2024, 11, 25), 1);
|
|
19
|
-
expect(result).toEqual(new Date(2025, 0, 1));
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe('getWeekOfMonth', () => {
|
|
23
|
-
it('should successfully get the week of month for a date', () => {
|
|
24
|
-
const result = DateService_1.default.getWeekOfMonth(new Date(2024, 0, 14));
|
|
25
|
-
expect(result).toEqual(3);
|
|
26
|
-
const result2 = DateService_1.default.getWeekOfMonth(new Date(2024, 0, 1));
|
|
27
|
-
expect(result2).toEqual(1);
|
|
28
|
-
const result3 = DateService_1.default.getWeekOfMonth(new Date(2024, 0, 31));
|
|
29
|
-
expect(result3).toEqual(5);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
describe('getWeekDayOfXWeekOfMonth', () => {
|
|
33
|
-
it('should successfully get the 2nd monday of January 2024', () => {
|
|
34
|
-
const result = DateService_1.default.getWeekDayOfXWeekOfMonth(new Date(2024, 0, 1), 1, 2);
|
|
35
|
-
expect(result).toEqual(new Date(2024, 0, 8));
|
|
36
|
-
});
|
|
37
|
-
it('should successfully get the 3rd monday of January 2024', () => {
|
|
38
|
-
const result = DateService_1.default.getWeekDayOfXWeekOfMonth(new Date(2024, 0, 1), 1, 3);
|
|
39
|
-
expect(result).toEqual(new Date(2024, 0, 15));
|
|
40
|
-
});
|
|
41
|
-
it('should successfully get the 3rd tuesday of January 2024', () => {
|
|
42
|
-
const result = DateService_1.default.getWeekDayOfXWeekOfMonth(new Date(2024, 0, 1), 2, 3);
|
|
43
|
-
expect(result).toEqual(new Date(2024, 0, 16));
|
|
44
|
-
});
|
|
45
|
-
it('should successfully get the 1st Saturday of January 2024', () => {
|
|
46
|
-
const result = DateService_1.default.getWeekDayOfXWeekOfMonth(new Date(2024, 0, 1), 6, 1);
|
|
47
|
-
expect(result).toEqual(new Date(2024, 0, 6));
|
|
48
|
-
});
|
|
49
|
-
it('should successfully get the 1st sunday of January 2024', () => {
|
|
50
|
-
const result = DateService_1.default.getWeekDayOfXWeekOfMonth(new Date(2024, 0, 1), 0, 1);
|
|
51
|
-
expect(result).toEqual(new Date(2024, 0, 7));
|
|
52
|
-
});
|
|
53
|
-
it('should successfully get the last sunday of January 2024', () => {
|
|
54
|
-
const result = DateService_1.default.getWeekDayOfXWeekOfMonth(new Date(2024, 0, 1), 0, 'last');
|
|
55
|
-
expect(result).toEqual(new Date(2024, 0, 28));
|
|
56
|
-
});
|
|
57
|
-
it('should return null if the week and day do not exist', () => {
|
|
58
|
-
const result = DateService_1.default.getWeekDayOfXWeekOfMonth(new Date(2024, 0, 1), 0, 5);
|
|
59
|
-
expect(result).toEqual(null);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystemService.spec.d.ts","sourceRoot":"","sources":["../../../src/services/FileSystemService/FileSystemService.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const promises_1 = require("fs/promises");
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const FileSystemService_1 = __importDefault(require("./FileSystemService"));
|
|
9
|
-
const TEST_FOLDER_NAME = '__fileSystemService-tests__';
|
|
10
|
-
describe('FileSystemService', () => {
|
|
11
|
-
afterAll(async () => {
|
|
12
|
-
await deleteTestFolder();
|
|
13
|
-
});
|
|
14
|
-
describe('copyFolderContents', () => {
|
|
15
|
-
it('should successfully copy all contents when target folder doesnt exist', async () => {
|
|
16
|
-
// Make a test folder with a folder and a couple files in it
|
|
17
|
-
const testName = 'copyFolderContents-1';
|
|
18
|
-
const sourceFolderName = `${testName}-source`;
|
|
19
|
-
const sourceFolderPath = await createTestFolder(sourceFolderName);
|
|
20
|
-
await createTestFiles(sourceFolderPath, {
|
|
21
|
-
'file1.txt': 'test text',
|
|
22
|
-
'file2.txt': 'test text',
|
|
23
|
-
subFolder: {
|
|
24
|
-
'subFile1.txt': 'sub test text',
|
|
25
|
-
'subFile2.txt': 'sub test text'
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
const targetFolderPath = path_1.default.join(TEST_FOLDER_NAME, `${testName}-target`);
|
|
29
|
-
// Execute
|
|
30
|
-
await FileSystemService_1.default.copyFolderContents(sourceFolderPath, targetFolderPath);
|
|
31
|
-
// Assert
|
|
32
|
-
const expectedContents = await FileSystemService_1.default.getAllFilePathsRelative(sourceFolderPath);
|
|
33
|
-
const actualContents = await FileSystemService_1.default.getAllFilePathsRelative(targetFolderPath);
|
|
34
|
-
expect(actualContents).toEqual(expectedContents);
|
|
35
|
-
});
|
|
36
|
-
it('should successfully copy only files that arent ignored', async () => {
|
|
37
|
-
// Make a test folder with a folder and a couple files in it
|
|
38
|
-
const testName = 'copyFolderContents-2';
|
|
39
|
-
const sourceFolderName = `${testName}-source`;
|
|
40
|
-
const sourceFolderPath = await createTestFolder(sourceFolderName);
|
|
41
|
-
await createTestFiles(sourceFolderPath, {
|
|
42
|
-
'file1.txt': 'test text',
|
|
43
|
-
'file2.txt': 'test text',
|
|
44
|
-
subFolder: {
|
|
45
|
-
'subFile1.txt': 'sub test text',
|
|
46
|
-
'subFile2.txt': 'sub test text'
|
|
47
|
-
},
|
|
48
|
-
javascript: {
|
|
49
|
-
'file1.js': 'test text',
|
|
50
|
-
'file2.js': 'test text'
|
|
51
|
-
},
|
|
52
|
-
typescript: {
|
|
53
|
-
'file1.ts': 'test text',
|
|
54
|
-
'file2.ts': 'test text'
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
const targetFolderPath = path_1.default.join(TEST_FOLDER_NAME, `${testName}-target`);
|
|
58
|
-
// Execute
|
|
59
|
-
await FileSystemService_1.default.copyFolderContents(sourceFolderPath, targetFolderPath, ['ts']);
|
|
60
|
-
// Assert
|
|
61
|
-
const expectedContents = (await FileSystemService_1.default.getAllFilePathsRelative(sourceFolderPath))
|
|
62
|
-
.filter((sourceFilePath) => !sourceFilePath.endsWith('.ts'))
|
|
63
|
-
.sort();
|
|
64
|
-
const actualContents = (await FileSystemService_1.default.getAllFilePathsRelative(targetFolderPath)).sort();
|
|
65
|
-
expect(actualContents).toEqual(expectedContents);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
async function createTestFiles(folderPath, fileStructure) {
|
|
70
|
-
await FileSystemService_1.default.checkOrCreateFolder(folderPath);
|
|
71
|
-
await Promise.all(Object.entries(fileStructure).map(async ([key, value]) => {
|
|
72
|
-
if (typeof value === 'string') {
|
|
73
|
-
await (0, promises_1.writeFile)(path_1.default.join(folderPath, key), value);
|
|
74
|
-
}
|
|
75
|
-
else if (typeof value === 'object') {
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
77
|
-
await createTestFiles(path_1.default.join(folderPath, key), value);
|
|
78
|
-
}
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
async function createTestFolder(folderName) {
|
|
82
|
-
const testFolderPath = path_1.default.join(TEST_FOLDER_NAME, folderName);
|
|
83
|
-
await FileSystemService_1.default.checkOrCreateFolder(testFolderPath);
|
|
84
|
-
return testFolderPath;
|
|
85
|
-
}
|
|
86
|
-
async function deleteTestFolder() {
|
|
87
|
-
await FileSystemService_1.default.deleteFolder(TEST_FOLDER_NAME);
|
|
88
|
-
}
|