medikoo / type

Runtime validation and processing of JavaScript types
ISC License
35 stars 4 forks source link

`object/is` returns true for functions #1

Closed JRJurman closed 3 years ago

JRJurman commented 3 years ago

Wasn't sure if this is intentional or not, but object/is returns true and object/ensure passes when you test a function.

image

For my use case I actually need to verify that it is non-primitive, and not a function. In reality, I could understand functions being considered "non-primitive", but it looks like neither primitive-object or object cover my use case of only objects and arrays, unless I'm missing something...

medikoo commented 3 years ago

@JRJurman object/is simply confirms whether we deal with a value that's not a primitive.

If your use case is about confirming a JSON non-primitive value (so either plain object or array) it might be more accurate to refer to plain-object/is and native Array.isArray (as isPlainObject(value) || Array.isArray(value))

JRJurman commented 3 years ago

Makes sense. Thanks for the prompt answer (and the amazing library)!