Skip to content

Instantly share code, notes, and snippets.

@rsoury
Created June 3, 2016 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsoury/5eb2cc61781a962a889fe8041d7ce425 to your computer and use it in GitHub Desktop.
Save rsoury/5eb2cc61781a962a889fe8041d7ce425 to your computer and use it in GitHub Desktop.
Increment your hash without characters that directory names don't like.
const incHash = (str) => {
const singles = str.split('');
let incNext = false;
let extendIt = false;
for(let i = singles.length - 1; i > -1; i --){
if(incNext || i == singles.length - 1){
incNext = false;
let ascii = singles[i].charCodeAt(0);
if(ascii == 57){
ascii = 65;
}else if(ascii == 90){
ascii = 97;
}else if(ascii == 122){
ascii = 48;
incNext = true;
}else{
ascii++;
}
if(i == 0 && incNext){
extendIt = true;
}
singles[i] = String.fromCharCode(ascii);
}
}
let newStr = singles.join('');
if(extendIt == true){
newStr = '0' + newStr;
}
return newStr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment