@alextheman/utility 3.2.0 → 3.3.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 +42 -0
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +41 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -520,6 +520,46 @@ function interpolateObjects(strings, ...values) {
|
|
|
520
520
|
}
|
|
521
521
|
var interpolateObjects_default = interpolateObjects;
|
|
522
522
|
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/functions/taggedTemplate/normaliseIndents.ts
|
|
525
|
+
function calculateTabSize$1(line, whitespaceLength) {
|
|
526
|
+
const potentialWhitespacePart = line.slice(0, whitespaceLength);
|
|
527
|
+
const trimmedString = line.trimStart();
|
|
528
|
+
if (potentialWhitespacePart.trim() !== "") return 0;
|
|
529
|
+
const tabSize = line.length - (trimmedString.length + whitespaceLength);
|
|
530
|
+
return tabSize < 0 ? 0 : tabSize;
|
|
531
|
+
}
|
|
532
|
+
function getWhitespaceLength$1(lines) {
|
|
533
|
+
const [firstNonEmptyLine] = lines.filter((line) => {
|
|
534
|
+
return line.trim() !== "";
|
|
535
|
+
});
|
|
536
|
+
return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
|
|
537
|
+
}
|
|
538
|
+
function reduceLines$1(lines, { preserveTabs = true }) {
|
|
539
|
+
const slicedLines = lines.slice(1);
|
|
540
|
+
const isFirstLineEmpty = lines[0].trim() === "";
|
|
541
|
+
const whitespaceLength = getWhitespaceLength$1(isFirstLineEmpty ? lines : slicedLines);
|
|
542
|
+
return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
|
|
543
|
+
const tabSize = calculateTabSize$1(line, whitespaceLength);
|
|
544
|
+
return (preserveTabs ? fillArray_default(() => {
|
|
545
|
+
return " ";
|
|
546
|
+
}, tabSize).join("") : "") + line.trimStart();
|
|
547
|
+
}).join("\n");
|
|
548
|
+
}
|
|
549
|
+
function normaliseIndents(first, ...args) {
|
|
550
|
+
if (typeof first === "object" && first !== null && !Array.isArray(first)) {
|
|
551
|
+
const options$1 = first;
|
|
552
|
+
return (strings$1, ...interpolations) => {
|
|
553
|
+
return normaliseIndents(strings$1, ...interpolations, options$1);
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
const strings = first;
|
|
557
|
+
const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
|
|
558
|
+
return reduceLines$1(interpolate_default(strings, ...[...args]).split("\n"), options);
|
|
559
|
+
}
|
|
560
|
+
const normalizeIndents = normaliseIndents;
|
|
561
|
+
var normaliseIndents_default = normaliseIndents;
|
|
562
|
+
|
|
523
563
|
//#endregion
|
|
524
564
|
//#region src/functions/taggedTemplate/removeIndents.ts
|
|
525
565
|
function calculateTabSize(line, whitespaceLength) {
|
|
@@ -601,7 +641,9 @@ exports.isOrdered = isOrdered_default;
|
|
|
601
641
|
exports.isSameDate = isSameDate_default;
|
|
602
642
|
exports.kebabToCamel = kebabToCamel_default;
|
|
603
643
|
exports.normaliseImportPath = normaliseImportPath;
|
|
644
|
+
exports.normaliseIndents = normaliseIndents_default;
|
|
604
645
|
exports.normalizeImportPath = normalizeImportPath_default;
|
|
646
|
+
exports.normalizeIndents = normalizeIndents;
|
|
605
647
|
exports.omitProperties = omitProperties_default;
|
|
606
648
|
exports.paralleliseArrays = paralleliseArrays_default;
|
|
607
649
|
exports.parseBoolean = parseBoolean_default;
|
package/dist/index.d.cts
CHANGED
|
@@ -177,12 +177,25 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
|
|
|
177
177
|
//#region src/functions/taggedTemplate/interpolateObjects.d.ts
|
|
178
178
|
declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
179
179
|
//#endregion
|
|
180
|
+
//#region src/functions/taggedTemplate/normaliseIndents.d.ts
|
|
181
|
+
interface NormaliseIndentsOptions {
|
|
182
|
+
preserveTabs?: boolean;
|
|
183
|
+
}
|
|
184
|
+
type NormalizeIndentsOptions = NormaliseIndentsOptions;
|
|
185
|
+
type NormaliseIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
|
|
186
|
+
type NormalizeIndentsFunction = NormaliseIndentsFunction;
|
|
187
|
+
declare function normaliseIndents(options: NormaliseIndentsOptions): NormaliseIndentsFunction;
|
|
188
|
+
declare function normaliseIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
189
|
+
declare const normalizeIndents: typeof normaliseIndents;
|
|
190
|
+
//#endregion
|
|
180
191
|
//#region src/functions/taggedTemplate/removeIndents.d.ts
|
|
181
192
|
interface RemoveIndentsOptions {
|
|
182
193
|
preserveTabs?: boolean;
|
|
183
194
|
}
|
|
184
195
|
type RemoveIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
|
|
196
|
+
/** @deprecated This function has been renamed to normaliseIndents */
|
|
185
197
|
declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunction;
|
|
198
|
+
/** @deprecated This function has been renamed to normaliseIndents */
|
|
186
199
|
declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
187
200
|
//#endregion
|
|
188
201
|
//#region src/functions/truncate.d.ts
|
|
@@ -191,4 +204,4 @@ declare function truncate(stringToTruncate: string, maxLength?: number): string;
|
|
|
191
204
|
//#region src/functions/wait.d.ts
|
|
192
205
|
declare function wait(seconds: number): Promise<void>;
|
|
193
206
|
//#endregion
|
|
194
|
-
export { APIError, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Email, Env, FormDataNullableResolutionStrategy
|
|
207
|
+
export { APIError, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Email, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, RecordKey, RemoveIndentsFunction, RemoveIndentsOptions, StringListToArrayOptions, UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEmail, parseEnv, parseFormData, parseIntStrict, parseUUID, parseZodSchema, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, truncate, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -177,12 +177,25 @@ declare function interpolate(strings: TemplateStringsArray, ...interpolations: u
|
|
|
177
177
|
//#region src/functions/taggedTemplate/interpolateObjects.d.ts
|
|
178
178
|
declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
179
179
|
//#endregion
|
|
180
|
+
//#region src/functions/taggedTemplate/normaliseIndents.d.ts
|
|
181
|
+
interface NormaliseIndentsOptions {
|
|
182
|
+
preserveTabs?: boolean;
|
|
183
|
+
}
|
|
184
|
+
type NormalizeIndentsOptions = NormaliseIndentsOptions;
|
|
185
|
+
type NormaliseIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
|
|
186
|
+
type NormalizeIndentsFunction = NormaliseIndentsFunction;
|
|
187
|
+
declare function normaliseIndents(options: NormaliseIndentsOptions): NormaliseIndentsFunction;
|
|
188
|
+
declare function normaliseIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
189
|
+
declare const normalizeIndents: typeof normaliseIndents;
|
|
190
|
+
//#endregion
|
|
180
191
|
//#region src/functions/taggedTemplate/removeIndents.d.ts
|
|
181
192
|
interface RemoveIndentsOptions {
|
|
182
193
|
preserveTabs?: boolean;
|
|
183
194
|
}
|
|
184
195
|
type RemoveIndentsFunction = (strings: TemplateStringsArray, ...interpolations: unknown[]) => string;
|
|
196
|
+
/** @deprecated This function has been renamed to normaliseIndents */
|
|
185
197
|
declare function removeIndents(options: RemoveIndentsOptions): RemoveIndentsFunction;
|
|
198
|
+
/** @deprecated This function has been renamed to normaliseIndents */
|
|
186
199
|
declare function removeIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
187
200
|
//#endregion
|
|
188
201
|
//#region src/functions/truncate.d.ts
|
|
@@ -191,4 +204,4 @@ declare function truncate(stringToTruncate: string, maxLength?: number): string;
|
|
|
191
204
|
//#region src/functions/wait.d.ts
|
|
192
205
|
declare function wait(seconds: number): Promise<void>;
|
|
193
206
|
//#endregion
|
|
194
|
-
export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, type Email, type Env, type
|
|
207
|
+
export { APIError, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, type Email, type Env, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type OptionalOnCondition, type RecordKey, RemoveIndentsFunction, RemoveIndentsOptions, type StringListToArrayOptions, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEmail, parseEnv, parseFormData, parseIntStrict, parseUUID, parseZodSchema, randomiseArray, range, removeDuplicates, removeIndents, stringListToArray, stringToBoolean, truncate, wait };
|
package/dist/index.js
CHANGED
|
@@ -491,6 +491,46 @@ function interpolateObjects(strings, ...values) {
|
|
|
491
491
|
}
|
|
492
492
|
var interpolateObjects_default = interpolateObjects;
|
|
493
493
|
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region src/functions/taggedTemplate/normaliseIndents.ts
|
|
496
|
+
function calculateTabSize$1(line, whitespaceLength) {
|
|
497
|
+
const potentialWhitespacePart = line.slice(0, whitespaceLength);
|
|
498
|
+
const trimmedString = line.trimStart();
|
|
499
|
+
if (potentialWhitespacePart.trim() !== "") return 0;
|
|
500
|
+
const tabSize = line.length - (trimmedString.length + whitespaceLength);
|
|
501
|
+
return tabSize < 0 ? 0 : tabSize;
|
|
502
|
+
}
|
|
503
|
+
function getWhitespaceLength$1(lines) {
|
|
504
|
+
const [firstNonEmptyLine] = lines.filter((line) => {
|
|
505
|
+
return line.trim() !== "";
|
|
506
|
+
});
|
|
507
|
+
return firstNonEmptyLine.length - firstNonEmptyLine.trimStart().length;
|
|
508
|
+
}
|
|
509
|
+
function reduceLines$1(lines, { preserveTabs = true }) {
|
|
510
|
+
const slicedLines = lines.slice(1);
|
|
511
|
+
const isFirstLineEmpty = lines[0].trim() === "";
|
|
512
|
+
const whitespaceLength = getWhitespaceLength$1(isFirstLineEmpty ? lines : slicedLines);
|
|
513
|
+
return (isFirstLineEmpty ? slicedLines : lines).map((line) => {
|
|
514
|
+
const tabSize = calculateTabSize$1(line, whitespaceLength);
|
|
515
|
+
return (preserveTabs ? fillArray_default(() => {
|
|
516
|
+
return " ";
|
|
517
|
+
}, tabSize).join("") : "") + line.trimStart();
|
|
518
|
+
}).join("\n");
|
|
519
|
+
}
|
|
520
|
+
function normaliseIndents(first, ...args) {
|
|
521
|
+
if (typeof first === "object" && first !== null && !Array.isArray(first)) {
|
|
522
|
+
const options$1 = first;
|
|
523
|
+
return (strings$1, ...interpolations) => {
|
|
524
|
+
return normaliseIndents(strings$1, ...interpolations, options$1);
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
const strings = first;
|
|
528
|
+
const options = typeof args[args.length - 1] === "object" && !Array.isArray(args[args.length - 1]) ? args.pop() : {};
|
|
529
|
+
return reduceLines$1(interpolate_default(strings, ...[...args]).split("\n"), options);
|
|
530
|
+
}
|
|
531
|
+
const normalizeIndents = normaliseIndents;
|
|
532
|
+
var normaliseIndents_default = normaliseIndents;
|
|
533
|
+
|
|
494
534
|
//#endregion
|
|
495
535
|
//#region src/functions/taggedTemplate/removeIndents.ts
|
|
496
536
|
function calculateTabSize(line, whitespaceLength) {
|
|
@@ -549,4 +589,4 @@ function wait(seconds) {
|
|
|
549
589
|
var wait_default = wait;
|
|
550
590
|
|
|
551
591
|
//#endregion
|
|
552
|
-
export { APIError_default as APIError, DataError_default as DataError, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normalizeImportPath_default as normalizeImportPath, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, Email_default as parseEmail, Env_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, UUID_default as parseUUID, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeIndents_default as removeIndents, stringListToArray_default as stringListToArray, stringToBoolean, truncate_default as truncate, wait_default as wait };
|
|
592
|
+
export { APIError_default as APIError, DataError_default as DataError, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, Email_default as parseEmail, Env_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, UUID_default as parseUUID, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, removeIndents_default as removeIndents, stringListToArray_default as stringListToArray, stringToBoolean, truncate_default as truncate, wait_default as wait };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "Helpful utility functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,19 +40,19 @@
|
|
|
40
40
|
"use-local-eslint-plugin": "npm --prefix ../eslint-plugin run create-local-package && npm uninstall @alextheman/eslint-plugin && npm install --save-dev ../eslint-plugin/alextheman-eslint-plugin-*.tgz"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"zod": "^4.1.
|
|
43
|
+
"zod": "^4.1.13"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@alextheman/eslint-plugin": "^4.
|
|
46
|
+
"@alextheman/eslint-plugin": "^4.2.2",
|
|
47
47
|
"@types/node": "^24.10.1",
|
|
48
48
|
"eslint": "^9.39.1",
|
|
49
49
|
"globals": "^16.5.0",
|
|
50
50
|
"husky": "^9.1.7",
|
|
51
51
|
"jsdom": "^27.2.0",
|
|
52
|
-
"prettier": "^3.
|
|
53
|
-
"tsdown": "^0.16.
|
|
52
|
+
"prettier": "^3.7.1",
|
|
53
|
+
"tsdown": "^0.16.8",
|
|
54
54
|
"typescript": "^5.9.3",
|
|
55
55
|
"vite-tsconfig-paths": "^5.1.4",
|
|
56
|
-
"vitest": "^4.0.
|
|
56
|
+
"vitest": "^4.0.14"
|
|
57
57
|
}
|
|
58
58
|
}
|