Comparing version 0.3.1 to 0.4.0
'use strict'; | ||
const sha1 = require('sha-1'); | ||
// See http://stackoverflow.com/a/2117523/1333873 for details. | ||
var uuidv4 = function () { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (character) { | ||
var randomNumber = Math.random() * 16 | 0, | ||
result = | ||
character === 'x' ? | ||
randomNumber : | ||
randomNumber & 0x3 | 0x8; | ||
const uuidv4 = function () { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, character => { | ||
/* eslint-disable no-bitwise */ | ||
const randomNumber = Math.random() * 16 | 0, | ||
result = | ||
character === 'x' ? | ||
randomNumber : | ||
randomNumber & 0x3 | 0x8; | ||
/* eslint-enable no-bitwise */ | ||
@@ -16,2 +20,4 @@ return result.toString(16); | ||
uuidv4.regex = /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$/; | ||
uuidv4.empty = function () { | ||
@@ -21,2 +27,13 @@ return '00000000-0000-0000-0000-000000000000'; | ||
uuidv4.fromString = function (text) { | ||
if (!text) { | ||
throw new Error('Text is missing.'); | ||
} | ||
const hash = sha1(text), | ||
uuid = `${hash.substring(0, 8)}-${hash.substring(8, 12)}-4${hash.substring(13, 16)}-8${hash.substring(17, 20)}-${hash.substring(20, 32)}`; | ||
return uuid; | ||
}; | ||
module.exports = uuidv4; |
{ | ||
"name": "uuidv4", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "uuid creates UUIDs.", | ||
@@ -16,8 +16,22 @@ "contributors": [ | ||
"main": "lib/uuidv4.js", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"sha-1": "0.1.1" | ||
}, | ||
"devDependencies": { | ||
"assertthat": "0.4.2", | ||
"grunt": "0.4.5", | ||
"tourism": "0.13.2" | ||
"assertthat": "0.8.0", | ||
"roboter": "0.13.5", | ||
"roboter-server": "0.13.5" | ||
}, | ||
"browserify": { | ||
"transform": [ | ||
[ | ||
"babelify", | ||
{ | ||
"presets": [ | ||
"es2015" | ||
] | ||
} | ||
] | ||
] | ||
}, | ||
"repository": { | ||
@@ -27,3 +41,7 @@ "type": "git", | ||
}, | ||
"keywords": [ | ||
"guid", | ||
"uuid" | ||
], | ||
"license": "MIT" | ||
} |
@@ -7,3 +7,5 @@ # uuid | ||
$ npm install uuidv4 | ||
```bash | ||
$ npm install uuidv4 | ||
``` | ||
@@ -15,3 +17,3 @@ ## Quick start | ||
```javascript | ||
var uuid = require('uuidv4'); | ||
const uuid = require('uuidv4'); | ||
``` | ||
@@ -23,5 +25,16 @@ | ||
console.log(uuid()); | ||
// => 11bf5b37-e0b8-42e0-8dcf-dc8c4aefc000 | ||
// => '11bf5b37-e0b8-42e0-8dcf-dc8c4aefc000' | ||
``` | ||
### Getting a UUID from a string | ||
From time to time you need an identifier that looks like a UUID, but is actually inferred from a string. For that, use the `fromString` function. | ||
```javascript | ||
console.log(uuid.fromString('the native web')); | ||
// => 'cc762e69-089e-4239-8b06-1ab26a005319' | ||
``` | ||
### Getting the empty UUID | ||
If you need a UUID that consists only of zeros, use the `empty` function. | ||
@@ -31,3 +44,3 @@ | ||
console.log(uuid.empty()); | ||
// => 00000000-0000-0000-0000-000000000000 | ||
// => '00000000-0000-0000-0000-000000000000' | ||
``` | ||
@@ -37,5 +50,7 @@ | ||
This module can be built using [Grunt](http://gruntjs.com/). Besides running the tests, this also analyses the code. To run Grunt, go to the folder where you have installed uuidv4 and run `grunt`. You need to have [grunt-cli](https://github.com/gruntjs/grunt-cli) installed. | ||
To build this module use [roboter](https://www.npmjs.com/package/roboter). | ||
$ grunt | ||
```bash | ||
$ bot | ||
``` | ||
@@ -45,3 +60,3 @@ ## License | ||
The MIT License (MIT) | ||
Copyright (c) 2014 the native web. | ||
Copyright (c) 2014-2016 the native web. | ||
@@ -48,0 +63,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6220
8
96
62
1
1
+ Addedsha-1@0.1.1
+ Addedsha-1@0.1.1(transitive)