deno_std
deno_std copied to clipboard
Question: value type check functions
Is your feature request related to a problem? Please describe.
There are lots of type check functions in std (isBoolean(), isObject(), isString() etc). As of now, each module implements its own functions (isObject() is implemented in assert/object_match.ts, expect/_utils.ts, yaml/utils.ts for example).
I wonder if we should gather them in @std/internal or even make them public in another mod.
Describe the solution you'd like
Put all type check functions at the same place which all std mods import them.
Describe alternatives you've considered
Leave as is. There is the danger that once we have some type check functions, then we should provide all of them and over-engineer simple checks. lodash provides lots of checks which might not be necessary.
I'm not in favor of having isBoolean or isString (even as internal utils). Inline expressions typeof val === "string" and typeof val === "boolean" should be better than having utils.
I agree, though these functions do a bit more, they also check against Boolean and String object instances respectively.
How about checking if a value is generated by object literal? Writing typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype is quite tedious.