New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

to-js-identifier

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-js-identifier

Convert any string (even reserved words) to a valid javascript identifier.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.6K
increased by14.76%
Maintainers
1
Weekly downloads
 
Created
Source

to-js-identifier

build status dependency status

Convert any string (even reserved words) to a valid javascript identifier.

Useful when writing compile to JS languages.

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

Keywords

FAQs

Package last updated on 27 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc