web4more / html-navigator

Navigator api for node.js
https://npmjs.com/package/node-navigator
MIT License
3 stars 0 forks source link

Polyfill instead of ponyfill by default #15

Open jcbhmr opened 1 year ago

jcbhmr commented 1 year ago

This is kinda a big change! 😬 I think it's a good one though! Using this as a polyfill first, but also exposing /navigator_.js (name collision with Navigator.js) and /Navigator.js as individual exports is a good idea!

For example:

// My library needs to access Navigator APIs, but I don't want to
// infect my client with a global navigator object. So, I use the ponyfill:
import navigator from "node-navigator/navigator_.js";

export const userAgent = navigator.userAgent;
// In my app, I want to use browser idiomatic code. And I also have
// a dependency that needs navigator for "reasons".
import "node-navigator";
import "dep-needs-navigator";

console.log(navigator.userAgent);
//=> 'Node/20.0.0'

There is a debate to be had over which should be the default export. I think the /ClassName.js has a very nice "fit" for individual plucking exports, whereas the default export goes where? /global.js? 🤔

@skdhg Thoughts? I'd love to hear your ideas! ❤️

jcbhmr commented 1 year ago

Don't worry about existing consumers! That's what major versions are for, remember! 😉

{
  "dependencies": {
    // Will NOT auto-install v2. Stays on v1.0.1!
    "node-navigator": "^1.0.1"
    //                 👆
    // This is the default when 'npm install node-navigator' is run:
    // The "^" caret range is vN.x.x
  }
}