{"_id":"line-column","_rev":"77285","name":"line-column","description":"Convert efficiently index to/from line-column in a string","dist-tags":{"latest":"1.0.2"},"maintainers":[{"name":"io-monad","email":"iride.monad@gmail.com"}],"time":{"modified":"2021-06-03T10:24:51.000Z","created":"2016-03-25T03:44:06.242Z","1.0.2":"2016-03-26T01:56:03.714Z","1.0.1":"2016-03-25T04:12:03.525Z","1.0.0":"2016-03-25T03:44:06.242Z"},"users":{"farskipper":true},"author":{"name":"IRIDE Monad","email":"iride.monad@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/io-monad/line-column.git"},"versions":{"1.0.2":{"name":"line-column","version":"1.0.2","description":"Convert efficiently index to/from line-column in a string","author":{"name":"IRIDE Monad","email":"iride.monad@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/io-monad/line-column.git"},"homepage":"https://github.com/io-monad/line-column","bugs":{"url":"https://github.com/io-monad/line-column/issues"},"keywords":["string","index","line","column","linecol","position"],"main":"lib/line-column.js","files":["lib"],"scripts":{"test":"gulp test","watch":"gulp watch","benchmark":"node benchmark/benchmark.js"},"devDependencies":{"benchmark":"^2.1.0","find-line-column":"^0.5.2","gulp":"^3.9.1","gulp-coveralls":"^0.1.4","gulp-istanbul":"^0.10.3","gulp-mocha":"^2.2.0","gulp-plumber":"^1.1.0","intelli-espower-loader":"^1.0.1","istanbul":"^0.4.2","mocha":"^2.4.5","power-assert":"^1.3.1"},"dependencies":{"isarray":"^1.0.0","isobject":"^2.0.0"},"gitHead":"490eaf5c51a665ab3ff92862e22c085b54b7641e","_id":"line-column@1.0.2","_shasum":"d25af2936b6f4849172b312e4792d1d987bc34a2","_from":".","_npmVersion":"3.8.1","_nodeVersion":"5.6.0","_npmUser":{"name":"io-monad","email":"iride.monad@gmail.com"},"dist":{"shasum":"d25af2936b6f4849172b312e4792d1d987bc34a2","size":4198,"noattachment":false,"key":"/line-column/-/line-column-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/line-column/download/line-column-1.0.2.tgz"},"maintainers":[{"name":"io-monad","email":"iride.monad@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/line-column-1.0.2.tgz_1458957361274_0.415254351682961"},"directories":{},"publish_time":1458957363714,"_cnpm_publish_time":1458957363714,"_hasShrinkwrap":false},"1.0.1":{"name":"line-column","version":"1.0.1","description":"Convert efficiently index to/from line-column in a string","author":{"name":"IRIDE Monad","email":"iride.monad@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/io-monad/line-column.git"},"homepage":"https://github.com/io-monad/line-column","bugs":{"url":"https://github.com/io-monad/line-column/issues"},"keywords":["string","index","line","column","linecol","position"],"main":"lib/line-column.js","files":["lib"],"scripts":{"test":"gulp test","watch":"gulp watch","benchmark":"node benchmark/benchmark.js"},"devDependencies":{"benchmark":"^2.1.0","find-line-column":"^0.5.2","gulp":"^3.9.1","gulp-coveralls":"^0.1.4","gulp-istanbul":"^0.10.3","gulp-mocha":"^2.2.0","gulp-plumber":"^1.1.0","intelli-espower-loader":"^1.0.1","istanbul":"^0.4.2","mocha":"^2.4.5","power-assert":"^1.3.1"},"dependencies":{"isarray":"^1.0.0","isobject":"^2.0.0"},"gitHead":"bb5c5c316af3676b683f81608bb5e583bdaf8d59","_id":"line-column@1.0.1","_shasum":"394d0e9aaeb3d2f152cf86fbb2230e701df76a0e","_from":".","_npmVersion":"3.8.1","_nodeVersion":"5.6.0","_npmUser":{"name":"io-monad","email":"iride.monad@gmail.com"},"dist":{"shasum":"394d0e9aaeb3d2f152cf86fbb2230e701df76a0e","size":4197,"noattachment":false,"key":"/line-column/-/line-column-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/line-column/download/line-column-1.0.1.tgz"},"maintainers":[{"name":"io-monad","email":"iride.monad@gmail.com"}],"_npmOperationalInternal":{"host":"packages-13-west.internal.npmjs.com","tmp":"tmp/line-column-1.0.1.tgz_1458879121246_0.4095685121137649"},"directories":{},"publish_time":1458879123525,"_cnpm_publish_time":1458879123525,"_hasShrinkwrap":false},"1.0.0":{"name":"line-column","version":"1.0.0","description":"Convert efficiently index to/from line-column in a string","author":{"name":"IRIDE Monad","email":"iride.monad@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/io-monad/line-column.git"},"homepage":"https://github.com/io-monad/line-column","bugs":{"url":"https://github.com/io-monad/line-column/issues"},"keywords":["string","index","line","column","linecol","position"],"main":"line-column.js","scripts":{"test":"gulp test","watch":"gulp watch","benchmark":"node benchmark/benchmark.js"},"devDependencies":{"benchmark":"^2.1.0","find-line-column":"^0.5.2","gulp":"^3.9.1","gulp-coveralls":"^0.1.4","gulp-istanbul":"^0.10.3","gulp-mocha":"^2.2.0","gulp-plumber":"^1.1.0","intelli-espower-loader":"^1.0.1","istanbul":"^0.4.2","mocha":"^2.4.5","power-assert":"^1.3.1"},"dependencies":{"isarray":"^1.0.0","isobject":"^2.0.0"},"gitHead":"5de341b627b78fe66e1967f6e6bc7d5b9879fce3","_id":"line-column@1.0.0","_shasum":"fbd4f22d25ac8fb5f0b8f8240329221599b4baba","_from":".","_npmVersion":"3.8.1","_nodeVersion":"5.6.0","_npmUser":{"name":"io-monad","email":"iride.monad@gmail.com"},"dist":{"shasum":"fbd4f22d25ac8fb5f0b8f8240329221599b4baba","size":12592,"noattachment":false,"key":"/line-column/-/line-column-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/line-column/download/line-column-1.0.0.tgz"},"maintainers":[{"name":"io-monad","email":"iride.monad@gmail.com"}],"_npmOperationalInternal":{"host":"packages-13-west.internal.npmjs.com","tmp":"tmp/line-column-1.0.0.tgz_1458877443966_0.142900045029819"},"directories":{},"publish_time":1458877446242,"_cnpm_publish_time":1458877446242,"_hasShrinkwrap":false}},"readme":"# line-column\n\n[![Build Status](https://travis-ci.org/io-monad/line-column.svg?branch=master)](https://travis-ci.org/io-monad/line-column) [![Coverage Status](https://coveralls.io/repos/github/io-monad/line-column/badge.svg?branch=master)](https://coveralls.io/github/io-monad/line-column?branch=master) [![npm version](https://badge.fury.io/js/line-column.svg)](https://badge.fury.io/js/line-column)\n\nNode module to convert efficiently index to/from line-column in a string.\n\n## Install\n\n    npm install line-column\n\n## Usage\n\n### lineColumn(str, options = {})\n\nReturns a `LineColumnFinder` instance for given string `str`.\n\n#### Options\n\n| Key     | Description | Default |\n| ------- | ----------- | ------- |\n| `origin`  | The origin value of line number and column number | `1` |\n\n### lineColumn(str, index)\n\nThis is just a shorthand for `lineColumn(str).fromIndex(index)`.\n\n### LineColumnFinder#fromIndex(index)\n\nFind line and column from index in the string.\n\nParameters:\n\n- `index` - `number` Index in the string. (0-origin)\n\nReturns:\n\n- `{ line: x, col: y }` Found line number and column number.\n- `null` if the given index is out of range.\n\n### LineColumnFinder#toIndex(line, column)\n\nFind index from line and column in the string.\n\nParameters:\n\n- `line` - `number` Line number in the string.\n- `column` - `number` Column number in the string.\n\nor\n\n- `{ line: x, col: y }` - `Object` line and column numbers in the string.<br>A key name `column` can be used instead of `col`.\n\nor\n\n- `[ line, col ]` - `Array` line and column numbers in the string.\n\nReturns:\n\n- `number` Found index in the string.\n- `-1` if the given line or column is out of range.\n\n## Example\n\n```js\nvar lineColumn = require(\"line-column\");\n\nvar testString = [\n  \"ABCDEFG\\n\",         // line:0, index:0\n  \"HIJKLMNOPQRSTU\\n\",  // line:1, index:8\n  \"VWXYZ\\n\",           // line:2, index:23\n  \"日本語の文字\\n\",    // line:3, index:29\n  \"English words\"      // line:4, index:36\n].join(\"\");            // length:49\n\nlineColumn(testString).fromIndex(3)   // { line: 1, col: 4 }\nlineColumn(testString).fromIndex(33)  // { line: 4, col: 5 }\nlineColumn(testString).toIndex(1, 4)  // 3\nlineColumn(testString).toIndex(4, 5)  // 33\n\n// Shorthand of .fromIndex (compatible with find-line-column)\nlineColumn(testString, 33)            // { line:4, col: 5 }\n\n// Object or Array is also acceptable\nlineColumn(testString).toIndex({ line: 4, col: 5 })     // 33\nlineColumn(testString).toIndex({ line: 4, column: 5 })  // 33\nlineColumn(testString).toIndex([4, 5])                  // 33\n\n// You can cache it for the same string. It is so efficient. (See benchmark)\nvar finder = lineColumn(testString);\n\nfinder.fromIndex(33)     // { line: 4, column: 5 }\nfinder.toIndex(4, 5)     // 33\n\n// For 0-origin line and column numbers\nvar oneOrigin = lineColumn(testString, { origin: 0 });\n\noneOrigin.fromIndex(33)  // { line: 3, column: 4 }\noneOrigin.toIndex(3, 4)  // 33\n```\n\n## Testing\n\n    npm test\n\n## Benchmark\n\nThe popular package [find-line-column](https://www.npmjs.com/package/find-line-column) provides the same \"index to line-column\" feature.\n\nHere is some benchmarking on `line-column` vs `find-line-column`. You can run this benchmark by `npm run benchmark`. See [benchmark/](benchmark/) for the source code.\n\n```\nlong text  + line-column (not cached) x     72,989 ops/sec ±0.83% (89 runs sampled)\nlong text  + line-column (cached)     x 13,074,242 ops/sec ±0.32% (89 runs sampled)\nlong text  + find-line-column         x     33,887 ops/sec ±0.54% (84 runs sampled)\nshort text + line-column (not cached) x  1,636,766 ops/sec ±0.77% (82 runs sampled)\nshort text + line-column (cached)     x 21,699,686 ops/sec ±1.04% (82 runs sampled)\nshort text + find-line-column         x    382,145 ops/sec ±1.04% (85 runs sampled)\n```\n\nAs you might have noticed, even not cached version of `line-column` is 2x - 4x faster than `find-line-column`, and cached version of `line-column` is remarkable 50x - 380x faster.\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## License\n\nMIT (See LICENSE)\n","_attachments":{},"homepage":"https://github.com/io-monad/line-column","bugs":{"url":"https://github.com/io-monad/line-column/issues"},"license":"MIT"}