@alextheman/utility 5.7.1 → 5.9.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 +13 -23
- package/dist/index.d.cts +11 -12
- package/dist/index.d.ts +11 -12
- package/dist/index.js +13 -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 +7 -7
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.
|
|
@@ -1541,6 +1519,18 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
|
1541
1519
|
return result;
|
|
1542
1520
|
}
|
|
1543
1521
|
//#endregion
|
|
1522
|
+
//#region src/root/functions/stringHelpers/escapeRegexPattern.ts
|
|
1523
|
+
/**
|
|
1524
|
+
* A function to properly handle escape sequences in a Regex pattern string, so it can be safely used with the `RegExp` constructor.
|
|
1525
|
+
*
|
|
1526
|
+
* @param regexPattern - The Regex pattern to escape.
|
|
1527
|
+
*
|
|
1528
|
+
* @returns A new string with escape sequences properly handled.
|
|
1529
|
+
*/
|
|
1530
|
+
function escapeRegexPattern(regexPattern) {
|
|
1531
|
+
return regexPattern.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
1532
|
+
}
|
|
1533
|
+
//#endregion
|
|
1544
1534
|
//#region src/root/functions/stringHelpers/kebabToCamel.ts
|
|
1545
1535
|
/**
|
|
1546
1536
|
* Converts a string from kebab-case to camelCase
|
|
@@ -1616,7 +1606,7 @@ exports.createFormData = createFormData;
|
|
|
1616
1606
|
exports.createTemplateStringsArray = createTemplateStringsArray;
|
|
1617
1607
|
exports.deepCopy = deepCopy;
|
|
1618
1608
|
exports.deepFreeze = deepFreeze;
|
|
1619
|
-
exports.
|
|
1609
|
+
exports.escapeRegexPattern = escapeRegexPattern;
|
|
1620
1610
|
exports.fillArray = fillArray;
|
|
1621
1611
|
exports.formatDateAndTime = formatDateAndTime;
|
|
1622
1612
|
exports.getRandomNumber = getRandomNumber;
|
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.
|
|
@@ -912,6 +901,16 @@ interface CamelToKebabOptions {
|
|
|
912
901
|
*/
|
|
913
902
|
declare function camelToKebab(string: string, options?: CamelToKebabOptions): string;
|
|
914
903
|
//#endregion
|
|
904
|
+
//#region src/root/functions/stringHelpers/escapeRegexPattern.d.ts
|
|
905
|
+
/**
|
|
906
|
+
* A function to properly handle escape sequences in a Regex pattern string, so it can be safely used with the `RegExp` constructor.
|
|
907
|
+
*
|
|
908
|
+
* @param regexPattern - The Regex pattern to escape.
|
|
909
|
+
*
|
|
910
|
+
* @returns A new string with escape sequences properly handled.
|
|
911
|
+
*/
|
|
912
|
+
declare function escapeRegexPattern(regexPattern: string): string;
|
|
913
|
+
//#endregion
|
|
915
914
|
//#region src/root/functions/stringHelpers/kebabToCamel.d.ts
|
|
916
915
|
/**
|
|
917
916
|
* Options to apply to the conversion from kebab-case to camelCase
|
|
@@ -1125,4 +1124,4 @@ declare const normalizeIndents: typeof normaliseIndents;
|
|
|
1125
1124
|
*/
|
|
1126
1125
|
type RecordKey = string | number | symbol;
|
|
1127
1126
|
//#endregion
|
|
1128
|
-
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,
|
|
1127
|
+
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, 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, 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.
|
|
@@ -912,6 +901,16 @@ interface CamelToKebabOptions {
|
|
|
912
901
|
*/
|
|
913
902
|
declare function camelToKebab(string: string, options?: CamelToKebabOptions): string;
|
|
914
903
|
//#endregion
|
|
904
|
+
//#region src/root/functions/stringHelpers/escapeRegexPattern.d.ts
|
|
905
|
+
/**
|
|
906
|
+
* A function to properly handle escape sequences in a Regex pattern string, so it can be safely used with the `RegExp` constructor.
|
|
907
|
+
*
|
|
908
|
+
* @param regexPattern - The Regex pattern to escape.
|
|
909
|
+
*
|
|
910
|
+
* @returns A new string with escape sequences properly handled.
|
|
911
|
+
*/
|
|
912
|
+
declare function escapeRegexPattern(regexPattern: string): string;
|
|
913
|
+
//#endregion
|
|
915
914
|
//#region src/root/functions/stringHelpers/kebabToCamel.d.ts
|
|
916
915
|
/**
|
|
917
916
|
* Options to apply to the conversion from kebab-case to camelCase
|
|
@@ -1125,4 +1124,4 @@ declare const normalizeIndents: typeof normaliseIndents;
|
|
|
1125
1124
|
*/
|
|
1126
1125
|
type RecordKey = string | number | symbol;
|
|
1127
1126
|
//#endregion
|
|
1128
|
-
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,
|
|
1127
|
+
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, 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, 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.
|
|
@@ -1516,6 +1495,18 @@ function camelToKebab(string, options = { preserveConsecutiveCapitals: true }) {
|
|
|
1516
1495
|
return result;
|
|
1517
1496
|
}
|
|
1518
1497
|
//#endregion
|
|
1498
|
+
//#region src/root/functions/stringHelpers/escapeRegexPattern.ts
|
|
1499
|
+
/**
|
|
1500
|
+
* A function to properly handle escape sequences in a Regex pattern string, so it can be safely used with the `RegExp` constructor.
|
|
1501
|
+
*
|
|
1502
|
+
* @param regexPattern - The Regex pattern to escape.
|
|
1503
|
+
*
|
|
1504
|
+
* @returns A new string with escape sequences properly handled.
|
|
1505
|
+
*/
|
|
1506
|
+
function escapeRegexPattern(regexPattern) {
|
|
1507
|
+
return regexPattern.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
1508
|
+
}
|
|
1509
|
+
//#endregion
|
|
1519
1510
|
//#region src/root/functions/stringHelpers/kebabToCamel.ts
|
|
1520
1511
|
/**
|
|
1521
1512
|
* Converts a string from kebab-case to camelCase
|
|
@@ -1570,4 +1561,4 @@ function truncate(stringToTruncate, maxLength = 5) {
|
|
|
1570
1561
|
return stringToTruncate.length > maxLength ? `${stringToTruncate.slice(0, maxLength)}...` : stringToTruncate;
|
|
1571
1562
|
}
|
|
1572
1563
|
//#endregion
|
|
1573
|
-
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,
|
|
1564
|
+
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, 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.9.0",
|
|
4
4
|
"description": "Helpful utility functions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"zod": "^4.3.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@alextheman/eslint-plugin": "^5.10.
|
|
39
|
+
"@alextheman/eslint-plugin": "^5.10.4",
|
|
40
40
|
"@types/node": "^25.5.0",
|
|
41
41
|
"alex-c-line": "^2.4.0",
|
|
42
42
|
"cross-env": "^10.1.0",
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
"jsdom": "^29.0.1",
|
|
48
48
|
"prettier": "^3.8.1",
|
|
49
49
|
"tempy": "^3.2.0",
|
|
50
|
-
"tsdown": "^0.21.
|
|
50
|
+
"tsdown": "^0.21.7",
|
|
51
51
|
"tsx": "^4.21.0",
|
|
52
52
|
"typedoc": "^0.28.18",
|
|
53
|
-
"typescript": "^
|
|
54
|
-
"typescript-eslint": "^8.
|
|
53
|
+
"typescript": "^6.0.2",
|
|
54
|
+
"typescript-eslint": "^8.58.0",
|
|
55
55
|
"vite-tsconfig-paths": "^6.1.1",
|
|
56
56
|
"vitest": "^4.1.2"
|
|
57
57
|
},
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"create-local-package": "pnpm run build && rm -f alextheman-utility-*.tgz && pnpm pack",
|
|
65
65
|
"create-release-note": "bash -c 'git pull origin main && alex-c-line template release-note create $@' --",
|
|
66
66
|
"format": "pnpm run format-prettier && pnpm run format-eslint",
|
|
67
|
-
"format-eslint": "eslint --fix --suppress-all \"package.json\" \"src
|
|
67
|
+
"format-eslint": "eslint --fix --suppress-all \"package.json\" \"{src,tests,configs}/**/*.ts\" && rm -f eslint-suppressions.json",
|
|
68
68
|
"format-prettier": "pnpm run format-prettier-typescript && pnpm run format-prettier-javascript && pnpm run format-prettier-yml",
|
|
69
69
|
"format-prettier-javascript": "prettier --write \"./**/*.js\"",
|
|
70
70
|
"format-prettier-typescript": "prettier --write --parser typescript \"./**/*.ts\"",
|
|
71
71
|
"format-prettier-yml": "prettier --write \"./**/*.{yml,yaml}\"",
|
|
72
72
|
"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
|
|
73
|
+
"lint-eslint": "eslint \"package.json\" \"{src,tests,configs}/**/*.ts\"",
|
|
74
74
|
"lint-pre-release": "alex-c-line package-json check --rules no-pre-release-dependencies",
|
|
75
75
|
"lint-prettier": "pnpm run lint-prettier-typescript && pnpm run lint-prettier-javascript && pnpm run lint-prettier-yml",
|
|
76
76
|
"lint-prettier-javascript": "prettier --check \"./**/*.js\"",
|