sindresorhus / ow

Function argument validation for humans
https://sindresorhus.com/ow/
MIT License
3.8k stars 105 forks source link

Do not use `type-fest` #218

Closed szmarczak closed 1 year ago

szmarczak commented 3 years ago

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.

szmarczak commented 3 years 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
sindresorhus commented 3 years ago

PR welcome. Note that the dot prop implementation has some checks to prevent prototype pollution.

szmarczak commented 3 years ago

This might be ambiguous:

dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot');

It can be foo.dot\\ + dot or foo.dot + \\dot.

Edit: let's leave dot-prop to be more consistent.