@salespark/toolkit 2.1.15 → 2.1.17

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 CHANGED
@@ -544,6 +544,22 @@ isNilOrEmpty(undefined);
544
544
  // Result: true
545
545
  ```
546
546
 
547
+ **`isNilEmptyOrEmptyObject(value: unknown): boolean`** — Checks if value is nil, empty string, or an empty plain object (no own keys).
548
+
549
+ ```javascript
550
+ isNilEmptyOrEmptyObject(null);
551
+ // Result: true
552
+
553
+ isNilEmptyOrEmptyObject("");
554
+ // Result: true
555
+
556
+ isNilEmptyOrEmptyObject({});
557
+ // Result: true
558
+
559
+ isNilEmptyOrEmptyObject({ a: 1 });
560
+ // Result: false
561
+ ```
562
+
547
563
  **`hasNilOrEmpty(array: unknown): boolean`** — Checks if any element in array is nil or empty.
548
564
 
549
565
  ```javascript
@@ -836,29 +852,29 @@ assessSecurityRisks([]);
836
852
  // Result: { score: 0, level: "safe", recommendations: ["Content appears safe to use"] }
837
853
  ```
838
854
 
839
- **`scrambleString(value: string, secret: string): string`**Scrambles a string using a repeating secret (XOR) and Base64. Reversible obfuscation only (not crypto).
855
+ **`encodeString(input: string, secret: string): SalesParkContract<any>`**Base64-encodes a string and scrambles it with the provided secret (obfuscation only).
840
856
 
841
857
  ```javascript
842
- const scrambled = scrambleString("Hello", "secret");
843
- // Result: "..." (base64)
858
+ const encoded = encodeString("Hello", "secret");
859
+ // Result: { status: true, data: "..." }
844
860
 
845
- const original = descrambleString(scrambled, "secret");
846
- // Result: "Hello"
861
+ const decoded = decodeString(encoded.data, "secret");
862
+ // Result: { status: true, data: "Hello" }
847
863
  ```
848
864
 
849
- **`descrambleString(value: string, secret: string): string`** — Reverses `scrambleString` using the same secret.
865
+ **`decodeString(encoded: string, secret: string): SalesParkContract<any>`** — Reverses `encodeString` using the same secret.
850
866
 
851
- **`encodeObject(input: object, secret: string): string`** — JSON-stringifies an object, Base64-encodes it, and scrambles the result (obfuscation only).
867
+ **`encodeObject(input: object, secret: string): SalesParkContract<object>`** — JSON-stringifies an object, Base64-encodes it, and scrambles the result (obfuscation only).
852
868
 
853
869
  ```javascript
854
870
  const encoded = encodeObject({ id: 1, name: "Ana" }, "secret");
855
- // Result: "..." (base64)
871
+ // Result: { status: true, data: "..." }
856
872
 
