@alextheman/utility 5.11.3 → 5.12.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
@@ -784,83 +784,6 @@ function isOrdered(array) {
784
784
  return true;
785
785
  }
786
786
  //#endregion
787
- //#region src/root/functions/recursive/deepFreeze.ts
788
- /**
789
- * Deeply freezes an object or array such that all child objects/arrays are also frozen.
790
- *
791
- * Note that this will also freeze the input itself as well.
792
- * If the intent is to create a newly frozen object with a different reference in memory, pass your object through deepCopy first before passing to deepFreeze.
793
- *
794
- * @category Recursive
795
- *
796
- * @template ObjectType - The type of the input object.
797
- *
798
- * @param object - The object to freeze. May also be an array.
799
- *
800
- * @returns The input object completely frozen.
801
- */
802
- function deepFreeze(object) {
803
- for (const value of Object.values(object)) {
804
- if (typeof value === "function") continue;
805
- if (value && typeof value === "object") deepFreeze(value);
806
- }
807
- return Object.freeze(object);
808
- }
809
- //#endregion
810
- //#region src/root/functions/taggedTemplate/createTemplateStringsArray.ts
811
- /**
812
- * Creates a template strings array given a regular array of strings
813
- *
814
- * @category Tagged Template
815
- *
816
- * @param strings - The array of strings.
817
- *
818
- * @returns A template strings array that can be passed as the first argument of any tagged template function.
819
- */
820
- function createTemplateStringsArray(strings) {
821
- return deepFreeze(Object.assign([...strings], { raw: [...strings] }));
822
- }
823
- //#endregion
824
- //#region src/root/functions/taggedTemplate/getStringsAndInterpolations.ts
825
- /**
826
- *
827
- * Gets the strings and interpolations separately from a template string.
828
- * You can pass a template string directly by doing:
829
- *
830
- * ```typescript
831
- * getStringsAndInterpolations`Template string here`;
832
- * ```
833
- *
834
- * @category Tagged Template
835
- *
836
- * @template InterpolationsType - The type of the interpolations.
837
- *
838
- * @param strings - The strings from the template to process.
839
- * @param interpolations - An array of all interpolations from the template.
840
- *
841
- * @returns A tuple where the first item is the strings from the template, and the remaining items are the interpolations.
842
- *
843
- * The return of this function may also be spread into any other tagged template function in the following way:
844
- *
845
- * ```typescript
846
- * import { interpolate } from "@alextheman/utility"; // Example function
847
- *
848
- * const packageName = "@alextheman/utility";
849
- * const packageManager = getPackageManager(packageName);
850
- *
851
- * interpolate(...getStringsAndInterpolations`The package ${packageName} uses the ${packageManager} package manager.`);
852
- * ```
853
- */
854
- function getStringsAndInterpolations(strings, ...interpolations) {
855
- if (strings.length !== interpolations.length + 1) throw new DataError({
856
- stringsLength: strings.length,
857
- interpolationsLength: interpolations.length,
858
- strings,
859
- interpolations
860
- }, "INVALID_STRINGS_AND_INTERPOLATIONS_LENGTH", "The length of the strings must be exactly one more than the length of the interpolations.");
861
- return [createTemplateStringsArray(strings), ...interpolations];
862
- }
863
- //#endregion
864
787
  //#region src/root/functions/taggedTemplate/interpolate.ts
865
788
  /**
866
789
  * Returns the result of interpolating a template string when given the strings and interpolations separately.
@@ -888,48 +811,6 @@ function interpolate(strings, ...interpolations) {
888
811
  return result;
889
812
  }
890
813
  //#endregion
891
- //#region src/root/functions/taggedTemplate/interpolateObjects.ts
892
- /**
893
- * Returns the result of interpolating a template string, also stringifying objects.
894
- *
895
- * You can pass a template string directly by doing:
896
- *
897
- * ```typescript
898
- * interpolateObjects`Template string here ${{ my: "object" }}`;
899
- * ```
900
- *
901
- * @category Tagged Template
902
- *
903
- * @template InterpolationsType - The type of the interpolations.
904
- *
905
- * @param strings - The strings from the template to process.
906
- * @param interpolations - An array of all interpolations from the template.
907
- *
908
- * @returns A new string with the strings and interpolations from the template applied, with objects stringified.
909
- */
910
- function interpolateObjects(strings, ...interpolations) {
911
- let result = "";
912
- for (let i = 0; i < strings.length; i++) {
913
- result += strings[i];
914
- if (i !== strings.length - 1) result += interpolations[i] && typeof interpolations[i] === "object" ? JSON.stringify(interpolations[i]) : interpolations[i];
915
- }
916
- return result;
917
- }
918
- //#endregion
919
- //#region src/root/functions/taggedTemplate/isTemplateStringsArray.ts
920
- /**
921
- * Determines whether or not the input is a valid `TemplateStringsArray`.
922
- *
923
- * @category Tagged Template
924
- *
925
- * @param input - The input to check
926
- *
927
- * @returns `true` if the input is a valid `TemplateStringsArray`, and false otherwise. The type of the input will also be narrowed down to `TemplateStringsArray` if `true`.
928
- */
929
- function isTemplateStringsArray(input) {
930
- return typeof input === "object" && input !== null && "raw" in input;
931
- }
932
- //#endregion
933
814
  //#region src/root/functions/taggedTemplate/normaliseIndents.ts
