-
-
Notifications
You must be signed in to change notification settings - Fork 903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add export const uuid = v4 #540
Comments
Type |
@broofa then a developer would have hard to remember what function with So why not implement naming that would be more developer-friendly by default? |
Thank you for raising this @syabro I do have to admit that personally I'm also not super happy with the current named exports. They have mostly historic reasons:
The reason we kept the I do admit though that in the ESM world we live in by now requiring aliasing when importing one of the algorithms is really not ideal and at least I didn't really consider that aspect enough when doing the migration to ESM. All that said I believe this might be a good chance to get rid of the confusing So instead of sticking to these names I suggest to export the algorithms with more telling names, like discussed in tc39/proposal-uuid#3 (comment). Something like:
An alternative would obviously be to export Thoughts? |
@ctavan thanks for clarifying.
PS As soon it's not default export I will be happy to see it :) |
"There are only two hard things in Computer Science: cache invalidation and naming things" I suspect this is exactly what Phil Karlton had in mind with the latter part of that quote. There's no clearly "right" naming scheme here. Developers are going to have to remember what the name is regardless of what we choose. The current scheme at least has the advantage of not having to remember how UUID/uuid/Uuid/UUId is capitalized. 😝 I don't see the "more harm than good" you mention of the current scheme.... at least not to an extent that warrants (again) breaking the API for M's of users. My vote? Stick with the current scheme until there's broader consensus on what the names should be. I.e. Wait until the standard uuid work settles out, and then go with whatever API scheme is decided there. |
I've always known that one as: "There are only two hard things in Computer Science: cache invalidation, naming things, and off by one errors" 😄
I'm leaning towards this also, even if I also feel the frustration every time I import the function. If we change to something like |
This is great PR, for god sake why I would always name function before importing it. Just name it uuidv4. uuidStringify and so on. |
Angular compilation warning: |
@gizm0bill This is not related issue. Please create new one if there is a bug. |
Actually it is... |
@gizm0bill From the warning it looks like you use some very old version without es modules support. |
FYI, you can just do this: import * as uuid from 'uuid';
uuid.v4() I quite like this syntax, actually. I think it should be recommended in the README. The main caveat is that, last I checked, treeshaking generally doesn't work when importing the whole namespace. I don't personally feel that matters too much here, though. |
@sholladay rollup and webpack 5 does not have the problem with namespaces. They are expanded into named imports unless used as value. |
@sholladay writing it manually is the same as |
Sort of, @syabro. It's the same in that I showed an alternative way to use the It could be simplified further by attaching the functions as properties of the default export object. Then you'd be able to do this: import uuid from 'uuid';
uuid.v4(); That would be the cleanest syntax. |
Marking as stale due to 90 days with no activity. |
Closing issue due to 30 days since being marked as stale. |
Is your feature request related to a problem? Please describe.
For all libraries I use I don't have to write imports manually in WebStorm. All I have to do just write code like
const x = doSomething<ALT + Enter>
and it shows me hintAdd "import doSomething from XXX'?
With
export const v4
I have to write manually import as in manualimport { v4 as uuidv4 } from 'uuid';
. It's frustrating.Describe the solution you'd like
Change
v4()
name or add one more export asexport const uuid4
. So after import it would be very clear what is it about and why.Describe alternatives you've considered
utils/uuid.ts
withThe text was updated successfully, but these errors were encountered: