@alextheman/utility 5.21.1 → 5.23.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
@@ -1110,6 +1110,27 @@ function omitProperties(object, keysToOmit) {
1110
1110
  return outputObject;
1111
1111
  }
1112
1112
  //#endregion
1113
+ //#region src/root/functions/objectHelpers/pickProperties.ts
1114
+ /**
1115
+ * Picks properties from a given object.
1116
+ *
1117
+ * @category Object Helpers
1118
+ *
1119
+ * @template ObjectType - The type of the input object.
1120
+ * @template KeysToPick - A type representing the keys to pick from the object.
1121
+ *
1122
+ * @param object - The object to pick properties from.
1123
+ * @param keysToPick - The keys to pick from the object. Can either be a single string to pick one, or an array to pick multiple.
1124
+ *
1125
+ * @returns An object with a new reference in memory, with the chosen properties present.
1126
+ */
1127
+ function pickProperties(object, keysToPick) {
1128
+ const keysArray = Array.isArray(keysToPick) ? keysToPick : [keysToPick];
1129
+ const outputObject = {};
1130
+ for (const key of keysArray) outputObject[key] = object[key];
1131
+ return outputObject;
1132
+ }
1133
+ //#endregion
1113
1134
  //#region src/root/functions/objectHelpers/removeUndefinedFromObject.ts