934
815
  function calculateTabSize(line, whitespaceLength) {
935
816
  const potentialWhitespacePart = line.slice(0, whitespaceLength);
@@ -1462,6 +1343,29 @@ function deepCopy(object) {
1462
1343
  return clonedObject;
1463
1344
  }
1464
1345
  //#endregion
1346
+ //#region src/root/functions/recursive/deepFreeze.ts
1347
+ /**
1348
+ * Deeply freezes an object or array such that all child objects/arrays are also frozen.
1349
+ *
1350
+ * Note that this will also freeze the input itself as well.
1351
+ * If the intent is to create a newly frozen object with a different reference in memory, pass your object through deepCopy first before passing to deepFreeze.
1352
+ *
1353
+ * @category Recursive
1354
+ *
1355
+ * @template ObjectType - The type of the input object.
1356
+ *
1357
+ * @param object - The object to freeze. May also be an array.
1358
+ *
1359
+ * @returns The input object completely frozen.
1360
+ */
1361
+ function deepFreeze(object) {
1362
+ for (const value of Object.values(object)) {
1363
+ if (typeof value === "function") continue;
1364
+ if (value && typeof value === "object") deepFreeze(value);
1365
+ }
1366
+ return Object.freeze(object);
1367
+ }
1368
+ //#endregion
1465
1369
  //#region src/root/functions/stringHelpers/appendSemicolon.ts
1466
1370
  /**
1467
1371
  * Appends a semicolon to the end of a string, trimming where necessary first.
@@ -1613,6 +1517,102 @@ function truncate(stringToTruncate, maxLength = 5) {
1613
1517
  return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
1614
1518
  }
1615
1519
  //#endregion
1520
+ //#region src/root/functions/taggedTemplate/createTemplateStringsArray.ts
1521
+ /**
1522
+ * Creates a template strings array given a regular array of strings
1523
+ *
1524
+ * @category Tagged Template
1525
+ *
1526
+ * @param strings - The array of strings.
1527
+ *
1528
+ * @returns A template strings array that can be passed as the first argument of any tagged template function.
1529
+ */
1530
+ function createTemplateStringsArray(strings) {
1531
+ return deepFreeze(Object.assign([...strings], { raw: [...strings] }));
1532
+ }
1533
+ //#endregion
1534
+ //#region src/root/functions/taggedTemplate/getStringsAndInterpolations.ts
1535
+ /**
1536
+ *
1537
+ * Gets the strings and interpolations separately from a template string.
1538
+ * You can pass a template string directly by doing:
1539
+ *
1540
+ * ```typescript
1541
+ * getStringsAndInterpolations`Template string here`;
1542
+ * ```
1543
+ *
1544
+ * @category Tagged Template
1545
+ *
1546
+ * @template InterpolationsType - The type of the interpolations.
1547
+ *
1548
+ * @param strings - The strings from the template to process.
1549
+ * @param interpolations - An array of all interpolations from the template.
1550
+ *
1551
+ * @returns A tuple where the first item is the strings from the template, and the remaining items are the interpolations.
1552
+ *
1553
+ * The return of this function may also be spread into any other tagged template function in the following way:
1554
+ *
1555
+ * ```typescript
1556
+ * import { interpolate } from "@alextheman/utility"; // Example function
1557
+ *
1558
+ * const packageName = "@alextheman/utility";
1559
+ * const packageManager = getPackageManager(packageName);
1560
+ *
1561
+ * interpolate(...getStringsAndInterpolations`The package ${packageName} uses the ${packageManager} package manager.`);
1562
+ * ```
1563
+ */
1564
+ function getStringsAndInterpolations(strings, ...interpolations) {
1565
+ if (strings.length !== interpolations.length + 1) throw new DataError({
1566
+ stringsLength: strings.length,
1567
+ interpolationsLength: interpolations.length,
1568
+ strings,
1569
+ interpolations
1570
+ }, "INVALID_STRINGS_AND_INTERPOLATIONS_LENGTH", "The length of the strings must be exactly one more than the length of the interpolations.");
1571
+ return [createTemplateStringsArray(strings), ...interpolations];
1572
+ }
1573
+ //#endregion
1574
+ //#region src/root/functions/taggedTemplate/interpolateObjects.ts
1575
+ /**
1576
+ * Returns the result of interpolating a template string, also stringifying objects.
1577
+ *
1578
+ * You can pass a template string directly by doing:
1579
+ *
1580
+ * ```typescript
1581
+ * interpolateObjects`Template string here ${{ my: "object" }}`;
1582
+ * ```
1583
+ *
1584
+ * @category Tagged Template
1585
+ *
1586
+ * @template InterpolationsType - The type of the interpolations.
1587
+ *
1588
+ * @param strings - The strings from the template to process.
1589
+ * @param interpolations - An array of all interpolations from the template.
1590
+ *
1591
+ * @returns A new string with the strings and interpolations from the template applied, with objects stringified.
1592
+ */
1593
+ function interpolateObjects(strings, ...interpolations) {
1594
+ let result = "";
1595
+ for (let i = 0; i < strings.length; i++) {
1596
+ result += strings[i];
1597
+ if (i !== strings.length - 1) result += interpolations[i] && typeof interpolations[i] === "object" ? JSON.stringify(interpolations[i]) : interpolations[i];
1598
+ }
1599
+ return result;
1600
+ }
1601
+ //#endregion
1602
+ //#region src/root/functions/taggedTemplate/isTemplateStringsArray.ts
1603
+ /**
1604
+ * Determines whether or not the input is a valid `TemplateStringsArray`.
1605
+ *
1606
+ * @category Tagged Template
1607
+ *
1608
+ * @param input - The input to check
1609
+ *
1610
+ * @returns `true` if the input is a valid `TemplateStringsArray`, and false otherwise. The type of the input will also be narrowed down to `TemplateStringsArray` if `true`.
1611
+ */
1612
+ function isTemplateStringsArray(input) {
1613
+ return typeof input === "object" && input !== null && "raw" in input;
1614
+ }
1615
+ //#endregion
1616
1616
  exports.APIError = APIError;
1617
1617
  exports.DataError = DataError;
1618
1618
  exports.Env = Env;
package/dist/index.js CHANGED
@@ -760,83 +760,6 @@ function isOrdered(array) {
760
760
  return true;
761
761
  }
762
762
  //#endregion
763
- //#region src/root/functions/recursive/deepFreeze.ts
764
- /**
765
- * Deeply freezes an object or array such that all child objects/arrays are also frozen.
766
- *
767
- * Note that this will also freeze the input itself as well.
768
- * If the intent is to create a newly frozen object with a different reference in memory, pass your object through deepCopy first before passing to deepFreeze.
769
- *
770
- * @category Recursive
771
- *
772
- * @template ObjectType - The type of the input object.
773
- *
774
- * @param object - The object to freeze. May also be an array.
775
- *
776
- * @returns The input object completely frozen.
777
- */
778
- function deepFreeze(object) {
779
- for (const value of Object.values(object)) {
780
- if (typeof value === "function") continue;
781
- if (value && typeof value === "object") deepFreeze(value);
782
- }
783
- return Object.freeze(object);
784
- }
785
- //#endregion
786
- //#region src/root/functions/taggedTemplate/createTemplateStringsArray.ts
787
- /**
788
- * Creates a template strings array given a regular array of strings
789
- *
790
- * @category Tagged Template
791
- *
792
- * @param strings - The array of strings.
793
- *
794
- * @returns A template strings array that can be passed as the first argument of any tagged template function.
795
- */
796
- function createTemplateStringsArray(strings) {
797
- return deepFreeze(Object.assign([...strings], { raw: [...strings] }));
798
- }
799
- //#endregion
800
- //#region src/root/functions/taggedTemplate/getStringsAndInterpolations.ts
801
- /**
802
- *
803
- * Gets the strings and interpolations separately from a template string.
804
- * You can pass a template string directly by doing:
805
- *
806
- * ```typescript
807
- * getStringsAndInterpolations`Template string here`;
808
- * ```
809
- *
810
- * @category Tagged Template
811
- *
812
- * @template InterpolationsType - The type of the interpolations.
813
- *
814
- * @param strings - The strings from the template to process.
815
- * @param interpolations - An array of all interpolations from the template.
816
- *
817
- * @returns A tuple where the first item is the strings from the template, and the remaining items are the interpolations.
818
- *
819
- * The return of this function may also be spread into any other tagged template function in the following way:
820
- *
821
- * ```typescript
822
- * import { interpolate } from "@alextheman/utility"; // Example function
823
- *
824
- * const packageName = "@alextheman/utility";
825
- * const packageManager = getPackageManager(packageName);
826
- *
827
- * interpolate(...getStringsAndInterpolations`The package ${packageName} uses the ${packageManager} package manager.`);
828
- * ```
829
- */
830
- function getStringsAndInterpolations(strings, ...interpolations) {
831
- if (strings.length !== interpolations.length + 1) throw new DataError({
832
- stringsLength: strings.length,
833
- interpolationsLength: interpolations.length,
834
- strings,
835
- interpolations
836
- }, "INVALID_STRINGS_AND_INTERPOLATIONS_LENGTH", "The length of the strings must be exactly one more than the length of the interpolations.");
837
- return [createTemplateStringsArray(strings), ...interpolations];
838
- }
839
- //#endregion
840
763
  //#region src/root/functions/taggedTemplate/interpolate.ts
841
764
  /**
842
765
  * Returns the result of interpolating a template string when given the strings and interpolations separately.
@@ -864,48 +787,6 @@ function interpolate(strings, ...interpolations) {
864
787
  return result;
865
788
  }
866
789
  //#endregion
867
- //#region src/root/functions/taggedTemplate/interpolateObjects.ts
868
- /**
869
- * Returns the result of interpolating a template string, also stringifying objects.
870
- *
871
- * You can pass a template string directly by doing:
872
- *
873
- * ```typescript
874
- * interpolateObjects`Template string here ${{ my: "object" }}`;
875
- * ```
876
- *
877
- * @category Tagged Template
878
- *
879
- * @template InterpolationsType - The type of the interpolations.
880
- *
881
- * @param strings - The strings from the template to process.
882
- * @param interpolations - An array of all interpolations from the template.
883
- *
884
- * @returns A new string with the strings and interpolations from the template applied, with objects stringified.
885
- */
886
- function interpolateObjects(strings, ...interpolations) {
887
- let result = "";
888
- for (let i = 0; i < strings.length; i++) {
889
- result += strings[i];
890
- if (i !== strings.length - 1) result += interpolations[i] && typeof interpolations[i] === "object" ? JSON.stringify(interpolations[i]) : interpolations[i];
891
- }
892
- return result;
893
- }
894
- //#endregion
895
- //#region src/root/functions/taggedTemplate/isTemplateStringsArray.ts
896
- /**
897
- * Determines whether or not the input is a valid `TemplateStringsArray`.
898
- *
899
- * @category Tagged Template
900
- *
901
- * @param input - The input to check
902
- *
903
- * @returns `true` if the input is a valid `TemplateStringsArray`, and false otherwise. The type of the input will also be narrowed down to `TemplateStringsArray` if `true`.
904
- */
905
- function isTemplateStringsArray(input) {
906
- return typeof input === "object" && input !== null && "raw" in input;
907
- }
908
- //#endregion
909
790
  //#region src/root/functions/taggedTemplate/normaliseIndents.ts
910
791
  function calculateTabSize(line, whitespaceLength) {
911
792
  const potentialWhitespacePart = line.slice(0, whitespaceLength);
@@ -1438,6 +1319,29 @@ function deepCopy(object) {
1438
1319
  return clonedObject;
1439
1320
  }
1440
1321
  //#endregion
1322
+ //#region src/root/functions/recursive/deepFreeze.ts
1323
+ /**
1324
+ * Deeply freezes an object or array such that all child objects/arrays are also frozen.
1325
+ *
1326
+ * Note that this will also freeze the input itself as well.
1327
+ * If the intent is to create a newly frozen object with a different reference in memory, pass your object through deepCopy first before passing to deepFreeze.
1328
+ *
1329
+ * @category Recursive
1330
+ *
1331
+ * @template ObjectType - The type of the input object.
1332
+ *
1333
+ * @param object - The object to freeze. May also be an array.
1334
+ *
1335
+ * @returns The input object completely frozen.
1336
+ */
1337
+ function deepFreeze(object) {
1338
+ for (const value of Object.values(object)) {
1339
+ if (typeof value === "function") continue;
1340
+ if (value && typeof value === "object") deepFreeze(value);
1341
+ }
1342
+ return Object.freeze(object);
1343
+ }
1344
+ //#endregion
1441
1345
  //#region src/root/functions/stringHelpers/appendSemicolon.ts
1442
1346
  /**
1443
1347
  * Appends a semicolon to the end of a string, trimming where necessary first.
@@ -1589,4 +1493,100 @@ function truncate(stringToTruncate, maxLength = 5) {
1589
1493
  return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
1590
1494
  }
1591
1495
  //#endregion
1496
+ //#region src/root/functions/taggedTemplate/createTemplateStringsArray.ts
1497
+ /**
1498
+ * Creates a template strings array given a regular array of strings
1499
+ *
1500
+ * @category Tagged Template
1501
+ *
1502
+ * @param strings - The array of strings.
1503
+ *
1504
+ * @returns A template strings array that can be passed as the first argument of any tagged template function.
1505
+ */
1506
+ function createTemplateStringsArray(strings) {
1507
+ return deepFreeze(Object.assign([...strings], { raw: [...strings] }));
1508
+ }
1509
+ //#endregion
1510
+ //#region src/root/functions/taggedTemplate/getStringsAndInterpolations.ts
1511
+ /**
1512
+ *
1513
+ * Gets the strings and interpolations separately from a template string.
1514
+ * You can pass a template string directly by doing:
1515
+ *
1516
+ * ```typescript
1517
+ * getStringsAndInterpolations`Template string here`;
1518
+ * ```
1519
+ *
1520
+ * @category Tagged Template
1521
+ *
1522
+ * @template InterpolationsType - The type of the interpolations.
1523
+ *
1524
+ * @param strings - The strings from the template to process.
1525
+ * @param interpolations - An array of all interpolations from the template.
1526
+ *
1527
+ * @returns A tuple where the first item is the strings from the template, and the remaining items are the interpolations.
1528
+ *
1529
+ * The return of this function may also be spread into any other tagged template function in the following way:
1530
+ *
1531
+ * ```typescript
1532
+ * import { interpolate } from "@alextheman/utility"; // Example function
1533
+ *
1534
+ * const packageName = "@alextheman/utility";
1535
+ * const packageManager = getPackageManager(packageName);
1536
+ *
1537
+ * interpolate(...getStringsAndInterpolations`The package ${packageName} uses the ${packageManager} package manager.`);
1538
+ * ```
1539
+ */
1540
+ function getStringsAndInterpolations(strings, ...interpolations) {
1541
+ if (strings.length !== interpolations.length + 1) throw new DataError({
1542
+ stringsLength: strings.length,
1543
+ interpolationsLength: interpolations.length,
1544
+ strings,
1545
+ interpolations
1546
+ }, "INVALID_STRINGS_AND_INTERPOLATIONS_LENGTH", "The length of the strings must be exactly one more than the length of the interpolations.");
1547
+ return [createTemplateStringsArray(strings), ...interpolations];
1548
+ }
1549
+ //#endregion
1550
+ //#region src/root/functions/taggedTemplate/interpolateObjects.ts
1551
+ /**
1552
+ * Returns the result of interpolating a template string, also stringifying objects.
1553
+ *
1554
+ * You can pass a template string directly by doing:
1555
+ *
1556
+ * ```typescript
1557
+ * interpolateObjects`Template string here ${{ my: "object" }}`;
1558
+ * ```
1559
+ *
1560
+ * @category Tagged Template
1561
+ *
1562
+ * @template InterpolationsType - The type of the interpolations.
1563
+ *
1564
+ * @param strings - The strings from the template to process.
1565
+ * @param interpolations - An array of all interpolations from the template.
1566
+ *
1567
+ * @returns A new string with the strings and interpolations from the template applied, with objects stringified.
1568
+ */
1569
+ function interpolateObjects(strings, ...interpolations) {
1570
+ let result = "";
1571
+ for (let i = 0; i < strings.length; i++) {
1572
+ result += strings[i];
1573
+ if (i !== strings.length - 1) result += interpolations[i] && typeof interpolations[i] === "object" ? JSON.stringify(interpolations[i]) : interpolations[i];
1574
+ }
1575
+ return result;
1576
+ }
1577
+ //#endregion
1578
+ //#region src/root/functions/taggedTemplate/isTemplateStringsArray.ts
1579
+ /**
1580
+ * Determines whether or not the input is a valid `TemplateStringsArray`.
1581
+ *
1582
+ * @category Tagged Template
1583
+ *
1584
+ * @param input - The input to check
1585
+ *
1586
+ * @returns `true` if the input is a valid `TemplateStringsArray`, and false otherwise. The type of the input will also be narrowed down to `TemplateStringsArray` if `true`.
1587
+ */
1588
+ function isTemplateStringsArray(input) {
1589
+ return typeof input === "object" && input !== null && "raw" in input;
1590
+ }
1591
+ //#endregion
1592
1592
  export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, ONE_DAY_IN_MILLISECONDS, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };