AlphaID
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_foldernpm 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
-
0.0.8 - Current Version - Download Source Code - NPM Package
- Release notes:
- Add Mocha tests
- Release notes:
-
0.0.7 - Old - Download Source Code - NPM Package
- Release notes:
- Changing to Vimia
- Test Correction
- Release notes:
-
0.0.5 - Old - Download Source Code
- Release notes:
- Travis Builds
- Test timing
- File structure
- Release notes:
-
0.0.4 - Old - Download Source Code
- Release notes:
- Added Event Support to callBacks
- Better test mode
- Release notes:
-
0.0.3 - Old - Download Source Code
RoadMap
Nothing yet, but please suggest here!