isobjvalid
v1.0.2
Published
Determine a key's existential state within an object
Downloads
3
Readme
Installation
npm install isobjvalid
Usage
const isObjValid = require("isobjvalid");
isObjValid(window, "location.href"); // true
isObjValid(window, "nothing.expected.here"); // false
isObjValid({ a: { b: "" } }, "a.b.c"); // false
isObjValid({ a: "" }, "a"); // true
const obj = {
apples: {
seeds: {
yes: "gotem"
}
},
bananas: {
seeds: false
},
canteloupe: {
seeds: {
seed: {
potential: {
canteloupe: "gotem"
}
}
}
}
};
isObjValid(obj, "apples.seeds.yes").should.be.true;
isObjValid(obj, "bananas.seeds").should.be.true;
isObjValid(obj, "canteloupe.seeds.seed.potential.canteloupe").should.be.true;