alpha-id

0.0.8 • Public • Published

AlphaID

Travis

What is AlphaID ?

AlphaID is a simple module do Create Alpha-numeric Indexes to Node.js.

Links

Example

Let say you have a blog, and your typical post url is something like:

http://myblog.com/posts/4815162342

If you use AlphaID you can convert to this:

http://myblog.com/posts/iWroDM

Something like YouTube's links ;)

Install

To install globally use:

npm install alpha-id -g

To install on a project use:

cd my_project_folder
npm install alpha-id

Coding

On the same folder, create the file "index.js", and put this content:

var AlphaID = require('alpha-id');
AlphaID.do(4815162342 ,false, function(e,s){
    console.log(s);
    AlphaID.do(s,true, function (e,n) {
        console.log(n);
    });
});

To test the code, execute on the terminal:

node index.js

Explaining

Inside AlphaID we have 3 main methods,

  • encode(number, callBack) - Convert a number into an alpha-numeric ID.
  • decode(string, callBack) - Convert a alpha-numeric ID into a number.
  • do(value,toNum, callBack) -Both cases, with 'toNum' boolean flag.

The default value to the flag 'toNum' is false.

When 'toNum' is false the function returns encode(n) and when 'toNum' is true the function returns decode(n).

CallBack

Since 0.0.4 AlphaID has CallBack support, the function structure is simple.

function callBack(error,return){};
  • Error - Return if the process eventually fails, and the reason to.
  • Return - The value that the function should return.
Changing Index

If you want to create your own index, use this code below to override...

Warnings:

  • Always remember to put the same amount of characters on the original index.
  • Also remember to don't use invalid URL chars, like #,%,@,& ... that will make AlphaID untrustable.
var AlphaID = require('alpha-id');
AlphaID.options.index = 'abcdefghijklmnopqrstuvxzABCDEFGHIJKLMNOPQRSTUVXZ0123456789';
AlphaID.do(4815162342 ,false, function(e,r){
    console.log(r);
});

Issues

Found a bug? Have any suggestion? Please open an issue!

Versions

RoadMap

Nothing yet, but please suggest here!

Package Sidebar

Install

npm i alpha-id

Weekly Downloads

2

Version

0.0.8

License

MIT

Last publish

Collaborators

  • marceloboeira