@alextheman/utility 2.18.1 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -64,6 +64,8 @@ __export(index_exports, {
64
64
  isOrdered: () => isOrdered_default,
65
65
  isSameDate: () => isSameDate_default,
66
66
  kebabToCamel: () => kebabToCamel_default,
67
+ normaliseImportPath: () => normaliseImportPath,
68
+ normalizeImportPath: () => normalizeImportPath_default,
67
69
  omitProperties: () => omitProperties_default,
68
70
  paralleliseArrays: () => paralleliseArrays_default,
69
71
  parseEmail: () => Email_default,
@@ -73,6 +75,7 @@ __export(index_exports, {
73
75
  randomiseArray: () => randomiseArray_default,
74
76
  range: () => range_default,
75
77
  removeDuplicates: () => removeDuplicates_default,
78
+ removeIndents: () => removeIndents_default,
76
79
  stringListToArray: () => stringListToArray_default,
77
80
  stringToBoolean: () => stringToBoolean_default,
78
81
  stripIndents: () => stripIndents_default,
@@ -389,6 +392,18 @@ function kebabToCamel(string, options) {
389
392
  }
390
393
  var kebabToCamel_default = kebabToCamel;
391
394
 
395
+ // src/functions/normalizeImportPath.ts
396
+ var import_path = __toESM(require("path"), 1);
397
+ function normalizeImportPath(importPath) {
398
+ const normalizedPath = import_path.default.posix.normalize(importPath);
399
+ if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) {
400
+ return `./${normalizedPath}`;
401
+ }
402
+ return normalizedPath;
403
+ }
404
+ var normaliseImportPath = normalizeImportPath;
405
+ var normalizeImportPath_default = normalizeImportPath;
406
+
392
407
  // src/functions/omitProperties.ts
393
408
  function omitProperties(object, keysToOmit) {
394
409
  const outputObject = __spreadValues({}, object);
@@ -519,8 +534,50 @@ function interpolateObjects(strings, ...values) {
519
534
  }
520
535
  var interpolateObjects_default = interpolateObjects;
521
536
 
537
+ // src/functions/taggedTemplate/removeIndents.ts
538
+ function calculateTabSize(line, whitespaceLength) {
539
+ const potentialWhitespacePart = line.slice(0, whitespaceLength);
540
+ const trimmedString = line.trimStart();
541
+ if (potentialWhitespacePart.trim() !== "") {
542
+ return 0;
543
+ }
544
+ const tabSize = line.length - (trimmedString.length + whitespaceLength);
545
+ return tabSize < 0 ? 0 : tabSize;
546
+ }
547
+ function getWhitespaceLength(lines) {
548
+ const [firstNonEmptyLine] = lines.filter((line) => {
549
+ return line.trim() !== "";
550
+ });
551
+ return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
552
+ }
553
+ function reduceLines(lines, { preserveTabs = true }) {
554
+ const slicedLines = lines.slice(1);
555
+ const isFirstLineEmpty = lines[0].trim() === "";
556
+ const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
557
+ return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
558
+ const tabSize = calculateTabSize(line, whitespaceLength);
559
+ return (preserveTabs ? fillArray_default(() => {
560
+ return " ";
561
+ }, tabSize).join("") : "") + line.trimStart();
562
+ }).join("\n");
563
+ }
564
+ function removeIndents(first, ...args) {
565
+ if (typeof first === "object" && first !== null && !Array.isArray(first)) {
566
+ const options2 = first;
567
+ return (strings2, ...interpolations2) => {
568
+ return removeIndents(strings2, ...interpolations2, options2);
569
+ };
570
+ }
571
+ const strings = first;
572
+ const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
573
+ const interpolations = [...args];
574
+ const fullString = interpolate_default(strings, ...interpolations);
575
+ return reduceLines(fullString.split("\n"), options);
576
+ }
577
+ var removeIndents_default = removeIndents;
578
+
522
579
  // src/functions/taggedTemplate/stripIndents.ts
523
- function calculateTabSize(line, whitespaceLength = 12) {
580
+ function calculateTabSize2(line, whitespaceLength = 12) {
524
581
  const potentialWhitespacePart = line.slice(0, whitespaceLength);
525
582
  const trimmedString = line.trimStart();
526
583
  if (potentialWhitespacePart.trim() !== "") {
@@ -529,9 +586,9 @@ function calculateTabSize(line, whitespaceLength = 12) {
529
586
  const tabSize = line.length - (trimmedString.length + whitespaceLength);
530
587
  return tabSize < 0 ? 0 : tabSize;
531
588
  }
532
- function reduceLines(lines, { whitespaceLength = 12, preserveTabs = true }) {
589
+ function reduceLines2(lines, { whitespaceLength = 12, preserveTabs = true }) {
533
590
  return lines.map((line) => {
534
- const tabSize = calculateTabSize(line, whitespaceLength);
591
+ const tabSize = calculateTabSize2(line, whitespaceLength);
535
592
  return (preserveTabs ? fillArray_default(() => {
536
593
  return " ";
537
594
  }, tabSize).join("") : "") + line.trimStart();
@@ -548,7 +605,7 @@ function stripIndents(first, ...args) {
548
605
  const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
549
606
  const interpolations = [...args];
550
607
  const fullString = interpolate_default(strings, ...interpolations);
551
- return reduceLines(fullString.split("\n"), options);
608
+ return reduceLines2(fullString.split("\n"), options);
552
609
  }
553
610
  var stripIndents_default = stripIndents;
554
611
 
@@ -628,6 +685,8 @@ var UUID_default = parseUUID;
628
685
  isOrdered,
629
686
  isSameDate,
630
687
  kebabToCamel,
688
+ normaliseImportPath,
689
+ normalizeImportPath,
631
690
  omitProperties,
632
691
  paralleliseArrays,
633
692
  parseEmail,
@@ -637,6 +696,7 @@ var UUID_default = parseUUID;
637
696
  randomiseArray,
638
697
  range,
639
698
  removeDuplicates,
699
+ removeIndents,
640
700
  stringListToArray,
641
701
  stringToBoolean,
642
702
  stripIndents,
package/dist/index.d.cts CHANGED
@@ -86,6 +86,9 @@ interface KebabToCamelOptions {
86
86
  }
87
87
  declare function kebabToCamel(string: string, options?: KebabToCamelOptions): string;
88
88
 
89
+ declare function normalizeImportPath(importPath: string): string;
90
+ declare const normaliseImportPath: typeof normalizeImportPath;
91
+
89
92
  declare function omitProperties<T extends Record<string, unknown> | Readonly<Record<string, unknown>>, K extends keyof T>(object: T, keysToOmit: K | readonly K[]): Omit<T, K>;
90
93
 
91
94
  type ParallelTuple<A, B> = [A, B | undefined];
@@ -115,6 +118,13 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
115
118
 
116
119
  declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
117
120
 
121
+ interface RemoveIndentsOptions {
122
+ preserveTabs?: boolean;
123
+ }
124
+ type RemoveIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
125
+ declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunction;
126
+ declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
127
+
118
128
  interface StripIndentsOptions {
119
129
  whitespaceLength?: number;
120
130
  preserveTabs?: boolean;
@@ -123,4 +133,4 @@ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: u
123
133
  declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
124
134
  declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
125
135
 
126
- export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type IgnoreCase, type KebabToCamelOptions, type NonUndefined, type OptionalOnCondition, type RecordKey, type StringListToArrayOptions, type StripIndentsFunction, type StripIndentsOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, stripIndents, truncate, wait };
136
+ export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type IgnoreCase, type KebabToCamelOptions, type NonUndefined, type OptionalOnCondition, type RecordKey, type RemoveIndentsFunction, type RemoveIndentsOptions, type StringListToArrayOptions, type StripIndentsFunction, type StripIndentsOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normalizeImportPath, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, stripIndents, truncate, wait };
package/dist/index.d.ts CHANGED
@@ -86,6 +86,9 @@ interface KebabToCamelOptions {
86
86
  }
87
87
  declare function kebabToCamel(string: string, options?: KebabToCamelOptions): string;
88
88
 
89
+ declare function normalizeImportPath(importPath: string): string;
90
+ declare const normaliseImportPath: typeof normalizeImportPath;
91
+
89
92
  declare function omitProperties<T extends Record<string, unknown> | Readonly<Record<string, unknown>>, K extends keyof T>(object: T, keysToOmit: K | readonly K[]): Omit<T, K>;
90
93
 
91
94
  type ParallelTuple<A, B> = [A, B | undefined];
@@ -115,6 +118,13 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
115
118
 
116
119
  declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
117
120
 
121
+ interface RemoveIndentsOptions {
122
+ preserveTabs?: boolean;
123
+ }
124
+ type RemoveIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
125
+ declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunction;
126
+ declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
127
+
118
128
  interface StripIndentsOptions {
119
129
  whitespaceLength?: number;
120
130
  preserveTabs?: boolean;
@@ -123,4 +133,4 @@ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: u
123
133
  declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
124
134
  declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
125
135
 
126
- export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type IgnoreCase, type KebabToCamelOptions, type NonUndefined, type OptionalOnCondition, type RecordKey, type StringListToArrayOptions, type StripIndentsFunction, type StripIndentsOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, stripIndents, truncate, wait };
136
+ export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, type DisallowUndefined, type Email, type Env, type FormDataNullableResolutionStrategy as FormDataResolutionStrategy, type HTTPErrorCode, type HTTPErrorCodes, type IgnoreCase, type KebabToCamelOptions, type NonUndefined, type OptionalOnCondition, type RecordKey, type RemoveIndentsFunction, type RemoveIndentsOptions, type StringListToArrayOptions, type StripIndentsFunction, type StripIndentsOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normalizeImportPath, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, stripIndents, truncate, wait };
package/dist/index.js CHANGED
@@ -324,6 +324,18 @@ function kebabToCamel(string, options) {
324
324
  }
325
325
  var kebabToCamel_default = kebabToCamel;
326
326
 
327
+ // src/functions/normalizeImportPath.ts
328
+ import path from "path";
329
+ function normalizeImportPath(importPath) {
330
+ const normalizedPath = path.posix.normalize(importPath);
331
+ if (importPath.startsWith("./") && !normalizedPath.startsWith("./")) {
332
+ return `./${normalizedPath}`;
333
+ }
334
+ return normalizedPath;
335
+ }
336
+ var normaliseImportPath = normalizeImportPath;
337
+ var normalizeImportPath_default = normalizeImportPath;
338
+
327
339
  // src/functions/omitProperties.ts
328
340
  function omitProperties(object, keysToOmit) {
329
341
  const outputObject = __spreadValues({}, object);
@@ -454,8 +466,50 @@ function interpolateObjects(strings, ...values) {
454
466
  }
455
467
  var interpolateObjects_default = interpolateObjects;
456
468
 
469
+ // src/functions/taggedTemplate/removeIndents.ts
470
+ function calculateTabSize(line, whitespaceLength) {
471
+ const potentialWhitespacePart = line.slice(0, whitespaceLength);
472
+ const trimmedString = line.trimStart();
473
+ if (potentialWhitespacePart.trim() !== "") {
474
+ return 0;
475
+ }
476
+ const tabSize = line.length - (trimmedString.length + whitespaceLength);
477
+ return tabSize < 0 ? 0 : tabSize;
478
+ }
479
+ function getWhitespaceLength(lines) {
480
+ const [firstNonEmptyLine] = lines.filter((line) => {
481
+ return line.trim() !== "";
482
+ });
483
+ return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
484
+ }
485
+ function reduceLines(lines, { preserveTabs = true }) {
486
+ const slicedLines = lines.slice(1);
487
+ const isFirstLineEmpty = lines[0].trim() === "";
488
+ const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
489
+ return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
490
+ const tabSize = calculateTabSize(line, whitespaceLength);
491
+ return (preserveTabs ? fillArray_default(() => {
492
+ return " ";
493
+ }, tabSize).join("") : "") + line.trimStart();
494
+ }).join("\n");
495
+ }
496
+ function removeIndents(first, ...args) {
497
+ if (typeof first === "object" && first !== null && !Array.isArray(first)) {
498
+ const options2 = first;
499
+ return (strings2, ...interpolations2) => {
500
+ return removeIndents(strings2, ...interpolations2, options2);
501
+ };
502
+ }
503
+ const strings = first;
504
+ const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
505
+ const interpolations = [...args];
506
+ const fullString = interpolate_default(strings, ...interpolations);
507
+ return reduceLines(fullString.split("\n"), options);
508
+ }
509
+ var removeIndents_default = removeIndents;
510
+
457
511
  // src/functions/taggedTemplate/stripIndents.ts
458
- function calculateTabSize(line, whitespaceLength = 12) {
512
+ function calculateTabSize2(line, whitespaceLength = 12) {
459
513
  const potentialWhitespacePart = line.slice(0, whitespaceLength);
460
514
  const trimmedString = line.trimStart();
461
515
  if (potentialWhitespacePart.trim() !== "") {
@@ -464,9 +518,9 @@ function calculateTabSize(line, whitespaceLength = 12) {
464
518
  const tabSize = line.length - (trimmedString.length + whitespaceLength);
465
519
  return tabSize < 0 ? 0 : tabSize;
466
520
  }
467
- function reduceLines(lines, { whitespaceLength = 12, preserveTabs = true }) {
521
+ function reduceLines2(lines, { whitespaceLength = 12, preserveTabs = true }) {
468
522
  return lines.map((line) => {
469
- const tabSize = calculateTabSize(line, whitespaceLength);
523
+ const tabSize = calculateTabSize2(line, whitespaceLength);
470
524
  return (preserveTabs ? fillArray_default(() => {
471
525
  return " ";
472
526
  }, tabSize).join("") : "") + line.trimStart();
@@ -483,7 +537,7 @@ function stripIndents(first, ...args) {
483
537
  const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
484
538
  const interpolations = [...args];
485
539
  const fullString = interpolate_default(strings, ...interpolations);
486
- return reduceLines(fullString.split("\n"), options);
540
+ return reduceLines2(fullString.split("\n"), options);
487
541
  }
488
542
  var stripIndents_default = stripIndents;
489
543
 
@@ -562,6 +616,8 @@ export {
562
616
  isOrdered_default as isOrdered,
563
617
  isSameDate_default as isSameDate,
564
618
  kebabToCamel_default as kebabToCamel,
619
+ normaliseImportPath,
620
+ normalizeImportPath_default as normalizeImportPath,
565
621
  omitProperties_default as omitProperties,
566
622
  paralleliseArrays_default as paralleliseArrays,
567
623
  Email_default as parseEmail,
@@ -571,6 +627,7 @@ export {
571
627
  randomiseArray_default as randomiseArray,
572
628
  range_default as range,
573
629
  removeDuplicates_default as removeDuplicates,
630
+ removeIndents_default as removeIndents,
574
631
  stringListToArray_default as stringListToArray,
575
632
  stringToBoolean_default as stringToBoolean,
576
633
  stripIndents_default as stripIndents,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "2.18.1",
3
+ "version": "2.20.0",
4
4
  "description": "Helpful utility functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,7 +40,7 @@
40
40
  "zod": "^4.1.12"
41
41
  },
42
42
  "devDependencies": {
43
- "@alextheman/eslint-plugin": "^3.0.0",
43
+ "@alextheman/eslint-plugin": "^3.2.1",
44
44
  "@types/node": "^24.10.1",
45
45
  "eslint": "^9.39.1",
46
46
  "globals": "^16.5.0",
@@ -50,6 +50,6 @@
50
50
  "tsup": "^8.5.1",
51
51
  "typescript": "^5.9.3",
52
52
  "vite-tsconfig-paths": "^5.1.4",
53
- "vitest": "^4.0.9"
53
+ "vitest": "^4.0.13"
54
54
  }
55
55
  }