1114
1135
  /**
1115
1136
  * Removes entries whose values are `undefined` from a given object (not including null etc.).
@@ -1611,6 +1632,18 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
1611
1632
  return result;
1612
1633
  }
1613
1634
  //#endregion
1635
+ //#region src/root/functions/stringHelpers/escapeHTML.ts
1636
+ /**
1637
+ * Escapes a raw HTML string so it can be safely used in HTML templates.
1638
+ *
1639
+ * @param rawString - The raw string to escape
1640
+ *
1641
+ * @returns A new string, with the contents of the original string but with HTML characters safely encoded.
1642
+ */
1643
+ function escapeHTML(rawString) {
1644
+ return rawString.replaceAll(/&/g, "&amp;").replaceAll(/</g, "&lt;").replaceAll(/>/g, "&gt;").replaceAll(/"/g, "&quot;").replaceAll(/'/g, "&#39;");
1645
+ }
1646
+ //#endregion
1614
1647
  //#region src/root/functions/stringHelpers/escapeRegexPattern.ts
1615
1648
  /**
1616
1649
  * A function to properly handle escape sequences in a Regex pattern string, so it can be safely used with the `RegExp` constructor.
@@ -2034,6 +2067,7 @@ exports.createFormData = createFormData;
2034
2067
  exports.createTemplateStringsArray = createTemplateStringsArray;
2035
2068
  exports.deepCopy = deepCopy;
2036
2069
  exports.deepFreeze = deepFreeze;
2070
+ exports.escapeHTML = escapeHTML;
2037
2071
  exports.escapeRegexPattern = escapeRegexPattern;
2038
2072
  exports.fillArray = fillArray;
2039
2073
  exports.formatDateAndTime = formatDateAndTime;
@@ -2065,6 +2099,7 @@ exports.parseUUID = parseUUID;
2065
2099
  exports.parseVersionType = parseVersionType;
2066
2100
  exports.parseZodSchema = parseZodSchema;
2067
2101
  exports.parseZodSchemaAsync = parseZodSchemaAsync;
2102
+ exports.pickProperties = pickProperties;
2068
2103
  exports.randomiseArray = randomiseArray;
2069
2104
  exports.range = range;
2070
2105
  exports.removeDuplicates = removeDuplicates;
package/dist/index.d.cts CHANGED
@@ -732,6 +732,22 @@ declare function getRecordKeys<InputRecordType extends Record<PropertyKey, unkno
732
732
  */
733
733
  declare function omitProperties<ObjectType extends object, KeysToOmit extends keyof ObjectType>(object: ObjectType, keysToOmit: KeysToOmit | ReadonlyArray<KeysToOmit>): Omit<ObjectType, KeysToOmit>;
734
734
  //#endregion
735
+ //#region src/root/functions/objectHelpers/pickProperties.d.ts
736
+ /**
737
+ * Picks properties from a given object.
738
+ *
739
+ * @category Object Helpers
740
+ *
741
+ * @template ObjectType - The type of the input object.
742
+ * @template KeysToPick - A type representing the keys to pick from the object.
743
+ *
744
+ * @param object - The object to pick properties from.
745
+ * @param keysToPick - The keys to pick from the object. Can either be a single string to pick one, or an array to pick multiple.
746
+ *
747
+ * @returns An object with a new reference in memory, with the chosen properties present.
748
+ */
749
+ declare function pickProperties<ObjectType extends object, KeysToPick extends keyof ObjectType>(object: ObjectType, keysToPick: KeysToPick | ReadonlyArray<KeysToPick>): Pick<ObjectType, KeysToPick>;
750
+ //#endregion
735
751
  //#region src/root/functions/objectHelpers/removeUndefinedFromObject.d.ts
736
752
  type RemoveUndefined<RecordType extends Record<PropertyKey, unknown>> = { [Key in keyof RecordType]: Exclude<RecordType[Key], undefined> };
737
753
  /**
@@ -924,6 +940,16 @@ interface CamelToKebabOptions {
924
940
  */
925
941
  declare function camelToKebab(string: string, options?: CamelToKebabOptions): string;
926
942
  //#endregion
943
+ //#region src/root/functions/stringHelpers/escapeHTML.d.ts
944
+ /**
945
+ * Escapes a raw HTML string so it can be safely used in HTML templates.
946
+ *
947
+ * @param rawString - The raw string to escape
948
+ *
949
+ * @returns A new string, with the contents of the original string but with HTML characters safely encoded.
950
+ */
951
+ declare function escapeHTML(rawString: string): string;
952
+ //#endregion
927
953
  //#region src/root/functions/stringHelpers/escapeRegexPattern.d.ts
928
954
  /**
929
955
  * A function to properly handle escape sequences in a Regex pattern string, so it can be safely used with the `RegExp` constructor.
@@ -1457,4 +1483,4 @@ interface ZodParsingErrorData {
1457
1483
  issues: Array<z.core.$ZodIssue>;
1458
1484
  }
1459
1485
  //#endregion
1460
- export { APIError, type ArrayElement, type CallReturnType, type CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, type KebabToCamelOptions, type NonNull, type NonUndefined, type NormaliseIndentsFunction, type NormaliseIndentsOptions, type NormalizeIndentsFunction, type NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, type ParallelTuple, type RecordKey, type RemoveUndefined, SortDirection, type StringListToArrayOptions, type ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, type ZodParsingErrorData, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
1486
+ export { APIError, type ArrayElement, type CallReturnType, type CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, type KebabToCamelOptions, type NonNull, type NonUndefined, type NormaliseIndentsFunction, type NormaliseIndentsOptions, type NormalizeIndentsFunction, type NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, type ParallelTuple, type RecordKey, type RemoveUndefined, SortDirection, type StringListToArrayOptions, type ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, type ZodParsingErrorData, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeHTML, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, pickProperties, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
package/dist/index.d.ts CHANGED
@@ -732,6 +732,22 @@ declare function getRecordKeys<InputRecordType extends Record<PropertyKey, unkno
732
732
  */
733
733
  declare function omitProperties<ObjectType extends object, KeysToOmit extends keyof ObjectType>(object: ObjectType, keysToOmit: KeysToOmit | ReadonlyArray<KeysToOmit>): Omit<ObjectType, KeysToOmit>;
734
734
  //#endregion
735
+ //#region src/root/functions/objectHelpers/pickProperties.d.ts
736
+ /**
737
+ * Picks properties from a given object.
738
+ *
739
+ * @category Object Helpers
740
+ *
741
+ * @template ObjectType - The type of the input object.
742
+ * @template KeysToPick - A type representing the keys to pick from the object.
743
+ *
744
+ * @param object - The object to pick properties from.
745
+ * @param keysToPick - The keys to pick from the object. Can either be a single string to pick one, or an array to pick multiple.
746
+ *
747
+ * @returns An object with a new reference in memory, with the chosen properties present.
748
+ */
749
+ declare function pickProperties<ObjectType extends object, KeysToPick extends keyof ObjectType>(object: ObjectType, keysToPick: KeysToPick | ReadonlyArray<KeysToPick>): Pick<ObjectType, KeysToPick>;
750
+ //#endregion
735
751
  //#region src/root/functions/objectHelpers/removeUndefinedFromObject.d.ts
736
752
  type RemoveUndefined<RecordType extends Record<PropertyKey, unknown>> = { [Key in keyof RecordType]: Exclude<RecordType[Key], undefined> };
737
753
  /**
@@ -924,6 +940,16 @@ interface CamelToKebabOptions {
924
940
  */
925
941
  declare function camelToKebab(string: string, options?: CamelToKebabOptions): string;
926
942
  //#endregion
943
+ //#region src/root/functions/stringHelpers/escapeHTML.d.ts
944
+ /**
945
+ * Escapes a raw HTML string so it can be safely used in HTML templates.
946
+ *
947
+ * @param rawString - The raw string to escape
948
+ *
949
+ * @returns A new string, with the contents of the original string but with HTML characters safely encoded.
950
+ */
951
+ declare function escapeHTML(rawString: string): string;
952
+ //#endregion
927
953
  //#region src/root/functions/stringHelpers/escapeRegexPattern.d.ts
928
954
  /**
929
955
  * A function to properly handle escape sequences in a Regex pattern string, so it can be safely used with the `RegExp` constructor.
@@ -1457,4 +1483,4 @@ interface ZodParsingErrorData {
1457
1483
  issues: Array<z$1.core.$ZodIssue>;
1458
1484
  }
1459
1485
  //#endregion
1460
- export { APIError, type ArrayElement, type CallReturnType, type CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, type KebabToCamelOptions, type NonNull, type NonUndefined, type NormaliseIndentsFunction, type NormaliseIndentsOptions, type NormalizeIndentsFunction, type NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, type ParallelTuple, type RecordKey, type RemoveUndefined, SortDirection, type StringListToArrayOptions, type ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, type ZodParsingErrorData, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
1486
+ export { APIError, type ArrayElement, type CallReturnType, type CamelToKebabOptions, type CreateEnumType, type CreateFormDataOptions, type CreateFormDataOptionsNullableResolution, type CreateFormDataOptionsUndefinedOrNullResolution, DataError, type DisallowUndefined, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, type FormDataArrayResolutionStrategy, type FormDataNullableResolutionStrategy, type HTTPErrorCode, type IgnoreCase, type IsTypeArgumentString, type KebabToCamelOptions, type NonNull, type NonUndefined, type NormaliseIndentsFunction, type NormaliseIndentsOptions, type NormalizeIndentsFunction, type NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, type ParallelTuple, type RecordKey, type RemoveUndefined, SortDirection, type StringListToArrayOptions, type ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, type ZodParsingErrorData, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeHTML, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, pickProperties, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
package/dist/index.js CHANGED
@@ -1086,6 +1086,27 @@ function omitProperties(object, keysToOmit) {
1086
1086
  return outputObject;
1087
1087
  }
1088
1088
  //#endregion
1089
+ //#region src/root/functions/objectHelpers/pickProperties.ts
1090
+ /**
1091
+ * Picks properties from a given object.
1092
+ *
1093
+ * @category Object Helpers
1094
+ *
1095
+ * @template ObjectType - The type of the input object.
1096
+ * @template KeysToPick - A type representing the keys to pick from the object.
1097
+ *
1098
+ * @param object - The object to pick properties from.
1099
+ * @param keysToPick - The keys to pick from the object. Can either be a single string to pick one, or an array to pick multiple.
1100
+ *
1101
+ * @returns An object with a new reference in memory, with the chosen properties present.
1102
+ */
1103
+ function pickProperties(object, keysToPick) {
1104
+ const keysArray = Array.isArray(keysToPick) ? keysToPick : [keysToPick];
1105
+ const outputObject = {};
1106
+ for (const key of keysArray) outputObject[key] = object[key];
1107
+ return outputObject;
1108
+ }
1109
+ //#endregion
1089
1110
  //#region src/root/functions/objectHelpers/removeUndefinedFromObject.ts
1090
1111
  /**
1091
1112
  * Removes entries whose values are `undefined` from a given object (not including null etc.).
@@ -1587,6 +1608,18 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
1587
1608
  return result;
1588
1609
  }
1589
1610
  //#endregion
1611
+ //#region src/root/functions/stringHelpers/escapeHTML.ts
1612
+ /**
1613
+ * Escapes a raw HTML string so it can be safely used in HTML templates.
1614
+ *
1615
+ * @param rawString - The raw string to escape
1616
+ *
1617
+ * @returns A new string, with the contents of the original string but with HTML characters safely encoded.
1618
+ */
1619
+ function escapeHTML(rawString) {
1620
+ return rawString.replaceAll(/&/g, "&amp;").replaceAll(/</g, "&lt;").replaceAll(/>/g, "&gt;").replaceAll(/"/g, "&quot;").replaceAll(/'/g, "&#39;");
1621
+ }
1622
+ //#endregion
1590
1623
  //#region src/root/functions/stringHelpers/escapeRegexPattern.ts
1591
1624
  /**
1592
1625
  * A function to properly handle escape sequences in a Regex pattern string, so it can be safely used with the `RegExp` constructor.
@@ -1983,4 +2016,4 @@ var DataError = class DataError extends Error {
1983
2016
  }
1984
2017
  };
1985
2018
  //#endregion
1986
- export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, ONE_DAY_IN_MILLISECONDS, SortDirection, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
2019
+ export { APIError, DataError, Env, FILE_PATH_PATTERN, FILE_PATH_REGEX, ONE_DAY_IN_MILLISECONDS, SortDirection, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, VersionType, addDaysToDate, appendSemicolon, assertNotNull, assertNotNullable, assertNotUndefined, az, calculateMonthlyDifference, camelToKebab, containsKeys, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, escapeHTML, escapeRegexPattern, fillArray, formatDateAndTime, getRandomNumber, getRecordKeys, getStringsAndInterpolations, httpErrorCodeLookup, identity, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isNonNullableObject, isOrdered, isSameDate, isTemplateStringsArray, kebabToCamel, normaliseIndents, normalizeIndents, objectContainsKeys, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseUUID, parseVersionType, parseZodSchema, parseZodSchemaAsync, pickProperties, randomiseArray, range, removeDuplicates, removeUndefinedFromObject, sayHello, sortBy, stringListToArray, stringifyDotenv, toTitleCase, truncate, wait, zodVersionNumber };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alextheman/utility",
3
- "version": "5.21.1",
3
+ "version": "5.23.0",
4
4
  "description": "Helpful utility functions.",
5
5
  "repository": {
6
6
  "type": "git",