utiller 1.0.296 → 1.0.297
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/lib/utiller/index.js +19 -0
- package/package.json +1 -1
- package/template/sample.package.json +1 -1
package/lib/utiller/index.js
CHANGED
|
@@ -3377,6 +3377,25 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
3377
3377
|
return Array.from(new Set(array));
|
|
3378
3378
|
}
|
|
3379
3379
|
}
|
|
3380
|
+
|
|
3381
|
+
/**
|
|
3382
|
+
* Extract unique values of a specific key from an array of objects.
|
|
3383
|
+
* array = [ { valueOfType: 1 }, { valueOfType: 7, valueOfSubType: 6 }, { valueOfType: 1 } ];
|
|
3384
|
+
console.log(getUniqueValuesBy(array, 'valueOfType')); //[1, 7]
|
|
3385
|
+
*
|
|
3386
|
+
* @param {Array<Object>} array - The array of objects to process.
|
|
3387
|
+
* @param {string} key - The key to extract values from. Default is 'valueOfType'.
|
|
3388
|
+
* @returns {Array<any>} A deduplicated array of the extracted values.
|
|
3389
|
+
*/
|
|
3390
|
+
}, {
|
|
3391
|
+
key: "getUniqueValuesBy",
|
|
3392
|
+
value: function getUniqueValuesBy(array) {
|
|
3393
|
+
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "valueOfType";
|
|
3394
|
+
return _lodash["default"].uniq(array.map(function (item) {
|
|
3395
|
+
return item[key];
|
|
3396
|
+
}));
|
|
3397
|
+
}
|
|
3398
|
+
/* 測試資料 */
|
|
3380
3399
|
}]);
|
|
3381
3400
|
}();
|
|
3382
3401
|
var _default = exports["default"] = Utiller;
|
package/package.json
CHANGED