Export ECMAScript modules (ESM)
While CJS continues to be an important part of the NodeJS world, it seems to be slowly moving towards ESM. I think we should export both cjs and ems.
The reason for this is so that libraries using negotiator like tinyhttp can be fully ESM. I am happy to help with a PR :)
I have created a new repository for an ESM/TS version of this package. Let me know what you think: https://github.com/colorninja/navigator-es
The branch is called ts-esm-port
Changed:
- Included lockfile (package-lock was ignored)
- Added TypeScript
- Changed package type to module
- Ported to TS
- Ensured exported types are the same or better than
@types/negotiator - Ensured exports are the same (default and named)
- Migrated tests to built-in node test module (reduce dependencies)
- very easy because already using assert built-in module
Remaining to do:
- Add backwards compatibility for CJS
- Ensure package will be published with correct files
- Improve TS types
Perhaps you should join this discussion https://github.com/expressjs/discussions/issues/297
Just want to mention that this package is also found in denoland/std's @std/http module. Header comment in these files point back to here.
Relevant files:
- https://github.com/denoland/std/blob/main/http/negotiation.ts
- https://github.com/denoland/std/blob/main/http/_negotiation/common.ts
- https://github.com/denoland/std/blob/main/http/_negotiation/encoding.ts
- https://github.com/denoland/std/blob/main/http/_negotiation/language.ts
- https://github.com/denoland/std/blob/main/http/_negotiation/media_type.ts
- https://github.com/denoland/std/blob/main/http/negotiation_test.ts