Skip to content

Commit

Permalink
create config and utils
Browse files Browse the repository at this point in the history
  • Loading branch information
tortuvshin committed Jan 9, 2018
1 parent 1ea17c3 commit 9cc5925
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
var base = alphabet.length;

function encode(num){
var encoded = '';
while (num){
var remainder = num % base;
num = Math.floor(num / base);
encoded = alphabet[remainder].toString() + encoded;
}
return encoded;
}

function decode(str){
var decoded = 0;
while (str){
var index = alphabet.indexOf(str[0]);
var power = str.length - 1;
decoded += index * (Math.pow(base, power));
str = str.substring(1);
}
return decoded;
}

module.exports.encode = encode;
module.exports.decode = decode;
9 changes: 9 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var config = {};

config.db = {};
config.webhost = 'https://localhost:3000/';

config.db.host = 'localhost';
config.db.name = 'url_shortener';

module.exports = config;

0 comments on commit 9cc5925

Please sign in to comment.