is icon indicating copy to clipboard operation
is copied to clipboard

Proposal: `is.create(URLSearchParams)`

Open szmarczak opened this issue 4 years ago • 3 comments

const isSearchParams = is.create(URLSearchParams);

is.any([is.string, isSearchParams]);

szmarczak avatar Jul 30 '21 11:07 szmarczak

Can you describe how exactly it should behave? Because you're passing in the constructor, which would mean you want a instanceof check internally, but that's not a good or portable way to check.

sindresorhus avatar Jul 30 '21 14:07 sindresorhus

that's not a good or portable way to check.

Is there a better choice? We could compare the names but that's not good either - e.g. there are many FormData implementations but they differ.

The create function returns another function. But it can have an extra feature: if used with any it will display that class name: E.g. Expected string or URLSearchParams instance, got ...

szmarczak avatar Jul 30 '21 17:07 szmarczak

Pass in a string and use https://github.com/sindresorhus/is/blob/238e8c80c7de926f62d3d0e903a257bf32667d0d/source/index.ts#L100

That's how most of the testing is done here.


Yes, we could read the name from the passed in constructor. I just fear that it will make people assume it does instance checking, which it does not.

sindresorhus avatar Jul 31 '21 10:07 sindresorhus