@alextheman/utility 2.18.0 → 2.18.1

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
@@ -520,27 +520,35 @@ function interpolateObjects(strings, ...values) {
520
520
  var interpolateObjects_default = interpolateObjects;
521
521
 
522
522
  // 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();
523
+ function calculateTabSize(line, whitespaceLength = 12) {
524
+ const potentialWhitespacePart = line.slice(0, whitespaceLength);
525
+ const trimmedString = line.trimStart();
527
526
  if (potentialWhitespacePart.trim() !== "") {
528
527
  return 0;
529
528
  }
530
- const tabSize = line.length - (trimmedString.length + defaultWhitespaceLength);
529
+ const tabSize = line.length - (trimmedString.length + whitespaceLength);
531
530
  return tabSize < 0 ? 0 : tabSize;
532
531
  }
533
- function reduceLines(lines) {
532
+ function reduceLines(lines, { whitespaceLength = 12, preserveTabs = true }) {
534
533
  return lines.map((line) => {
535
- const tabSize = calculateTabSize(line);
536
- return fillArray_default(() => {
534
+ const tabSize = calculateTabSize(line, whitespaceLength);
535
+ return (preserveTabs ? fillArray_default(() => {
537
536
  return " ";
538
- }, tabSize).join("") + line.trim();
537
+ }, tabSize).join("") : "") + line.trimStart();
539
538
  }).join("\n");
540
539
  }
541
- function stripIndents(strings, ...interpolations) {
540
+ function stripIndents(first, ...args) {
541
+ if (typeof first === "object" && first !== null && !Array.isArray(first)) {
542
+ const options2 = first;
543
+ return (strings2, ...interpolations2) => {
544
+ return stripIndents(strings2, ...interpolations2, options2);
545
+ };
546
+ }
547
+ const strings = first;
548
+ const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
549
+ const interpolations = [...args];
542
550
  const fullString = interpolate_default(strings, ...interpolations);
543
- return reduceLines(fullString.split("\n"));
551
+ return reduceLines(fullString.split("\n"), options);
544
552
  }
545
553
  var stripIndents_default = stripIndents;
546
554
 
package/dist/index.d.cts CHANGED
@@ -115,6 +115,12 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
115
115
 
116
116
  declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
117
117
 
118
+ interface StripIndentsOptions {
119
+ whitespaceLength?: number;
120
+ preserveTabs?: boolean;
121
+ }
122
+ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
123
+ declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
118
124
  declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
119
125
 
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 };
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 };
package/dist/index.d.ts CHANGED
@@ -115,6 +115,12 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
115
115
 
116
116
  declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
117
117
 
118
+ interface StripIndentsOptions {
119
+ whitespaceLength?: number;
120
+ preserveTabs?: boolean;
121
+ }
122
+ type StripIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
123
+ declare function stripIndents(options: StripIndentsOptions): StripIndentsFunction;
118
124
  declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
119
125
 
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 };
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 };
package/dist/index.js CHANGED
@@ -455,27 +455,35 @@ function interpolateObjects(strings, ...values) {
455
455
  var interpolateObjects_default = interpolateObjects;
456
456
 
457
457
  // 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();
458
+ function calculateTabSize(line, whitespaceLength = 12) {
459
+ const potentialWhitespacePart = line.slice(0, whitespaceLength);
460
+ const trimmedString = line.trimStart();
462
461
  if (potentialWhitespacePart.trim() !== "") {
463
462
  return 0;
464
463
  }
465
- const tabSize = line.length - (trimmedString.length + defaultWhitespaceLength);
464
+ const tabSize = line.length - (trimmedString.length + whitespaceLength);
466
465
  return tabSize < 0 ? 0 : tabSize;
467
466
  }
468
- function reduceLines(lines) {
467
+ function reduceLines(lines, { whitespaceLength = 12, preserveTabs = true }) {
469
468
  return lines.map((line) => {
470
- const tabSize = calculateTabSize(line);
471
- return fillArray_default(() => {
469
+ const tabSize = calculateTabSize(line, whitespaceLength);
470
+ return (preserveTabs ? fillArray_default(() => {
472
471
  return " ";
473
- }, tabSize).join("") + line.trim();
472
+ }, tabSize).join("") : "") + line.trimStart();
474
473
  }).join("\n");
475
474
  }
476
- function stripIndents(strings, ...interpolations) {
475
+ function stripIndents(first, ...args) {
476
+ if (typeof first === "object" && first !== null && !Array.isArray(first)) {
477
+ const options2 = first;
478
+ return (strings2, ...interpolations2) => {
479
+ return stripIndents(strings2, ...interpolations2, options2);
480
+ };
481
+ }
482
+ const strings = first;
483
+ const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
484
+ const interpolations = [...args];
477
485
  const fullString = interpolate_default(strings, ...interpolations);
478
- return reduceLines(fullString.split("\n"));
486
+ return reduceLines(fullString.split("\n"), options);
479
487
  }
480
488
  var stripIndents_default = stripIndents;
481
489
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "2.18.0",
3
+ "version": "2.18.1",
4
4
  "description": "Helpful utility functions",
5
5
  "repository": {
6
6
  "type": "git",