@dereekb/util 13.0.5 → 13.0.6
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/fetch/package.json +2 -2
- package/index.cjs.js +387 -58
- package/index.esm.js +387 -58
- package/package.json +1 -1
- package/src/lib/object/object.filter.pojo.d.ts +476 -62
- package/test/package.json +2 -2
package/index.esm.js
CHANGED
|
@@ -5480,9 +5480,28 @@ function _unsupported_iterable_to_array$j(o, minLen) {
|
|
|
5480
5480
|
}
|
|
5481
5481
|
// MARK: Object Merging/Overriding
|
|
5482
5482
|
/**
|
|
5483
|
-
* Assigns all
|
|
5484
|
-
*
|
|
5485
|
-
*
|
|
5483
|
+
* Assigns all non-filtered values from one or more source objects into the target object.
|
|
5484
|
+
*
|
|
5485
|
+
* Builds a template from the source objects (in order, so later sources win) and applies it to the target.
|
|
5486
|
+
* By default, undefined values in the source objects are excluded from the template, so they will not override existing target values.
|
|
5487
|
+
*
|
|
5488
|
+
* @param target - The object to override values on.
|
|
5489
|
+
* @param config - Configuration for the override operation.
|
|
5490
|
+
* @param config.copy - Whether to return a shallow copy instead of mutating the target. Defaults to `false`.
|
|
5491
|
+
* @param config.from - One or more source objects whose values will be applied to the target.
|
|
5492
|
+
* @param config.filter - Optional filter to control which key/value pairs from sources are included. Defaults to filtering out `undefined` values.
|
|
5493
|
+
* @returns The modified target (or a copy if `copy` is `true`).
|
|
5494
|
+
*
|
|
5495
|
+
* @example
|
|
5496
|
+
* ```typescript
|
|
5497
|
+
* const target = { a: 1, b: 2 };
|
|
5498
|
+
* overrideInObject(target, { from: [{ a: 10, c: 3 }] });
|
|
5499
|
+
* // target is now { a: 10, b: 2, c: 3 }
|
|
5500
|
+
*
|
|
5501
|
+
* // undefined values in source are ignored by default:
|
|
5502
|
+
* overrideInObject(target, { from: [{ a: undefined, b: 99 }] });
|
|
5503
|
+
* // target.a remains 10, target.b becomes 99
|
|
5504
|
+
* ```
|
|
5486
5505
|
*/ function overrideInObject(target, param) {
|
|
5487
5506
|
var _param_copy = param.copy, copy = _param_copy === void 0 ? false : _param_copy, from = param.from, filter = param.filter;
|
|
5488
5507
|
return overrideInObjectFunctionFactory({
|
|
@@ -5491,7 +5510,27 @@ function _unsupported_iterable_to_array$j(o, minLen) {
|
|
|
5491
5510
|
dynamic: true // using only once, so no need to use the cache
|
|
5492
5511
|
})(asArray(from))(target);
|
|
5493
5512
|
}
|
|
5494
|
-
|
|
5513
|
+
/**
|
|
5514
|
+
* Creates an {@link OverrideInObjectFunctionFactory} that merges source objects into a template,
|
|
5515
|
+
* then applies that template to target objects.
|
|
5516
|
+
*
|
|
5517
|
+
* The template is built by iterating the source objects in order (later sources override earlier ones),
|
|
5518
|
+
* filtering each through the configured filter. When applied to a target, the template's values overwrite
|
|
5519
|
+
* corresponding keys on the target.
|
|
5520
|
+
*
|
|
5521
|
+
* By default, `undefined` values in sources are excluded from the template.
|
|
5522
|
+
*
|
|
5523
|
+
* @param config - Configuration controlling filtering, copying, and caching behavior.
|
|
5524
|
+
* @returns A factory function that accepts source objects and returns an override function.
|
|
5525
|
+
*
|
|
5526
|
+
* @example
|
|
5527
|
+
* ```typescript
|
|
5528
|
+
* const factory = overrideInObjectFunctionFactory({ copy: true });
|
|
5529
|
+
* const overrideFn = factory([{ color: 'red' }, { size: 10 }]);
|
|
5530
|
+
* const result = overrideFn({ color: 'blue', size: 5 });
|
|
5531
|
+
* // result is { color: 'red', size: 10 } (a new copy)
|
|
5532
|
+
* ```
|
|
5533
|
+
*/ function overrideInObjectFunctionFactory(param) {
|
|
5495
5534
|
var filter = param.filter, copy = param.copy, _param_dynamic = param.dynamic, dynamic = _param_dynamic === void 0 ? false : _param_dynamic;
|
|
5496
5535
|
var filterToRelevantValuesObject = filter != null ? filterFromPOJOFunction({
|
|
5497
5536
|
filter: filter,
|
|
@@ -5518,15 +5557,49 @@ function overrideInObjectFunctionFactory(param) {
|
|
|
5518
5557
|
};
|
|
5519
5558
|
}
|
|
5520
5559
|
/**
|
|
5521
|
-
* Merges all input objects into
|
|
5560
|
+
* Merges all input objects into a single object.
|
|
5561
|
+
*
|
|
5562
|
+
* Objects are applied left-to-right, so the right-most (last) item in the array has the highest priority.
|
|
5563
|
+
* `Maybe` values (null/undefined entries in the array) are silently ignored.
|
|
5564
|
+
*
|
|
5565
|
+
* By default, `undefined` values within each source object are excluded from the merge,
|
|
5566
|
+
* meaning an `undefined` value will not overwrite a previously set value.
|
|
5522
5567
|
*
|
|
5523
|
-
*
|
|
5568
|
+
* @param objects - Array of objects (or null/undefined) to merge together.
|
|
5569
|
+
* @param filter - Optional filter controlling which key/value pairs are included. Defaults to filtering out `undefined` values (`KeyValueTypleValueFilter.UNDEFINED`).
|
|
5570
|
+
* @returns A new object containing the merged result.
|
|
5524
5571
|
*
|
|
5525
|
-
* @
|
|
5572
|
+
* @example
|
|
5573
|
+
* ```typescript
|
|
5574
|
+
* const result = mergeObjects([{ a: 1, b: 2 }, { b: 3, c: 4 }]);
|
|
5575
|
+
* // result is { a: 1, b: 3, c: 4 }
|
|
5576
|
+
*
|
|
5577
|
+
* // undefined values in sources do not override:
|
|
5578
|
+
* const result2 = mergeObjects([{ a: 1 }, { a: undefined, b: 2 }]);
|
|
5579
|
+
* // result2 is { a: 1, b: 2 }
|
|
5580
|
+
* ```
|
|
5526
5581
|
*/ function mergeObjects(objects, filter) {
|
|
5527
5582
|
return mergeObjectsFunction(filter)(objects);
|
|
5528
5583
|
}
|
|
5529
|
-
|
|
5584
|
+
/**
|
|
5585
|
+
* Creates a reusable {@link MergeObjectsFunction} with a pre-configured filter.
|
|
5586
|
+
*
|
|
5587
|
+
* Useful when you need to merge objects multiple times with the same filter configuration.
|
|
5588
|
+
* By default, `undefined` values are filtered out of the result (`KeyValueTypleValueFilter.UNDEFINED`).
|
|
5589
|
+
*
|
|
5590
|
+
* @param filter - Optional filter controlling which key/value pairs are included. Defaults to filtering out `undefined` values.
|
|
5591
|
+
* @returns A reusable merge function.
|
|
5592
|
+
*
|
|
5593
|
+
* @example
|
|
5594
|
+
* ```typescript
|
|
5595
|
+
* const merge = mergeObjectsFunction();
|
|
5596
|
+
* const result = merge([{ a: 1 }, { b: 2 }, { a: 3 }]);
|
|
5597
|
+
* // result is { a: 3, b: 2 }
|
|
5598
|
+
*
|
|
5599
|
+
* // With null filter to also exclude null values:
|
|
5600
|
+
* const mergeNoNulls = mergeObjectsFunction(KeyValueTypleValueFilter.NULL);
|
|
5601
|
+
* ```
|
|
5602
|
+
*/ function mergeObjectsFunction(filter) {
|
|
5530
5603
|
var overrideFn = overrideInObjectFunctionFactory({
|
|
5531
5604
|
filter: filter,
|
|
5532
5605
|
copy: false,
|
|
@@ -5538,20 +5611,37 @@ function mergeObjectsFunction(filter) {
|
|
|
5538
5611
|
}
|
|
5539
5612
|
// MARK: POJO
|
|
5540
5613
|
/**
|
|
5541
|
-
* Returns a copy of the input object with all undefined
|
|
5614
|
+
* Returns a copy of the input object with all `undefined` values removed.
|
|
5615
|
+
* When `filterNull` is `true`, `null` values are also removed.
|
|
5542
5616
|
*
|
|
5543
|
-
* @
|
|
5544
|
-
*
|
|
5617
|
+
* This is a convenience wrapper around {@link filterOnlyUndefinedValues} and {@link filterNullAndUndefinedValues}.
|
|
5618
|
+
*
|
|
5619
|
+
* @param obj - The object to filter.
|
|
5620
|
+
* @param filterNull - If `true`, both `null` and `undefined` values are removed. Defaults to `false`.
|
|
5621
|
+
* @returns A shallow copy of the object with filtered values removed.
|
|
5622
|
+
*
|
|
5623
|
+
* @example
|
|
5624
|
+
* ```typescript
|
|
5625
|
+
* filterUndefinedValues({ a: 1, b: undefined, c: null });
|
|
5626
|
+
* // { a: 1, c: null }
|
|
5627
|
+
*
|
|
5628
|
+
* filterUndefinedValues({ a: 1, b: undefined, c: null }, true);
|
|
5629
|
+
* // { a: 1 }
|
|
5630
|
+
* ```
|
|
5545
5631
|
*/ function filterUndefinedValues(obj) {
|
|
5546
5632
|
var filterNull = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
5547
5633
|
var filterFn = filterNull ? filterNullAndUndefinedValues : filterOnlyUndefinedValues;
|
|
5548
5634
|
return filterFn(obj);
|
|
5549
5635
|
}
|
|
5550
5636
|
/**
|
|
5551
|
-
*
|
|
5637
|
+
* Pre-built filter that returns a copy of the input object with all `undefined` values removed.
|
|
5638
|
+
* Keys with `null` or other falsy values are retained.
|
|
5552
5639
|
*
|
|
5553
|
-
* @
|
|
5554
|
-
*
|
|
5640
|
+
* @example
|
|
5641
|
+
* ```typescript
|
|
5642
|
+
* filterOnlyUndefinedValues({ a: 1, b: undefined, c: null });
|
|
5643
|
+
* // { a: 1, c: null }
|
|
5644
|
+
* ```
|
|
5555
5645
|
*/ var filterOnlyUndefinedValues = filterFromPOJOFunction({
|
|
5556
5646
|
copy: true,
|
|
5557
5647
|
filter: {
|
|
@@ -5559,10 +5649,14 @@ function mergeObjectsFunction(filter) {
|
|
|
5559
5649
|
}
|
|
5560
5650
|
});
|
|
5561
5651
|
/**
|
|
5562
|
-
*
|
|
5652
|
+
* Pre-built filter that returns a copy of the input object with all `null` and `undefined` values removed.
|
|
5653
|
+
* Keys with other falsy values (0, false, '') are retained.
|
|
5563
5654
|
*
|
|
5564
|
-
* @
|
|
5565
|
-
*
|
|
5655
|
+
* @example
|
|
5656
|
+
* ```typescript
|
|
5657
|
+
* filterNullAndUndefinedValues({ a: 1, b: undefined, c: null, d: 0 });
|
|
5658
|
+
* // { a: 1, d: 0 }
|
|
5659
|
+
* ```
|
|
5566
5660
|
*/ var filterNullAndUndefinedValues = filterFromPOJOFunction({
|
|
5567
5661
|
copy: true,
|
|
5568
5662
|
filter: {
|
|
@@ -5570,10 +5664,14 @@ function mergeObjectsFunction(filter) {
|
|
|
5570
5664
|
}
|
|
5571
5665
|
});
|
|
5572
5666
|
/**
|
|
5573
|
-
*
|
|
5667
|
+
* Pre-built filter that returns a copy of the input object with all empty values removed.
|
|
5668
|
+
* Empty values include `null`, `undefined`, empty strings (`''`), empty arrays (`[]`), and empty objects (`{}`).
|
|
5574
5669
|
*
|
|
5575
|
-
* @
|
|
5576
|
-
*
|
|
5670
|
+
* @example
|
|
5671
|
+
* ```typescript
|
|
5672
|
+
* filterEmptyPojoValues({ a: 1, b: '', c: [], d: null, e: 'hello' });
|
|
5673
|
+
* // { a: 1, e: 'hello' }
|
|
5674
|
+
* ```
|
|
5577
5675
|
*/ var filterEmptyPojoValues = filterFromPOJOFunction({
|
|
5578
5676
|
copy: true,
|
|
5579
5677
|
filter: {
|
|
@@ -5581,10 +5679,14 @@ function mergeObjectsFunction(filter) {
|
|
|
5581
5679
|
}
|
|
5582
5680
|
});
|
|
5583
5681
|
/**
|
|
5584
|
-
*
|
|
5682
|
+
* Pre-built filter that returns a copy of the input object with all falsy and empty values removed.
|
|
5683
|
+
* Removes `null`, `undefined`, `0`, `false`, `''`, empty arrays, and empty objects.
|
|
5585
5684
|
*
|
|
5586
|
-
* @
|
|
5587
|
-
*
|
|
5685
|
+
* @example
|
|
5686
|
+
* ```typescript
|
|
5687
|
+
* filterFalsyAndEmptyValues({ a: 1, b: false, c: 0, d: '', e: 'hello' });
|
|
5688
|
+
* // { a: 1, e: 'hello' }
|
|
5689
|
+
* ```
|
|
5588
5690
|
*/ var filterFalsyAndEmptyValues = filterFromPOJOFunction({
|
|
5589
5691
|
copy: true,
|
|
5590
5692
|
filter: {
|
|
@@ -5592,40 +5694,76 @@ function mergeObjectsFunction(filter) {
|
|
|
5592
5694
|
}
|
|
5593
5695
|
});
|
|
5594
5696
|
/**
|
|
5595
|
-
*
|
|
5697
|
+
* Pre-built function that returns all keys from a POJO whose values are not `undefined`.
|
|
5698
|
+
* Keys with `null` or other falsy values are included in the result.
|
|
5596
5699
|
*
|
|
5597
|
-
* @
|
|
5598
|
-
*
|
|
5700
|
+
* @example
|
|
5701
|
+
* ```typescript
|
|
5702
|
+
* allNonUndefinedKeys({ a: 'test', b: undefined, c: null, d: 0 });
|
|
5703
|
+
* // ['a', 'c', 'd']
|
|
5704
|
+
* ```
|
|
5599
5705
|
*/ var allNonUndefinedKeys = findPOJOKeysFunction({
|
|
5600
5706
|
valueFilter: KeyValueTypleValueFilter.UNDEFINED
|
|
5601
5707
|
});
|
|
5602
5708
|
/**
|
|
5603
|
-
*
|
|
5709
|
+
* Pre-built function that returns all keys from a POJO whose values are not falsy or empty.
|
|
5710
|
+
* Excludes keys with `null`, `undefined`, `0`, `false`, `''`, empty arrays, or empty objects.
|
|
5604
5711
|
*
|
|
5605
|
-
* @
|
|
5606
|
-
*
|
|
5712
|
+
* @example
|
|
5713
|
+
* ```typescript
|
|
5714
|
+
* allFalsyOrEmptyKeys({ a: 'test', b: false, c: 0, d: null });
|
|
5715
|
+
* // ['a']
|
|
5716
|
+
* ```
|
|
5607
5717
|
*/ var allFalsyOrEmptyKeys = findPOJOKeysFunction({
|
|
5608
5718
|
valueFilter: KeyValueTypleValueFilter.FALSY_AND_EMPTY
|
|
5609
5719
|
});
|
|
5610
5720
|
/**
|
|
5611
|
-
*
|
|
5721
|
+
* Pre-built function that returns all keys from a POJO whose values are not `null` or `undefined`.
|
|
5722
|
+
* Keys with other falsy values (0, false, '') are included.
|
|
5612
5723
|
*
|
|
5613
|
-
* @
|
|
5614
|
-
*
|
|
5724
|
+
* @example
|
|
5725
|
+
* ```typescript
|
|
5726
|
+
* allMaybeSoKeys({ a: 'test', b: undefined, c: null, d: 0 });
|
|
5727
|
+
* // ['a', 'd']
|
|
5728
|
+
* ```
|
|
5615
5729
|
*/ var allMaybeSoKeys = findPOJOKeysFunction({
|
|
5616
5730
|
valueFilter: KeyValueTypleValueFilter.NULL
|
|
5617
5731
|
});
|
|
5618
5732
|
// MARK: FindPOJOKeys
|
|
5619
5733
|
/**
|
|
5620
|
-
* Finds keys from the POJO
|
|
5734
|
+
* Finds and returns keys from the POJO whose values pass the given filter.
|
|
5621
5735
|
*
|
|
5622
|
-
*
|
|
5623
|
-
*
|
|
5624
|
-
*
|
|
5736
|
+
* The filter determines which values are considered "matching" — matched values have their keys included in the result.
|
|
5737
|
+
* For example, using `KeyValueTypleValueFilter.UNDEFINED` returns all keys whose values are NOT `undefined`.
|
|
5738
|
+
*
|
|
5739
|
+
* @param obj - The object to inspect.
|
|
5740
|
+
* @param filter - A {@link FilterKeyValueTuplesInput} controlling which key/value pairs match. Required (no default).
|
|
5741
|
+
* @returns Array of keys whose values pass the filter.
|
|
5742
|
+
*
|
|
5743
|
+
* @example
|
|
5744
|
+
* ```typescript
|
|
5745
|
+
* findPOJOKeys({ a: 1, b: undefined, c: null }, KeyValueTypleValueFilter.NULL);
|
|
5746
|
+
* // ['a'] — only 'a' has a non-null, non-undefined value
|
|
5747
|
+
* ```
|
|
5625
5748
|
*/ function findPOJOKeys(obj, filter) {
|
|
5626
5749
|
return findPOJOKeysFunction(filter)(obj);
|
|
5627
5750
|
}
|
|
5628
|
-
|
|
5751
|
+
/**
|
|
5752
|
+
* Creates a reusable {@link FindPOJOKeysFunction} with a pre-configured filter.
|
|
5753
|
+
*
|
|
5754
|
+
* The returned function inspects each key/value pair on the input object and collects keys
|
|
5755
|
+
* whose values pass the filter.
|
|
5756
|
+
*
|
|
5757
|
+
* @param filter - A {@link FilterKeyValueTuplesInput} controlling which values match. Required (no default).
|
|
5758
|
+
* @returns A reusable function that returns matching keys from any input object.
|
|
5759
|
+
*
|
|
5760
|
+
* @example
|
|
5761
|
+
* ```typescript
|
|
5762
|
+
* const findDefinedKeys = findPOJOKeysFunction(KeyValueTypleValueFilter.UNDEFINED);
|
|
5763
|
+
* findDefinedKeys({ a: 1, b: undefined, c: 'hello' });
|
|
5764
|
+
* // ['a', 'c']
|
|
5765
|
+
* ```
|
|
5766
|
+
*/ function findPOJOKeysFunction(filter) {
|
|
5629
5767
|
var findEachMatchingKeyOnTarget = forEachKeyValueOnPOJOFunction({
|
|
5630
5768
|
filter: filter,
|
|
5631
5769
|
forEach: function forEach(param, i, obj, context) {
|
|
@@ -5643,16 +5781,41 @@ function findPOJOKeysFunction(filter) {
|
|
|
5643
5781
|
}
|
|
5644
5782
|
// MARK: CountPOJOKeys
|
|
5645
5783
|
/**
|
|
5646
|
-
*
|
|
5784
|
+
* Counts the number of keys on the POJO whose values pass the given filter.
|
|
5647
5785
|
*
|
|
5648
|
-
*
|
|
5649
|
-
*
|
|
5650
|
-
* @
|
|
5786
|
+
* By default, counts all keys whose values are not `undefined` (`KeyValueTypleValueFilter.UNDEFINED`).
|
|
5787
|
+
*
|
|
5788
|
+
* @param obj - The object to inspect.
|
|
5789
|
+
* @param filter - A {@link FilterKeyValueTuplesInput} controlling which values are counted. Defaults to `KeyValueTypleValueFilter.UNDEFINED`.
|
|
5790
|
+
* @returns The number of keys whose values pass the filter.
|
|
5791
|
+
*
|
|
5792
|
+
* @example
|
|
5793
|
+
* ```typescript
|
|
5794
|
+
* countPOJOKeys({ a: 1, b: undefined, c: null });
|
|
5795
|
+
* // 2 — 'a' and 'c' are not undefined
|
|
5796
|
+
*
|
|
5797
|
+
* countPOJOKeys({ a: 1, b: undefined, c: null }, KeyValueTypleValueFilter.NULL);
|
|
5798
|
+
* // 1 — only 'a' is not null or undefined
|
|
5799
|
+
* ```
|
|
5651
5800
|
*/ function countPOJOKeys(obj) {
|
|
5652
5801
|
var filter = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : KeyValueTypleValueFilter.UNDEFINED;
|
|
5653
5802
|
return countPOJOKeysFunction(filter)(obj);
|
|
5654
5803
|
}
|
|
5655
|
-
|
|
5804
|
+
/**
|
|
5805
|
+
* Creates a reusable {@link CountPOJOKeysFunction} with a pre-configured filter.
|
|
5806
|
+
*
|
|
5807
|
+
* By default, counts all keys whose values are not `undefined` (`KeyValueTypleValueFilter.UNDEFINED`).
|
|
5808
|
+
*
|
|
5809
|
+
* @param filter - A {@link FilterKeyValueTuplesInput} controlling which values are counted. Defaults to `KeyValueTypleValueFilter.UNDEFINED`.
|
|
5810
|
+
* @returns A reusable function that counts matching keys on any input object.
|
|
5811
|
+
*
|
|
5812
|
+
* @example
|
|
5813
|
+
* ```typescript
|
|
5814
|
+
* const countDefined = countPOJOKeysFunction();
|
|
5815
|
+
* countDefined({ a: 1, b: undefined, c: 'test' });
|
|
5816
|
+
* // 2
|
|
5817
|
+
* ```
|
|
5818
|
+
*/ function countPOJOKeysFunction() {
|
|
5656
5819
|
var filter = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : KeyValueTypleValueFilter.UNDEFINED;
|
|
5657
5820
|
var countEachMatchingKeyOnTarget = forEachKeyValueOnPOJOFunction({
|
|
5658
5821
|
filter: filter,
|
|
@@ -5669,15 +5832,53 @@ function countPOJOKeysFunction() {
|
|
|
5669
5832
|
};
|
|
5670
5833
|
}
|
|
5671
5834
|
/**
|
|
5672
|
-
* Removes values
|
|
5835
|
+
* Removes values from the input object based on the filter configuration.
|
|
5836
|
+
*
|
|
5837
|
+
* By default, removes `undefined` values and does NOT copy the object (mutates in place).
|
|
5838
|
+
* Pass `{ copy: true }` to get a new object without modifying the original.
|
|
5673
5839
|
*
|
|
5674
|
-
* @param obj POJO to
|
|
5675
|
-
* @param
|
|
5840
|
+
* @param obj - The POJO to filter values from.
|
|
5841
|
+
* @param config - Configuration for filtering and copying behavior. Defaults to removing `undefined` values without copying.
|
|
5842
|
+
* @returns The filtered object (either the mutated original or a shallow copy, depending on `config.copy`).
|
|
5843
|
+
*
|
|
5844
|
+
* @example
|
|
5845
|
+
* ```typescript
|
|
5846
|
+
* // Remove undefined values (default):
|
|
5847
|
+
* filterFromPOJO({ a: 1, b: undefined, c: 'hello' });
|
|
5848
|
+
* // { a: 1, c: 'hello' }
|
|
5849
|
+
*
|
|
5850
|
+
* // Remove null and undefined values:
|
|
5851
|
+
* filterFromPOJO({ a: 1, b: null, c: undefined }, { filter: { valueFilter: KeyValueTypleValueFilter.NULL } });
|
|
5852
|
+
* // { a: 1 }
|
|
5853
|
+
* ```
|
|
5676
5854
|
*/ function filterFromPOJO(obj) {
|
|
5677
5855
|
var config = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
5678
5856
|
return filterFromPOJOFunction(config)(obj);
|
|
5679
5857
|
}
|
|
5680
|
-
|
|
5858
|
+
/**
|
|
5859
|
+
* Creates a reusable {@link FilterFromPOJOFunction} with a pre-configured filter and copy behavior.
|
|
5860
|
+
*
|
|
5861
|
+
* The returned function removes key/value pairs that match the filter from the input object.
|
|
5862
|
+
* Internally, the filter is inverted so that matching values are deleted while non-matching values are retained.
|
|
5863
|
+
*
|
|
5864
|
+
* By default, removes `undefined` values (`KeyValueTypleValueFilter.UNDEFINED`) and does not copy (`copy: false`).
|
|
5865
|
+
*
|
|
5866
|
+
* @param config - Configuration for filtering and copying. Defaults to `{ copy: false, filter: { valueFilter: KeyValueTypleValueFilter.UNDEFINED } }`.
|
|
5867
|
+
* @returns A reusable filter function. The returned function also accepts a `copyOverride` argument to override the copy behavior per-call.
|
|
5868
|
+
*
|
|
5869
|
+
* @example
|
|
5870
|
+
* ```typescript
|
|
5871
|
+
* // Default: removes undefined values, mutates in place
|
|
5872
|
+
* const filterUndef = filterFromPOJOFunction();
|
|
5873
|
+
* const obj = { a: 1, b: undefined };
|
|
5874
|
+
* filterUndef(obj); // obj is now { a: 1 }
|
|
5875
|
+
*
|
|
5876
|
+
* // With copy and null filter:
|
|
5877
|
+
* const filterNulls = filterFromPOJOFunction({ copy: true, filter: { valueFilter: KeyValueTypleValueFilter.NULL } });
|
|
5878
|
+
* const result = filterNulls({ a: 1, b: null, c: undefined });
|
|
5879
|
+
* // result is { a: 1 }, original is unchanged
|
|
5880
|
+
* ```
|
|
5881
|
+
*/ function filterFromPOJOFunction() {
|
|
5681
5882
|
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref_copy = _ref.copy, copy = _ref_copy === void 0 ? false : _ref_copy, tmp = _ref.filter, inputFilter = tmp === void 0 ? {
|
|
5682
5883
|
valueFilter: KeyValueTypleValueFilter.UNDEFINED
|
|
5683
5884
|
} : tmp;
|
|
@@ -5700,19 +5901,60 @@ function filterFromPOJOFunction() {
|
|
|
5700
5901
|
};
|
|
5701
5902
|
}
|
|
5702
5903
|
/**
|
|
5703
|
-
*
|
|
5904
|
+
* Pre-built {@link FilterFromPOJOFunction} that removes `undefined` values by mutating the input object (no copy).
|
|
5905
|
+
*
|
|
5906
|
+
* Used internally as the default filter for {@link overrideInObjectFunctionFactory} when no filter is provided.
|
|
5907
|
+
*
|
|
5908
|
+
* @example
|
|
5909
|
+
* ```typescript
|
|
5910
|
+
* const obj = { a: 1, b: undefined };
|
|
5911
|
+
* defaultFilterFromPOJOFunctionNoCopy(obj);
|
|
5912
|
+
* // obj is now { a: 1 }
|
|
5913
|
+
* ```
|
|
5704
5914
|
*/ var defaultFilterFromPOJOFunctionNoCopy = filterFromPOJOFunction({
|
|
5705
5915
|
copy: false
|
|
5706
5916
|
});
|
|
5707
5917
|
// MARK: AssignValuesToPOJO
|
|
5708
|
-
|
|
5918
|
+
/**
|
|
5919
|
+
* Assigns filtered values from `obj` onto `target`.
|
|
5920
|
+
*
|
|
5921
|
+
* By default, only non-`undefined` values from `obj` are assigned, and a copy of `target` is returned (the original is not mutated).
|
|
5922
|
+
*
|
|
5923
|
+
* @param target - The object to assign values onto.
|
|
5924
|
+
* @param obj - The source object whose matching values will be assigned.
|
|
5925
|
+
* @param input - Optional filter/copy configuration. Defaults to `KeyValueTypleValueFilter.UNDEFINED` with `copy: true`.
|
|
5926
|
+
* @returns The target with values assigned (either a copy or the original, depending on configuration).
|
|
5927
|
+
*
|
|
5928
|
+
* @example
|
|
5929
|
+
* ```typescript
|
|
5930
|
+
* const target = { a: 1, b: 2 };
|
|
5931
|
+
* const result = assignValuesToPOJO(target, { a: 10, b: undefined });
|
|
5932
|
+
* // result is { a: 10, b: 2 } (copy), target unchanged
|
|
5933
|
+
* ```
|
|
5934
|
+
*/ function assignValuesToPOJO(target, obj, input) {
|
|
5709
5935
|
return assignValuesToPOJOFunction(input)(target, obj);
|
|
5710
5936
|
}
|
|
5711
5937
|
/**
|
|
5712
|
-
* Creates a AssignValuesToPOJOFunction
|
|
5938
|
+
* Creates a reusable {@link AssignValuesToPOJOFunction} with a pre-configured filter and copy behavior.
|
|
5713
5939
|
*
|
|
5714
|
-
*
|
|
5715
|
-
*
|
|
5940
|
+
* The returned function assigns key/value pairs from a source object onto a target, skipping pairs
|
|
5941
|
+
* that are filtered out. By default, `undefined` values are filtered out (`KeyValueTypleValueFilter.UNDEFINED`)
|
|
5942
|
+
* and the target is copied before assignment (`copy: true`).
|
|
5943
|
+
*
|
|
5944
|
+
* @param input - Filter and copy configuration. Defaults to `KeyValueTypleValueFilter.UNDEFINED` (filter undefined, copy target).
|
|
5945
|
+
* @returns A reusable assign function with a `_returnCopyByDefault` property indicating the configured copy behavior.
|
|
5946
|
+
*
|
|
5947
|
+
* @example
|
|
5948
|
+
* ```typescript
|
|
5949
|
+
* // Default: filters undefined, returns a copy
|
|
5950
|
+
* const assign = assignValuesToPOJOFunction();
|
|
5951
|
+
* const target = { a: 1, b: 2 };
|
|
5952
|
+
* const result = assign(target, { a: 10, b: undefined });
|
|
5953
|
+
* // result is { a: 10, b: 2 }, target is unchanged
|
|
5954
|
+
*
|
|
5955
|
+
* // With NULL filter and no copy:
|
|
5956
|
+
* const assignNoNulls = assignValuesToPOJOFunction({ valueFilter: KeyValueTypleValueFilter.NULL, copy: false });
|
|
5957
|
+
* ```
|
|
5716
5958
|
*/ function assignValuesToPOJOFunction() {
|
|
5717
5959
|
var input = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : KeyValueTypleValueFilter.UNDEFINED;
|
|
5718
5960
|
var _ref;
|
|
@@ -5736,12 +5978,48 @@ function assignValuesToPOJO(target, obj, input) {
|
|
|
5736
5978
|
}
|
|
5737
5979
|
// MARK: ValuesFromPOJO
|
|
5738
5980
|
/**
|
|
5739
|
-
*
|
|
5981
|
+
* Extracts values from the POJO whose key/value pairs pass the given filter, returning them as an array.
|
|
5982
|
+
*
|
|
5983
|
+
* By default, only non-`undefined` values are included (`KeyValueTypleValueFilter.UNDEFINED`).
|
|
5984
|
+
*
|
|
5985
|
+
* @param target - The object to extract values from.
|
|
5986
|
+
* @param filter - A {@link FilterKeyValueTuplesInput} controlling which values are included. Defaults to `KeyValueTypleValueFilter.UNDEFINED`.
|
|
5987
|
+
* @returns Array of values whose key/value pairs passed the filter.
|
|
5988
|
+
*
|
|
5989
|
+
* @example
|
|
5990
|
+
* ```typescript
|
|
5991
|
+
* valuesFromPOJO({ a: 1, b: undefined, c: 'hello' });
|
|
5992
|
+
* // [1, 'hello']
|
|
5993
|
+
*
|
|
5994
|
+
* valuesFromPOJO({ a: 1, b: null, c: 'hello' }, KeyValueTypleValueFilter.NULL);
|
|
5995
|
+
* // [1, 'hello'] — null excluded
|
|
5996
|
+
* ```
|
|
5740
5997
|
*/ function valuesFromPOJO(target) {
|
|
5741
5998
|
var filter = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : KeyValueTypleValueFilter.UNDEFINED;
|
|
5742
5999
|
return valuesFromPOJOFunction(filter)(target);
|
|
5743
6000
|
}
|
|
5744
|
-
|
|
6001
|
+
/**
|
|
6002
|
+
* Creates a reusable {@link ValuesFromPOJOFunction} with a pre-configured filter.
|
|
6003
|
+
*
|
|
6004
|
+
* The returned function iterates each key/value pair on the input object, collects values
|
|
6005
|
+
* from pairs that pass the filter, and returns them as an array.
|
|
6006
|
+
*
|
|
6007
|
+
* By default, only non-`undefined` values are included (`KeyValueTypleValueFilter.UNDEFINED`).
|
|
6008
|
+
*
|
|
6009
|
+
* @param filter - A {@link FilterKeyValueTuplesInput} controlling which values are included. Defaults to `KeyValueTypleValueFilter.UNDEFINED`.
|
|
6010
|
+
* @returns A reusable function that extracts matching values from any input object.
|
|
6011
|
+
*
|
|
6012
|
+
* @example
|
|
6013
|
+
* ```typescript
|
|
6014
|
+
* const getDefinedValues = valuesFromPOJOFunction();
|
|
6015
|
+
* getDefinedValues({ a: 1, b: undefined, c: 'test' });
|
|
6016
|
+
* // [1, 'test']
|
|
6017
|
+
*
|
|
6018
|
+
* const getNonNullValues = valuesFromPOJOFunction(KeyValueTypleValueFilter.NULL);
|
|
6019
|
+
* getNonNullValues({ a: 1, b: null, c: undefined });
|
|
6020
|
+
* // [1]
|
|
6021
|
+
* ```
|
|
6022
|
+
*/ function valuesFromPOJOFunction() {
|
|
5745
6023
|
var filter = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : KeyValueTypleValueFilter.UNDEFINED;
|
|
5746
6024
|
var addValuesFromObjectToContext = forEachKeyValueOnPOJOFunction({
|
|
5747
6025
|
filter: filter,
|
|
@@ -5760,10 +6038,25 @@ function valuesFromPOJOFunction() {
|
|
|
5760
6038
|
}
|
|
5761
6039
|
// MARK: Filter Keys
|
|
5762
6040
|
/**
|
|
5763
|
-
*
|
|
6041
|
+
* Creates a {@link FilterTuplesOnPOJOFunction} that retains only keys present in `keysToFilter`,
|
|
6042
|
+
* or excludes them if `invertFilter` is `true`.
|
|
5764
6043
|
*
|
|
5765
|
-
*
|
|
5766
|
-
*
|
|
6044
|
+
* Always returns a new object (never mutates the input).
|
|
6045
|
+
*
|
|
6046
|
+
* @param keysToFilter - The set of keys to include (or exclude when inverted).
|
|
6047
|
+
* @param invertFilter - When `true`, keys in `keysToFilter` are excluded instead of included. Defaults to `false`.
|
|
6048
|
+
* @returns A function that filters keys on any input POJO.
|
|
6049
|
+
*
|
|
6050
|
+
* @example
|
|
6051
|
+
* ```typescript
|
|
6052
|
+
* const pickAB = filterKeysOnPOJOFunction(['a', 'b']);
|
|
6053
|
+
* pickAB({ a: 1, b: 2, c: 3 });
|
|
6054
|
+
* // { a: 1, b: 2 }
|
|
6055
|
+
*
|
|
6056
|
+
* const omitAB = filterKeysOnPOJOFunction(['a', 'b'], true);
|
|
6057
|
+
* omitAB({ a: 1, b: 2, c: 3 });
|
|
6058
|
+
* // { c: 3 }
|
|
6059
|
+
* ```
|
|
5767
6060
|
*/ function filterKeysOnPOJOFunction(keysToFilter) {
|
|
5768
6061
|
var invertFilter = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
5769
6062
|
var keysSet = new Set(keysToFilter);
|
|
@@ -5773,7 +6066,22 @@ function valuesFromPOJOFunction() {
|
|
|
5773
6066
|
}, invertFilter);
|
|
5774
6067
|
return filterTuplesOnPOJOFunction(filterFn);
|
|
5775
6068
|
}
|
|
5776
|
-
|
|
6069
|
+
/**
|
|
6070
|
+
* Creates a {@link FilterTuplesOnPOJOFunction} from a raw entry filter predicate.
|
|
6071
|
+
*
|
|
6072
|
+
* The returned function iterates all entries of the input object, applies the predicate,
|
|
6073
|
+
* and returns a new object containing only the entries that pass.
|
|
6074
|
+
*
|
|
6075
|
+
* @param filterTupleOnObject - Predicate applied to each `[key, value]` entry.
|
|
6076
|
+
* @returns A function that filters entries on any input POJO.
|
|
6077
|
+
*
|
|
6078
|
+
* @example
|
|
6079
|
+
* ```typescript
|
|
6080
|
+
* const keepStrings = filterTuplesOnPOJOFunction(([, value]) => typeof value === 'string');
|
|
6081
|
+
* keepStrings({ a: 'hello', b: 42, c: 'world' });
|
|
6082
|
+
* // { a: 'hello', c: 'world' }
|
|
6083
|
+
* ```
|
|
6084
|
+
*/ function filterTuplesOnPOJOFunction(filterTupleOnObject) {
|
|
5777
6085
|
return function(input) {
|
|
5778
6086
|
var result = {};
|
|
5779
6087
|
Object.entries(input).filter(filterTupleOnObject).forEach(function(tuple) {
|
|
@@ -5782,7 +6090,28 @@ function filterTuplesOnPOJOFunction(filterTupleOnObject) {
|
|
|
5782
6090
|
return result;
|
|
5783
6091
|
};
|
|
5784
6092
|
}
|
|
5785
|
-
|
|
6093
|
+
/**
|
|
6094
|
+
* Creates a reusable function that iterates over filtered key/value pairs of a POJO,
|
|
6095
|
+
* invoking a callback for each matching pair.
|
|
6096
|
+
*
|
|
6097
|
+
* This is the low-level building block used by {@link filterFromPOJOFunction}, {@link findPOJOKeysFunction},
|
|
6098
|
+
* {@link countPOJOKeysFunction}, {@link assignValuesToPOJOFunction}, and {@link valuesFromPOJOFunction}.
|
|
6099
|
+
*
|
|
6100
|
+
* When no filter is provided, all key/value pairs are iterated.
|
|
6101
|
+
*
|
|
6102
|
+
* @param config - The filter and forEach callback configuration.
|
|
6103
|
+
* @returns A function that iterates matching key/value pairs on any input object.
|
|
6104
|
+
*
|
|
6105
|
+
* @example
|
|
6106
|
+
* ```typescript
|
|
6107
|
+
* const logDefined = forEachKeyValueOnPOJOFunction<Record<string, unknown>, void>({
|
|
6108
|
+
* filter: KeyValueTypleValueFilter.UNDEFINED,
|
|
6109
|
+
* forEach: ([key, value]) => console.log(key, value)
|
|
6110
|
+
* });
|
|
6111
|
+
* logDefined({ a: 1, b: undefined, c: 'test' });
|
|
6112
|
+
* // logs: 'a' 1, 'c' 'test'
|
|
6113
|
+
* ```
|
|
6114
|
+
*/ function forEachKeyValueOnPOJOFunction(param) {
|
|
5786
6115
|
var forEach = param.forEach, filter = param.filter;
|
|
5787
6116
|
var filterKeyValues = filterKeyValueTuplesFunction(filter);
|
|
5788
6117
|
return function(obj, context) {
|