Closed szmarczak closed 1 year ago
Also is dot-prop
really needed?
const has = (object, dot) => {
const elements = dot.split('.');
for (const element of elements) {
if (element in object) {
object = object[element];
} else {
return false;
}
}
return true;
};
has({a: 123}, 'b'); //=> false
has({a: 123}, 'a'); //=> true
has({a: 123, foo: {bar: 'test'}}, 'foo'); //=> true
has({a: 123, foo: {bar: 'test'}}, 'foo.bar'); //=> true
has({a: 123, foo: {bar: 'test'}}, 'foo.baz'); //=> false
PR welcome. Note that the dot prop implementation has some checks to prevent prototype pollution.
https://packagephobia.com/result?p=@sindresorhus/is@4.0.1,callsites@3.1.0,dot-prop@6.0.1,lodash.isequal@4.5.0,type-fest@1.2.1,vali-date@1.0.0
Just copy and paste https://github.com/sindresorhus/type-fest/blob/main/source/typed-array.d.ts
This way we'll save 133KB. It's A LOT.