uuidjs / uuid Goto Github PK
View Code? Open in Web Editor NEWGenerate RFC-compliant UUIDs in JavaScript
License: MIT License
Generate RFC-compliant UUIDs in JavaScript
License: MIT License
Bower.json is missing in the project, you should add one.
Can I choose either license? Is there a fee associated with either license? Why dual-license with such a permissive license if there is no associated fee?
Apparently this is by design: The randomly generated node id is only guaranteed to stay constant for the lifetime of the current JS runtime. But what is the point of this? It also kind of conflicts with the description of the msec option which says: Default: The current time is used._ But apparently the current time is only used on the first call to v1 and then that uuid is cached and returned over and over on each call to v1. So now if I want to generate a fresh v1 I have to always call nodeuuid.v1({msec: new Date().getTime()})
I'm using nvm & node v0.10.30
after npm install -g node-uuid
there is no uuid link in ~/.nvm/v0.10.30/bin
neither the ~/.nvm/v0.10.30/lib/node_modules/node-uuid/bin
directory
The following commit seems like it was supposed to prevent browserify from shimming 'crypto' and Buffer:
319dc6e
But it doesn't seem to be working (at least with the latest version of browserify)
The check for module
here https://github.com/broofa/node-uuid/blob/master/uuid.js#L235 returns true since QUnit defines a module
method. This should probably check that module
is an object vs just checking that it's defined.
It would be great to have uuid's in base62/64 format for docs, urls, or for couchdb _id
npm WARN [email protected] dependencies field should be hash of <name>:<version-range> pairs
...says it all ;)
Hi,
I have been using node-uuid for a while, and it has in total generated about 500k IDs that I use. I now ran a check and found, to my surprise, 2 collisions among those IDs.
The collisions were generated in a sequence where 5-10 IDs are created synchronously and stored in the same database document. For one of the collisions it happened directly following the original entry. For the other collision there were 2 entries between them.
One of the collisions was:
e7a69040-b412-11e2-ad2c-57e3dd379c2d
Should this really be possible? Perhaps there is some flaw in the implementation.
I was using Node 0.8 at the time, if that matters.
crypto.randomBytes wasn't added until node v0.6.0. The compatibility check (try/catch) doesn't work.
_rb gets set as undefined and doesn't fail until it's later called (outside of the try/catch).
https://github.com/broofa/node-uuid/blob/master/uuid.js#L44
resulting error:
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: undefined is not a function
at CALL_NON_FUNCTION (native)
at /app/node_modules/node-uuid/uuid.js:47:14
at /app/node_modules/node-uuid/uuid.js:103:20
at Object.<anonymous> (/app/node_modules/node-uuid/uuid.js:249:1)
at Module._compile (module.js:411:26)
at Object..js (module.js:417:10)
at Module.load (module.js:343:31)
at Function._load (module.js:302:12)
at require (module.js:355:19)
Is it possible to extend this to be like your Math.uuid.js so it can also generate random IDs of any length?
I'm using node v0.4.11
Everything works with node-uuid 1.3.0
But when I used node-uuid 1.3.2, on launch of my app :
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: undefined is not a function
at CALL_NON_FUNCTION (native)
at /xxx/node_modules/node-uuid/uuid.js:47:14
at /xxx/node_modules/node-uuid/uuid.js:103:20
at Object. (/xxx/node_modules/node-uuid/uuid.js:249:1)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at require (module.js:346:19)
at Object. (/xxx/server/lib/server.js:16:12)
Thoughts on providing a .verify method which will return true or false if the string or buffer is a valid uuid? Maybe only relevant for strings? but I think it is useful for basic error checking of user input.
While implementing node-uuid with node-cassandra-client I came across this test written by the node-cassandra-client authors: https://github.com/ctavan/node-cassandra-client/blob/node-uuid/test/test_uuid.js#L13-29
It fails with node-uuid since setting msecs
bypasses the internal clockseq-counter. What was the particular reason for you to put it that way? The only reason I can see is code readability.
Reading through the RFC again, IMO setting msecs
and nsecs
to a value in the future and then to a value lower than that future-value can just be interpreted as "setting the clock backwards". So unless the clockseq
is explicitly specified I think node-uuid should take care of setting the clockseq according to the RFC (and not the calling application, which would be necessary at the moment).
I admit that this will add complexity to the v1 logic, but still I think it would be more in the sense of the RFC... What are your thoughts?
When creating v1 uuids in the browser (with browserify), only the first part of the id changes, while the rest is static, e.g:
ae355c10-6109-11e4-9d2c-85cd1908178e
ae68a110-6109-11e4-9d2c-85cd1908178e
ae872590-6109-11e4-9d2c-85cd1908178e
aea69470-6109-11e4-9d2c-85cd1908178e
aec08510-6109-11e4-9d2c-85cd1908178e
aedc7180-6109-11e4-9d2c-85cd1908178e
aef77390-6109-11e4-9d2c-85cd1908178e
af111610-6109-11e4-9d2c-85cd1908178e
531d64c0-610a-11e4-9d2c-85cd1908178e
6109-11e4-9d2c-85cd1908178e
never changes whether generated milliseconds or minutes apart. v1 generator works fine when run by nodejs.
The readme states "Cryptographically strong random # generation on supporting platforms". Could you mention what platforms would support this, or how to check?
Take inspiration from:
https://github.com/boundary/flake
"Flake ids are 128-bits wide described here from most significant to least significant bits.
64-bit timestamp - milliseconds since the epoch (Jan 1 1970)
48-bit worker id - MAC address from a configurable device
16-bit sequence # - usually 0, incremented when more than one id is requested in the same millisecond and reset to 0 when the clock ticks forward
UUID-1 is an odd beast. First, the timestamp is based on the number of 100 nanosecond intervals since October 15, 1582. This is not how most of us familiar with Unix timestamps reason about time. If that isn't bad enough, the timestamp is an odd 60-bits in length with the most significant bits shifted to the least significant bits of the UUID. This property makes lexical ordering essentially meaningless. The remaining bits contain a clock id (initially set to a random number) and a node id (usually the MAC address).
The first problem is the timestamp. We could rearrange the bits to get some k-ordering love, but reasoning on timestamps of this nature makes reasoning about the resulting ids more complex than it needs to be. This is why flake uses a standard 64-bit Unix timestamp, unaltered, as the most significant bits."
I realise that this project is focused on UUIDs as defined in RFC4122, so this sort of ID generation wouldn't fit within that goal - but I hadn't seen a similar Node.js project as yet and thought I'd check to see if you wanted to implement it here.
For a project we need to support the uuids v3 which is namespaced by a string passed in. In checking the RFC and testing out, here's a pure python version of it:
https://github.com/mitechie/Bookie/blob/feature%2Fchrome_ext/extensions/uuid/impl.py
Is there any thought to supporting this in the node-uuid library?
UUIDs conceptually are supposed to generate unique ids at any point of space and time. So, does this module also guarantee the same across a nodejs cluster ?
Thanks
Hi there
I'm using uuid.v1()
for keys within my LevelDB + node.js app. Whenever I list entries from the LevelDB, the sorting happens by these keys and unfortunately it is very random.
I mean, in a boring relational DB you increment the primary keys. Whenever you query the rows, the are sorted by these primary keys as a default behavior. This is good, you always know that recently inserted rows appear on top.
But with UUIDs v1 as keys, the sequence is pretty random.
Is there a solution for that? Do I need to fine-tune some options to achieve that behavior or can this be implemented at all in a new version?
Hi Broofa, nice project here. ;) Just a suggestion. It would be nice if there was a method sort of like:
nodeUuid.isV4(someUuidString);
That way it would be easy to know if a string is a valid UUID v4. Right now, I have to resort to something janky like this:
if (!uuid || uuid.length < 32 || uuid.indexOf("-") < 0) {
uuid = nodeUuid.v4();
}
Hi,
I can't use uuid with qunit (http://qunitjs.com/) because qunit define "module" global variable name.
Regards,
Stephane
Specifying your license in package.json
makes it a lot easier for your users to find and comply with GNU Affero licenses.
Also giving licenses
(an array of objects with type
and url
keys) helps users whose legal departments request both the license name and the text. See this example from async:
"licenses": [{
"type": "MIT",
"url": "https://github.com/caolan/async/raw/master/LICENSE"
}]
Though licenses
isn't specified in the npm package.json spec, it is supported by the NPM site, as you'll see if you check async's NPM page.
Thanks!
Hi,
I need to generate numeric uuids. Any solution, method or module for that?
Sorry by this question but:
there is a way to use the uuid like ObjectId() in mongoDb
Regards.
Since v4 performance is so dependent on which RNG is used, it seemed appropriate to allow this aspect of the code to be testable. Hence broofa/node-uuid@master...rng_refactor includes ...
options.rng
objectAnd while I was at it ...
Hi, could you update the release notes for the latest release?
npmjs.org cliams this project is at version 1.4.0 but that version does not exist as a tag here at github.
Please always tag releases, to ease tracking by distributors (some prefer to use other package handling than npm - like me: I maintain the official Debian package for this project).
In the old Math.uuid code you could do Math.uuid(8) and get a unique confirmation number and it is not possible anymore with this code.
hello, node-uuid result can be use it in a url?
I mean, if I need to encode it before using it on a url.
var uuid = require ('node-uuid'),
token = uuid.v4(),
url;
// is this ok?
url = 'http://localhost/myurl/' + token;
// or this:
url = 'http://localhost/myurl/' + functionToBase64url (token);
why
return bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]];
not
return bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]];
I think 02a2ce90143211e185580b488e4fc115
is more beautiful than 02a2ce90-1432-11e1-8558-0b488e4fc115
MIT admit things that GPL don't admit. Then can you clarify to me...
Can I use this code in a commercial development?
What are the conditions to use it?
DP: Sorry my English isn't very good.
I'm assuming uuid.v1 is sortable, but it's not.
a=uuid.v1()
b=uuid.v1()
a<b is not always true.
When installing by npm install node-uuid
(version 1.1.0, per npm info node-uuid
), the distributed package includes a x86-64 binary file, test/benchmark-native
, which my (puny 32-bit) machine refuses to include in a debian package.
> wget http://registry.npmjs.org/node-uuid/-/node-uuid-1.1.0.tgz
> tar -zxf node-uuid-1.1.0.tgz
> file package/test/benchmark-native
package/test/benchmark-native: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
While I'm no NPM expert, the executable should either be compiled install-time, or it should not be included at all.
(For good measure, I'm trying to use npm bundle install
as a hack to build quick debian packages for Node.js programs.)
The version my app depends on was yanked from the NPM registry. Any way you can put the old versions back, but keep 'latest' pointed at the most recent version?
Hi
fails in yui compressor, due to use of future reserved keyword 'byte'. simply use another variable name to solve the yui compressor compatibility.
s.toLowerCase().replace(/[0-9a-f]{2}/g, function(byte).....
Kind regards
Jari Berg
I run npm to install this module with no error.
node panics after it cannot require("uuid").
I know you provide main script in package.json but nothing exists at '/build/default/uuid.node'.
uuid.node is still located at /build/Release/
node 0.8.1
npm 1.1.33
macos 10.8
npm install
npm WARN [email protected] dependencies field should be hash of <name>:<version-range> pairs
I think you want your package.json dependencies to change to this:
...
dependencies: {},
...
In some cases the timestamp can reduce collisions, so if you use the javascript Date to put the timestamp into the UUID that could help. There's an example here that puts the timestamp in:
http://af-design.com/blog/2008/09/05/updated-javascript-uuid-generator-v03/
That one doesn't support the built-in crypto APIs, however, like yours does so having both in your lib would make yours the most comprehensive.
Not sure if this belongs here but when doing npm install node-uuid it seems to get a pretty old version of the package (no v1, v4 methods etc) the version I get is 1.2
Not sure whether I should report it here on the npm forum but I am unable to install node-uuid using npm. The system is running Centos-5.5 x86_64. I was able to install other things using npm so the problem seems to be just with this tgz file.
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info fetch http://registry.npmjs.org/node-uuid/-/node-uuid-1.1.0.tgz
npm info calculating sha1 /tmp/npm-1296348137194/1296348137194-0.9728793394751847/tmp.tgz
npm info shasum 9a7027279bc670e50980e94c55958117272c4f37
npm ERR! Failed unpacking the tarball.
npm ERR! This is very rare. Perhaps the 'gzip' or 'tar' configs
npm ERR! are set improperly?
npm ERR!
npm ERR! couldn't unpack /tmp/npm-1296348137194/1296348137194-0.9728793394751847/tmp.tgz to /tmp/npm-1296348137194/1296348137194-0.9728793394751847/contents
npm ERR! Error installing [email protected]
npm ERR! Error: Failed /bin/gtar "-vxpf" "-" "-C" "/tmp/npm-1296348137194/1296348137194-0.9728793394751847/contents"
npm ERR! exited with 2
npm ERR! at ChildProcess. (/usr/local/lib/node/.npm/npm/0.2.16/package/lib/utils/exec.js:48:8)
npm ERR! at ChildProcess.emit (events.js:45:17)
npm ERR! at ChildProcess.onexit (child_process.js:171:12)
npm ERR! Report this entire log at http://github.com/isaacs/npm/issues
npm ERR! or email it to [email protected]
npm ERR! Just tweeting a tiny part of the error will not be helpful.
npm not ok
I'm trying to see what happens if you create two UUID at exactly same time (hours, minutes, seconds and milliseconds)... but I can't be sure about.
create the same UUID?
or the math.random (but random based on time) minimize this probability?
Thanks in advance!
Can you add a function that checks if a string is a valid uuid? If you receive a uuid from the user, before sending it to the databse you typically want to check if it's a valid uuid. If it's not valid it makes no sense to send it to the database and slow down the user experience.
function isValid (s){
return /^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/i
.test (s);
};
If you would please update your README to reflect how it's intended to be called. uuid() instead of uuid.v1() or v4()
A thing came in mind when I was running some tests with v1 UUIDs: Should we allow the user of the v1()
method to optionally specify a timestamp that will be used instead of Date().getTime()
?
There are two cases in which this might make sense:
I see that we're getting to a point where we're tempted to make node-uuid bloated which should be avoided IMO. I therefore had the idea of using node-uuid as the underlying fast & lightweight uuid generator for a wrapper similar to uuid-js that provides you with some convenience methods like conversion between string- and buffer-representation, validation, extraction of the timestamp, etc, see my discussion with @pnegri: https://github.com/pnegri/uuid-js/issues/10
He also had the brilliant idea of naming it node-uuid-utils which I really like.
Being able to specify the timestamp when calling v1()
would be the only addition to node-uuid I can think of right now that would be needed to build node-uuid-utils. What do you think?
Would it be possible to add support for generating v3 and v5 UUIDs? Code (PHP) can be found here:
var bytes = uuid.parse('797ff043-11eb-11e1-80d6-510998755d10'); // -> <Buffer 79 7f f0 43 11 eb 11 e1 80 d6 51 09 98 75 5d 10>
this returns [79,127,...,10]
Hi,
installing uuid through npm install uuid
fails:
Build failed: -> task failed (err #1):
{task: cxx uuid.cc -> uuid_1.o}
npm ERR! error installing [email protected]
npm ERR! [email protected] preinstall: `node-waf configure && node-waf build`
npm ERR! `sh "-c" "node-waf configure && node-waf build"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the uuid package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure && node-waf build
npm ERR! You can get their info via:
npm ERR! npm owner ls uuid
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 3.2.0-32-generic
npm ERR! command "node" "/usr/bin/npm" "install" "uuid"
npm ERR! cwd /home/vk/code/javascript/jsuggest
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] preinstall: `node-waf configure && node-waf build`
npm ERR! message `sh "-c" "node-waf configure && node-waf build"` failed with 1
npm ERR! errno {}
I can provide additional information if necessary
-- ooxi
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.