Created
June 3, 2016 16:05
-
-
Save rsoury/5eb2cc61781a962a889fe8041d7ce425 to your computer and use it in GitHub Desktop.
Increment your hash without characters that directory names don't like.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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