deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

Question: value type check functions

Open timreichen opened this issue 1 year ago • 3 comments

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.

timreichen avatar Aug 18 '24 14:08 timreichen

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.

kt3k avatar Aug 20 '24 11:08 kt3k

I agree, though these functions do a bit more, they also check against Boolean and String object instances respectively.

timreichen avatar Aug 22 '24 10:08 timreichen

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.

yuhr avatar Sep 09 '24 19:09 yuhr