@alextheman/utility 2.16.1 → 2.18.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
@@ -51,11 +51,13 @@ __export(index_exports, {
51
51
  camelToKebab: () => camelToKebab_default,
52
52
  convertFileToBase64: () => convertFileToBase64_default,
53
53
  createFormData: () => createFormData_default,
54
+ createTemplateStringsArray: () => createTemplateStringsArray_default,
54
55
  fillArray: () => fillArray_default,
55
56
  formatDateAndTime: () => formatDateAndTime_default,
56
57
  getRandomNumber: () => getRandomNumber_default,
57
58
  getRecordKeys: () => getRecordKeys_default,
58
59
  httpErrorCodeLookup: () => httpErrorCodeLookup,
60
+ interpolate: () => interpolate_default,
59
61
  interpolateObjects: () => interpolateObjects_default,
60
62
  isLeapYear: () => isLeapYear_default,
61
63
  isMonthlyMultiple: () => isMonthlyMultiple_default,
@@ -73,6 +75,7 @@ __export(index_exports, {
73
75
  removeDuplicates: () => removeDuplicates_default,
74
76
  stringListToArray: () => stringListToArray_default,
75
77
  stringToBoolean: () => stringToBoolean_default,
78
+ stripIndents: () => stripIndents_default,
76
79
  truncate: () => truncate_default,
77
80
  wait: () => wait_default
78
81
  });
@@ -211,6 +214,12 @@ function createFormData(data, options = {
211
214
  }
212
215
  var createFormData_default = createFormData;
213
216
 
217
+ // src/functions/createTemplateStringsArray.ts
218
+ function createTemplateStringsArray(strings) {
219
+ return Object.assign([...strings], { raw: [...strings] });
220
+ }
221
+ var createTemplateStringsArray_default = createTemplateStringsArray;
222
+
214
223
  // src/functions/fillArray.ts
215
224
  function fillArray(callback, length = 1) {
216
225
  const outputArray = new Array(length).fill(null).map((_, index) => {
@@ -487,6 +496,16 @@ function wait(seconds) {
487
496
  }
488
497
  var wait_default = wait;
489
498
 
499
+ // src/functions/taggedTemplate/interpolate.ts
500
+ function interpolate(strings, ...interpolations) {
501
+ let result = "";
502
+ for (const [string, interpolation = ""] of paralleliseArrays_default(strings, interpolations)) {
503
+ result += string + interpolation;
504
+ }
505
+ return result;
506
+ }
507
+ var interpolate_default = interpolate;
508
+
490
509
  // src/functions/taggedTemplate/interpolateObjects.ts
491
510
  function interpolateObjects(strings, ...values) {
492
511
  let result = "";
@@ -500,6 +519,31 @@ function interpolateObjects(strings, ...values) {
500
519
  }
501
520
  var interpolateObjects_default = interpolateObjects;
502
521
 
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();
527
+ if (potentialWhitespacePart.trim() !== "") {
528
+ return 0;
529
+ }
530
+ const tabSize = line.length - (trimmedString.length + defaultWhitespaceLength);
531
+ return tabSize < 0 ? 0 : tabSize;
532
+ }
533
+ function reduceLines(lines) {
534
+ return lines.map((line) => {
535
+ const tabSize = calculateTabSize(line);
536
+ return fillArray_default(() => {
537
+ return " ";
538
+ }, tabSize).join("") + line.trim();
539
+ }).join("\n");
540
+ }
541
+ function stripIndents(strings, ...interpolations) {
542
+ const fullString = interpolate_default(strings, ...interpolations);
543
+ return reduceLines(fullString.split("\n"));
544
+ }
545
+ var stripIndents_default = stripIndents;
546
+
503
547
  // src/types/APIError.ts
504
548
  var httpErrorCodeLookup = {
505
549
  400: "BAD_REQUEST",
@@ -563,11 +607,13 @@ var UUID_default = parseUUID;
563
607
  camelToKebab,
564
608
  convertFileToBase64,
565
609
  createFormData,
610
+ createTemplateStringsArray,
566
611
  fillArray,
567
612
  formatDateAndTime,
568
613
  getRandomNumber,
569
614
  getRecordKeys,
570
615
  httpErrorCodeLookup,
616
+ interpolate,
571
617
  interpolateObjects,
572
618
  isLeapYear,
573
619
  isMonthlyMultiple,
@@ -585,6 +631,7 @@ var UUID_default = parseUUID;
585
631
  removeDuplicates,
586
632
  stringListToArray,
587
633
  stringToBoolean,
634
+ stripIndents,
588
635
  truncate,
589
636
  wait
590
637
  });
package/dist/index.d.cts CHANGED
@@ -62,6 +62,8 @@ interface CreateFormDataOptionsNullableResolution<K extends RecordKey> extends C
62
62
  type CreateFormDataOptions<K extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<K> | CreateFormDataOptionsNullableResolution<K>;
63
63
  declare function createFormData<T extends Record<RecordKey, unknown>>(data: T, options?: CreateFormDataOptions<keyof T>): FormData;
64
64
 
65
+ declare function createTemplateStringsArray(strings: readonly string[]): TemplateStringsArray;
66
+
65
67
  declare function fillArray<T>(callback: (index: number) => Promise<T>, length?: number): Promise<T[]>;
66
68
  declare function fillArray<T>(callback: (index: number) => T, length?: number): T[];
67
69
 
@@ -109,6 +111,10 @@ declare function truncate(stringToTruncate: string, maxLength?: number): string;
109
111
 
110
112
  declare function wait(seconds: number): Promise<void>;
111
113
 
114
+ declare function interpolate(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
115
+
112
116
  declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
113
117
 
114
- 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, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
118
+ declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
119
+
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 };
package/dist/index.d.ts CHANGED
@@ -62,6 +62,8 @@ interface CreateFormDataOptionsNullableResolution<K extends RecordKey> extends C
62
62
  type CreateFormDataOptions<K extends RecordKey> = CreateFormDataOptionsUndefinedOrNullResolution<K> | CreateFormDataOptionsNullableResolution<K>;
63
63
  declare function createFormData<T extends Record<RecordKey, unknown>>(data: T, options?: CreateFormDataOptions<keyof T>): FormData;
64
64
 
65
+ declare function createTemplateStringsArray(strings: readonly string[]): TemplateStringsArray;
66
+
65
67
  declare function fillArray<T>(callback: (index: number) => Promise<T>, length?: number): Promise<T[]>;
66
68
  declare function fillArray<T>(callback: (index: number) => T, length?: number): T[];
67
69
 
@@ -109,6 +111,10 @@ declare function truncate(stringToTruncate: string, maxLength?: number): string;
109
111
 
110
112
  declare function wait(seconds: number): Promise<void>;
111
113
 
114
+ declare function interpolate(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
115
+
112
116
  declare function interpolateObjects(strings: TemplateStringsArray, ...values: unknown[]): string;
113
117
 
114
- 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, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, omitProperties, paralleliseArrays, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
118
+ declare function stripIndents(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
119
+
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 };
package/dist/index.js CHANGED
@@ -149,6 +149,12 @@ function createFormData(data, options = {
149
149
  }
150
150
  var createFormData_default = createFormData;
151
151
 
152
+ // src/functions/createTemplateStringsArray.ts
153
+ function createTemplateStringsArray(strings) {
154
+ return Object.assign([...strings], { raw: [...strings] });
155
+ }
156
+ var createTemplateStringsArray_default = createTemplateStringsArray;
157
+
152
158
  // src/functions/fillArray.ts
153
159
  function fillArray(callback, length = 1) {
154
160
  const outputArray = new Array(length).fill(null).map((_, index) => {
@@ -425,6 +431,16 @@ function wait(seconds) {
425
431
  }
426
432
  var wait_default = wait;
427
433
 
434
+ // src/functions/taggedTemplate/interpolate.ts
435
+ function interpolate(strings, ...interpolations) {
436
+ let result = "";
437
+ for (const [string, interpolation = ""] of paralleliseArrays_default(strings, interpolations)) {
438
+ result += string + interpolation;
439
+ }
440
+ return result;
441
+ }
442
+ var interpolate_default = interpolate;
443
+
428
444
  // src/functions/taggedTemplate/interpolateObjects.ts
429
445
  function interpolateObjects(strings, ...values) {
430
446
  let result = "";
@@ -438,6 +454,31 @@ function interpolateObjects(strings, ...values) {
438
454
  }
439
455
  var interpolateObjects_default = interpolateObjects;
440
456
 
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();
462
+ if (potentialWhitespacePart.trim() !== "") {
463
+ return 0;
464
+ }
465
+ const tabSize = line.length - (trimmedString.length + defaultWhitespaceLength);
466
+ return tabSize < 0 ? 0 : tabSize;
467
+ }
468
+ function reduceLines(lines) {
469
+ return lines.map((line) => {
470
+ const tabSize = calculateTabSize(line);
471
+ return fillArray_default(() => {
472
+ return " ";
473
+ }, tabSize).join("") + line.trim();
474
+ }).join("\n");
475
+ }
476
+ function stripIndents(strings, ...interpolations) {
477
+ const fullString = interpolate_default(strings, ...interpolations);
478
+ return reduceLines(fullString.split("\n"));
479
+ }
480
+ var stripIndents_default = stripIndents;
481
+
441
482
  // src/types/APIError.ts
442
483
  var httpErrorCodeLookup = {
443
484
  400: "BAD_REQUEST",
@@ -500,11 +541,13 @@ export {
500
541
  camelToKebab_default as camelToKebab,
501
542
  convertFileToBase64_default as convertFileToBase64,
502
543
  createFormData_default as createFormData,
544
+ createTemplateStringsArray_default as createTemplateStringsArray,
503
545
  fillArray_default as fillArray,
504
546
  formatDateAndTime_default as formatDateAndTime,
505
547
  getRandomNumber_default as getRandomNumber,
506
548
  getRecordKeys_default as getRecordKeys,
507
549
  httpErrorCodeLookup,
550
+ interpolate_default as interpolate,
508
551
  interpolateObjects_default as interpolateObjects,
509
552
  isLeapYear_default as isLeapYear,
510
553
  isMonthlyMultiple_default as isMonthlyMultiple,
@@ -522,6 +565,7 @@ export {
522
565
  removeDuplicates_default as removeDuplicates,
523
566
  stringListToArray_default as stringListToArray,
524
567
  stringToBoolean_default as stringToBoolean,
568
+ stripIndents_default as stripIndents,
525
569
  truncate_default as truncate,
526
570
  wait_default as wait
527
571
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "2.16.1",
3
+ "version": "2.18.0",
4
4
  "description": "Helpful utility functions",
5
5
  "repository": {
6
6
  "type": "git",