857
- const decoded = decodeObject(encoded, "secret");
858
- // Result: { id: 1, name: "Ana" }
873
+ const decoded = decodeObject(encoded.data, "secret");
874
+ // Result: { status: true, data: { id: 1, name: "Ana" } }
859
875
  ```
860
876
 
861
- **`decodeObject(encoded: string, secret: string): object`** — Reverses `encodeObject` using the same secret.
877
+ **`decodeObject(encoded: string, secret: string): SalesParkContract<object>`** — Reverses `encodeObject` using the same secret.
862
878
 
863
879
  ### ✅ Validation Utilities
864
880
 
@@ -993,5 +1009,5 @@ MIT © [SalesPark](https://salespark.io)
993
1009
 
994
1010
  ---
995
1011
 
996
- _Document version: 13_
997
- _Last update: 09-01-2026_
1012
+ _Document version: 14_
1013
+ _Last update: 06-02-2026_
package/dist/index.cjs CHANGED
@@ -506,6 +506,17 @@ var isNilOrEmpty = (value) => {
506
506
  return true;
507
507
  }
508
508
  };
509
+ var isNilEmptyOrEmptyObject = (value) => {
510
+ try {
511
+ if (isNilOrEmpty(value)) return true;
512
+ if (typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0) {
513
+ return true;
514
+ }
515
+ return false;
516
+ } catch {
517
+ return true;
518
+ }
519
+ };
509
520
  var hasNilOrEmpty = (array) => {
510
521
  try {
511
522
  if (!Array.isArray(array)) return true;
@@ -1824,57 +1835,116 @@ var binaryToUtf8 = (binary) => {
1824
1835
  var toBase64 = (value) => base64EncodeBinary(utf8ToBinary(value));
1825
1836
  var fromBase64 = (value) => binaryToUtf8(base64DecodeToBinary(value));
1826
1837
  var scrambleString = (value, secret) => {
1827
- if (typeof value !== "string") {
1828
- throw new TypeError("Value must be a string");
1829
- }
1830
- if (!secret || typeof secret !== "string") {
1831
- throw new TypeError("Secret must be a non-empty string");
1832
- }
1833
- let result = "";
1834
- for (let i = 0; i < value.length; i++) {
1835
- const charCode = value.charCodeAt(i) & 255;
1836
- const keyCode = secret.charCodeAt(i % secret.length) & 255;
1837
- result += String.fromCharCode(charCode ^ keyCode);
1838
+ try {
1839
+ if (typeof value !== "string") {
1840
+ return { status: false, data: "Value must be a string" };
1841
+ }
1842
+ if (!secret || typeof secret !== "string") {
1843
+ return { status: false, data: "Secret must be a non-empty string" };
1844
+ }
1845
+ let result = "";
1846
+ for (let i = 0; i < value.length; i++) {
1847
+ const charCode = value.charCodeAt(i) & 255;
1848
+ const keyCode = secret.charCodeAt(i % secret.length) & 255;
1849
+ result += String.fromCharCode(charCode ^ keyCode);
1850
+ }
1851
+ return { status: true, data: base64EncodeBinary(result) };
1852
+ } catch (error) {
1853
+ return { status: false, data: error };
1838
1854
  }
1839
- return base64EncodeBinary(result);
1840
1855
  };
1841
1856
  var descrambleString = (value, secret) => {
1842
- if (typeof value !== "string") {
1843
- throw new TypeError("Value must be a string");
1844
- }
1845
- if (!secret || typeof secret !== "string") {
1846
- throw new TypeError("Secret must be a non-empty string");
1847
- }
1848
- const decoded = base64DecodeToBinary(value);
1849
- let result = "";
1850
- for (let i = 0; i < decoded.length; i++) {
1851
- const charCode = decoded.charCodeAt(i) & 255;
1852
- const keyCode = secret.charCodeAt(i % secret.length) & 255;
1853
- result += String.fromCharCode(charCode ^ keyCode);
1857
+ try {
1858
+ if (typeof value !== "string") {
1859
+ return { status: false, data: "Value must be a string" };
1860
+ }
1861
+ if (!secret || typeof secret !== "string") {
1862
+ return { status: false, data: "Secret must be a non-empty string" };
1863
+ }
1864
+ const decoded = base64DecodeToBinary(value);
1865
+ let result = "";
1866
+ for (let i = 0; i < decoded.length; i++) {
1867
+ const charCode = decoded.charCodeAt(i) & 255;
1868
+ const keyCode = secret.charCodeAt(i % secret.length) & 255;
1869
+ result += String.fromCharCode(charCode ^ keyCode);
1870
+ }
1871
+ return { status: true, data: result };
1872
+ } catch (error) {
1873
+ return { status: false, data: error };
1854
1874
  }
1855
- return result;
1856
1875
  };
1857
1876
  var encodeObject = (input, secret) => {
1858
- if (!input || typeof input !== "object") {
1859
- throw new TypeError("Input must be an object");
1877
+ try {
1878
+ if (!input || typeof input !== "object") {
1879
+ return { status: false, data: "Input must be an object" };
1880
+ }
1881
+ if (!secret || typeof secret !== "string") {
1882
+ return { status: false, data: "Secret must be a non-empty string" };
1883
+ }
1884
+ const jsonString = JSON.stringify(input);
1885
+ const base64 = toBase64(jsonString);
1886
+ const scrambledResponse = scrambleString(base64, secret);
1887
+ if (!scrambledResponse.status) {
1888
+ return { status: false, data: "Scrambling failed" };
1889
+ }
1890
+ return { status: true, data: scrambledResponse.data };
1891
+ } catch (error) {
1892
+ return { status: false, data: error };
1860
1893
  }
1861
- if (!secret || typeof secret !== "string") {
1862
- throw new TypeError("Secret must be a non-empty string");
1894
+ };
1895
+ var encodeString = (input, secret) => {
1896
+ try {
1897
+ if (typeof input !== "string") {
1898
+ return { status: false, data: "Input must be a string" };
1899
+ }
1900
+ if (!secret || typeof secret !== "string") {
1901
+ return { status: false, data: "Secret must be a non-empty string" };
1902
+ }
1903
+ const base64 = toBase64(input);
1904
+ const scrambledResponse = scrambleString(base64, secret);
1905
+ if (!scrambledResponse.status) {
1906
+ return { status: false, data: "Scrambling failed" };
1907
+ }
1908
+ return { status: true, data: scrambledResponse.data };
1909
+ } catch (error) {
1910
+ return { status: false, data: error };
1863
1911
  }
1864
- const jsonString = JSON.stringify(input);
1865
- const base64 = toBase64(jsonString);
1866
- return scrambleString(base64, secret);
1867
1912
  };
1868
1913
  var decodeObject = (encoded, secret) => {
1869
- if (typeof encoded !== "string") {
1870
- throw new TypeError("Encoded value must be a string");
1914
+ try {
1915
+ if (typeof encoded !== "string") {
1916
+ return { status: false, data: "Encoded value must be a string" };
1917
+ }
1918
+ if (!secret || typeof secret !== "string") {
1919
+ return { status: false, data: "Secret must be a non-empty string" };
1920
+ }
1921
+ const descrambledResponse = descrambleString(encoded, secret);
1922
+ if (!descrambledResponse.status) {
1923
+ return { status: false, data: "Descrambling failed" };
1924
+ }
1925
+ const jsonString = fromBase64(descrambledResponse.data);
1926
+ return { status: true, data: JSON.parse(jsonString) };
1927
+ } catch (error) {
1928
+ return { status: false, data: error };
1871
1929
  }
1872
- if (!secret || typeof secret !== "string") {
1873
- throw new TypeError("Secret must be a non-empty string");
1930
+ };
1931
+ var decodeString = (encoded, secret) => {
1932
+ try {
1933
+ if (typeof encoded !== "string") {
1934
+ return { status: false, data: "Encoded value must be a string" };
1935
+ }
1936
+ if (!secret || typeof secret !== "string") {
1937
+ return { status: false, data: "Secret must be a non-empty string" };
1938
+ }
1939
+ const descrambledResponse = descrambleString(encoded, secret);
1940
+ if (!descrambledResponse.status) {
1941
+ return { status: false, data: "Descrambling failed" };
1942
+ }
1943
+ const value = fromBase64(descrambledResponse.data);
1944
+ return { status: true, data: value };
1945
+ } catch (error) {
1946
+ return { status: false, data: error };
1874
1947
  }
1875
- const descrambled = descrambleString(encoded, secret);
1876
- const jsonString = fromBase64(descrambled);
1877
- return JSON.parse(jsonString);
1878
1948
  };
1879
1949
 
1880
1950
  // src/utils/defer.ts
@@ -1982,14 +2052,15 @@ exports.currencyToSymbol = currencyToSymbol;
1982
2052
  exports.debounce = debounce;
1983
2053
  exports.deburr = deburr;
1984
2054
  exports.decodeObject = decodeObject;
2055
+ exports.decodeString = decodeString;
1985
2056
  exports.deferAfterResponse = deferAfterResponse;
1986
2057
  exports.deferAfterResponseNonCritical = deferAfterResponseNonCritical;
1987
2058
  exports.deferNonCritical = deferNonCritical;
1988
2059
  exports.deferPostReturn = deferPostReturn;
1989
2060
  exports.delay = delay;
1990
- exports.descrambleString = descrambleString;
1991
2061
  exports.difference = difference;
1992
2062
  exports.encodeObject = encodeObject;
2063
+ exports.encodeString = encodeString;
1993
2064
  exports.fill = fill;
1994
2065
  exports.flatten = flatten;
1995
2066
  exports.flattenDepth = flattenDepth;
@@ -2007,6 +2078,7 @@ exports.intersection = intersection;
2007
2078
  exports.isBrowser = isBrowser;
2008
2079
  exports.isFlattenable = isFlattenable;
2009
2080
  exports.isNil = isNil;
2081
+ exports.isNilEmptyOrEmptyObject = isNilEmptyOrEmptyObject;
2010
2082
  exports.isNilEmptyOrZeroLen = isNilEmptyOrZeroLen;
2011
2083
  exports.isNilEmptyOrZeroLength = isNilEmptyOrZeroLength;
2012
2084
  exports.isNilOrEmpty = isNilOrEmpty;
@@ -2049,7 +2121,6 @@ exports.safeParseInt = safeParseInt;
2049
2121
  exports.safeSubtract = safeSubtract;
2050
2122
  exports.sanitize = sanitize;
2051
2123
  exports.sanitizeMarkdown = sanitizeMarkdown;
2052
- exports.scrambleString = scrambleString;
2053
2124
  exports.sentenceCase = sentenceCase;
2054
2125
  exports.shuffle = shuffle;
2055
2126
  exports.slugify = slugify;