@alextheman/utility 5.8.0 → 5.10.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 +27 -23
- package/dist/index.d.cts +24 -12
- package/dist/index.d.ts +24 -12
- package/dist/index.js +27 -22
- package/dist/internal/index.cjs +0 -1
- package/dist/internal/index.js +0 -1
- package/dist/node/index.cjs +23 -1
- package/dist/node/index.d.cts +12 -1
- package/dist/node/index.d.ts +12 -1
- package/dist/node/index.js +22 -2
- package/package.json +27 -26
package/dist/index.cjs
CHANGED
|
@@ -23,8 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
//#endregion
|
|
24
24
|
let zod = require("zod");
|
|
25
25
|
zod = __toESM(zod);
|
|
26
|
-
let libsodium_wrappers = require("libsodium-wrappers");
|
|
27
|
-
libsodium_wrappers = __toESM(libsodium_wrappers);
|
|
28
26
|
//#region src/root/constants/FILE_PATH_REGEX.ts
|
|
29
27
|
const FILE_PATH_PATTERN = String.raw`(?<directory>.+)[\/\\](?<base>[^\/\\]+)`;
|
|
30
28
|
const FILE_PATH_REGEX = RegExp(`^${FILE_PATH_PATTERN}$`);
|
|
@@ -1464,26 +1462,6 @@ function deepCopy(object) {
|
|
|
1464
1462
|
return clonedObject;
|
|
1465
1463
|
}
|
|
1466
1464
|
//#endregion
|
|
1467
|
-
//#region src/root/functions/security/encryptWithKey.ts
|
|
1468
|
-
/**
|
|
1469
|
-
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
1470
|
-
*
|
|
1471
|
-
* @param publicKey - The public base64 key to encrypt with.
|
|
1472
|
-
* @param plaintextValue - The value to encrypt in plaintext.
|
|
1473
|
-
*
|
|
1474
|
-
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
1475
|
-
*/
|
|
1476
|
-
async function encryptWithKey(publicKey, plaintextValue) {
|
|
1477
|
-
try {
|
|
1478
|
-
await libsodium_wrappers.default.ready;
|
|
1479
|
-
const base64Key = libsodium_wrappers.default.from_base64(publicKey, libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
1480
|
-
const encryptedValue = libsodium_wrappers.default.crypto_box_seal(plaintextValue, base64Key);
|
|
1481
|
-
return libsodium_wrappers.default.to_base64(encryptedValue, libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
1482
|
-
} catch {
|
|
1483
|
-
throw new DataError({ publicKey }, "ENCRYPTION_FAILED", "Encryption failed. Please double-check that the given key is a valid base 64 string.");
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
//#endregion
|
|
1487
1465
|
//#region src/root/functions/stringHelpers/appendSemicolon.ts
|
|
1488
1466
|
/**
|
|
1489
1467
|
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
@@ -1592,6 +1570,32 @@ function kebabToCamel(input, options) {
|
|
|
1592
1570
|
return outputString;
|
|
1593
1571
|
}
|
|
1594
1572
|
//#endregion
|
|
1573
|
+
//#region src/root/functions/stringHelpers/toTitleCase.ts
|
|
1574
|
+
/**
|
|
1575
|
+
* Converts a string to a human-readable Title Case string.
|
|
1576
|
+
*
|
|
1577
|
+
* Words are split on spaces, underscores, and hyphens. Every first letter of each word is capitalised except for words specified in `options.preserveWords`.
|
|
1578
|
+
*
|
|
1579
|
+
* The comparison for preserved words is case-insensitive, but the original casing provided in `preserveWords` is retained in the output.
|
|
1580
|
+
*
|
|
1581
|
+
* @param input - The string to convert.
|
|
1582
|
+
* @param options - Additional options to apply.
|
|
1583
|
+
*
|
|
1584
|
+
* @returns A new string, converted into Title Case.
|
|
1585
|
+
*/
|
|
1586
|
+
function toTitleCase(input, options) {
|
|
1587
|
+
const preservedWords = removeDuplicates(options?.preserveWords?.map((word) => {
|
|
1588
|
+
return {
|
|
1589
|
+
normalised: word.toLowerCase(),
|
|
1590
|
+
original: word
|
|
1591
|
+
};
|
|
1592
|
+
}) ?? []);
|
|
1593
|
+
return input.split(/[_\s-]+/).filter(Boolean).map((word) => {
|
|
1594
|
+
for (const preservedWord of preservedWords) if (preservedWord.normalised === word.toLowerCase()) return preservedWord.original;
|
|
1595
|
+
return word[0].toUpperCase() + word.slice(1).toLowerCase();
|
|
1596
|
+
}).join(" ");
|
|
1597
|
+
}
|
|
1598
|
+
//#endregion
|
|
1595
1599
|
//#region src/root/functions/stringHelpers/truncate.ts
|
|
1596
1600
|
/**
|
|
1597
1601
|
* Truncates a string and appends `...` to the end of it
|
|
@@ -1628,7 +1632,6 @@ exports.createFormData = createFormData;
|
|
|
1628
1632
|
exports.createTemplateStringsArray = createTemplateStringsArray;
|
|
1629
1633
|
exports.deepCopy = deepCopy;
|
|
1630
1634
|
exports.deepFreeze = deepFreeze;
|
|
1631
|
-
exports.encryptWithKey = encryptWithKey;
|
|
1632
1635
|
exports.escapeRegexPattern = escapeRegexPattern;
|
|
1633
1636
|
exports.fillArray = fillArray;
|
|
1634
1637
|
exports.formatDateAndTime = formatDateAndTime;
|
|
@@ -1664,6 +1667,7 @@ exports.removeUndefinedFromObject = removeUndefinedFromObject;
|
|
|
1664
1667
|
exports.sayHello = sayHello;
|
|
1665
1668
|
exports.stringListToArray = stringListToArray;
|
|
1666
1669
|
exports.stringifyDotenv = stringifyDotenv;
|
|
1670
|
+
exports.toTitleCase = toTitleCase;
|
|
1667
1671
|
exports.truncate = truncate;
|
|
1668
1672
|
exports.wait = wait;
|
|
1669
1673
|
exports.zodVersionNumber = zodVersionNumber;
|
package/dist/index.d.cts
CHANGED
|
@@ -865,17 +865,6 @@ declare function deepCopy<ObjectType extends object>(object: ObjectType): Object
|
|
|
865
865
|
*/
|
|
866
866
|
declare function deepFreeze<ObjectType extends object>(object: ObjectType): Readonly<ObjectType>;
|
|
867
867
|
//#endregion
|
|
868
|
-
//#region src/root/functions/security/encryptWithKey.d.ts
|
|
869
|
-
/**
|
|
870
|
-
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
871
|
-
*
|
|
872
|
-
* @param publicKey - The public base64 key to encrypt with.
|
|
873
|
-
* @param plaintextValue - The value to encrypt in plaintext.
|
|
874
|
-
*
|
|
875
|
-
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
876
|
-
*/
|
|
877
|
-
declare function encryptWithKey(publicKey: string, plaintextValue: string): Promise<string>;
|
|
878
|
-
//#endregion
|
|
879
868
|
//#region src/root/functions/stringHelpers/appendSemicolon.d.ts
|
|
880
869
|
/**
|
|
881
870
|
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
@@ -944,6 +933,29 @@ interface KebabToCamelOptions {
|
|
|
944
933
|
*/
|
|
945
934
|
declare function kebabToCamel(input: string, options?: KebabToCamelOptions): string;
|
|
946
935
|
//#endregion
|
|
936
|
+
//#region src/root/functions/stringHelpers/toTitleCase.d.ts
|
|
937
|
+
interface ToTitleCaseOptions {
|
|
938
|
+
/**
|
|
939
|
+
* An array of words to keep as is in the title.
|
|
940
|
+
*
|
|
941
|
+
* Note that the comparison is case insensitive, and if a match is found it will use the casing as found in the options.
|
|
942
|
+
*/
|
|
943
|
+
preserveWords?: Array<string>;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Converts a string to a human-readable Title Case string.
|
|
947
|
+
*
|
|
948
|
+
* Words are split on spaces, underscores, and hyphens. Every first letter of each word is capitalised except for words specified in `options.preserveWords`.
|
|
949
|
+
*
|
|
950
|
+
* The comparison for preserved words is case-insensitive, but the original casing provided in `preserveWords` is retained in the output.
|
|
951
|
+
*
|
|
952
|
+
* @param input - The string to convert.
|
|
953
|
+
* @param options - Additional options to apply.
|
|
954
|
+
*
|
|
955
|
+
* @returns A new string, converted into Title Case.
|
|
956
|
+
*/
|
|
957
|
+
declare function toTitleCase(input: string, options?: ToTitleCaseOptions): string;
|
|
958
|
+
//#endregion
|
|
947
959
|
//#region src/root/functions/stringHelpers/truncate.d.ts
|
|
948
960
|
/**
|
|
949
961
|
* Truncates a string and appends `...` to the end of it
|
|
@@ -1135,4 +1147,4 @@ declare const normalizeIndents: typeof normaliseIndents;
|
|
|
1135
1147
|
*/
|
|
1136
1148
|
type RecordKey = string | number | symbol;
|
|
1137
1149
|
//#endregion
|
|
1138
|
-
export { APIError, type ArrayElement, type CallReturnType, 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, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze,
|
|
1150
|
+
export { APIError, type ArrayElement, type CallReturnType, 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, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -865,17 +865,6 @@ declare function deepCopy<ObjectType extends object>(object: ObjectType): Object
|
|
|
865
865
|
*/
|
|
866
866
|
declare function deepFreeze<ObjectType extends object>(object: ObjectType): Readonly<ObjectType>;
|
|
867
867
|
//#endregion
|
|
868
|
-
//#region src/root/functions/security/encryptWithKey.d.ts
|
|
869
|
-
/**
|
|
870
|
-
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
871
|
-
*
|
|
872
|
-
* @param publicKey - The public base64 key to encrypt with.
|
|
873
|
-
* @param plaintextValue - The value to encrypt in plaintext.
|
|
874
|
-
*
|
|
875
|
-
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
876
|
-
*/
|
|
877
|
-
declare function encryptWithKey(publicKey: string, plaintextValue: string): Promise<string>;
|
|
878
|
-
//#endregion
|
|
879
868
|
//#region src/root/functions/stringHelpers/appendSemicolon.d.ts
|
|
880
869
|
/**
|
|
881
870
|
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
@@ -944,6 +933,29 @@ interface KebabToCamelOptions {
|
|
|
944
933
|
*/
|
|
945
934
|
declare function kebabToCamel(input: string, options?: KebabToCamelOptions): string;
|
|
946
935
|
//#endregion
|
|
936
|
+
//#region src/root/functions/stringHelpers/toTitleCase.d.ts
|
|
937
|
+
interface ToTitleCaseOptions {
|
|
938
|
+
/**
|
|
939
|
+
* An array of words to keep as is in the title.
|
|
940
|
+
*
|
|
941
|
+
* Note that the comparison is case insensitive, and if a match is found it will use the casing as found in the options.
|
|
942
|
+
*/
|
|
943
|
+
preserveWords?: Array<string>;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Converts a string to a human-readable Title Case string.
|
|
947
|
+
*
|
|
948
|
+
* Words are split on spaces, underscores, and hyphens. Every first letter of each word is capitalised except for words specified in `options.preserveWords`.
|
|
949
|
+
*
|
|
950
|
+
* The comparison for preserved words is case-insensitive, but the original casing provided in `preserveWords` is retained in the output.
|
|
951
|
+
*
|
|
952
|
+
* @param input - The string to convert.
|
|
953
|
+
* @param options - Additional options to apply.
|
|
954
|
+
*
|
|
955
|
+
* @returns A new string, converted into Title Case.
|
|
956
|
+
*/
|
|
957
|
+
declare function toTitleCase(input: string, options?: ToTitleCaseOptions): string;
|
|
958
|
+
//#endregion
|
|
947
959
|
//#region src/root/functions/stringHelpers/truncate.d.ts
|
|
948
960
|
/**
|
|
949
961
|
* Truncates a string and appends `...` to the end of it
|
|
@@ -1135,4 +1147,4 @@ declare const normalizeIndents: typeof normaliseIndents;
|
|
|
1135
1147
|
*/
|
|
1136
1148
|
type RecordKey = string | number | symbol;
|
|
1137
1149
|
//#endregion
|
|
1138
|
-
export { APIError, type ArrayElement, type CallReturnType, 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, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, calculateMonthlyDifference, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze,
|
|
1150
|
+
export { APIError, type ArrayElement, type CallReturnType, 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, KebabToCamelOptions, type NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, type NullableOnCondition, ONE_DAY_IN_MILLISECONDS, type OptionalOnCondition, ParallelTuple, RecordKey, RemoveUndefined, type StringListToArrayOptions, ToTitleCaseOptions, UUID_PATTERN, UUID_REGEX, VERSION_NUMBER_PATTERN, VERSION_NUMBER_REGEX, VersionNumber, type FormatOptionsBase as VersionNumberToStringOptions, 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 };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import z$1, { z } from "zod";
|
|
2
|
-
import sodium from "libsodium-wrappers";
|
|
3
2
|
//#region src/root/constants/FILE_PATH_REGEX.ts
|
|
4
3
|
const FILE_PATH_PATTERN = String.raw`(?<directory>.+)[\/\\](?<base>[^\/\\]+)`;
|
|
5
4
|
const FILE_PATH_REGEX = RegExp(`^${FILE_PATH_PATTERN}$`);
|
|
@@ -1439,26 +1438,6 @@ function deepCopy(object) {
|
|
|
1439
1438
|
return clonedObject;
|
|
1440
1439
|
}
|
|
1441
1440
|
//#endregion
|
|
1442
|
-
//#region src/root/functions/security/encryptWithKey.ts
|
|
1443
|
-
/**
|
|
1444
|
-
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
1445
|
-
*
|
|
1446
|
-
* @param publicKey - The public base64 key to encrypt with.
|
|
1447
|
-
* @param plaintextValue - The value to encrypt in plaintext.
|
|
1448
|
-
*
|
|
1449
|
-
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
1450
|
-
*/
|
|
1451
|
-
async function encryptWithKey(publicKey, plaintextValue) {
|
|
1452
|
-
try {
|
|
1453
|
-
await sodium.ready;
|
|
1454
|
-
const base64Key = sodium.from_base64(publicKey, sodium.base64_variants.ORIGINAL);
|
|
1455
|
-
const encryptedValue = sodium.crypto_box_seal(plaintextValue, base64Key);
|
|
1456
|
-
return sodium.to_base64(encryptedValue, sodium.base64_variants.ORIGINAL);
|
|
1457
|
-
} catch {
|
|
1458
|
-
throw new DataError({ publicKey }, "ENCRYPTION_FAILED", "Encryption failed. Please double-check that the given key is a valid base 64 string.");
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
//#endregion
|
|
1462
1441
|
//#region src/root/functions/stringHelpers/appendSemicolon.ts
|
|
1463
1442
|
/**
|
|
1464
1443
|
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
@@ -1567,6 +1546,32 @@ function kebabToCamel(input, options) {
|
|
|
1567
1546
|
return outputString;
|
|
1568
1547
|
}
|
|
1569
1548
|
//#endregion
|
|
1549
|
+
//#region src/root/functions/stringHelpers/toTitleCase.ts
|
|
1550
|
+
/**
|
|
1551
|
+
* Converts a string to a human-readable Title Case string.
|
|
1552
|
+
*
|
|
1553
|
+
* Words are split on spaces, underscores, and hyphens. Every first letter of each word is capitalised except for words specified in `options.preserveWords`.
|
|
1554
|
+
*
|
|
1555
|
+
* The comparison for preserved words is case-insensitive, but the original casing provided in `preserveWords` is retained in the output.
|
|
1556
|
+
*
|
|
1557
|
+
* @param input - The string to convert.
|
|
1558
|
+
* @param options - Additional options to apply.
|
|
1559
|
+
*
|
|
1560
|
+
* @returns A new string, converted into Title Case.
|
|
1561
|
+
*/
|
|
1562
|
+
function toTitleCase(input, options) {
|
|
1563
|
+
const preservedWords = removeDuplicates(options?.preserveWords?.map((word) => {
|
|
1564
|
+
return {
|
|
1565
|
+
normalised: word.toLowerCase(),
|
|
1566
|
+
original: word
|
|
1567
|
+
};
|
|
1568
|
+
}) ?? []);
|
|
1569
|
+
return input.split(/[_\s-]+/).filter(Boolean).map((word) => {
|
|
1570
|
+
for (const preservedWord of preservedWords) if (preservedWord.normalised === word.toLowerCase()) return preservedWord.original;
|
|
1571
|
+
return word[0].toUpperCase() + word.slice(1).toLowerCase();
|
|
1572
|
+
}).join(" ");
|
|
1573
|
+
}
|
|
1574
|
+
//#endregion
|
|
1570
1575
|
//#region src/root/functions/stringHelpers/truncate.ts
|
|
1571
1576
|
/**
|
|
1572
1577
|
* Truncates a string and appends `...` to the end of it
|
|
@@ -1582,4 +1587,4 @@ function truncate(stringToTruncate, maxLength = 5) {
|
|
|
1582
1587
|
return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
|
|
1583
1588
|
}
|
|
1584
1589
|
//#endregion
|
|
1585
|
-
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,
|
|
1590
|
+
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 };
|
package/dist/internal/index.cjs
CHANGED
|
@@ -23,7 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
//#endregion
|
|
24
24
|
let zod = require("zod");
|
|
25
25
|
zod = __toESM(zod);
|
|
26
|
-
require("libsodium-wrappers");
|
|
27
26
|
let execa = require("execa");
|
|
28
27
|
let node_fs_promises = require("node:fs/promises");
|
|
29
28
|
let node_path = require("node:path");
|
package/dist/internal/index.js
CHANGED
package/dist/node/index.cjs
CHANGED
|
@@ -25,7 +25,8 @@ let node_path = require("node:path");
|
|
|
25
25
|
node_path = __toESM(node_path);
|
|
26
26
|
let zod = require("zod");
|
|
27
27
|
zod = __toESM(zod);
|
|
28
|
-
require("libsodium-wrappers");
|
|
28
|
+
let libsodium_wrappers = require("libsodium-wrappers");
|
|
29
|
+
libsodium_wrappers = __toESM(libsodium_wrappers);
|
|
29
30
|
//#region src/node/functions/normalizeImportPath.ts
|
|
30
31
|
/**
|
|
31
32
|
* Normalizes an import path meant for use in an import statement in JavaScript.
|
|
@@ -655,6 +656,27 @@ function parseFilePath(filePath) {
|
|
|
655
656
|
//#region src/node/functions/sayHello.ts
|
|
656
657
|
var sayHello_default = sayHello;
|
|
657
658
|
//#endregion
|
|
659
|
+
//#region src/node/functions/security/encryptWithKey.ts
|
|
660
|
+
/**
|
|
661
|
+
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
662
|
+
*
|
|
663
|
+
* @param publicKey - The public base64 key to encrypt with.
|
|
664
|
+
* @param plaintextValue - The value to encrypt in plaintext.
|
|
665
|
+
*
|
|
666
|
+
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
667
|
+
*/
|
|
668
|
+
async function encryptWithKey(publicKey, plaintextValue) {
|
|
669
|
+
try {
|
|
670
|
+
await libsodium_wrappers.default.ready;
|
|
671
|
+
const base64Key = libsodium_wrappers.default.from_base64(publicKey, libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
672
|
+
const encryptedValue = libsodium_wrappers.default.crypto_box_seal(plaintextValue, base64Key);
|
|
673
|
+
return libsodium_wrappers.default.to_base64(encryptedValue, libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
674
|
+
} catch {
|
|
675
|
+
throw new DataError({ publicKey }, "ENCRYPTION_FAILED", "Encryption failed. Please double-check that the given key is a valid base 64 string.");
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
//#endregion
|
|
679
|
+
exports.encryptWithKey = encryptWithKey;
|
|
658
680
|
exports.normaliseImportPath = normaliseImportPath;
|
|
659
681
|
exports.normalizeImportPath = normalizeImportPath;
|
|
660
682
|
exports.parseFilePath = parseFilePath;
|
package/dist/node/index.d.cts
CHANGED
|
@@ -65,4 +65,15 @@ declare function sayHello(): string;
|
|
|
65
65
|
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
66
66
|
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
67
67
|
//#endregion
|
|
68
|
-
|
|
68
|
+
//#region src/node/functions/security/encryptWithKey.d.ts
|
|
69
|
+
/**
|
|
70
|
+
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
71
|
+
*
|
|
72
|
+
* @param publicKey - The public base64 key to encrypt with.
|
|
73
|
+
* @param plaintextValue - The value to encrypt in plaintext.
|
|
74
|
+
*
|
|
75
|
+
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
76
|
+
*/
|
|
77
|
+
declare function encryptWithKey(publicKey: string, plaintextValue: string): Promise<string>;
|
|
78
|
+
//#endregion
|
|
79
|
+
export { type IsTypeArgumentString, encryptWithKey, normaliseImportPath, normalizeImportPath, parseFilePath, sayHello };
|
package/dist/node/index.d.ts
CHANGED
|
@@ -66,4 +66,15 @@ declare function sayHello(): string;
|
|
|
66
66
|
//#region src/root/types/IsTypeArgumentString.d.ts
|
|
67
67
|
type IsTypeArgumentString<Argument extends string> = Argument;
|
|
68
68
|
//#endregion
|
|
69
|
-
|
|
69
|
+
//#region src/node/functions/security/encryptWithKey.d.ts
|
|
70
|
+
/**
|
|
71
|
+
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
72
|
+
*
|
|
73
|
+
* @param publicKey - The public base64 key to encrypt with.
|
|
74
|
+
* @param plaintextValue - The value to encrypt in plaintext.
|
|
75
|
+
*
|
|
76
|
+
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
77
|
+
*/
|
|
78
|
+
declare function encryptWithKey(publicKey: string, plaintextValue: string): Promise<string>;
|
|
79
|
+
//#endregion
|
|
80
|
+
export { type IsTypeArgumentString, encryptWithKey, normaliseImportPath, normalizeImportPath, parseFilePath, sayHello };
|
package/dist/node/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import z from "zod";
|
|
3
|
-
import "libsodium-wrappers";
|
|
3
|
+
import sodium from "libsodium-wrappers";
|
|
4
4
|
//#region src/node/functions/normalizeImportPath.ts
|
|
5
5
|
/**
|
|
6
6
|
* Normalizes an import path meant for use in an import statement in JavaScript.
|
|
@@ -630,4 +630,24 @@ function parseFilePath(filePath) {
|
|
|
630
630
|
//#region src/node/functions/sayHello.ts
|
|
631
631
|
var sayHello_default = sayHello;
|
|
632
632
|
//#endregion
|
|
633
|
-
|
|
633
|
+
//#region src/node/functions/security/encryptWithKey.ts
|
|
634
|
+
/**
|
|
635
|
+
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
636
|
+
*
|
|
637
|
+
* @param publicKey - The public base64 key to encrypt with.
|
|
638
|
+
* @param plaintextValue - The value to encrypt in plaintext.
|
|
639
|
+
*
|
|
640
|
+
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
641
|
+
*/
|
|
642
|
+
async function encryptWithKey(publicKey, plaintextValue) {
|
|
643
|
+
try {
|
|
644
|
+
await sodium.ready;
|
|
645
|
+
const base64Key = sodium.from_base64(publicKey, sodium.base64_variants.ORIGINAL);
|
|
646
|
+
const encryptedValue = sodium.crypto_box_seal(plaintextValue, base64Key);
|
|
647
|
+
return sodium.to_base64(encryptedValue, sodium.base64_variants.ORIGINAL);
|
|
648
|
+
} catch {
|
|
649
|
+
throw new DataError({ publicKey }, "ENCRYPTION_FAILED", "Encryption failed. Please double-check that the given key is a valid base 64 string.");
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
//#endregion
|
|
653
|
+
export { encryptWithKey, normaliseImportPath, normalizeImportPath, parseFilePath, sayHello_default as sayHello };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.10.0",
|
|
4
4
|
"description": "Helpful utility functions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,54 +30,55 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"dotenv": "
|
|
34
|
-
"execa": "
|
|
35
|
-
"libsodium-wrappers": "
|
|
36
|
-
"zod": "
|
|
33
|
+
"dotenv": "17.4.0",
|
|
34
|
+
"execa": "9.6.1",
|
|
35
|
+
"libsodium-wrappers": "0.8.2",
|
|
36
|
+
"zod": "4.3.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@alextheman/eslint-plugin": "
|
|
40
|
-
"@types/node": "
|
|
41
|
-
"alex-c-line": "
|
|
42
|
-
"cross-env": "
|
|
43
|
-
"dotenv-cli": "
|
|
44
|
-
"eslint": "
|
|
45
|
-
"globals": "
|
|
46
|
-
"husky": "
|
|
47
|
-
"jsdom": "
|
|
48
|
-
"prettier": "
|
|
49
|
-
"tempy": "
|
|
50
|
-
"tsdown": "
|
|
51
|
-
"tsx": "
|
|
52
|
-
"typedoc": "
|
|
53
|
-
"typescript": "
|
|
54
|
-
"typescript-eslint": "
|
|
55
|
-
"vite-tsconfig-paths": "
|
|
56
|
-
"vitest": "
|
|
39
|
+
"@alextheman/eslint-plugin": "5.11.0",
|
|
40
|
+
"@types/node": "25.5.2",
|
|
41
|
+
"alex-c-line": "2.5.0",
|
|
42
|
+
"cross-env": "10.1.0",
|
|
43
|
+
"dotenv-cli": "11.0.0",
|
|
44
|
+
"eslint": "10.2.0",
|
|
45
|
+
"globals": "17.4.0",
|
|
46
|
+
"husky": "9.1.7",
|
|
47
|
+
"jsdom": "29.0.1",
|
|
48
|
+
"prettier": "3.8.1",
|
|
49
|
+
"tempy": "3.2.0",
|
|
50
|
+
"tsdown": "0.21.7",
|
|
51
|
+
"tsx": "4.21.0",
|
|
52
|
+
"typedoc": "0.28.18",
|
|
53
|
+
"typescript": "6.0.2",
|
|
54
|
+
"typescript-eslint": "8.58.0",
|
|
55
|
+
"vite-tsconfig-paths": "6.1.1",
|
|
56
|
+
"vitest": "4.1.2"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=22.3.0"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "tsdown",
|
|
63
|
+
"build-configs": "tsdown --config tsdown.configs.config.ts",
|
|
63
64
|
"create-feature-docs": "typedoc",
|
|
64
65
|
"create-local-package": "pnpm run build && rm -f alextheman-utility-*.tgz && pnpm pack",
|
|
65
66
|
"create-release-note": "bash -c 'git pull origin main && alex-c-line template release-note create $@' --",
|
|
66
67
|
"format": "pnpm run format-prettier && pnpm run format-eslint",
|
|
67
|
-
"format-eslint": "eslint --fix --suppress-all \"package.json\" \"src
|
|
68
|
+
"format-eslint": "eslint --fix --suppress-all \"package.json\" \"{src,tests,configs}/**/*.ts\" && rm -f eslint-suppressions.json",
|
|
68
69
|
"format-prettier": "pnpm run format-prettier-typescript && pnpm run format-prettier-javascript && pnpm run format-prettier-yml",
|
|
69
70
|
"format-prettier-javascript": "prettier --write \"./**/*.js\"",
|
|
70
71
|
"format-prettier-typescript": "prettier --write --parser typescript \"./**/*.ts\"",
|
|
71
72
|
"format-prettier-yml": "prettier --write \"./**/*.{yml,yaml}\"",
|
|
72
73
|
"lint": "pnpm run lint-tsc && pnpm run lint-eslint && pnpm run lint-prettier && pnpm run lint-pre-release",
|
|
73
|
-
"lint-eslint": "eslint \"package.json\" \"src
|
|
74
|
+
"lint-eslint": "eslint \"package.json\" \"{src,tests,configs}/**/*.ts\"",
|
|
74
75
|
"lint-pre-release": "alex-c-line package-json check --rules no-pre-release-dependencies",
|
|
75
76
|
"lint-prettier": "pnpm run lint-prettier-typescript && pnpm run lint-prettier-javascript && pnpm run lint-prettier-yml",
|
|
76
77
|
"lint-prettier-javascript": "prettier --check \"./**/*.js\"",
|
|
77
78
|
"lint-prettier-typescript": "prettier --check --parser typescript \"./**/*.ts\"",
|
|
78
79
|
"lint-prettier-yml": "prettier --check \"./**/*.{yml,yaml}\"",
|
|
79
80
|
"lint-tsc": "tsc --noEmit",
|
|
80
|
-
"pre-commit": "alex-c-line pre-commit",
|
|
81
|
+
"pre-commit": "pnpm run build-configs && alex-c-line pre-commit",
|
|
81
82
|
"prepare-live-eslint-plugin": "pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev @alextheman/eslint-plugin",
|
|
82
83
|
"prepare-local-eslint-plugin": "dotenv -e .env -- sh -c 'ESLINT_PLUGIN_PATH=${LOCAL_ESLINT_PLUGIN_PATH:-../eslint-plugin}; pnpm --prefix \"$ESLINT_PLUGIN_PATH\" run build && pnpm uninstall @alextheman/eslint-plugin && pnpm install --save-dev file:\"$ESLINT_PLUGIN_PATH\"'",
|
|
83
84
|
"test": "vitest run",
|