@salespark/toolkit 2.1.16 → 2.1.18
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/README.md +67 -7
- package/dist/index.cjs +241 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -31
- package/dist/index.d.ts +79 -31
- package/dist/index.js +237 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -538,6 +538,14 @@ declare const isNilText: (value: unknown) => boolean;
|
|
|
538
538
|
* 18-10-2025: Trim before checking empty
|
|
539
539
|
****************************************************/
|
|
540
540
|
declare const isNilOrEmpty: (value: unknown) => boolean;
|
|
541
|
+
/******************************************************
|
|
542
|
+
* ##: Nil, Empty String, or Empty Object Check
|
|
543
|
+
* Checks if value is nil, an empty string, or an empty plain object (no own keys).
|
|
544
|
+
* @param {unknown} value - Value to check
|
|
545
|
+
* History:
|
|
546
|
+
* 06-02-2026: Created
|
|
547
|
+
****************************************************/
|
|
548
|
+
declare const isNilEmptyOrEmptyObject: (value: unknown) => boolean;
|
|
541
549
|
/******************************************************
|
|
542
550
|
* ##: Array Nil or Empty Element Check
|
|
543
551
|
* Checks if any element in array is nil or empty (""). Returns true if input is not an array.
|
|
@@ -854,36 +862,6 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
|
|
|
854
862
|
* Lightweight XOR scrambling for strings and JSON-serializable objects.
|
|
855
863
|
* Notes: This is reversible obfuscation and NOT cryptographic security.
|
|
856
864
|
******************************************************************/
|
|
857
|
-
/******************************************************************
|
|
858
|
-
* ##: Scramble a string by XOR-ing each character with a repeating secret key
|
|
859
|
-
* Applies an XOR operation between each character code and a repeating key character code.
|
|
860
|
-
* The XOR result is then Base64-encoded for transport as a printable string.
|
|
861
|
-
*
|
|
862
|
-
* TL;DR: Obfuscate a string by XOR-ing it with a repeating secret and Base64-encoding the result.
|
|
863
|
-
* Use only for reversible scrambling, not cryptographic protection.
|
|
864
|
-
* @param {string} value - Plain string to scramble (typically a Base64-encoded JSON payload).
|
|
865
|
-
* @param {string} secret - Secret key used as the repeating XOR mask.
|
|
866
|
-
* @returns {SalesParkContract<any>} - Return a SalesPark Contract object
|
|
867
|
-
* History:
|
|
868
|
-
* 28-01-2026: Created
|
|
869
|
-
* 04-02-2026: Refactored + return SalesPark Contract object
|
|
870
|
-
******************************************************************/
|
|
871
|
-
declare const scrambleString: (value: string, secret: string) => SalesParkContract<any>;
|
|
872
|
-
/******************************************************************
|
|
873
|
-
* ##: Descramble a Base64 string by reversing XOR with a repeating secret key
|
|
874
|
-
* Base64-decodes the scrambled input to a binary string, then XORs each character with the key.
|
|
875
|
-
* This reverses the scramble operation as long as the same secret key is used.
|
|
876
|
-
*
|
|
877
|
-
* TL;DR: Reverse the XOR-based scrambling using the same secret key.
|
|
878
|
-
* It Base64-decodes, then XORs again to recover the original string.
|
|
879
|
-
* @param {string} value - Base64-encoded scrambled input produced by the scrambler.
|
|
880
|
-
* @param {string} secret - Secret key used as the repeating XOR mask (must match the encoding key).
|
|
881
|
-
* @returns {SalesParkContract<any>} - Return a SalesPark Contract object
|
|
882
|
-
* History:
|
|
883
|
-
* 28-01-2026: Created
|
|
884
|
-
* 04-02-2026: Refactored + return SalesPark Contract object
|
|
885
|
-
******************************************************************/
|
|
886
|
-
declare const descrambleString: (value: string, secret: string) => SalesParkContract<any>;
|
|
887
865
|
/******************************************************************
|
|
888
866
|
* ##: Encode object into scrambled Base64 string using a secret key
|
|
889
867
|
* Serializes an input object to JSON, Base64-encodes it, and scrambles the result using a secret key.
|
|
@@ -900,6 +878,19 @@ declare const descrambleString: (value: string, secret: string) => SalesParkCont
|
|
|
900
878
|
* 04-02-2026: Refactored + return SalesPark Contract object
|
|
901
879
|
******************************************************************/
|
|
902
880
|
declare const encodeObject: (input: object, secret: string) => SalesParkContract<any>;
|
|
881
|
+
/******************************************************************
|
|
882
|
+
* ##: Encode string into scrambled Base64 string using a secret key
|
|
883
|
+
* Base64-encodes an input string and scrambles it using a secret key.
|
|
884
|
+
* This is intended for lightweight obfuscation, not for cryptographic security.
|
|
885
|
+
*
|
|
886
|
+
* TL;DR: Turn a string into a scrambled Base64 payload using a secret key.
|
|
887
|
+
* @param {string} input - Plain string to encode.
|
|
888
|
+
* @param {string} secret - Secret key used to scramble the Base64 payload.
|
|
889
|
+
* @returns {SalesParkContract<any>} - Return a SalesPark Contract object
|
|
890
|
+
* History:
|
|
891
|
+
* 06-02-2026: Created
|
|
892
|
+
******************************************************************/
|
|
893
|
+
declare const encodeString: (input: string, secret: string) => SalesParkContract<any>;
|
|
903
894
|
/******************************************************************
|
|
904
895
|
* ##: Decode scrambled string back into an object using a secret key
|
|
905
896
|
* Descrambles an encoded string with the provided secret, Base64-decodes it, and parses it as JSON.
|
|
@@ -915,6 +906,19 @@ declare const encodeObject: (input: object, secret: string) => SalesParkContract
|
|
|
915
906
|
* 04-02-2026: Refactored + return SalesPark Contract object
|
|
916
907
|
******************************************************************/
|
|
917
908
|
declare const decodeObject: (encoded: string, secret: string) => SalesParkContract<any>;
|
|
909
|
+
/******************************************************************
|
|
910
|
+
* ##: Decode scrambled Base64 string back into a string using a secret key
|
|
911
|
+
* Descrambles the encoded input with the provided secret and Base64-decodes it.
|
|
912
|
+
* This reverses the encode flow and returns the original string if inputs are valid.
|
|
913
|
+
*
|
|
914
|
+
* TL;DR: Convert a scrambled string back into the original string using the same key.
|
|
915
|
+
* @param {string} encoded - Scrambled Base64 string produced by the encoder/scrambler.
|
|
916
|
+
* @param {string} secret - Secret key used to descramble the payload.
|
|
917
|
+
* @returns {SalesParkContract<any>} - Return a SalesPark Contract object
|
|
918
|
+
* History:
|
|
919
|
+
* 06-02-2026: Created
|
|
920
|
+
******************************************************************/
|
|
921
|
+
declare const decodeString: (encoded: string, secret: string) => SalesParkContract<any>;
|
|
918
922
|
|
|
919
923
|
type DeferFn = () => void | Promise<void>;
|
|
920
924
|
/******************************************************************
|
|
@@ -977,8 +981,52 @@ declare const deferAfterResponse: (res: HttpResponseLike, fn: DeferFn) => void;
|
|
|
977
981
|
******************************************************************/
|
|
978
982
|
declare const deferAfterResponseNonCritical: (res: HttpResponseLike, fn: DeferFn) => void;
|
|
979
983
|
|
|
984
|
+
/******************************************************
|
|
985
|
+
* ##: Reversible Base36 Code Encoder/Decoder (No Deps)
|
|
986
|
+
* Encodes a base36 identifier into a lower-case base36 code using a secret key.
|
|
987
|
+
* Decodes back with the same secret and configuration.
|
|
988
|
+
* History:
|
|
989
|
+
* 16-02-2026: Created
|
|
990
|
+
****************************************************/
|
|
991
|
+
type EncodeDecodeConfig = {
|
|
992
|
+
secret: string;
|
|
993
|
+
bitSize?: number;
|
|
994
|
+
rotateBits?: number;
|
|
995
|
+
addConstant?: string;
|
|
996
|
+
};
|
|
997
|
+
/******************************************************************
|
|
998
|
+
* ##: Encode Base36 Identifier
|
|
999
|
+
* Obfuscates a base36 identifier into a reversible lowercase base36 code using XOR mixing, constant addition, and rotation.
|
|
1000
|
+
*
|
|
1001
|
+
* TL;DR: Encodes a base36 identifier into a reversible base36 code.
|
|
1002
|
+
* Uses a secret-derived key and fixed-width math to keep outputs bounded and reversible.
|
|
1003
|
+
* @param {string} identifier - Source identifier in base36 format
|
|
1004
|
+
* @param {EncodeDecodeConfig} config - Encoding configuration including secret and optional parameters
|
|
1005
|
+
* @returns {SalesParkContract<{ code: string }>} - Return a SalesPark Contract object.
|
|
1006
|
+
* History:
|
|
1007
|
+
* 16-02-2026: Created
|
|
1008
|
+
******************************************************************/
|
|
1009
|
+
declare const encodeBase36Code: (identifier: string, config: EncodeDecodeConfig) => SalesParkContract<{
|
|
1010
|
+
code: string;
|
|
1011
|
+
}>;
|
|
1012
|
+
/******************************************************************
|
|
1013
|
+
* ##: Decode Base36 Code
|
|
1014
|
+
* Reverses the obfuscation steps to restore the original identifier using the same secret and configuration parameters.
|
|
1015
|
+
*
|
|
1016
|
+
* TL;DR: Decodes a base36 code back into the original identifier.
|
|
1017
|
+
* Requires the same secret and config to reliably reverse XOR, add, and rotation.
|
|
1018
|
+
* @param {string} code - Encoded base36 code to decode
|
|
1019
|
+
* @param {EncodeDecodeConfig} config - Decoding configuration including secret and optional parameters
|
|
1020
|
+
* @returns {SalesParkContract<{ identifier: string }>} - Return a SalesPark Contract object.
|
|
1021
|
+
* History:
|
|
1022
|
+
* 16-02-2026: Created
|
|
1023
|
+
******************************************************************/
|
|
1024
|
+
declare const decodeBase36Code: (code: string, config: EncodeDecodeConfig) => SalesParkContract<{
|
|
1025
|
+
identifier: string;
|
|
1026
|
+
}>;
|
|
1027
|
+
|
|
980
1028
|
/** Environment helpers (runtime-agnostic checks) */
|
|
981
1029
|
declare const isBrowser: boolean;
|
|
982
1030
|
declare const isNode: boolean;
|
|
983
1031
|
|
|
984
|
-
export { type CapitalizeFirstOptions, type CapitalizeWordsOptions, type DeferFn, type FormatCurrencyProOptions, type HttpResponseLike, type SecurityCheckResult, type SecurityRisk, type SentenceCaseOptions, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, capitalizeFirst, capitalizeWords, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, decodeObject, deferAfterResponse, deferAfterResponseNonCritical, deferNonCritical, deferPostReturn, delay,
|
|
1032
|
+
export { type CapitalizeFirstOptions, type CapitalizeWordsOptions, type DeferFn, type EncodeDecodeConfig, type FormatCurrencyProOptions, type HttpResponseLike, type SecurityCheckResult, type SecurityRisk, type SentenceCaseOptions, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, capitalizeFirst, capitalizeWords, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, decodeBase36Code, decodeObject, decodeString, deferAfterResponse, deferAfterResponseNonCritical, deferNonCritical, deferPostReturn, delay, difference, encodeBase36Code, encodeObject, encodeString, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatCurrencyPro, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrEmptyObject, isNilEmptyOrZeroLen, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeJSONParse, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, sentenceCase, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
package/dist/index.d.ts
CHANGED
|
@@ -538,6 +538,14 @@ declare const isNilText: (value: unknown) => boolean;
|
|
|
538
538
|
* 18-10-2025: Trim before checking empty
|
|
539
539
|
****************************************************/
|
|
540
540
|
declare const isNilOrEmpty: (value: unknown) => boolean;
|
|
541
|
+
/******************************************************
|
|
542
|
+
* ##: Nil, Empty String, or Empty Object Check
|
|
543
|
+
* Checks if value is nil, an empty string, or an empty plain object (no own keys).
|
|
544
|
+
* @param {unknown} value - Value to check
|
|
545
|
+
* History:
|
|
546
|
+
* 06-02-2026: Created
|
|
547
|
+
****************************************************/
|
|
548
|
+
declare const isNilEmptyOrEmptyObject: (value: unknown) => boolean;
|
|
541
549
|
/******************************************************
|
|
542
550
|
* ##: Array Nil or Empty Element Check
|
|
543
551
|
* Checks if any element in array is nil or empty (""). Returns true if input is not an array.
|
|
@@ -854,36 +862,6 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
|
|
|
854
862
|
* Lightweight XOR scrambling for strings and JSON-serializable objects.
|
|
855
863
|
* Notes: This is reversible obfuscation and NOT cryptographic security.
|
|
856
864
|
******************************************************************/
|
|
857
|
-
/******************************************************************
|
|
858
|
-
* ##: Scramble a string by XOR-ing each character with a repeating secret key
|
|
859
|
-
* Applies an XOR operation between each character code and a repeating key character code.
|
|
860
|
-
* The XOR result is then Base64-encoded for transport as a printable string.
|
|
861
|
-
*
|
|
862
|
-
* TL;DR: Obfuscate a string by XOR-ing it with a repeating secret and Base64-encoding the result.
|
|
863
|
-
* Use only for reversible scrambling, not cryptographic protection.
|
|
864
|
-
* @param {string} value - Plain string to scramble (typically a Base64-encoded JSON payload).
|
|
865
|
-
* @param {string} secret - Secret key used as the repeating XOR mask.
|
|
866
|
-
* @returns {SalesParkContract<any>} - Return a SalesPark Contract object
|
|
867
|
-
* History:
|
|
868
|
-
* 28-01-2026: Created
|
|
869
|
-
* 04-02-2026: Refactored + return SalesPark Contract object
|
|
870
|
-
******************************************************************/
|
|
871
|
-
declare const scrambleString: (value: string, secret: string) => SalesParkContract<any>;
|
|
872
|
-
/******************************************************************
|
|
873
|
-
* ##: Descramble a Base64 string by reversing XOR with a repeating secret key
|
|
874
|
-
* Base64-decodes the scrambled input to a binary string, then XORs each character with the key.
|
|
875
|
-
* This reverses the scramble operation as long as the same secret key is used.
|
|
876
|
-
*
|
|
877
|
-
* TL;DR: Reverse the XOR-based scrambling using the same secret key.
|
|
878
|
-
* It Base64-decodes, then XORs again to recover the original string.
|
|
879
|
-
* @param {string} value - Base64-encoded scrambled input produced by the scrambler.
|
|
880
|
-
* @param {string} secret - Secret key used as the repeating XOR mask (must match the encoding key).
|
|
881
|
-
* @returns {SalesParkContract<any>} - Return a SalesPark Contract object
|
|
882
|
-
* History:
|
|
883
|
-
* 28-01-2026: Created
|
|
884
|
-
* 04-02-2026: Refactored + return SalesPark Contract object
|
|
885
|
-
******************************************************************/
|
|
886
|
-
declare const descrambleString: (value: string, secret: string) => SalesParkContract<any>;
|
|
887
865
|
/******************************************************************
|
|
888
866
|
* ##: Encode object into scrambled Base64 string using a secret key
|
|
889
867
|
* Serializes an input object to JSON, Base64-encodes it, and scrambles the result using a secret key.
|
|
@@ -900,6 +878,19 @@ declare const descrambleString: (value: string, secret: string) => SalesParkCont
|
|
|
900
878
|
* 04-02-2026: Refactored + return SalesPark Contract object
|
|
901
879
|
******************************************************************/
|
|
902
880
|
declare const encodeObject: (input: object, secret: string) => SalesParkContract<any>;
|
|
881
|
+
/******************************************************************
|
|
882
|
+
* ##: Encode string into scrambled Base64 string using a secret key
|
|
883
|
+
* Base64-encodes an input string and scrambles it using a secret key.
|
|
884
|
+
* This is intended for lightweight obfuscation, not for cryptographic security.
|
|
885
|
+
*
|
|
886
|
+
* TL;DR: Turn a string into a scrambled Base64 payload using a secret key.
|
|
887
|
+
* @param {string} input - Plain string to encode.
|
|
888
|
+
* @param {string} secret - Secret key used to scramble the Base64 payload.
|
|
889
|
+
* @returns {SalesParkContract<any>} - Return a SalesPark Contract object
|
|
890
|
+
* History:
|
|
891
|
+
* 06-02-2026: Created
|
|
892
|
+
******************************************************************/
|
|
893
|
+
declare const encodeString: (input: string, secret: string) => SalesParkContract<any>;
|
|
903
894
|
/******************************************************************
|
|
904
895
|
* ##: Decode scrambled string back into an object using a secret key
|
|
905
896
|
* Descrambles an encoded string with the provided secret, Base64-decodes it, and parses it as JSON.
|
|
@@ -915,6 +906,19 @@ declare const encodeObject: (input: object, secret: string) => SalesParkContract
|
|
|
915
906
|
* 04-02-2026: Refactored + return SalesPark Contract object
|
|
916
907
|
******************************************************************/
|
|
917
908
|
declare const decodeObject: (encoded: string, secret: string) => SalesParkContract<any>;
|
|
909
|
+
/******************************************************************
|
|
910
|
+
* ##: Decode scrambled Base64 string back into a string using a secret key
|
|
911
|
+
* Descrambles the encoded input with the provided secret and Base64-decodes it.
|
|
912
|
+
* This reverses the encode flow and returns the original string if inputs are valid.
|
|
913
|
+
*
|
|
914
|
+
* TL;DR: Convert a scrambled string back into the original string using the same key.
|
|
915
|
+
* @param {string} encoded - Scrambled Base64 string produced by the encoder/scrambler.
|
|
916
|
+
* @param {string} secret - Secret key used to descramble the payload.
|
|
917
|
+
* @returns {SalesParkContract<any>} - Return a SalesPark Contract object
|
|
918
|
+
* History:
|
|
919
|
+
* 06-02-2026: Created
|
|
920
|
+
******************************************************************/
|
|
921
|
+
declare const decodeString: (encoded: string, secret: string) => SalesParkContract<any>;
|
|
918
922
|
|
|
919
923
|
type DeferFn = () => void | Promise<void>;
|
|
920
924
|
/******************************************************************
|
|
@@ -977,8 +981,52 @@ declare const deferAfterResponse: (res: HttpResponseLike, fn: DeferFn) => void;
|
|
|
977
981
|
******************************************************************/
|
|
978
982
|
declare const deferAfterResponseNonCritical: (res: HttpResponseLike, fn: DeferFn) => void;
|
|
979
983
|
|
|
984
|
+
/******************************************************
|
|
985
|
+
* ##: Reversible Base36 Code Encoder/Decoder (No Deps)
|
|
986
|
+
* Encodes a base36 identifier into a lower-case base36 code using a secret key.
|
|
987
|
+
* Decodes back with the same secret and configuration.
|
|
988
|
+
* History:
|
|
989
|
+
* 16-02-2026: Created
|
|
990
|
+
****************************************************/
|
|
991
|
+
type EncodeDecodeConfig = {
|
|
992
|
+
secret: string;
|
|
993
|
+
bitSize?: number;
|
|
994
|
+
rotateBits?: number;
|
|
995
|
+
addConstant?: string;
|
|
996
|
+
};
|
|
997
|
+
/******************************************************************
|
|
998
|
+
* ##: Encode Base36 Identifier
|
|
999
|
+
* Obfuscates a base36 identifier into a reversible lowercase base36 code using XOR mixing, constant addition, and rotation.
|
|
1000
|
+
*
|
|
1001
|
+
* TL;DR: Encodes a base36 identifier into a reversible base36 code.
|
|
1002
|
+
* Uses a secret-derived key and fixed-width math to keep outputs bounded and reversible.
|
|
1003
|
+
* @param {string} identifier - Source identifier in base36 format
|
|
1004
|
+
* @param {EncodeDecodeConfig} config - Encoding configuration including secret and optional parameters
|
|
1005
|
+
* @returns {SalesParkContract<{ code: string }>} - Return a SalesPark Contract object.
|
|
1006
|
+
* History:
|
|
1007
|
+
* 16-02-2026: Created
|
|
1008
|
+
******************************************************************/
|
|
1009
|
+
declare const encodeBase36Code: (identifier: string, config: EncodeDecodeConfig) => SalesParkContract<{
|
|
1010
|
+
code: string;
|
|
1011
|
+
}>;
|
|
1012
|
+
/******************************************************************
|
|
1013
|
+
* ##: Decode Base36 Code
|
|
1014
|
+
* Reverses the obfuscation steps to restore the original identifier using the same secret and configuration parameters.
|
|
1015
|
+
*
|
|
1016
|
+
* TL;DR: Decodes a base36 code back into the original identifier.
|
|
1017
|
+
* Requires the same secret and config to reliably reverse XOR, add, and rotation.
|
|
1018
|
+
* @param {string} code - Encoded base36 code to decode
|
|
1019
|
+
* @param {EncodeDecodeConfig} config - Decoding configuration including secret and optional parameters
|
|
1020
|
+
* @returns {SalesParkContract<{ identifier: string }>} - Return a SalesPark Contract object.
|
|
1021
|
+
* History:
|
|
1022
|
+
* 16-02-2026: Created
|
|
1023
|
+
******************************************************************/
|
|
1024
|
+
declare const decodeBase36Code: (code: string, config: EncodeDecodeConfig) => SalesParkContract<{
|
|
1025
|
+
identifier: string;
|
|
1026
|
+
}>;
|
|
1027
|
+
|
|
980
1028
|
/** Environment helpers (runtime-agnostic checks) */
|
|
981
1029
|
declare const isBrowser: boolean;
|
|
982
1030
|
declare const isNode: boolean;
|
|
983
1031
|
|
|
984
|
-
export { type CapitalizeFirstOptions, type CapitalizeWordsOptions, type DeferFn, type FormatCurrencyProOptions, type HttpResponseLike, type SecurityCheckResult, type SecurityRisk, type SentenceCaseOptions, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, capitalizeFirst, capitalizeWords, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, decodeObject, deferAfterResponse, deferAfterResponseNonCritical, deferNonCritical, deferPostReturn, delay,
|
|
1032
|
+
export { type CapitalizeFirstOptions, type CapitalizeWordsOptions, type DeferFn, type EncodeDecodeConfig, type FormatCurrencyProOptions, type HttpResponseLike, type SecurityCheckResult, type SecurityRisk, type SentenceCaseOptions, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, capitalizeFirst, capitalizeWords, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, decodeBase36Code, decodeObject, decodeString, deferAfterResponse, deferAfterResponseNonCritical, deferNonCritical, deferPostReturn, delay, difference, encodeBase36Code, encodeObject, encodeString, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatCurrencyPro, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrEmptyObject, isNilEmptyOrZeroLen, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeJSONParse, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, sentenceCase, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
package/dist/index.js
CHANGED
|
@@ -504,6 +504,17 @@ var isNilOrEmpty = (value) => {
|
|
|
504
504
|
return true;
|
|
505
505
|
}
|
|
506
506
|
};
|
|
507
|
+
var isNilEmptyOrEmptyObject = (value) => {
|
|
508
|
+
try {
|
|
509
|
+
if (isNilOrEmpty(value)) return true;
|
|
510
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0) {
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
513
|
+
return false;
|
|
514
|
+
} catch {
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
};
|
|
507
518
|
var hasNilOrEmpty = (array) => {
|
|
508
519
|
try {
|
|
509
520
|
if (!Array.isArray(array)) return true;
|
|
@@ -1879,6 +1890,24 @@ var encodeObject = (input, secret) => {
|
|
|
1879
1890
|
return { status: false, data: error };
|
|
1880
1891
|
}
|
|
1881
1892
|
};
|
|
1893
|
+
var encodeString = (input, secret) => {
|
|
1894
|
+
try {
|
|
1895
|
+
if (typeof input !== "string") {
|
|
1896
|
+
return { status: false, data: "Input must be a string" };
|
|
1897
|
+
}
|
|
1898
|
+
if (!secret || typeof secret !== "string") {
|
|
1899
|
+
return { status: false, data: "Secret must be a non-empty string" };
|
|
1900
|
+
}
|
|
1901
|
+
const base64 = toBase64(input);
|
|
1902
|
+
const scrambledResponse = scrambleString(base64, secret);
|
|
1903
|
+
if (!scrambledResponse.status) {
|
|
1904
|
+
return { status: false, data: "Scrambling failed" };
|
|
1905
|
+
}
|
|
1906
|
+
return { status: true, data: scrambledResponse.data };
|
|
1907
|
+
} catch (error) {
|
|
1908
|
+
return { status: false, data: error };
|
|
1909
|
+
}
|
|
1910
|
+
};
|
|
1882
1911
|
var decodeObject = (encoded, secret) => {
|
|
1883
1912
|
try {
|
|
1884
1913
|
if (typeof encoded !== "string") {
|
|
@@ -1897,6 +1926,24 @@ var decodeObject = (encoded, secret) => {
|
|
|
1897
1926
|
return { status: false, data: error };
|
|
1898
1927
|
}
|
|
1899
1928
|
};
|
|
1929
|
+
var decodeString = (encoded, secret) => {
|
|
1930
|
+
try {
|
|
1931
|
+
if (typeof encoded !== "string") {
|
|
1932
|
+
return { status: false, data: "Encoded value must be a string" };
|
|
1933
|
+
}
|
|
1934
|
+
if (!secret || typeof secret !== "string") {
|
|
1935
|
+
return { status: false, data: "Secret must be a non-empty string" };
|
|
1936
|
+
}
|
|
1937
|
+
const descrambledResponse = descrambleString(encoded, secret);
|
|
1938
|
+
if (!descrambledResponse.status) {
|
|
1939
|
+
return { status: false, data: "Descrambling failed" };
|
|
1940
|
+
}
|
|
1941
|
+
const value = fromBase64(descrambledResponse.data);
|
|
1942
|
+
return { status: true, data: value };
|
|
1943
|
+
} catch (error) {
|
|
1944
|
+
return { status: false, data: error };
|
|
1945
|
+
}
|
|
1946
|
+
};
|
|
1900
1947
|
|
|
1901
1948
|
// src/utils/defer.ts
|
|
1902
1949
|
var swallow = (p) => p.catch(() => {
|
|
@@ -1982,10 +2029,199 @@ var deferAfterResponseNonCritical = (res, fn) => {
|
|
|
1982
2029
|
}
|
|
1983
2030
|
};
|
|
1984
2031
|
|
|
2032
|
+
// src/utils/base36.ts
|
|
2033
|
+
var DEFAULTS = {
|
|
2034
|
+
bitSize: 80,
|
|
2035
|
+
rotateBits: 17,
|
|
2036
|
+
addConstant: "0x1fd0a5b7c3"
|
|
2037
|
+
};
|
|
2038
|
+
var isValidBase36 = (value) => /^[a-z0-9]+$/i.test(value);
|
|
2039
|
+
var normalizeInput = (value) => (value || "").trim();
|
|
2040
|
+
var assertSecret = (secret) => {
|
|
2041
|
+
if (typeof secret !== "string" || secret.trim().length < 12) {
|
|
2042
|
+
return { status: false, data: { message: "Missing or weak secret" } };
|
|
2043
|
+
}
|
|
2044
|
+
return { status: true, data: true };
|
|
2045
|
+
};
|
|
2046
|
+
var parseBase36BigInt = (value) => {
|
|
2047
|
+
try {
|
|
2048
|
+
const normalizedValue = normalizeInput(value);
|
|
2049
|
+
if (!normalizedValue) {
|
|
2050
|
+
return { status: false, data: { message: "Empty input" } };
|
|
2051
|
+
}
|
|
2052
|
+
if (!isValidBase36(normalizedValue)) {
|
|
2053
|
+
return { status: false, data: { message: "Invalid base36 input" } };
|
|
2054
|
+
}
|
|
2055
|
+
const safeValue = normalizedValue.toLowerCase();
|
|
2056
|
+
let output = 0n;
|
|
2057
|
+
for (let i = 0; i < safeValue.length; i++) {
|
|
2058
|
+
const char = safeValue[i];
|
|
2059
|
+
const digit = char >= "0" && char <= "9" ? BigInt(char.charCodeAt(0) - 48) : BigInt(char.charCodeAt(0) - 87);
|
|
2060
|
+
output = output * 36n + digit;
|
|
2061
|
+
}
|
|
2062
|
+
return { status: true, data: output };
|
|
2063
|
+
} catch (error) {
|
|
2064
|
+
return {
|
|
2065
|
+
status: false,
|
|
2066
|
+
data: { message: "Failed to parse base36 input", error }
|
|
2067
|
+
};
|
|
2068
|
+
}
|
|
2069
|
+
};
|
|
2070
|
+
var toBase36Lower = (value) => {
|
|
2071
|
+
try {
|
|
2072
|
+
if (value < 0n) {
|
|
2073
|
+
return {
|
|
2074
|
+
status: false,
|
|
2075
|
+
data: { message: "Negative values are not supported" }
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
return { status: true, data: value.toString(36) };
|
|
2079
|
+
} catch (error) {
|
|
2080
|
+
return {
|
|
2081
|
+
status: false,
|
|
2082
|
+
data: { message: "Failed to convert to base36", error }
|
|
2083
|
+
};
|
|
2084
|
+
}
|
|
2085
|
+
};
|
|
2086
|
+
var getParams = (config) => {
|
|
2087
|
+
try {
|
|
2088
|
+
const bitSizeRaw = BigInt(config.bitSize ?? DEFAULTS.bitSize);
|
|
2089
|
+
if (bitSizeRaw <= 0n) {
|
|
2090
|
+
return {
|
|
2091
|
+
status: false,
|
|
2092
|
+
data: { message: "bitSize must be greater than 0" }
|
|
2093
|
+
};
|
|
2094
|
+
}
|
|
2095
|
+
const rotateRaw = BigInt(config.rotateBits ?? DEFAULTS.rotateBits);
|
|
2096
|
+
const rotateBits = (rotateRaw % bitSizeRaw + bitSizeRaw) % bitSizeRaw;
|
|
2097
|
+
const addConstant = BigInt(config.addConstant ?? DEFAULTS.addConstant);
|
|
2098
|
+
const mask = (1n << bitSizeRaw) - 1n;
|
|
2099
|
+
return {
|
|
2100
|
+
status: true,
|
|
2101
|
+
data: { bitSize: bitSizeRaw, rotateBits, addConstant, mask }
|
|
2102
|
+
};
|
|
2103
|
+
} catch (error) {
|
|
2104
|
+
return { status: false, data: { message: "Invalid configuration", error } };
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
var secretToKey = (secret, mask) => {
|
|
2108
|
+
let key = 0n;
|
|
2109
|
+
const safeSecret = secret.trim();
|
|
2110
|
+
for (let i = 0; i < safeSecret.length; i++) {
|
|
2111
|
+
key = key * 131n + BigInt(safeSecret.charCodeAt(i)) & mask;
|
|
2112
|
+
}
|
|
2113
|
+
return key;
|
|
2114
|
+
};
|
|
2115
|
+
var rotl = (x, r, bitSize, mask) => {
|
|
2116
|
+
if (r === 0n) return x & mask;
|
|
2117
|
+
return (x << r | x >> bitSize - r) & mask;
|
|
2118
|
+
};
|
|
2119
|
+
var rotr = (x, r, bitSize, mask) => {
|
|
2120
|
+
if (r === 0n) return x & mask;
|
|
2121
|
+
return (x >> r | x << bitSize - r) & mask;
|
|
2122
|
+
};
|
|
2123
|
+
var encodeBase36Code = (identifier, config) => {
|
|
2124
|
+
try {
|
|
2125
|
+
const secretCheck = assertSecret(config?.secret);
|
|
2126
|
+
if (!secretCheck.status) {
|
|
2127
|
+
return { status: false, data: secretCheck.data };
|
|
2128
|
+
}
|
|
2129
|
+
const input = normalizeInput(identifier);
|
|
2130
|
+
if (!input) {
|
|
2131
|
+
return { status: false, data: { message: "Identifier is required" } };
|
|
2132
|
+
}
|
|
2133
|
+
if (!isValidBase36(input)) {
|
|
2134
|
+
return {
|
|
2135
|
+
status: false,
|
|
2136
|
+
data: { message: "Identifier must be base36 (0-9, A-Z)" }
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
const parsed = parseBase36BigInt(input);
|
|
2140
|
+
if (!parsed.status) {
|
|
2141
|
+
return { status: false, data: parsed.data };
|
|
2142
|
+
}
|
|
2143
|
+
const params = getParams(config);
|
|
2144
|
+
if (!params.status) {
|
|
2145
|
+
return { status: false, data: params.data };
|
|
2146
|
+
}
|
|
2147
|
+
const {
|
|
2148
|
+
bitSize,
|
|
2149
|
+
rotateBits,
|
|
2150
|
+
addConstant,
|
|
2151
|
+
mask
|
|
2152
|
+
} = params.data;
|
|
2153
|
+
const key = secretToKey(config.secret, mask);
|
|
2154
|
+
let value = parsed.data & mask;
|
|
2155
|
+
value = value ^ key;
|
|
2156
|
+
value = value + addConstant & mask;
|
|
2157
|
+
value = rotl(value, rotateBits, bitSize, mask);
|
|
2158
|
+
const codeResult = toBase36Lower(value);
|
|
2159
|
+
if (!codeResult.status) {
|
|
2160
|
+
return { status: false, data: codeResult.data };
|
|
2161
|
+
}
|
|
2162
|
+
return { status: true, data: { code: codeResult.data } };
|
|
2163
|
+
} catch (error) {
|
|
2164
|
+
return {
|
|
2165
|
+
status: false,
|
|
2166
|
+
data: { message: "Failed to encode code", error }
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2170
|
+
var decodeBase36Code = (code, config) => {
|
|
2171
|
+
try {
|
|
2172
|
+
const secretCheck = assertSecret(config?.secret);
|
|
2173
|
+
if (!secretCheck.status) {
|
|
2174
|
+
return { status: false, data: secretCheck.data };
|
|
2175
|
+
}
|
|
2176
|
+
const input = normalizeInput(code);
|
|
2177
|
+
if (!input) {
|
|
2178
|
+
return { status: false, data: { message: "Code is required" } };
|
|
2179
|
+
}
|
|
2180
|
+
if (!isValidBase36(input)) {
|
|
2181
|
+
return {
|
|
2182
|
+
status: false,
|
|
2183
|
+
data: { message: "Code must be base36 (0-9, a-z)" }
|
|
2184
|
+
};
|
|
2185
|
+
}
|
|
2186
|
+
const parsed = parseBase36BigInt(input);
|
|
2187
|
+
if (!parsed.status) {
|
|
2188
|
+
return { status: false, data: parsed.data };
|
|
2189
|
+
}
|
|
2190
|
+
const params = getParams(config);
|
|
2191
|
+
if (!params.status) {
|
|
2192
|
+
return { status: false, data: params.data };
|
|
2193
|
+
}
|
|
2194
|
+
const {
|
|
2195
|
+
bitSize,
|
|
2196
|
+
rotateBits,
|
|
2197
|
+
addConstant,
|
|
2198
|
+
mask
|
|
2199
|
+
} = params.data;
|
|
2200
|
+
const key = secretToKey(config.secret, mask);
|
|
2201
|
+
let value = parsed.data & mask;
|
|
2202
|
+
value = rotr(value, rotateBits, bitSize, mask);
|
|
2203
|
+
value = value - addConstant & mask;
|
|
2204
|
+
value = value ^ key;
|
|
2205
|
+
const identifierResult = toBase36Lower(value);
|
|
2206
|
+
if (!identifierResult.status) {
|
|
2207
|
+
return { status: false, data: identifierResult.data };
|
|
2208
|
+
}
|
|
2209
|
+
return {
|
|
2210
|
+
status: true,
|
|
2211
|
+
data: { identifier: identifierResult.data.toUpperCase() }
|
|
2212
|
+
};
|
|
2213
|
+
} catch (error) {
|
|
2214
|
+
return {
|
|
2215
|
+
status: false,
|
|
2216
|
+
data: { message: "Failed to decode code", error }
|
|
2217
|
+
};
|
|
2218
|
+
}
|
|
2219
|
+
};
|
|
2220
|
+
|
|
1985
2221
|
// src/index.ts
|
|
1986
2222
|
var isBrowser = typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
|
|
1987
2223
|
var isNode = typeof process !== "undefined" && !!process.versions?.node;
|
|
1988
2224
|
|
|
1989
|
-
export { addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, capitalizeFirst, capitalizeWords, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, decodeObject, deferAfterResponse, deferAfterResponseNonCritical, deferNonCritical, deferPostReturn, delay,
|
|
2225
|
+
export { addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, capitalizeFirst, capitalizeWords, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, decodeBase36Code, decodeObject, decodeString, deferAfterResponse, deferAfterResponseNonCritical, deferNonCritical, deferPostReturn, delay, difference, encodeBase36Code, encodeObject, encodeString, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatCurrencyPro, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrEmptyObject, isNilEmptyOrZeroLen, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeJSONParse, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, sentenceCase, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
|
1990
2226
|
//# sourceMappingURL=index.js.map
|
|
1991
2227
|
//# sourceMappingURL=index.js.map
|