Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uid2

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uid2 - npm Package Compare versions

Comparing version 0.0.4 to 1.0.0

promises.js

12

HISTORY.md

@@ -0,1 +1,11 @@

# 1.0.0 - August 24, 2021
- Switch from `crypto.pseudoRandomBytes()` back to `crypto.randomBytes()` (Both are equivalent in Node 4.x and above, and `pseudoRandomBytes()` is deprecated in Node 11.x and above)
- Add `engines` field to _package.json_
- Fix character distribution non-uniformity issue by adding back `-` and `_` to generated ids
- Add character distribution test
- Enable strict mode
- Fix JSDoc optional parameter syntax
- Add `Promise`-based API
# 0.0.4 - August 24, 2021

@@ -6,3 +16,3 @@

- Add `license` field to _package.json_
- Removed unused var, added param documentation
- Remove unused var, added param documentation

@@ -9,0 +19,0 @@ # 0.0.3 - July 6, 2013

25

index.js

@@ -0,1 +1,2 @@

'use strict';
/**

@@ -8,6 +9,6 @@ * Module dependencies

/**
* 62 characters in the ascii range that can be used in URLs without special
* 64 characters in the ascii range that can be used in URLs without special
* encoding.
*/
var UIDCHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var UIDCHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';

@@ -22,10 +23,9 @@ /**

function tostr(bytes) {
var r, i;
var r = '', i;
r = [];
for (i = 0; i < bytes.length; i++) {
r.push(UIDCHARS[bytes[i] % UIDCHARS.length]);
r += UIDCHARS[bytes[i] % 64];
}
return r.join('');
return r;
}

@@ -37,3 +37,3 @@

* @param {Number} length The number of chars of the uid
* @param {Number} cb (optional) Callback for async uid generation
* @param {Number} [cb] Callback for async uid generation
* @api public

@@ -43,10 +43,9 @@ */

function uid(length, cb) {
if (typeof cb === 'undefined') {
return tostr(crypto.pseudoRandomBytes(length));
return tostr(crypto.randomBytes(length));
} else {
crypto.pseudoRandomBytes(length, function(err, bytes) {
if (err) return cb(err);
cb(null, tostr(bytes));
})
crypto.randomBytes(length, function (err, bytes) {
if (err) return cb(err);
cb(null, tostr(bytes));
});
}

@@ -53,0 +52,0 @@ }

@@ -5,3 +5,3 @@ {

"tags": ["uid"],
"version": "0.0.4",
"version": "1.0.0",
"repository": {

@@ -11,4 +11,10 @@ "type": "git",

},
"engines": {
"node": ">= 4.0.0"
},
"license": "MIT",
"scripts": {
"test": "node test.js"
},
"dependencies": {}
}
}

@@ -17,4 +17,6 @@ # uid2

```js
uid(10)
// => "hbswt489ts"
const uid = require('uid2');
const id = uid(10);
// id => "hbswt489ts"
```

@@ -25,2 +27,4 @@

```js
const uid = require('uid2');
uid(10, function (err, id) {

@@ -32,4 +36,15 @@ if (err) throw err;

Imported via `uid2/promises` it returns a `Promise`:
```js
const uid = require('uid2/promises');
async function foo() {
const id = await uid(10);
// id => "hbswt489ts"
}
```
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc