@alextheman/utility 4.4.2 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +24 -1
- package/package.json +7 -4
package/dist/index.cjs
CHANGED
|
@@ -27,6 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
//#endregion
|
|
28
28
|
let zod = require("zod");
|
|
29
29
|
zod = __toESM(zod);
|
|
30
|
+
let libsodium_wrappers = require("libsodium-wrappers");
|
|
31
|
+
libsodium_wrappers = __toESM(libsodium_wrappers);
|
|
30
32
|
let node_path = require("node:path");
|
|
31
33
|
node_path = __toESM(node_path);
|
|
32
34
|
|
|
@@ -978,6 +980,28 @@ function deepFreeze(object) {
|
|
|
978
980
|
}
|
|
979
981
|
var deepFreeze_default = deepFreeze;
|
|
980
982
|
|
|
983
|
+
//#endregion
|
|
984
|
+
//#region src/functions/security/encryptWithKey.ts
|
|
985
|
+
/**
|
|
986
|
+
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
987
|
+
*
|
|
988
|
+
* @param publicKey - The public base64 key to encrypt with.
|
|
989
|
+
* @param plaintextValue - The value to encrypt in plaintext.
|
|
990
|
+
*
|
|
991
|
+
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
992
|
+
*/
|
|
993
|
+
async function encryptWithKey(publicKey, plaintextValue) {
|
|
994
|
+
try {
|
|
995
|
+
await libsodium_wrappers.default.ready;
|
|
996
|
+
const base64Key = libsodium_wrappers.default.from_base64(publicKey, libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
997
|
+
const encryptedValue = libsodium_wrappers.default.crypto_box_seal(plaintextValue, base64Key);
|
|
998
|
+
return libsodium_wrappers.default.to_base64(encryptedValue, libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
999
|
+
} catch {
|
|
1000
|
+
throw new DataError_default({ publicKey }, "ENCRYPTION_FAILED", "Encryption failed. Please double-check that the given key is a valid base 64 string.");
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
var encryptWithKey_default = encryptWithKey;
|
|
1004
|
+
|
|
981
1005
|
//#endregion
|
|
982
1006
|
//#region src/functions/stringHelpers/appendSemicolon.ts
|
|
983
1007
|
/**
|
|
@@ -1426,6 +1450,7 @@ exports.createTemplateStringsArray = createTemplateStringsArray_default;
|
|
|
1426
1450
|
exports.deepCopy = deepCopy_default;
|
|
1427
1451
|
exports.deepFreeze = deepFreeze_default;
|
|
1428
1452
|
exports.determineVersionType = determineVersionType_default;
|
|
1453
|
+
exports.encryptWithKey = encryptWithKey_default;
|
|
1429
1454
|
exports.fillArray = fillArray_default;
|
|
1430
1455
|
exports.formatDateAndTime = formatDateAndTime_default;
|
|
1431
1456
|
exports.getIndividualVersionNumbers = getIndividualVersionNumbers_default;
|
package/dist/index.d.cts
CHANGED
|
@@ -713,6 +713,17 @@ declare function deepCopy<ObjectType extends object>(object: ObjectType): Object
|
|
|
713
713
|
*/
|
|
714
714
|
declare function deepFreeze<ObjectType extends object>(object: ObjectType): Readonly<ObjectType>;
|
|
715
715
|
//#endregion
|
|
716
|
+
//#region src/functions/security/encryptWithKey.d.ts
|
|
717
|
+
/**
|
|
718
|
+
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
719
|
+
*
|
|
720
|
+
* @param publicKey - The public base64 key to encrypt with.
|
|
721
|
+
* @param plaintextValue - The value to encrypt in plaintext.
|
|
722
|
+
*
|
|
723
|
+
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
724
|
+
*/
|
|
725
|
+
declare function encryptWithKey(publicKey: string, plaintextValue: string): Promise<string>;
|
|
726
|
+
//#endregion
|
|
716
727
|
//#region src/functions/stringHelpers/appendSemicolon.d.ts
|
|
717
728
|
/**
|
|
718
729
|
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
@@ -1025,4 +1036,4 @@ interface ParseVersionOptions {
|
|
|
1025
1036
|
*/
|
|
1026
1037
|
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
1027
1038
|
//#endregion
|
|
1028
|
-
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
|
1039
|
+
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -713,6 +713,17 @@ declare function deepCopy<ObjectType extends object>(object: ObjectType): Object
|
|
|
713
713
|
*/
|
|
714
714
|
declare function deepFreeze<ObjectType extends object>(object: ObjectType): Readonly<ObjectType>;
|
|
715
715
|
//#endregion
|
|
716
|
+
//#region src/functions/security/encryptWithKey.d.ts
|
|
717
|
+
/**
|
|
718
|
+
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
719
|
+
*
|
|
720
|
+
* @param publicKey - The public base64 key to encrypt with.
|
|
721
|
+
* @param plaintextValue - The value to encrypt in plaintext.
|
|
722
|
+
*
|
|
723
|
+
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
724
|
+
*/
|
|
725
|
+
declare function encryptWithKey(publicKey: string, plaintextValue: string): Promise<string>;
|
|
726
|
+
//#endregion
|
|
716
727
|
//#region src/functions/stringHelpers/appendSemicolon.d.ts
|
|
717
728
|
/**
|
|
718
729
|
* Appends a semicolon to the end of a string, trimming where necessary first.
|
|
@@ -1025,4 +1036,4 @@ interface ParseVersionOptions {
|
|
|
1025
1036
|
*/
|
|
1026
1037
|
declare function parseVersion(input: string, options?: ParseVersionOptions): string;
|
|
1027
1038
|
//#endregion
|
|
1028
|
-
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, type ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
|
1039
|
+
export { APIError, ArrayElement, CamelToKebabOptions, CreateEnumType, CreateFormDataOptions, CreateFormDataOptionsNullableResolution, CreateFormDataOptionsUndefinedOrNullResolution, DataError, DisallowUndefined, Env, FormDataArrayResolutionStrategy, FormDataNullableResolutionStrategy, HTTPErrorCode, IgnoreCase, type IncrementVersionOptions, KebabToCamelOptions, NAMESPACE_EXPORT_REGEX, NonUndefined, NormaliseIndentsFunction, NormaliseIndentsOptions, NormalizeIndentsFunction, NormalizeIndentsOptions, OptionalOnCondition, ParallelTuple, type ParseVersionOptions, RecordKey, StringListToArrayOptions, VERSION_NUMBER_REGEX, VersionNumber, VersionNumberToStringOptions, VersionType, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, createFormData, createTemplateStringsArray, deepCopy, deepFreeze, determineVersionType, encryptWithKey, fillArray, formatDateAndTime, getIndividualVersionNumbers, getInterpolations, getRandomNumber, getRecordKeys, httpErrorCodeLookup, incrementVersion, interpolate, interpolateObjects, isAnniversary, isLeapYear, isMonthlyMultiple, isOrdered, isSameDate, kebabToCamel, normaliseImportPath, normaliseIndents, normalizeImportPath, normalizeIndents, omitProperties, paralleliseArrays, parseBoolean, parseEnv, parseFormData, parseIntStrict, parseVersion, parseVersionType, parseZodSchema, randomiseArray, range, removeDuplicates, stringListToArray, truncate, wait };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import z, { z as z$1 } from "zod";
|
|
2
|
+
import sodium from "libsodium-wrappers";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
|
|
4
5
|
//#region src/constants/NAMESPACE_EXPORT_REGEX.ts
|
|
@@ -949,6 +950,28 @@ function deepFreeze(object) {
|
|
|
949
950
|
}
|
|
950
951
|
var deepFreeze_default = deepFreeze;
|
|
951
952
|
|
|
953
|
+
//#endregion
|
|
954
|
+
//#region src/functions/security/encryptWithKey.ts
|
|
955
|
+
/**
|
|
956
|
+
* Encrypt a secret given the public base64 key and the thing you want to encrypt.
|
|
957
|
+
*
|
|
958
|
+
* @param publicKey - The public base64 key to encrypt with.
|
|
959
|
+
* @param plaintextValue - The value to encrypt in plaintext.
|
|
960
|
+
*
|
|
961
|
+
* @returns The encrypted string. This value will be different on repeat calls, but the result should always decrypt to the initial `plaintextValue` argument.
|
|
962
|
+
*/
|
|
963
|
+
async function encryptWithKey(publicKey, plaintextValue) {
|
|
964
|
+
try {
|
|
965
|
+
await sodium.ready;
|
|
966
|
+
const base64Key = sodium.from_base64(publicKey, sodium.base64_variants.ORIGINAL);
|
|
967
|
+
const encryptedValue = sodium.crypto_box_seal(plaintextValue, base64Key);
|
|
968
|
+
return sodium.to_base64(encryptedValue, sodium.base64_variants.ORIGINAL);
|
|
969
|
+
} catch {
|
|
970
|
+
throw new DataError_default({ publicKey }, "ENCRYPTION_FAILED", "Encryption failed. Please double-check that the given key is a valid base 64 string.");
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
var encryptWithKey_default = encryptWithKey;
|
|
974
|
+
|
|
952
975
|
//#endregion
|
|
953
976
|
//#region src/functions/stringHelpers/appendSemicolon.ts
|
|
954
977
|
/**
|
|
@@ -1381,4 +1404,4 @@ function incrementVersion(version, incrementType, options) {
|
|
|
1381
1404
|
var incrementVersion_default = incrementVersion;
|
|
1382
1405
|
|
|
1383
1406
|
//#endregion
|
|
1384
|
-
export { APIError_default as APIError, DataError_default as DataError, Env, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, VersionNumber_default as VersionNumber, VersionType, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getInterpolations_default as getInterpolations, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, stringListToArray_default as stringListToArray, truncate_default as truncate, wait_default as wait };
|
|
1407
|
+
export { APIError_default as APIError, DataError_default as DataError, Env, NAMESPACE_EXPORT_REGEX_default as NAMESPACE_EXPORT_REGEX, VERSION_NUMBER_REGEX_default as VERSION_NUMBER_REGEX, VersionNumber_default as VersionNumber, VersionType, addDaysToDate_default as addDaysToDate, appendSemicolon_default as appendSemicolon, camelToKebab_default as camelToKebab, convertFileToBase64_default as convertFileToBase64, createFormData_default as createFormData, createTemplateStringsArray_default as createTemplateStringsArray, deepCopy_default as deepCopy, deepFreeze_default as deepFreeze, determineVersionType_default as determineVersionType, encryptWithKey_default as encryptWithKey, fillArray_default as fillArray, formatDateAndTime_default as formatDateAndTime, getIndividualVersionNumbers_default as getIndividualVersionNumbers, getInterpolations_default as getInterpolations, getRandomNumber_default as getRandomNumber, getRecordKeys_default as getRecordKeys, httpErrorCodeLookup, incrementVersion_default as incrementVersion, interpolate_default as interpolate, interpolateObjects_default as interpolateObjects, isAnniversary_default as isAnniversary, isLeapYear_default as isLeapYear, isMonthlyMultiple_default as isMonthlyMultiple, isOrdered_default as isOrdered, isSameDate_default as isSameDate, kebabToCamel_default as kebabToCamel, normaliseImportPath, normaliseIndents_default as normaliseIndents, normalizeImportPath_default as normalizeImportPath, normalizeIndents, omitProperties_default as omitProperties, paralleliseArrays_default as paralleliseArrays, parseBoolean_default as parseBoolean, parseEnv_default as parseEnv, parseFormData_default as parseFormData, parseIntStrict_default as parseIntStrict, parseVersion_default as parseVersion, parseVersionType_default as parseVersionType, parseZodSchema_default as parseZodSchema, randomiseArray_default as randomiseArray, range_default as range, removeDuplicates_default as removeDuplicates, stringListToArray_default as stringListToArray, truncate_default as truncate, wait_default as wait };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"description": "Helpful utility functions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"libsodium-wrappers": "^0.8.0",
|
|
19
20
|
"zod": "^4.3.5"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@alextheman/eslint-plugin": "^5.4.2",
|
|
23
|
-
"@types/
|
|
24
|
-
"
|
|
24
|
+
"@types/libsodium-wrappers": "^0.7.14",
|
|
25
|
+
"@types/node": "^25.0.5",
|
|
26
|
+
"@typescript-eslint/types": "^8.52.0",
|
|
27
|
+
"alex-c-line": "^1.17.0",
|
|
25
28
|
"dotenv-cli": "^11.0.0",
|
|
26
29
|
"eslint": "^9.39.2",
|
|
27
30
|
"globals": "^17.0.0",
|
|
@@ -31,7 +34,7 @@
|
|
|
31
34
|
"tsdown": "^0.18.4",
|
|
32
35
|
"typedoc": "^0.28.15",
|
|
33
36
|
"typescript": "^5.9.3",
|
|
34
|
-
"vite-tsconfig-paths": "^6.0.
|
|
37
|
+
"vite-tsconfig-paths": "^6.0.4",
|
|
35
38
|
"vitest": "^4.0.16"
|
|
36
39
|
},
|
|
37
40
|
"engines": {
|