@alextheman/utility 2.18.1 → 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,8 +520,50 @@ 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, whitespaceLength = 12) {
566
+ function calculateTabSize2(line, whitespaceLength = 12) {
524
567
  const potentialWhitespacePart = line.slice(0, whitespaceLength);
525
568
  const trimmedString = line.trimStart();
526
569
  if (potentialWhitespacePart.trim() !== "") {
@@ -529,9 +572,9 @@ function calculateTabSize(line, whitespaceLength = 12) {
529
572
  const tabSize = line.length - (trimmedString.length + whitespaceLength);
530
573
  return tabSize < 0 ? 0 : tabSize;
531
574
  }
532
- function reduceLines(lines, { whitespaceLength = 12, preserveTabs = true }) {
575
+ function reduceLines2(lines, { whitespaceLength = 12, preserveTabs = true }) {
533
576
  return lines.map((line) => {
534
- const tabSize = calculateTabSize(line, whitespaceLength);
577
+ const tabSize = calculateTabSize2(line, whitespaceLength);
535
578
  return (preserveTabs ? fillArray_default(() => {
536
579
  return " ";
537
580
  }, tabSize).join("") : "") + line.trimStart();
@@ -548,7 +591,7 @@ function stripIndents(first, ...args) {
548
591
  const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
549
592
  const interpolations = [...args];
550
593
  const fullString = interpolate_default(strings, ...interpolations);
551
- return reduceLines(fullString.split("\n"), options);
594
+ return reduceLines2(fullString.split("\n"), options);
552
595
  }
553
596
  var stripIndents_default = stripIndents;
554
597
 
@@ -637,6 +680,7 @@ var UUID_default = parseUUID;
637
680
  randomiseArray,
638
681
  range,
639
682
  removeDuplicates,
683
+ removeIndents,
640
684
  stringListToArray,
641
685
  stringToBoolean,
642
686
  stripIndents,
package/dist/index.d.cts CHANGED
@@ -115,6 +115,13 @@ 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
+
118
125
  interface StripIndentsOptions {
119
126
  whitespaceLength?: number;
120
127
  preserveTabs?: boolean;
@@ -123,4 +130,4 @@ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: u
123
130
  declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
124
131
  declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
125
132
 
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 };
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,13 @@ 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
+
118
125
  interface StripIndentsOptions {
119
126
  whitespaceLength?: number;
120
127
  preserveTabs?: boolean;
@@ -123,4 +130,4 @@ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: u
123
130
  declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
124
131
  declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
125
132
 
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 };
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,8 +454,50 @@ 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, whitespaceLength = 12) {
500
+ function calculateTabSize2(line, whitespaceLength = 12) {
459
501
  const potentialWhitespacePart = line.slice(0, whitespaceLength);
460
502
  const trimmedString = line.trimStart();
461
503
  if (potentialWhitespacePart.trim() !== "") {
@@ -464,9 +506,9 @@ function calculateTabSize(line, whitespaceLength = 12) {
464
506
  const tabSize = line.length - (trimmedString.length + whitespaceLength);
465
507
  return tabSize < 0 ? 0 : tabSize;
466
508
  }
467
- function reduceLines(lines, { whitespaceLength = 12, preserveTabs = true }) {
509
+ function reduceLines2(lines, { whitespaceLength = 12, preserveTabs = true }) {
468
510
  return lines.map((line) => {
469
- const tabSize = calculateTabSize(line, whitespaceLength);
511
+ const tabSize = calculateTabSize2(line, whitespaceLength);
470
512
  return (preserveTabs ? fillArray_default(() => {
471
513
  return " ";
472
514
  }, tabSize).join("") : "") + line.trimStart();
@@ -483,7 +525,7 @@ function stripIndents(first, ...args) {
483
525
  const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
484
526
  const interpolations = [...args];
485
527
  const fullString = interpolate_default(strings, ...interpolations);
486
- return reduceLines(fullString.split("\n"), options);
528
+ return reduceLines2(fullString.split("\n"), options);
487
529
  }
488
530
  var stripIndents_default = stripIndents;
489
531
 
@@ -571,6 +613,7 @@ export {
571
613
  randomiseArray_default as randomiseArray,
572
614
  range_default as range,
573
615
  removeDuplicates_default as removeDuplicates,
616
+ removeIndents_default as removeIndents,
574
617
  stringListToArray_default as stringListToArray,
575
618
  stringToBoolean_default as stringToBoolean,
576
619
  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.19.0",
4
4
  "description": "Helpful utility functions",
5
5
  "repository": {
6
6
  "type": "git",