sindresorhus / is

Type check values

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ESM conversion plan: what exports?

fregante opened this issue · comments

What will this module export as a ESM? Will it still be a single default object like it is now or will it export isUndefined and the like?

It could potentially use both:

export function isUndefined(){}
const is = {
  undefined: isUndefined
}
export default is;

I support the sibling approach as you've outlined: exporting both the individual named exports and a comprehensive default object give consumers flexibility. This will allow for both of the following:

import * as is from '@sindresorhus/is'
is.isUndefined(undefined)

// also

import { isUndefined } from '@sindreshorus/is'
isUndefined(undefined)

Neither example uses the default export. Did you mean import is from in the first line?

I was planning on a default export. I don't really see the benefit of named exports. It becomes very boilerplaty having to import every method and it won't really benefit tree-shaking anyway.

I could allow both, but I prefer having only one way to do something, for consistency.

it won't really benefit tree-shaking anyway

Sure it would? import {isUndefined} from '@sindresorhus/is' would definitely treeshake everything else

Hmm. I haven't really seen tree-shaking work in practice, but I guess it will be a common request.

I usually prefer having only a single way to do something, but it would be nice to preserve backwards-compatibility and have a nicer API for apps that don't need tree-shaking (servers and CLIs).

So the assert API would be import {assertUndefined} from '@sindresorhus/is'.

Alright. Let's do both.

Does this job ad still exist? I can finish it. @sindresorhus


Before that I would like to talk to you about api that we have everywhere, does it have to start with assert? Or do you have a new idea?

My personal preference:

import { assertUndefined, assertAny, assertString } from '@sindresorhus/is'

is has fewer characters than assert, but assertUndefined is better because it conveys more clearly what the function does: assert whether a value is undefined or not. The naming of isUndefined, on the other hand, makes it easier to think of it as a function that returns a boolean value to indicate whether a value is undefined or not.