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.2 to 0.0.3

LICENSE

26

index.js

@@ -8,9 +8,9 @@ /**

/**
* The size ratio between a base64 string and the equivalent byte buffer
* 62 characters in the ascii range that can be used in URLs without special
* encoding.
*/
var UIDCHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var ratio = Math.log(64) / Math.log(256);
/**
* Make a Base64 string ready for use in URLs
* Make a Buffer into a string ready for use in URLs
*

@@ -21,5 +21,11 @@ * @param {String}

*/
function tostr(bytes) {
var chars, r, i;
function urlReady(str) {
return str.replace(/\+/g, '_').replace(/\//g, '-');
r = [];
for (i = 0; i < bytes.length; i++) {
r.push(UIDCHARS[bytes[i] % UIDCHARS.length]);
}
return r.join('');
}

@@ -36,9 +42,9 @@

function uid(length, cb) {
var numbytes = Math.ceil(length * ratio);
if (typeof cb === 'undefined') {
return urlReady(crypto.randomBytes(numbytes).toString('base64').slice(0, length));
return tostr(crypto.pseudoRandomBytes(length));
} else {
crypto.randomBytes(numbytes, function(err, bytes) {
crypto.pseudoRandomBytes(length, function(err, bytes) {
if (err) return cb(err);
cb(null, urlReady(bytes.toString('base64').slice(0, length)));
cb(null, tostr(bytes));
})

@@ -45,0 +51,0 @@ }

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

"tags": ["uid"],
"version": "0.0.2",
"version": "0.0.3",
"dependencies": {
}
}
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