Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smallhelm/to-js-identifier
Convert any string (even reserved words) to a valid javascript identifier.
https://github.com/smallhelm/to-js-identifier
code-generation compile-to-js compiler
Last synced: about 2 months ago
JSON representation
Convert any string (even reserved words) to a valid javascript identifier.
- Host: GitHub
- URL: https://github.com/smallhelm/to-js-identifier
- Owner: smallhelm
- License: mit
- Created: 2016-06-27T16:47:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-06-27T18:14:18.000Z (over 8 years ago)
- Last Synced: 2024-11-13T09:59:05.629Z (3 months ago)
- Topics: code-generation, compile-to-js, compiler
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# to-js-identifier
[![build status](https://secure.travis-ci.org/smallhelm/to-js-identifier.svg)](https://travis-ci.org/smallhelm/to-js-identifier)
[![dependency status](https://david-dm.org/smallhelm/to-js-identifier.svg)](https://david-dm.org/smallhelm/to-js-identifier)Convert any string (even reserved words) to a valid javascript identifier.
Useful when writing compile to JS languages.
```js
var toId = require('to-js-identifier');//valid ids just go right through
toId('foo') === 'foo'//convert your string to a valid js identifier
toId('not-js') === '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
toId('$') === '$36$'//reserved words are escaped
toId('null') === '$null$'
toId('var') === '$var$'// yes I know undefined is technically an identifier, but it shouldn't be!!!
toId('undefined') === '$undefined$'
```## License
MIT