# to-js-identifier

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

Latest version **1.0.0** (published 2016-06-27) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install to-js-identifier
pnpm add to-js-identifier
yarn add to-js-identifier
bun add to-js-identifier
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-06-27 |
| First published | 2016-06-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | farskipper |
| Maintainers | farskipper |
| Keywords | javascript, identifier, compiler, language, ECMAScript, words |

## Links

- npm: https://www.npmjs.com/package/to-js-identifier
- Repository: https://github.com/smallhelm/to-js-identifier
- Homepage: https://github.com/smallhelm/to-js-identifier#readme
- Issues: https://github.com/smallhelm/to-js-identifier/issues
- npm.io page: https://npm.io/package/to-js-identifier

## Dependencies (1)

- [reserved](https://npm.io/package/reserved.md) ^0.1.2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-06-27

## 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

---
_Source: https://npm.io/package/to-js-identifier · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
