denoland / std

The Deno Standard Library
https://jsr.io/@std
MIT License
3.16k stars 620 forks source link

Question: value type check functions #5714

Open timreichen opened 2 months ago

timreichen commented 2 months ago

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.

kt3k commented 2 months ago

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.

timreichen commented 2 months ago

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

yuhr commented 1 month ago

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.