@aneuhold/core-ts-lib 2.2.7 → 2.2.8

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.
Files changed (40) hide show
  1. package/lib/index.d.ts +4 -3
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +2 -1
  4. package/lib/index.js.map +1 -1
  5. package/lib/index.ts +7 -5
  6. package/lib/interfaces/ITracer.d.ts.map +1 -1
  7. package/lib/interfaces/ITracer.js.map +1 -1
  8. package/lib/interfaces/ITracer.ts +2 -8
  9. package/lib/services/ArrayService.d.ts.map +1 -1
  10. package/lib/services/ArrayService.js.map +1 -1
  11. package/lib/services/ArrayService.ts +1 -4
  12. package/lib/services/DateService/DateService.d.ts.map +1 -1
  13. package/lib/services/DateService/DateService.js +1 -3
  14. package/lib/services/DateService/DateService.js.map +1 -1
  15. package/lib/services/DateService/DateService.ts +7 -25
  16. package/lib/services/DependencyService.d.ts.map +1 -1
  17. package/lib/services/DependencyService.js +1 -3
  18. package/lib/services/DependencyService.js.map +1 -1
  19. package/lib/services/DependencyService.ts +10 -32
  20. package/lib/services/FileSystemService/FileSystemService.d.ts +38 -12
  21. package/lib/services/FileSystemService/FileSystemService.d.ts.map +1 -1
  22. package/lib/services/FileSystemService/FileSystemService.js +83 -26
  23. package/lib/services/FileSystemService/FileSystemService.js.map +1 -1
  24. package/lib/services/FileSystemService/FileSystemService.ts +138 -53
  25. package/lib/services/FileSystemService/GlobMatchingService.d.ts +48 -0
  26. package/lib/services/FileSystemService/GlobMatchingService.d.ts.map +1 -0
  27. package/lib/services/FileSystemService/GlobMatchingService.js +129 -0
  28. package/lib/services/FileSystemService/GlobMatchingService.js.map +1 -0
  29. package/lib/services/FileSystemService/GlobMatchingService.ts +153 -0
  30. package/lib/services/PackageService.d.ts +60 -4
  31. package/lib/services/PackageService.d.ts.map +1 -1
  32. package/lib/services/PackageService.js +182 -43
  33. package/lib/services/PackageService.js.map +1 -1
  34. package/lib/services/PackageService.ts +241 -119
  35. package/lib/utils/ErrorUtils.d.ts.map +1 -1
  36. package/lib/utils/ErrorUtils.js.map +1 -1
  37. package/lib/utils/ErrorUtils.ts +1 -3
  38. package/package.json +1 -1
  39. package/lib/services/DateService/DateService.spec.ts +0 -98
  40. package/lib/services/FileSystemService/FileSystemService.spec.ts +0 -133
