ai

alpha-id

Alpha-numeric Indexes creation.

Showing:

Popularity

Downloads/wk

1

Maintenance

No Maintenance Data Available

Package

Dependencies

0

Size (min+gzip)

0.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

AlphaID

Travis

What is AlphaID ?

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

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!

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100