to-js-identifier
Convert any string (even reserved words) to a valid javascript identifier.
Useful when writing compile to JS languages.
var toId = ; //valid ids just go right through === 'foo' //convert your string to a valid js identifier === 'not$45$js' //as use can see it wraps invalid chars with '$' + c.charCodeAt(0) + '$'//Even though $ is a valid identifier, this function will escape it, so it//is not possible that 2 inputs generate the same output === '$36$' //reserved words are escaped === '$null$' === '$var$' // yes I know undefined is technically an identifier, but it shouldn't be!!! === '$undefined$'
License
MIT