Comparing version 0.58.0 to 0.59.0
@@ -1340,2 +1340,39 @@ /** | ||
/** | ||
* Has, creates an array of values corresponding to paths of the object | ||
* | ||
* @param {object} object input object | ||
* @param {Array|string} path strings describing paths to be returned from an object | ||
* @returns {boolean} boolean true is a direct property of the object | ||
* | ||
* @example | ||
* const result = objects.has({ front: [1, 3, 5], back: [37, 39] }); | ||
* console.log(result, 'back[1]'); | ||
* > true | ||
* | ||
* @example | ||
* const result = objects.has({ front: [1, 3, 5], back: [37, 39] }); | ||
* console.log(result, ['front', 1]); | ||
* > true | ||
*/ | ||
function has (object, path) { | ||
if (typeof path === 'undefined') { return false; } | ||
let pathArray; | ||
if (Array.isArray(path)) { | ||
pathArray = path; | ||
} else { | ||
pathArray = String(path).replace(/\[(\w+)\]/g, '.$1').split('.'); | ||
} | ||
return undefined !== pathArray.reduce((result, search) => { | ||
if (result === undefined) { return undefined; } | ||
if (Object.prototype.hasOwnProperty.call(result, search)) { | ||
return result[search]; | ||
} else { | ||
return undefined; | ||
} | ||
}, object); | ||
} | ||
/** | ||
* Include filters elements in a new object based on an array of keys to include | ||
@@ -1530,2 +1567,3 @@ * | ||
findKey: findKey, | ||
has: has, | ||
include: include, | ||
@@ -1532,0 +1570,0 @@ invert: invert, |
{ | ||
"name": "absurdum", | ||
"version": "0.58.0", | ||
"version": "0.59.0", | ||
"description": "Reductio Ad Absurdum - The Ridiculous Application of Reduce", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -136,2 +136,3 @@ [![GitHub Releases](https://img.shields.io/github/release/vanillaes/absurdum.svg)](https://github.com/vanillaes/absurdum/releases) | ||
- [findKey][objects.findKey] | ||
- [has][objects.has] | ||
- [include][objects.include] | ||
@@ -149,2 +150,3 @@ - [invert][objects.invert] | ||
[objects.findKey]: ./docs/objects/findKey.md | ||
[objects.has]: ./docs/objects/has.md | ||
[objects.include]: ./docs/objects/include.md | ||
@@ -151,0 +153,0 @@ [objects.invert]: ./docs/objects/invert.md |
@@ -5,2 +5,3 @@ export { at } from "./at.js"; | ||
export { findKey } from "./findKey.js"; | ||
export { has } from "./has.js"; | ||
export { include } from "./include.js"; | ||
@@ -7,0 +8,0 @@ export { invert } from "./invert.js"; |
@@ -5,2 +5,3 @@ export { at } from './at.js'; | ||
export { findKey } from './findKey.js'; | ||
export { has } from './has.js'; | ||
export { include } from './include.js'; | ||
@@ -7,0 +8,0 @@ export { invert } from './invert.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
211213
175
5358
187