@alextheman/utility 2.17.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 +35 -0
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +34 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -75,6 +75,7 @@ __export(index_exports, {
|
|
|
75
75
|
removeDuplicates: () => removeDuplicates_default,
|
|
76
76
|
stringListToArray: () => stringListToArray_default,
|
|
77
77
|
stringToBoolean: () => stringToBoolean_default,
|
|
78
|
+
stripIndents: () => stripIndents_default,
|
|
78
79
|
truncate: () => truncate_default,
|
|
79
80
|
wait: () => wait_default
|
|
80
81
|
});
|
|
@@ -518,6 +519,39 @@ function interpolateObjects(strings, ...values) {
|
|
|
518
519
|
}
|
|
519
520
|
var interpolateObjects_default = interpolateObjects;
|
|
520
521
|
|
|
522
|
+
// src/functions/taggedTemplate/stripIndents.ts
|
|
523
|
+
function calculateTabSize(line, whitespaceLength = 12) {
|
|
524
|
+
const potentialWhitespacePart = line.slice(0, whitespaceLength);
|
|
525
|
+
const trimmedString = line.trimStart();
|
|
526
|
+
if (potentialWhitespacePart.trim() !== "") {
|
|
527
|
+
return 0;
|
|
528
|
+
}
|
|
529
|
+
const tabSize = line.length - (trimmedString.length + whitespaceLength);
|
|
530
|
+
return tabSize < 0 ? 0 : tabSize;
|
|
531
|
+
}
|
|
532
|
+
function reduceLines(lines, { whitespaceLength = 12, preserveTabs = true }) {
|
|
533
|
+
return lines.map((line) => {
|
|
534
|
+
const tabSize = calculateTabSize(line, whitespaceLength);
|
|
535
|
+
return (preserveTabs ? fillArray_default(() => {
|
|
536
|
+
return " ";
|
|
537
|
+
}, tabSize).join("") : "") + line.trimStart();
|
|
538
|
+
}).join("\n");
|
|
539
|
+
}
|
|
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];
|
|
550
|
+
const fullString = interpolate_default(strings, ...interpolations);
|
|
551
|
+
return reduceLines(fullString.split("\n"), options);
|
|
552
|
+
}
|
|
553
|
+
var stripIndents_default = stripIndents;
|
|
554
|
+
|
|
521
555
|
// src/types/APIError.ts
|
|
522
556
|
var httpErrorCodeLookup = {
|
|
523
557
|
400: "BAD_REQUEST",
|
|
@@ -605,6 +639,7 @@ var UUID_default = parseUUID;
|
|
|
605
639
|
removeDuplicates,
|
|
606
640
|
stringListToArray,
|
|
607
641
|
stringToBoolean,
|
|
642
|
+
stripIndents,
|
|
608
643
|
truncate,
|
|
609
644
|
wait
|
|
610
645
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -115,4 +115,12 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
|
|
|
115
115
|
|
|
116
116
|
declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
117
117
|
|
|
118
|
-
|
|
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;
|
|
124
|
+
declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
125
|
+
|
|
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,4 +115,12 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
|
|
|
115
115
|
|
|
116
116
|
declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
117
117
|
|
|
118
|
-
|
|
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;
|
|
124
|
+
declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
125
|
+
|
|
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
|
@@ -454,6 +454,39 @@ function interpolateObjects(strings, ...values) {
|
|
|
454
454
|
}
|
|
455
455
|
var interpolateObjects_default = interpolateObjects;
|
|
456
456
|
|
|
457
|
+
// src/functions/taggedTemplate/stripIndents.ts
|
|
458
|
+
function calculateTabSize(line, whitespaceLength = 12) {
|
|
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 reduceLines(lines, { whitespaceLength = 12, preserveTabs = true }) {
|
|
468
|
+
return lines.map((line) => {
|
|
469
|
+
const tabSize = calculateTabSize(line, whitespaceLength);
|
|
470
|
+
return (preserveTabs ? fillArray_default(() => {
|
|
471
|
+
return " ";
|
|
472
|
+
}, tabSize).join("") : "") + line.trimStart();
|
|
473
|
+
}).join("\n");
|
|
474
|
+
}
|
|
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];
|
|
485
|
+
const fullString = interpolate_default(strings, ...interpolations);
|
|
486
|
+
return reduceLines(fullString.split("\n"), options);
|
|
487
|
+
}
|
|
488
|
+
var stripIndents_default = stripIndents;
|
|
489
|
+
|
|
457
490
|
// src/types/APIError.ts
|
|
458
491
|
var httpErrorCodeLookup = {
|
|
459
492
|
400: "BAD_REQUEST",
|
|
@@ -540,6 +573,7 @@ export {
|
|
|
540
573
|
removeDuplicates_default as removeDuplicates,
|
|
541
574
|
stringListToArray_default as stringListToArray,
|
|
542
575
|
stringToBoolean_default as stringToBoolean,
|
|
576
|
+
stripIndents_default as stripIndents,
|
|
543
577
|
truncate_default as truncate,
|
|
544
578
|
wait_default as wait
|
|
545
579
|
};
|