@alextheman/utility 2.18.0 → 2.19.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
@@ -73,6 +73,7 @@ __export(index_exports, {
73
73
  randomiseArray: () => randomiseArray_default,
74
74
  range: () => range_default,
75
75
  removeDuplicates: () => removeDuplicates_default,
76
+ removeIndents: () => removeIndents_default,
76
77
  stringListToArray: () => stringListToArray_default,
77
78
  stringToBoolean: () => stringToBoolean_default,
78
79
  stripIndents: () => stripIndents_default,
@@ -519,28 +520,78 @@ function interpolateObjects(strings, ...values) {
519
520
  }
520
521
  var interpolateObjects_default = interpolateObjects;
521
522
 
523
+ // src/functions/taggedTemplate/removeIndents.ts
524
+ function calculateTabSize(line, whitespaceLength) {
525
+ const potentialWhitespacePart = line.slice(0, whitespaceLength);
526
+ const trimmedString = line.trimStart();
527
+ if (potentialWhitespacePart.trim() !== "") {
528
+ return 0;
529
+ }
530
+ const tabSize = line.length - (trimmedString.length + whitespaceLength);
531
+ return tabSize < 0 ? 0 : tabSize;
532
+ }
533
+ function getWhitespaceLength(lines) {
534
+ const [firstNonEmptyLine] = lines.filter((line) => {
535
+ return line.trim() !== "";
536
+ });
537
+ return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
538
+ }
539
+ function reduceLines(lines, { preserveTabs = true }) {
540
+ const slicedLines = lines.slice(1);
541
+ const isFirstLineEmpty = lines[0].trim() === "";
542
+ const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
543
+ return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
544
+ const tabSize = calculateTabSize(line, whitespaceLength);
545
+ return (preserveTabs ? fillArray_default(() => {
546
+ return " ";
547
+ }, tabSize).join("") : "") + line.trimStart();
548
+ }).join("\n");
549
+ }
550
+ function removeIndents(first, ...args) {
551
+ if (typeof first === "object" && first !== null && !Array.isArray(first)) {
552
+ const options2 = first;
553
+ return (strings2, ...interpolations2) => {
554
+ return removeIndents(strings2, ...interpolations2, options2);
555
+ };
556
+ }
557
+ const strings = first;
558
+ const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
559
+ const interpolations = [...args];
560
+ const fullString = interpolate_default(strings, ...interpolations);
561
+ return reduceLines(fullString.split("\n"), options);
562
+ }
563
+ var removeIndents_default = removeIndents;
564
+
522
565
  // src/functions/taggedTemplate/stripIndents.ts
523
- function calculateTabSize(line) {
524
- const defaultWhitespaceLength = 12;
525
- const potentialWhitespacePart = line.slice(0, defaultWhitespaceLength);
526
- const trimmedString = line.trim();
566
+ function calculateTabSize2(line, whitespaceLength = 12) {
567
+ const potentialWhitespacePart = line.slice(0, whitespaceLength);
568
+ const trimmedString = line.trimStart();
527
569
  if (potentialWhitespacePart.trim() !== "") {
528
570
  return 0;
529
571
  }
530
- const tabSize = line.length - (trimmedString.length + defaultWhitespaceLength);
572
+ const tabSize = line.length - (trimmedString.length + whitespaceLength);
531
573
  return tabSize < 0 ? 0 : tabSize;
532
574
  }
533
- function reduceLines(lines) {
575
+ function reduceLines2(lines, { whitespaceLength = 12, preserveTabs = true }) {
534
576
  return lines.map((line) => {
535
- const tabSize = calculateTabSize(line);
536
- return fillArray_default(() => {
577
+ const tabSize = calculateTabSize2(line, whitespaceLength);
578
+ return (preserveTabs ? fillArray_default(() => {
537
579
  return " ";
538
- }, tabSize).join("") + line.trim();
580
+ }, tabSize).join("") : "") + line.trimStart();
539
581
  }).join("\n");
540
582
  }
541
- function stripIndents(strings, ...interpolations) {
583
+ function stripIndents(first, ...args) {
584
+ if (typeof first === "object" && first !== null && !Array.isArray(first)) {
585
+ const options2 = first;
586
+ return (strings2, ...interpolations2) => {
587
+ return stripIndents(strings2, ...interpolations2, options2);
588
+ };
589
+ }
590
+ const strings = first;
591
+ const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
592
+ const interpolations = [...args];
542
593
  const fullString = interpolate_default(strings, ...interpolations);
543
- return reduceLines(fullString.split("\n"));
594
+ return reduceLines2(fullString.split("\n"), options);
544
595
  }
545
596
  var stripIndents_default = stripIndents;
546
597
 
@@ -629,6 +680,7 @@ var UUID_default = parseUUID;
629
680
  randomiseArray,
630
681
  range,
631
682
  removeDuplicates,
683
+ removeIndents,
632
684
  stringListToArray,
633
685
  stringToBoolean,
634
686
  stripIndents,
package/dist/index.d.cts CHANGED
@@ -115,6 +115,19 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
115
115
 
116
116
  declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
117
117
 
118
+ interface RemoveIndentsOptions {
119
+ preserveTabs?: boolean;
120
+ }
121
+ type RemoveIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
122
+ declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunction;
123
+ declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
124
+
125
+ interface StripIndentsOptions {
126
+ whitespaceLength?: number;
127
+ preserveTabs?: boolean;
128
+ }
129
+ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
130
+ declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
118
131
  declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
119
132
 
120
- 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 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 };
133
+ 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, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, stripIndents, truncate, wait };
package/dist/index.d.ts CHANGED
@@ -115,6 +115,19 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
115
115
 
116
116
  declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
117
117
 
118
+ interface RemoveIndentsOptions {
119
+ preserveTabs?: boolean;
120
+ }
121
+ type RemoveIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
122
+ declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunction;
123
+ declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
124
+
125
+ interface StripIndentsOptions {
126
+ whitespaceLength?: number;
127
+ preserveTabs?: boolean;
128
+ }
129
+ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
130
+ declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
118
131
  declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
119
132
 
120
- 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 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 };
133
+ 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, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, stripIndents, truncate, wait };
package/dist/index.js CHANGED
@@ -454,28 +454,78 @@ function interpolateObjects(strings, ...values) {
454
454
  }
