{"_id":"to-valid-identifier","_rev":"4249742","name":"to-valid-identifier","description":"Convert a string to a valid JavaScript identifier","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-03-29T21:54:22.000Z","created":"2024-05-05T18:32:07.648Z","1.0.0":"2025-10-15T02:23:38.881Z","0.1.1":"2024-05-28T10:37:10.914Z","0.1.0":"2024-05-05T18:32:07.648Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/to-valid-identifier.git"},"versions":{"1.0.0":{"name":"to-valid-identifier","version":"1.0.0","description":"Convert a string to a valid JavaScript identifier","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/to-valid-identifier.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && ava"},"keywords":["valid","identifier","safe","sanitize","variable","property","ecmascript","javascript","js","reserved","keyword","word","property"],"dependencies":{"@sindresorhus/base62":"^1.0.0","reserved-identifiers":"^1.0.0"},"devDependencies":{"ava":"^6.4.1","xo":"^1.2.3"},"gitHead":"27f29b8e452f09f4af039bab5c48d8f194ba65f3","types":"./index.d.ts","_id":"to-valid-identifier@1.0.0","bugs":{"url":"https://github.com/sindresorhus/to-valid-identifier/issues"},"homepage":"https://github.com/sindresorhus/to-valid-identifier#readme","_nodeVersion":"24.9.0","_npmVersion":"11.6.1","dist":{"shasum":"27337955333c3c517feb60bea533cf27ce54b79f","size":2197,"noattachment":false,"key":"/to-valid-identifier/-/to-valid-identifier-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/to-valid-identifier/download/to-valid-identifier-1.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/to-valid-identifier_1.0.0_1760495018649_0.17480167179009287"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-10-15T02:23:38.881Z","publish_time":1760495018881,"_source_registry_name":"default","_cnpm_publish_time":1760495018881},"0.1.1":{"name":"to-valid-identifier","version":"0.1.1","description":"Convert a string to a valid JavaScript identifier","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/to-valid-identifier.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava"},"keywords":["valid","identifier","safe","sanitize","variable","property","ecmascript","javascript","js","reserved","keyword","word","property"],"dependencies":{"@sindresorhus/base62":"^0.1.0","reserved-identifiers":"^1.0.0"},"devDependencies":{"ava":"^6.1.2","xo":"^0.58.0"},"_id":"to-valid-identifier@0.1.1","gitHead":"06962df047ebf79021f09215bff3501b8e4b53be","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/to-valid-identifier/issues"},"homepage":"https://github.com/sindresorhus/to-valid-identifier#readme","_nodeVersion":"18.20.2","_npmVersion":"10.6.0","dist":{"shasum":"bfd09b8c63ab0c0235e23c8243f7630f45b3e7a9","size":2169,"noattachment":false,"key":"/to-valid-identifier/-/to-valid-identifier-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/to-valid-identifier/download/to-valid-identifier-0.1.1.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/to-valid-identifier_0.1.1_1716892630763_0.09631021252624206"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-05-28T10:37:10.914Z","publish_time":1716892630914,"_source_registry_name":"default","_cnpm_publish_time":1716892630914},"0.1.0":{"name":"to-valid-identifier","version":"0.1.0","description":"Convert a string to a valid JavaScript identifier","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/to-valid-identifier.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava"},"keywords":["valid","identifier","safe","sanitize","variable","property","ecmascript","javascript","js","reserved","keyword","word","property"],"dependencies":{"@sindresorhus/base62":"^0.1.0","reserved-identifiers":"^1.0.0"},"devDependencies":{"ava":"^6.1.2","xo":"^0.58.0"},"_id":"to-valid-identifier@0.1.0","gitHead":"ff135dc688c01fb88aebc08858e00ddd1bad3f16","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/to-valid-identifier/issues"},"homepage":"https://github.com/sindresorhus/to-valid-identifier#readme","_nodeVersion":"20.12.2","_npmVersion":"10.6.0","dist":{"shasum":"baddd75dd1d30e8666171ec81b55169425a03906","size":2172,"noattachment":false,"key":"/to-valid-identifier/-/to-valid-identifier-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/to-valid-identifier/download/to-valid-identifier-0.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/to-valid-identifier_0.1.0_1714933927495_0.19167055756430007"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-05-05T18:32:07.648Z","publish_time":1714933927648,"_source_registry_name":"default","_cnpm_publish_time":1714933927648}},"readme":"# to-valid-identifier\n\n> Convert a string to a valid [JavaScript identifier](https://developer.mozilla.org/docs/Glossary/Identifier)\n\n## Install\n\n```sh\nnpm install to-valid-identifier\n```\n\n## Usage\n\n```js\nimport toValidIdentifier from 'to-valid-identifier';\n\ntoValidIdentifier('foo');\n//=> 'foo'\n\ntoValidIdentifier('foo-bar');\n//=> 'foo$j$bar'\n\ntoValidIdentifier('$');\n//=> '$a$'\n\ntoValidIdentifier('undefined');\n//=> '$_undefined$'\n```\n\n## API\n\n### toValidIdentifier(string)\n\nConvert the given string to a valid JavaScript identifier.\n\nDifferent inputs will always generate unique identifiers.\n\n## Use cases\n\n- **Code Generation:** Automate safe variable naming in scripts, avoiding syntax errors from invalid characters.\n- **Compilers/Transpilers:** Essential for non-JavaScript languages compiling to JavaScript, ensuring that identifiers are compliant.\n- **Dynamic Function Names:** Generate unique and valid function names from dynamic content such as user inputs or database fields.\n- **API Wrappers:** Convert API response properties into valid JavaScript object keys for easier access.\n- **Template Processing:** Ensure template placeholders are converted to valid JavaScript identifiers when replaced with dynamic values.\n\n## Related\n\n- [is-identifier](https://github.com/sindresorhus/is-identifier) - Check if a string is a valid JavaScript identifier\n","_attachments":{},"homepage":"https://github.com/sindresorhus/to-valid-identifier#readme","bugs":{"url":"https://github.com/sindresorhus/to-valid-identifier/issues"},"license":"MIT"}