@@ -22,61 +22,187 @@ export default class PackageService {
22
22
  * project has any pending changes first, then update the version of the
23
23
  * jsr.json to match the package.json file, then run the
24
24
  * `jsr publish --dry-run` command, and finally cleanup the changes made.
25
+ *
26
+ * @param alternativePackageNames Optional array of alternative package names to validate publishing under
27
+ *
28
+ * **Warning:** This method uses simple string replacement for package names, which may have unintended effects
29
+ * if the package name appears in unexpected places. Use with caution.
25
30
  */
26
- static async validateJsrPublish(): Promise<void> {
31
+ static async validateJsrPublish(alternativePackageNames?: string[]): Promise<void> {
27
32
  if (await FileSystemService.hasPendingChanges()) {
28
33
  DR.logger.error('Please commit or stash your changes before publishing.');
29
34
  process.exit(1);
30
35
  }
31
- await PackageService.replaceMonorepoImportsWithNpmSpecifiers();
32
- const { packageName, version: currentVersion } =
33
- await PackageService.updateJsrFromPackageJson();
34
- const successfulDryRun = await PackageService.publishJsrDryRun(
35
- packageName,
36
- currentVersion
37
- );
38
- await PackageService.revertGitChanges();
39
36
 
40
- if (!successfulDryRun) {
41
- process.exit(1);
42
- } else {
43
- DR.logger.success('Successfully validated JSR publishing.');
37
+ const { packageName: originalPackageName } = await PackageService.getPackageInfo();
38
+ const packageNamesToValidate = [originalPackageName, ...(alternativePackageNames || [])];
39
+
40
+ for (const packageName of packageNamesToValidate) {
41
+ const isAlternativeName = packageName !== originalPackageName;
42
+
43
+ DR.logger.info(`Validating JSR publishing for package: ${packageName}`);
44
+
45
+ if (isAlternativeName) {
46
+ await PackageService.replacePackageName(originalPackageName, packageName);
47
+ }
48
+
49
+ await PackageService.replaceMonorepoImportsWithNpmSpecifiers();
50
+ const { version: currentVersion } = await PackageService.updateJsrFromPackageJson();
51
+ const successfulDryRun = await PackageService.publishJsrDryRun(packageName, currentVersion);
52
+
53
+ await PackageService.resetGitChanges();
54
+
55
+ if (!successfulDryRun) {
56
+ process.exit(1);
57
+ }
44
58
  }
59
+
60
+ DR.logger.success('Successfully validated JSR publishing for all package names.');
45
61
  }
46
62
 
47
- static async publishToJsr(): Promise<void> {
63
+ /**
64
+ * Publishes the current project to JSR.
65
+ *
66
+ * @param alternativePackageNames Optional array of alternative package names to publish under
67
+ *
68
+ * **Warning:** This method uses simple string replacement for package names, which may have unintended effects
69
+ * if the package name appears in unexpected places. Use with caution.
70
+ */
71
+ static async publishToJsr(alternativePackageNames?: string[]): Promise<void> {
48
72
  if (await FileSystemService.hasPendingChanges()) {
49
73
  DR.logger.error('Please commit or stash your changes before publishing.');
50
74
  process.exit(1);
51
75
  }
52
- await PackageService.replaceMonorepoImportsWithNpmSpecifiers();
53
- await PackageService.updateJsrFromPackageJson();
54
- const result = await PackageService.publishJsr();
55
- await PackageService.revertGitChanges();
56
76
 
57
- if (!result) {
58
- process.exit(1);
59
- } else {
60
- DR.logger.success('Successfully published to JSR.');
77
+ const { packageName: originalPackageName } = await PackageService.getPackageInfo();
78
+ const packageNamesToPublish = [originalPackageName, ...(alternativePackageNames || [])];
79
+
80
+ for (const packageName of packageNamesToPublish) {
81
+ const isAlternativeName = packageName !== originalPackageName;
82
+
83
+ DR.logger.info(`Publishing to JSR for package: ${packageName}`);
84
+
85
+ if (isAlternativeName) {
86
+ await PackageService.replacePackageName(originalPackageName, packageName);
87
+ }
88
+
89
+ await PackageService.replaceMonorepoImportsWithNpmSpecifiers();
90
+ await PackageService.updateJsrFromPackageJson();
91
+ const result = await PackageService.publishJsr();
92
+
93
+ await PackageService.resetGitChanges();
94
+
95
+ if (!result) {
96
+ process.exit(1);
97
+ }
61
98
  }
99
+
100
+ DR.logger.success('Successfully published to JSR for all package names.');
62
101
  }
63
102
 
64
103
  /**
65
104
  * Validates the current project for publishing to npm. This will run
66
105
  * `npm publish --access public --dry-run` and check for version conflicts
67
106
  * on the npm registry.
107
+ *
108
+ * @param alternativePackageNames Optional array of alternative package names to validate publishing under
109
+ *
110
+ * **Warning:** This method uses simple string replacement for package names, which may have unintended effects
111
+ * if the package name appears in unexpected places. Use with caution.
68
112
  */
69
- static async validateNpmPublish(): Promise<void> {
70
- const { packageName, version: currentVersion } =
113
+ static async validateNpmPublish(alternativePackageNames?: string[]): Promise<void> {
114
+ if (await FileSystemService.hasPendingChanges()) {
115
+ DR.logger.error('Please commit or stash your changes before publishing.');
116
+ process.exit(1);
117
+ }
118
+
119
+ const { packageName: originalPackageName, version: currentVersion } =
71
120
  await PackageService.getPackageInfo();
121
+ const packageNamesToValidate = [originalPackageName, ...(alternativePackageNames || [])];
122
+
123
+ for (const packageName of packageNamesToValidate) {
124
+ const isAlternativeName = packageName !== originalPackageName;
125
+
126
+ DR.logger.info(`Validating npm publishing for package: ${packageName}`);
127
+
128
+ if (isAlternativeName) {
129
+ await PackageService.replacePackageName(originalPackageName, packageName);
130
+ }
131
+
132
+ const successfulDryRun = await PackageService.publishNpmDryRun();
133
+ if (!successfulDryRun) {
134
+ if (isAlternativeName) {
135
+ await PackageService.resetGitChanges();
136
+ }
137
+ process.exit(1);
138
+ }
139
+
140
+ await PackageService.checkNpmVersionConflicts(packageName, currentVersion);
141
+
142
+ if (isAlternativeName) {
143
+ await PackageService.resetGitChanges();
144
+ }
145
+ }
146
+
147
+ DR.logger.success('Successfully validated npm publishing for all package names.');
148
+ }
72
149
 
73
- const successfulDryRun = await PackageService.publishNpmDryRun();
74
- if (!successfulDryRun) {
150
+ /**
151
+ * Publishes the current project to npm.
152
+ *
153
+ * @param alternativePackageNames Optional array of alternative package names to publish under
154
+ *
155
+ * **Warning:** This method uses simple string replacement for package names, which may have unintended effects
156
+ * if the package name appears in unexpected places. Use with caution.
157
+ */
158
+ static async publishToNpm(alternativePackageNames?: string[]): Promise<void> {
159
+ if (await FileSystemService.hasPendingChanges()) {
160
+ DR.logger.error('Please commit or stash your changes before publishing.');
75
161
  process.exit(1);
76
162
  }
77
163
 
78
- await PackageService.checkNpmVersionConflicts(packageName, currentVersion);
79
- DR.logger.success('Successfully validated npm publishing.');
164
+ const { packageName: originalPackageName } = await PackageService.getPackageInfo();
165
+ const packageNamesToPublish = [originalPackageName, ...(alternativePackageNames || [])];
166
+
167
+ for (const packageName of packageNamesToPublish) {
168
+ const isAlternativeName = packageName !== originalPackageName;
169
+
170
+ DR.logger.info(`Publishing to npm for package: ${packageName}`);
171
+
172
+ if (isAlternativeName) {
173
+ await PackageService.replacePackageName(originalPackageName, packageName);
174
+ }
175
+
176
+ const result = await PackageService.publishNpm();
177
+
178
+ if (isAlternativeName) {
179
+ await PackageService.resetGitChanges();
180
+ }
181
+
182
+ if (!result) {
183
+ process.exit(1);
184
+ }
185
+ }
186
+
187
+ DR.logger.success('Successfully published to npm for all package names.');
188
+ }
189
+
190
+ /**
191
+ * Test method for string replacement functionality. This method allows testing
192
+ * the string replacement behavior without performing actual publishing operations.
193
+ *
194
+ * @param originalString The original string to replace
195
+ * @param newString The new string to replace it with
196
+ *
197
+ * **Warning:** This method uses simple string replacement, which may have unintended effects
198
+ * if the string appears in unexpected places. Use with caution.
199
+ */
200
+ static async testStringReplacement(originalString: string, newString: string): Promise<void> {
201
+ DR.logger.info(`Testing string replacement from "${originalString}" to "${newString}"`);
202
+
203
+ await PackageService.replacePackageName(originalString, newString);
204
+
205
+ DR.logger.info('Test completed - package name replacement has been applied');
80
206
  }
81
207
 
82
208
  /**
@@ -101,9 +227,7 @@ export default class PackageService {
101
227
 
102
228
  try {
103
229
  const { packageName, version } = await PackageService.getPackageInfo();
104
- const packageJsonData = JSON.parse(
105
- await readFile(packageJsonPath, 'utf-8')
106
- ) as PackageJson;
230
+ const packageJsonData = JSON.parse(await readFile(packageJsonPath, 'utf-8')) as PackageJson;
107
231
  const jsrJsonData = JSON.parse(
108
232
  await readFile(jsrJsonPath, 'utf-8')
109
233
  ) as JsonWithVersionProperty;
@@ -112,15 +236,10 @@ export default class PackageService {
112
236
  jsrJsonData.version = version;
113
237
 
114
238
  // Resolve wildcard dependencies in package.json for JSR compatibility
115
- await this.resolveWildcardDependenciesInPackageJson(
116
- packageJsonData,
117
- packageJsonPath
118
- );
239
+ await this.resolveWildcardDependenciesInPackageJson(packageJsonData, packageJsonPath);
119
240
 
120
241
  await writeFile(jsrJsonPath, JSON.stringify(jsrJsonData, null, 2));
121
- DR.logger.info(
122
- 'Updated jsr.json from package.json to version ' + version
123
- );
242
+ DR.logger.info('Updated jsr.json from package.json to version ' + version);
124
243
 
125
244
  return {
126
245
  packageName,
@@ -128,9 +247,7 @@ export default class PackageService {
128
247
  };
129
248
  } catch (error) {
130
249
  const errorString = ErrorUtils.getErrorString(error);
131
- DR.logger.error(
132
- `Failed to update jsr.json from package.json: ${errorString}`
133
- );
250
+ DR.logger.error(`Failed to update jsr.json from package.json: ${errorString}`);
134
251
  throw error;
135
252
  }
136
253
  }
@@ -152,16 +269,13 @@ export default class PackageService {
152
269
  const childPackages = await DependencyService.getChildPackageJsons('../');
153
270
 
154
271
  // Helper function to resolve dependencies
155
- const resolveDependencies = (
156
- deps: Record<string, string> | undefined
157
- ): void => {
272
+ const resolveDependencies = (deps: Record<string, string> | undefined): void => {
158
273
  if (!deps) return;
159
274
 
160
275
  for (const [depName, depVersion] of Object.entries(deps)) {
161
276
  if (depVersion === '*' && depName in childPackages) {
162
277
  // Replace wildcard with "*" + actual version from the monorepo
163
- deps[depName] =
164
- `*${childPackages[depName].packageJsonContents.version}`;
278
+ deps[depName] = `*${childPackages[depName].packageJsonContents.version}`;
165
279
  }
166
280
  }
167
281
  };
@@ -173,19 +287,12 @@ export default class PackageService {
173
287
  resolveDependencies(packageJsonData.optionalDependencies);
174
288
 
175
289
  // Write the updated package.json
176
- await writeFile(
177
- packageJsonPath,
178
- JSON.stringify(packageJsonData, null, 2)
179
- );
290
+ await writeFile(packageJsonPath, JSON.stringify(packageJsonData, null, 2));
180
291
 
181
- DR.logger.info(
182
- 'Resolved wildcard dependencies in package.json for JSR compatibility'
183
- );
292
+ DR.logger.info('Resolved wildcard dependencies in package.json for JSR compatibility');
184
293
  } catch (error) {
185
294
  const errorString = ErrorUtils.getErrorString(error);
186
- DR.logger.error(
187
- `Failed to resolve wildcard dependencies: ${errorString}`
188
- );
295
+ DR.logger.error(`Failed to resolve wildcard dependencies: ${errorString}`);
189
296
  throw error;
190
297
  }
191
298
  }
@@ -208,17 +315,13 @@ export default class PackageService {
208
315
 
209
316
  DR.logger.info('Running `jsr publish --dry-run`');
210
317
  try {
211
- const { stdout, stderr } = await execAsync(
212
- 'jsr publish --allow-dirty --dry-run'
213
- );
318
+ const { stdout, stderr } = await execAsync('jsr publish --allow-dirty --dry-run');
214
319
  if (stderr) {
215
320
  DR.logger.info(stderr);
216
321
  }
217
322
  DR.logger.info(stdout);
218
323
  } catch (error) {
219
- DR.logger.error(
220
- `Failed to run 'jsr publish --dry-run': ${ErrorUtils.getErrorString(error)}`
221
- );
324
+ DR.logger.error(`Failed to run 'jsr publish --dry-run': ${ErrorUtils.getErrorString(error)}`);
222
325
  return false;
223
326
  }
224
327
  return true;
@@ -266,9 +369,7 @@ export default class PackageService {
266
369
  }
267
370
 
268
371
  try {
269
- const packageJsonData = JSON.parse(
270
- await readFile(packageJsonPath, 'utf-8')
271
- ) as PackageJson;
372
+ const packageJsonData = JSON.parse(await readFile(packageJsonPath, 'utf-8')) as PackageJson;
272
373
 
273
374
  return {
274
375
  packageName: packageJsonData.name,
@@ -309,9 +410,7 @@ export default class PackageService {
309
410
  packageName: string,
310
411
  currentVersion: string
311
412
  ): Promise<void> {
312
- DR.logger.info(
313
- `Checking npm registry for existing versions of ${packageName}...`
314
- );
413
+ DR.logger.info(`Checking npm registry for existing versions of ${packageName}...`);
315
414
 
316
415
  try {
317
416
  const { stdout } = await execAsync(`npm view ${packageName}`);
@@ -320,28 +419,19 @@ export default class PackageService {
320
419
  const latestVersionMatch = stdout.match(/latest:\s*([^\s|]+)/);
321
420
  if (latestVersionMatch) {
322
421
  const latestVersion = latestVersionMatch[1];
323
- PackageService.checkVersionConflict(
324
- currentVersion,
325
- latestVersion,
326
- 'npm'
327
- );
422
+ PackageService.checkVersionConflict(currentVersion, latestVersion, 'npm');
328
423
  }
329
424
  } catch (error) {
330
425
  const errorString = ErrorUtils.getErrorString(error);
331
426
 
332
427
  // If the package doesn't exist on npm, that's fine for first publish
333
428
  if (errorString.includes('404') || errorString.includes('not found')) {
334
- DR.logger.info(
335
- 'Package not found on npm - this appears to be a first publish.'
336
- );
429
+ DR.logger.info('Package not found on npm - this appears to be a first publish.');
337
430
  return;
338
431
  }
339
432
 
340
433
  // Re-throw version conflict errors
341
- if (
342
- errorString.includes('already exists') ||
343
- errorString.includes('is lower than')
344
- ) {
434
+ if (errorString.includes('already exists') || errorString.includes('is lower than')) {
345
435
  throw error;
346
436
  }
347
437
 
@@ -415,9 +505,7 @@ export default class PackageService {
415
505
  // Get all TypeScript files in the src directory
416
506
  const allFiles = await FileSystemService.getAllFilePathsRelative(srcDir);
417
507
  const tsFiles = allFiles
418
- .filter(
419
- (filePath) => filePath.endsWith('.ts') && !filePath.endsWith('.spec.ts')
420
- )
508
+ .filter((filePath) => filePath.endsWith('.ts') && !filePath.endsWith('.spec.ts'))
421
509
  .map((filePath) => path.join(srcDir, filePath));
422
510
 
423
511
  DR.logger.info(
@@ -459,9 +547,7 @@ export default class PackageService {
459
547
  );
460
548
  }
461
549
  } catch (error) {
462
- DR.logger.error(
463
- `Failed to process file ${filePath}: ${ErrorUtils.getErrorString(error)}`
464
- );
550
+ DR.logger.error(`Failed to process file ${filePath}: ${ErrorUtils.getErrorString(error)}`);
465
551
  }
466
552
  }
467
553
 
@@ -470,19 +556,6 @@ export default class PackageService {
470
556
  );
471
557
  }
472
558
 
473
- private static async revertGitChanges(): Promise<void> {
474
- DR.logger.info(
475
- 'Reverting changes made to jsr.json, package.json, and source files'
476
- );
477
- try {
478
- await execAsync('git checkout -- jsr.json package.json src/');
479
- } catch (error) {
480
- DR.logger.error(
481
- `Failed to revert changes: ${ErrorUtils.getErrorString(error)}`
482
- );
483
- }
484
- }
485
-
486
559
  /**
487
560
  * Checks for version conflicts on JSR by looking up the current package
488
561
  * and comparing versions. Throws an error if the current version already
@@ -505,31 +578,19 @@ export default class PackageService {
505
578
  if (latestVersionMatch) {
506
579
  const latestVersion = latestVersionMatch[1];
507
580
 
508
- PackageService.checkVersionConflict(
509
- currentVersion,
510
- latestVersion,
511
- 'JSR'
512
- );
581
+ PackageService.checkVersionConflict(currentVersion, latestVersion, 'JSR');
513
582
  }
514
583
  } catch (error) {
515
584
  const errorString = ErrorUtils.getErrorString(error);
516
585
 
517
586
  // If the package doesn't exist on JSR, that's fine for first publish
518
- if (
519
- errorString.includes('Package not found') ||
520
- errorString.includes('404')
521
- ) {
522
- DR.logger.info(
523
- 'Package not found on JSR - this appears to be a first publish.'
524
- );
587
+ if (errorString.includes('Package not found') || errorString.includes('404')) {
588
+ DR.logger.info('Package not found on JSR - this appears to be a first publish.');
525
589
  return;
526
590
  }
527
591
 
528
592
  // Re-throw version conflict errors
529
- if (
530
- errorString.includes('already exists') ||
531
- errorString.includes('is lower than')
532
- ) {
593
+ if (errorString.includes('already exists') || errorString.includes('is lower than')) {
533
594
  throw error;
534
595
  }
535
596
 
@@ -555,10 +616,7 @@ export default class PackageService {
555
616
  );
556
617
 
557
618
  // Compare versions using semver-like comparison
558
- const comparison = StringService.compareSemanticVersions(
559
- currentVersion,
560
- latestVersion
561
- );
619
+ const comparison = StringService.compareSemanticVersions(currentVersion, latestVersion);
562
620
 
563
621
  if (comparison === 0) {
564
622
  throw new Error(
@@ -572,4 +630,68 @@ export default class PackageService {
572
630
 
573
631
  DR.logger.info('Version check passed - ready to publish.');
574
632
  }
633
+
634
+ /**
635
+ * Replaces the package name in all files in the root directory, but no child directories,
636
+ * with a new name.
637
+ *
638
+ * @param originalPackageName The original package name to replace
639
+ * @param newPackageName The new package name to use
640
+ */
641
+ private static async replacePackageName(
642
+ originalPackageName: string,
643
+ newPackageName: string
644
+ ): Promise<void> {
645
+ DR.logger.info(`Replacing package name from "${originalPackageName}" to "${newPackageName}"`);
646
+
647
+ const rootDir = process.cwd();
648
+
649
+ // Replace in all files in the root directory
650
+ await FileSystemService.replaceInFiles({
651
+ searchString: originalPackageName,
652
+ replaceString: newPackageName,
653
+ rootPath: rootDir,
654
+ includePatterns: ['*'],
655
+ excludePatterns: []
656
+ });
657
+
658
+ DR.logger.info(`Successfully replaced package name in configuration files`);
659
+ }
660
+
661
+ /**
662
+ * Performs a git reset to discard all changes in the working directory.
663
+ * This is used between alternative package name operations.
664
+ */
665
+ private static async resetGitChanges(): Promise<void> {
666
+ DR.logger.info('Resetting git changes');
667
+ try {
668
+ await execAsync('git reset --hard HEAD');
669
+ } catch (error) {
670
+ DR.logger.error(`Failed to reset git changes: ${ErrorUtils.getErrorString(error)}`);
671
+ throw error;
672
+ }
673
+ }
674
+
675
+ /**
676
+ * Publishes the current project to npm.
677
+ *
678
+ * @returns true if the publish was successful, false otherwise.
679
+ */
680
+ private static async publishNpm(): Promise<boolean> {
681
+ DR.logger.info('Running `npm publish --access public`');
682
+ return new Promise((resolve) => {
683
+ const child = spawn('npm publish', ['--access', 'public'], {
684
+ stdio: 'inherit',
685
+ shell: true
686
+ });
687
+
688
+ child.on('exit', (code) => {
689
+ if (code === 0) {
690
+ resolve(true);
691
+ } else {
692
+ resolve(false);
693
+ }
694
+ });
695
+ });
696
+ }
575
697
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorUtils.d.ts","sourceRoot":"","sources":["../../src/utils/ErrorUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,eAAe,EAAE,MAAM;IAUlE;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM;IAI/D;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;CAS9C"}
1
+ {"version":3,"file":"ErrorUtils.d.ts","sourceRoot":"","sources":["../../src/utils/ErrorUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,eAAe,EAAE,MAAM;IAQlE;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM;IAI/D;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;CAS9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorUtils.js","sourceRoot":"","sources":["../../src/utils/ErrorUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,SAAmB,EAAE,eAAuB;QAChE,IAAI,WAAW,GAAG,EAAE,CAAC;QACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,WAAW,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;QACrC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,GAAG,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAC5D,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,YAAoB,EAAE,eAAuB;QAC7D,UAAU,CAAC,cAAc,CAAC,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,KAAc;QAClC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;QACvB,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,KAAK,CAAC;QACf,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;CACF"}
1
+ {"version":3,"file":"ErrorUtils.js","sourceRoot":"","sources":["../../src/utils/ErrorUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,SAAmB,EAAE,eAAuB;QAChE,IAAI,WAAW,GAAG,EAAE,CAAC;QACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,WAAW,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;QACrC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,GAAG,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/E,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,YAAoB,EAAE,eAAuB;QAC7D,UAAU,CAAC,cAAc,CAAC,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,KAAc;QAClC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;QACvB,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,KAAK,CAAC;QACf,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;CACF"}
@@ -13,9 +13,7 @@ export default class ErrorUtils {
13
13
  for (let i = 0; i < errorList.length; i += 1) {
14
14
  errorString += `${errorList[i]}\n`;
15
15
  }
16
- throw new Error(
17
- `${errorString}${JSON.stringify(erroneousObject, null, 2)}`
18
- );
16
+ throw new Error(`${errorString}${JSON.stringify(erroneousObject, null, 2)}`);
19
17
  }
20
18
 
21
19
  /**
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@aneuhold/core-ts-lib",
3
3
  "author": "Anton G. Neuhold Jr.",
4
4
  "license": "MIT",
5
- "version": "2.2.7",
5
+ "version": "2.2.8",
6
6
  "description": "A core library for all of my TypeScript projects",
7
7
  "type": "module",
8
8
  "scripts": {
@@ -1,98 +0,0 @@
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
- });