{"_id":"locate-character","_rev":"4177080","name":"locate-character","description":"Get the line and column number of a specific character in a string","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"rich_harris","email":""}],"time":{"modified":"2026-03-01T21:37:03.000Z","created":"2016-08-07T19:42:26.304Z","3.0.0":"2023-06-15T16:16:42.915Z","2.0.5":"2018-01-14T15:08:39.331Z","2.0.4":"2018-01-14T15:06:43.983Z","2.0.3":"2017-11-27T17:22:38.398Z","2.0.2":"2017-11-27T17:21:39.176Z","2.0.1":"2017-05-21T20:22:40.224Z","2.0.0":"2016-09-02T01:10:55.508Z","1.0.0":"2016-08-07T19:42:26.304Z"},"users":{},"author":{"name":"Rich Harris"},"repository":{"type":"git","url":"git+https://gitlab.com/Rich-Harris/locate-character.git"},"versions":{"3.0.0":{"name":"locate-character","version":"3.0.0","description":"Get the line and column number of a specific character in a string","type":"module","types":"./types/index.d.ts","exports":{"types":"./types/index.d.ts","import":"./src/index.js"},"scripts":{"test":"node test/test.js","build":"dts-buddy","prepublishOnly":"npm test && npm run build"},"repository":{"type":"git","url":"git+https://gitlab.com/Rich-Harris/locate-character.git"},"keywords":["string","character","locate","line","column","location"],"author":{"name":"Rich Harris"},"license":"MIT","bugs":{"url":"https://gitlab.com/Rich-Harris/locate-character/issues"},"homepage":"https://gitlab.com/Rich-Harris/locate-character#README","devDependencies":{"dts-buddy":"^0.1.6","typescript":"^5.1.3"},"packageManager":"pnpm@8.6.2","gitHead":"4f08a59ec248121f7002abd02ee7b94e8eda06bc","_id":"locate-character@3.0.0","_nodeVersion":"18.15.0","_npmVersion":"9.5.0","dist":{"shasum":"0305c5b8744f61028ef5d01f444009e00779f974","size":2113,"noattachment":false,"key":"/locate-character/-/locate-character-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/locate-character/download/locate-character-3.0.0.tgz"},"_npmUser":{"name":"rich_harris","email":"richard.a.harris@gmail.com"},"directories":{},"maintainers":[{"name":"rich_harris","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/locate-character_3.0.0_1686845802689_0.5428094200104574"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-06-15T16:16:42.915Z","publish_time":1686845802915,"_source_registry_name":"default","_cnpm_publish_time":1686845802915},"2.0.5":{"name":"locate-character","version":"2.0.5","description":"Get the line and column number of a specific character in a string","main":"dist/locate-character.umd.js","jsnext:main":"dist/locate-character.es.js","module":"dist/locate-character.es.js","scripts":{"test":"mocha","pretest":"npm run build","build":"rollup -c && tsc","prepublish":"npm test"},"files":["dist/*.js","dist/**/*.d.ts","README.md"],"repository":{"type":"git","url":"git+https://github.com/Rich-Harris/locate-character.git"},"keywords":["string","character","locate","line","column","location"],"author":{"name":"Rich Harris"},"license":"MIT","bugs":{"url":"https://github.com/Rich-Harris/locate-character/issues"},"homepage":"https://github.com/Rich-Harris/locate-character#README","devDependencies":{"mocha":"^3.0.1","rollup":"^0.34.7","rollup-plugin-typescript":"^0.8.1","typescript":"^2.3.2"},"types":"./dist/types/index.d.ts","gitHead":"6b10d06e851570f4beb67f5d8c7171ed1b6d25fe","_id":"locate-character@2.0.5","_npmVersion":"5.5.1","_nodeVersion":"9.1.0","_npmUser":{"name":"rich_harris","email":"richard.a.harris@gmail.com"},"dist":{"shasum":"f2d2614d49820ecb3c92d80d193b8db755f74c0f","size":2302,"noattachment":false,"key":"/locate-character/-/locate-character-2.0.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/locate-character/download/locate-character-2.0.5.tgz"},"maintainers":[{"name":"rich_harris","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/locate-character-2.0.5.tgz_1515942519225_0.4085224133450538"},"directories":{},"publish_time":1515942519331,"_cnpm_publish_time":1515942519331,"_hasShrinkwrap":false},"2.0.4":{"name":"locate-character","version":"2.0.4","description":"Get the line and column number of a specific character in a string","main":"dist/locate-character.umd.js","jsnext:main":"dist/locate-character.es.js","module":"dist/locate-character.es.js","scripts":{"test":"mocha","pretest":"npm run build","build":"rollup -c && tsc","prepublish":"npm test"},"files":["dist/*.js","dist/**/*.d.ts","README.md"],"repository":{"type":"git","url":"git+https://gitlab.com/Rich-Harris/locate-character.git"},"keywords":["string","character","locate","line","column","location"],"author":{"name":"Rich Harris"},"license":"MIT","bugs":{"url":"https://gitlab.com/Rich-Harris/locate-character/issues"},"homepage":"https://gitlab.com/Rich-Harris/locate-character#README","devDependencies":{"mocha":"^3.0.1","rollup":"^0.34.7","rollup-plugin-typescript":"^0.8.1","typescript":"^2.3.2"},"types":"./dist/types/index.d.ts","gitHead":"2b289c61730d6752d0f7bb6711884283b1861e9d","_id":"locate-character@2.0.4","_npmVersion":"5.5.1","_nodeVersion":"9.1.0","_npmUser":{"name":"rich_harris","email":"richard.a.harris@gmail.com"},"dist":{"shasum":"afc6c90ad4fb45fc4de02d3b79f1c7a28ae81047","size":2299,"noattachment":false,"key":"/locate-character/-/locate-character-2.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/locate-character/download/locate-character-2.0.4.tgz"},"maintainers":[{"name":"rich_harris","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/locate-character-2.0.4.tgz_1515942403803_0.7476214652415365"},"directories":{},"publish_time":1515942403983,"_hasShrinkwrap":false,"_cnpm_publish_time":1515942403983},"2.0.3":{"name":"locate-character","version":"2.0.3","description":"Get the line and column number of a specific character in a string","main":"dist/locate-character.umd.js","jsnext:main":"dist/locate-character.es.js","module":"dist/locate-character.es.js","scripts":{"test":"mocha","pretest":"npm run build","build":"rollup -c","prepublish":"npm test"},"files":["dist","types.d.ts","README.md"],"repository":{"type":"git","url":"git+https://gitlab.com/Rich-Harris/locate-character.git"},"keywords":["string","character","locate","line","column","location"],"author":{"name":"Rich Harris"},"license":"MIT","bugs":{"url":"https://gitlab.com/Rich-Harris/locate-character/issues"},"homepage":"https://gitlab.com/Rich-Harris/locate-character#README","devDependencies":{"mocha":"^3.0.1","rollup":"^0.34.7","rollup-plugin-typescript":"^0.8.1","typescript":"^2.3.2"},"types":"./types.d.ts","gitHead":"e93ef9c7551f97d0bc762fb1fef16a4ddd2a4d2f","_id":"locate-character@2.0.3","_npmVersion":"5.5.1","_nodeVersion":"9.1.0","_npmUser":{"name":"rich_harris","email":"richard.a.harris@gmail.com"},"dist":{"shasum":"85a5aedae26b3536c3e97016af164cdaa3ae5ae1","size":2265,"noattachment":false,"key":"/locate-character/-/locate-character-2.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/locate-character/download/locate-character-2.0.3.tgz"},"maintainers":[{"name":"rich_harris","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/locate-character-2.0.3.tgz_1511803358163_0.08301289239898324"},"directories":{},"publish_time":1511803358398,"_cnpm_publish_time":1511803358398,"_hasShrinkwrap":false},"2.0.2":{"name":"locate-character","version":"2.0.2","description":"Get the line and column number of a specific character in a string","main":"dist/locate-character.umd.js","jsnext:main":"dist/locate-character.es.js","module":"dist/locate-character.es.js","scripts":{"test":"mocha","pretest":"npm run build","build":"rollup -c","prepublish":"npm test"},"files":["dist","types","README.md"],"repository":{"type":"git","url":"git+https://gitlab.com/Rich-Harris/locate-character.git"},"keywords":["string","character","locate","line","column","location"],"author":{"name":"Rich Harris"},"license":"MIT","bugs":{"url":"https://gitlab.com/Rich-Harris/locate-character/issues"},"homepage":"https://gitlab.com/Rich-Harris/locate-character#README","devDependencies":{"mocha":"^3.0.1","rollup":"^0.34.7","rollup-plugin-typescript":"^0.8.1","typescript":"^2.3.2"},"types":"./types.d.ts","gitHead":"c491d5cf6a2dbc3752b9a47c34cb251e1bd61d7b","_id":"locate-character@2.0.2","_npmVersion":"5.5.1","_nodeVersion":"9.1.0","_npmUser":{"name":"rich_harris","email":"richard.a.harris@gmail.com"},"dist":{"shasum":"3df66b253b2bd0e30f283d61b6b15dbce560c28c","size":2122,"noattachment":false,"key":"/locate-character/-/locate-character-2.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/locate-character/download/locate-character-2.0.2.tgz"},"maintainers":[{"name":"rich_harris","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/locate-character-2.0.2.tgz_1511803298232_0.20204413798637688"},"directories":{},"publish_time":1511803299176,"_hasShrinkwrap":false,"_cnpm_publish_time":1511803299176},"2.0.1":{"name":"locate-character","version":"2.0.1","description":"Get the line and column number of a specific character in a string","main":"dist/locate-character.umd.js","jsnext:main":"dist/locate-character.es.js","module":"dist/locate-character.es.js","scripts":{"test":"mocha","pretest":"npm run build","build":"rollup -c","prepublish":"npm test"},"files":["dist","README.md"],"repository":{"type":"git","url":"git+https://gitlab.com/Rich-Harris/locate-character.git"},"keywords":["string","character","locate","line","column","location"],"author":{"name":"Rich Harris"},"license":"MIT","bugs":{"url":"https://gitlab.com/Rich-Harris/locate-character/issues"},"homepage":"https://gitlab.com/Rich-Harris/locate-character#README","devDependencies":{"mocha":"^3.0.1","rollup":"^0.34.7","rollup-plugin-typescript":"^0.8.1","typescript":"^2.3.2"},"types":"./types.d.ts","gitHead":"fbccf96847a2cce145dd77a31fd7b9c7d21583f2","_id":"locate-character@2.0.1","_shasum":"48f9599f342daf26f73db32f45941eae37bae391","_from":".","_npmVersion":"4.6.1","_nodeVersion":"7.8.0","_npmUser":{"name":"rich_harris","email":"richard.a.harris@gmail.com"},"dist":{"shasum":"48f9599f342daf26f73db32f45941eae37bae391","size":2111,"noattachment":false,"key":"/locate-character/-/locate-character-2.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/locate-character/download/locate-character-2.0.1.tgz"},"maintainers":[{"name":"rich_harris","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/locate-character-2.0.1.tgz_1495398159282_0.061098309233784676"},"directories":{},"publish_time":1495398160224,"_hasShrinkwrap":false,"_cnpm_publish_time":1495398160224},"2.0.0":{"name":"locate-character","version":"2.0.0","description":"Get the line and column number of a specific character in a string","main":"dist/locate-character.umd.js","jsnext:main":"dist/locate-character.es.js","module":"dist/locate-character.es.js","scripts":{"test":"mocha","pretest":"npm run build","build":"rollup -c","prepublish":"npm test"},"files":["dist","README.md"],"repository":{"type":"git","url":"git+https://gitlab.com/Rich-Harris/locate-character.git"},"keywords":["string","character","locate","line","column","location"],"author":{"name":"Rich Harris"},"license":"MIT","bugs":{"url":"https://gitlab.com/Rich-Harris/locate-character/issues"},"homepage":"https://gitlab.com/Rich-Harris/locate-character#README","devDependencies":{"mocha":"^3.0.1","rollup":"^0.34.7","rollup-plugin-buble":"^0.12.1"},"gitHead":"2060b3b158daabb635375293dee21dfd34f84206","_id":"locate-character@2.0.0","_shasum":"8eb94df3a899e53c8d4cee6d13c9effb76213699","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rich_harris","email":"richard.a.harris@gmail.com"},"dist":{"shasum":"8eb94df3a899e53c8d4cee6d13c9effb76213699","size":2142,"noattachment":false,"key":"/locate-character/-/locate-character-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/locate-character/download/locate-character-2.0.0.tgz"},"maintainers":[{"name":"rich_harris","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/locate-character-2.0.0.tgz_1472778653613_0.24177161091938615"},"directories":{},"publish_time":1472778655508,"_cnpm_publish_time":1472778655508,"_hasShrinkwrap":false},"1.0.0":{"name":"locate-character","version":"1.0.0","description":"Get the line and column number of a specific character in a string","main":"dist/locate-character.umd.js","jsnext:main":"dist/locate-character.es.js","module":"dist/locate-character.es.js","scripts":{"test":"mocha","pretest":"npm run build","build":"rollup -c","prepublish":"npm test"},"files":["dist","README.md"],"repository":{"type":"git","url":"git+https://gitlab.com/Rich-Harris/locate-character.git"},"keywords":["string","character","locate","line","column","location"],"author":{"name":"Rich Harris"},"license":"MIT","bugs":{"url":"https://gitlab.com/Rich-Harris/locate-character/issues"},"homepage":"https://gitlab.com/Rich-Harris/locate-character#README","devDependencies":{"mocha":"^3.0.1","rollup":"^0.34.7","rollup-plugin-buble":"^0.12.1"},"gitHead":"2780530692d52ae5f383eae3cfd4409dad089b57","_id":"locate-character@1.0.0","_shasum":"116443c23f29fae28900cac285ba0c71f2693f6d","_from":".","_npmVersion":"3.8.9","_nodeVersion":"6.2.0","_npmUser":{"name":"rich_harris","email":"richard.a.harris@gmail.com"},"dist":{"shasum":"116443c23f29fae28900cac285ba0c71f2693f6d","size":1313,"noattachment":false,"key":"/locate-character/-/locate-character-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/locate-character/download/locate-character-1.0.0.tgz"},"maintainers":[{"name":"rich_harris","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/locate-character-1.0.0.tgz_1470598944504_0.15524782706052065"},"directories":{},"publish_time":1470598946304,"_cnpm_publish_time":1470598946304,"_hasShrinkwrap":false}},"readme":"# locate-character\n\nGet the line and column number of a particular character in a string.\n\n## Installation\n\n`npm install locate-character`, or get it from [unpkg.com/locate-character](https://unpkg.com/locate-character).\n\n## Usage\n\nTo search for a particular character, using the index or a search string, use `locate`:\n\n```js\nimport { locate } from 'locate-character';\n\nconst sample = `\nA flea and a fly in a flue\nWere imprisoned, so what could they do?\nSaid the fly, \"let us flee!\"\n\"Let us fly!\" said the flea.\nSo they flew through a flaw in the flue.\n`.trim();\n\n// Using a character index\nconst index = sample.indexOf('fly');\nlocate(sample, index);\n// -> { line: 0, column: 13, character: 13 }\n\n// Using the string itself\nlocate(sample, 'fly');\n// -> { line: 0, column: 13, character: 13 }\n\n// Using the string with a start index\nlocate(sample, 'fly', { startIndex: 14 });\n// -> { line: 2, column: 9, character: 76 }\n```\n\nIf you will be searching the same string repeatedly, it's much faster if you use `getLocator`:\n\n```js\nimport { getLocator } from 'locate-character';\n\nconst locate = getLocator(sample);\n\nlet location = locate(13);\n// -> { line: 0, column: 13, character: 13 }\n\nlocation = locate('fly', { startIndex: location.character + 1 });\n// -> { line: 2, column: 9, character: 76 }\n\nlocation = locate('fly', { startIndex: location.character + 1 });\n// -> { line: 3, column: 8, character: 104 }\n```\n\nIn some situations (for example, dealing with sourcemaps), you need one-based line numbers:\n\n```js\ngetLocator(sample, { offsetLine: 1 });\nlocate(sample, { offsetLine: 1 });\n```\n\nThere's also an `offsetColumn` option which is less useful in real-world situations.\n\n## License\n\nMIT\n","_attachments":{},"homepage":"https://gitlab.com/Rich-Harris/locate-character#README","bugs":{"url":"https://gitlab.com/Rich-Harris/locate-character/issues"},"license":"MIT"}