@salespark/toolkit 2.1.7 → 2.1.8

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
@@ -267,16 +267,31 @@ objectToString({ name: "John", age: 30 });
267
267
  // Result: "name=John_age=30"
268
268
  ```
269
269
 
270
- **`cleanObject<T>(obj: T): any`** — Deep-cleans an object by removing null/undefined values.
270
+ **`cleanObject<T>(obj: T, removeEmptyString?: boolean): any`** — Deep-cleans an object by removing null/undefined-like values, with optional empty-string removal.
271
271
 
272
272
  ```javascript
273
+ // Default behaviour: keep empty strings
273
274
  cleanObject({
274
275
  name: "John",
275
276
  age: null,
276
277
  city: undefined,
278
+ note: "",
277
279
  data: { valid: true, invalid: null },
278
280
  });
279
- // Result: {name: 'John', data: {valid: true}}
281
+ // Result: {name: 'John', note: '', data: {valid: true}}
282
+
283
+ // With removeEmptyString enabled
284
+ cleanObject(
285
+ {
286
+ name: "John",
287
+ age: null,
288
+ city: undefined,
289
+ note: "",
290
+ tags: ["", "ok"],
291
+ },
292
+ true
293
+ );
294
+ // Result: {name: 'John', tags: ['ok']}
280
295
  ```
281
296
 
282
297
  ### 🔤 String Utilities
@@ -856,5 +871,5 @@ MIT © [SalesPark](https://salespark.io)
856
871
 
857
872
  ---
858
873
 
859
- _Document version: 9_
860
- _Last update: 01-12-2025_
874
+ _Document version: 10_
875
+ _Last update: 11-12-2025_
package/dist/index.cjs CHANGED
@@ -187,18 +187,18 @@ function objectToString(obj) {
187
187
  }
188
188
  }
189
189
  }
190
- var isRemovable = (v) => v === null || v === void 0 || v === "null" || v === "undefined";
191
- function cleanObject(obj) {
190
+ var isRemovable = (v, removeEmptyString) => v === null || v === void 0 || v === "null" || v === "undefined" || removeEmptyString && v === "";
191
+ function cleanObject(obj, removeEmptyString = false) {
192
192
  if (Array.isArray(obj)) {
193
- const cleanedArray = obj.map((item) => cleanObject(item)).filter((item) => !isRemovable(item));
193
+ const cleanedArray = obj.map((item) => cleanObject(item, removeEmptyString)).filter((item) => !isRemovable(item, removeEmptyString));
194
194
  return cleanedArray;
195
195
  }
196
196
  if (obj !== null && typeof obj === "object") {
197
197
  const cleaned = {};
198
198
  for (const [key, value] of Object.entries(obj)) {
199
- if (isRemovable(value)) continue;
200
- const nested = cleanObject(value);
201
- if (isRemovable(nested)) continue;
199
+ if (isRemovable(value, removeEmptyString)) continue;
200
+ const nested = cleanObject(value, removeEmptyString);
201
+ if (isRemovable(nested, removeEmptyString)) continue;
202
202
  const isObj = typeof nested === "object" && nested !== null;
203
203
  const isEmptyObj = isObj && !Array.isArray(nested) && Object.keys(nested).length === 0;
204
204
  const isEmptyArr = Array.isArray(nested) && nested.length === 0;