455
455
  var interpolateObjects_default = interpolateObjects;
456
456
 
457
+ // src/functions/taggedTemplate/removeIndents.ts
458
+ function calculateTabSize(line, whitespaceLength) {
459
+ const potentialWhitespacePart = line.slice(0, whitespaceLength);
460
+ const trimmedString = line.trimStart();
461
+ if (potentialWhitespacePart.trim() !== "") {
462
+ return 0;
463
+ }
464
+ const tabSize = line.length - (trimmedString.length + whitespaceLength);
465
+ return tabSize < 0 ? 0 : tabSize;
466
+ }
467
+ function getWhitespaceLength(lines) {
468
+ const [firstNonEmptyLine] = lines.filter((line) => {
469
+ return line.trim() !== "";
470
+ });
471
+ return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
472
+ }
473
+ function reduceLines(lines, { preserveTabs = true }) {
474
+ const slicedLines = lines.slice(1);
475
+ const isFirstLineEmpty = lines[0].trim() === "";
476
+ const whitespaceLength = getWhitespaceLength(isFirstLineEmpty ? lines : slicedLines);
477
+ return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
478
+ const tabSize = calculateTabSize(line, whitespaceLength);
479
+ return (preserveTabs ? fillArray_default(() => {
480
+ return " ";
481
+ }, tabSize).join("") : "") + line.trimStart();
482
+ }).join("\n");
483
+ }
484
+ function removeIndents(first, ...args) {
485
+ if (typeof first === "object" && first !== null && !Array.isArray(first)) {
486
+ const options2 = first;
487
+ return (strings2, ...interpolations2) => {
488
+ return removeIndents(strings2, ...interpolations2, options2);
489
+ };
490
+ }
491
+ const strings = first;
492
+ const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
493
+ const interpolations = [...args];
494
+ const fullString = interpolate_default(strings, ...interpolations);
495
+ return reduceLines(fullString.split("\n"), options);
496
+ }
497
+ var removeIndents_default = removeIndents;
498
+
457
499
  // src/functions/taggedTemplate/stripIndents.ts
458
- function calculateTabSize(line) {
459
- const defaultWhitespaceLength = 12;
460
- const potentialWhitespacePart = line.slice(0, defaultWhitespaceLength);
461
- const trimmedString = line.trim();
500
+ function calculateTabSize2(line, whitespaceLength = 12) {
501
+ const potentialWhitespacePart = line.slice(0, whitespaceLength);
502
+ const trimmedString = line.trimStart();
462
503
  if (potentialWhitespacePart.trim() !== "") {
463
504
  return 0;
464
505
  }
465
- const tabSize = line.length - (trimmedString.length + defaultWhitespaceLength);
506
+ const tabSize = line.length - (trimmedString.length + whitespaceLength);
466
507
  return tabSize < 0 ? 0 : tabSize;
467
508
  }
468
- function reduceLines(lines) {
509
+ function reduceLines2(lines, { whitespaceLength = 12, preserveTabs = true }) {
469
510
  return lines.map((line) => {
470
- const tabSize = calculateTabSize(line);
471
- return fillArray_default(() => {
511
+ const tabSize = calculateTabSize2(line, whitespaceLength);
512
+ return (preserveTabs ? fillArray_default(() => {
472
513
  return " ";
473
- }, tabSize).join("") + line.trim();
514
+ }, tabSize).join("") : "") + line.trimStart();
474
515
  }).join("\n");
475
516
  }
476
- function stripIndents(strings, ...interpolations) {
517
+ function stripIndents(first, ...args) {
518
+ if (typeof first === "object" && first !== null && !Array.isArray(first)) {
519
+ const options2 = first;
520
+ return (strings2, ...interpolations2) => {
521
+ return stripIndents(strings2, ...interpolations2, options2);
522
+ };
523
+ }
524
+ const strings = first;
525
+ const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
526
+ const interpolations = [...args];
477
527
  const fullString = interpolate_default(strings, ...interpolations);
478
- return reduceLines(fullString.split("\n"));
528
+ return reduceLines2(fullString.split("\n"), options);
479
529
  }
480
530
  var stripIndents_default = stripIndents;
481
531
 
@@ -563,6 +613,7 @@ export {
563
613
  randomiseArray_default as randomiseArray,
564
614
  range_default as range,
565
615
  removeDuplicates_default as removeDuplicates,
616
+ removeIndents_default as removeIndents,
566
617
  stringListToArray_default as stringListToArray,
567
618
  stringToBoolean_default as stringToBoolean,
568
619
  stripIndents_default as stripIndents,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "2.18.0",
3
+ "version": "2.19.0",
4
4
  "description": "Helpful utility functions",
5
5
  "repository": {
6
6
  "type": "git",