Comparing version 0.49.0 to 0.50.0
@@ -1235,4 +1235,32 @@ /** | ||
/** | ||
* Pick returns a new object composed from the selected object properties. | ||
* | ||
* @param {object} object input object | ||
* @param {...(string|string[])} paths paths names of properties to be returned from an object | ||
* @returns {object} object with selected properties | ||
* | ||
* @example | ||
* const result = Objects.pick({ a: 'mixed', b34: 'toast', 45: 'pasta' }, 'a', 45); | ||
* console.log(result); | ||
* > { 45: 'pasta', a: 'mixed' } | ||
*/ | ||
function pick (object, ...paths) { | ||
if (paths.length === 0) { return {}; } | ||
const args = new Set(); | ||
if (Array.isArray(paths[0])) { | ||
paths[0].forEach(val => args.add(String(val))); | ||
} else { | ||
paths.forEach(val => args.add(String(val))); | ||
} | ||
return Object.keys(object).reduce((acc, curr) => { | ||
if (args.has(curr)) { acc[curr] = object[curr]; } | ||
return acc; | ||
}, {}); | ||
} | ||
var index$2 = /*#__PURE__*/Object.freeze({ | ||
@@ -1243,5 +1271,6 @@ __proto__: null, | ||
invert: invert, | ||
keys: keys | ||
keys: keys, | ||
pick: pick | ||
}); | ||
export { index as arrays, index$2 as objects, index$1 as strings }; |
{ | ||
"name": "absurdum", | ||
"version": "0.49.0", | ||
"version": "0.50.0", | ||
"description": "Reductio Ad Absurdum - The Ridiculous Application of Reduce", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -121,2 +121,3 @@ [![GitHub Releases](https://img.shields.io/github/release/vanillaes/absurdum.svg)](https://github.com/vanillaes/absurdum/releases) | ||
- [keys][objects.keys] | ||
- [pick][objects.pick] | ||
@@ -127,2 +128,3 @@ [objects.exclude]: ./docs/objects/exclude.md | ||
[objects.keys]: ./docs/objects/keys.md | ||
[objects.pick]: ./docs/objects/pick.md | ||
@@ -129,0 +131,0 @@ ### Strings |
export { exclude } from "./exclude.js"; | ||
export { include } from "./include.js"; | ||
export { invert } from "./invert.js"; | ||
export { keys } from "./keys.js"; | ||
export { keys } from "./keys.js"; | ||
export { pick} from "./pick.js"; |
export { exclude } from './exclude.js'; | ||
export { include } from './include.js'; | ||
export { invert } from './invert.js'; | ||
export { keys } from './keys.js'; | ||
export { keys } from './keys.js'; | ||
export { pick } from './pick.js'; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
173829
151
4390
158