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

uuid-base62

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uuid-base62 - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.travis.yml

8

package.json
{
"name": "uuid-base62",
"version": "0.0.1",
"version": "0.0.2",
"description": "Base62 non-sequential url-safe UUID generator (RFC4122)",

@@ -18,4 +18,6 @@ "main": "uuid-base62.js",

"id",
"identifier",
"url-friendly",
"generator"
"generator",
"base64"
],

@@ -29,3 +31,3 @@ "author": "Dario Marcelino <dario@appscot.com>",

"dependencies": {
"b62": "0.0.1",
"b62": "^0.0.1",
"node-uuid": "^1.4.3"

@@ -32,0 +34,0 @@ },

# uuid-base62
Base62 non-sequential url-friendly UUID generator (RFC4122)
[![npm version](https://badge.fury.io/js/uuid-base62.svg)](http://badge.fury.io/js/uuid-base62)
[![Build Status](https://travis-ci.org/dmarcelino/uuid-base62.svg?branch=master)](https://travis-ci.org/dmarcelino/uuid-base62)
## Overview
uuid-base62 makes it easy to generate short base62 (or any other base) UUIDs. The unencoded UUIDs are generated by [node-uuid](https://github.com/broofa/node-uuid) which follows [RFC4122](http://www.ietf.org/rfc/rfc4122.txt).
## Instalation
```shell
npm i uuid-base62 -S
```
## Usage
```javascript
var uuidBase62 = require('uuid-base62');
var uuid = uuidBase62.v4(); // -> 2qY9COoAhfMrsH7mCyh86T
// if the original uuid is needed
var originalUuid = uuidBase62.decode(uuid); // -> 9af099b2-6244-4fc1-b72b-1d69a24481b7
// if an uuid needs to be encoded
var encoded = uuidBase62.encode('8fc60e7c-3b3c-48e9-a6a7-a5fe4f1fbc31'); // -> 2fNwVYePN8WqqDFvVf7XMN
```
That's it. node-base62 also supports other bases, example for base64:
```javascript
uuidBase62.customBase = new uuidBase62.b62("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_");
// -> 31LoSI_BVeQpXtwu_-GEbL
```
## License
MIT

@@ -58,2 +58,22 @@ var assert = require('assert');

});
describe('other bases', function () {
uuidBase62.customBase = new uuidBase62.b62("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_");
it('should generate a unique id without any params in base64', function () {
var res = uuidBase62.v4();
assert(res);
assert.equal(typeof res, 'string');
assert(res.length <= 22);
});
it('should encode and decode a uuid in Base64', function () {
var uuid = '72be7291-fbf6-400f-87c4-455e23d01cd5';
var uuidB64 = uuidBase62.encode(uuid);
assert.equal(uuidB64, '1OLDah-_p03Uv4hlUzQ1Pl');
var res = uuidBase62.decode(uuidB64);
assert.equal(res, uuid);
});
});
});

@@ -10,2 +10,3 @@ 'use strict';

module.exports.b62 = b62;
module.exports.customBase = b62;

@@ -56,3 +57,3 @@ /**

}
return b62.encode(input, encoding);
return this.customBase.encode(input, encoding);
};

@@ -65,3 +66,3 @@

encoding = encoding || 'hex';
var res = b62.decode(b62Str, encoding);
var res = this.customBase.decode(b62Str, encoding);

@@ -68,0 +69,0 @@ // re-add the dashes so the result looks like an uuid

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