plurals / pluralize

Pluralize or singularize any word based on a count
MIT License
2.15k stars 184 forks source link

ES6 modules #171

Open tyteen4a03 opened 3 years ago

tyteen4a03 commented 3 years ago

Hi, are there any plans to migrate this module to ES6 modules?

blakeembrey commented 3 years ago

Not for the foreseeable future, no.

jarrodek commented 3 years ago

Hey @blakeembrey would you accept a PR with an ES6 module for this library? Bundles widely support ESM so it doesn't make much of a difference for them. For a direct use (including in a web app to a global scope), well, with a breaking change devs have minimal work to do to upgrade to a new major version.

blakeembrey commented 3 years ago

I'd probably release it alongside a rewrite of the library. The main thing I don't want to be doing is maintaining two versions or breaking existing node use-cases. Since all supported node versions now have ESM support, it should be easier, but it's still hard for people to migrate.

capaj commented 3 years ago

but it's still hard for people to migrate.

why would they need to migrate? If you add a module entry point to package.json and add pluralize.esm.js it will satisfy both ES6 and legacy consumers.

Of course it requires adding a build step, but that's trivial with microbundle or similar.

friday commented 3 years ago

You don't need to refactor, but you do need a build/bundle step. Just delete your module wrapper code and use rollup or something similar to bundle different versions. Reference those in package.json main, module (and web if you minify). You probably want to gitignore the folder you put them in.

The output from rollup is very clean.

silverwind commented 1 year ago

I'd be nice if the CJS exports of this module would be statically analyzeable, so things like https://github.com/nodejs/cjs-module-lexer can provide named exports when importing it in ESM.

If it would assign it's exported to module.exports, it will work in all environments. Stuff like AMD or globals (ugh) are no longer necessary in the modern JS world.