{"_id":"line-counter","_rev":"5-18f6e133e05dea6e2f4b0f619dcedbe1","name":"line-counter","description":"A simple class that allows to count lines while iterating over a string","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"line-counter","version":"1.0.0","description":"A simple class that allows to count lines while iterating over a string","main":"index.js","scripts":{"test":"jasmine"},"repository":{"type":"git","url":"https://github.com/nknapp/line-counter.git"},"author":{"name":"Nils Knappmeier"},"license":"MIT","bugs":{"url":"https://github.com/nknapp/line-counter/issues"},"homepage":"https://github.com/nknapp/line-counter","devDependencies":{"jasmine":"^2.3.1","verb":"^0.7.4"},"gitHead":"a1e99c8c7ff85331cb67ea0a4bd5ef44dc74d5fd","_id":"line-counter@1.0.0","_shasum":"f6d52418af3d6140cd83518194015a904a48788e","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"knappi","email":"npm@knappi.org"},"maintainers":[{"name":"knappi","email":"npm@knappi.org"}],"dist":{"shasum":"f6d52418af3d6140cd83518194015a904a48788e","tarball":"https://registry.npmjs.org/line-counter/-/line-counter-1.0.0.tgz","integrity":"sha512-o7YIOnd6A/Tmp4YRb0LuQtXmKJIeDL4HncK7xLMbAJ9B4PyFBqQuY/CctaURg7EtzBZn1hzCLlALbKkXA2yiLA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBUy7nUkEDN9kX9NVKXl9Wl6NAHis34Fdn7i3MZw5xZ9AiEAm+HEyjnMv9vU1z2hllwCBvIpaqHAhw3jgA8UC2Zph6g="}]}},"1.0.3":{"name":"line-counter","version":"1.0.3","description":"A simple class that allows to count lines while iterating over a string","main":"index.js","scripts":{"test":"jasmine"},"repository":{"type":"git","url":"https://github.com/nknapp/line-counter.git"},"author":{"name":"Nils Knappmeier"},"license":"MIT","bugs":{"url":"https://github.com/nknapp/line-counter/issues"},"homepage":"https://github.com/nknapp/line-counter","devDependencies":{"jasmine":"^2.3.1","verb":"^0.7.4"},"gitHead":"da3ef9825d2441d3c22c541dccd05c66fd46d0b6","_id":"line-counter@1.0.3","_shasum":"b32f63cc2add3f5d462fee29d88ef0283457f542","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"knappi","email":"npm@knappi.org"},"maintainers":[{"name":"knappi","email":"npm@knappi.org"}],"dist":{"shasum":"b32f63cc2add3f5d462fee29d88ef0283457f542","tarball":"https://registry.npmjs.org/line-counter/-/line-counter-1.0.3.tgz","integrity":"sha512-z+edcepiL6n2ukTGPWeuBWR8VU0uUAFa0ShwXd22DpAXOalWTGojxMGjg8M2LMaBY1xuQn8JjM2ade88bHlxfw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDF+G6AhKL/AOTSRXHE8+QbNuUPYQC+juKMc5o/AcNGwwIgWRZRtDdEGtbFAugQx8k5IGGm+C7QI3xL5fjlR9Qcy6M="}]}},"1.1.0":{"name":"line-counter","version":"1.1.0","description":"A simple class that allows to count lines while iterating over a string","main":"index.js","scripts":{"test":"jasmine"},"repository":{"type":"git","url":"https://github.com/nknapp/line-counter.git"},"author":{"name":"Nils Knappmeier"},"license":"MIT","bugs":{"url":"https://github.com/nknapp/line-counter/issues"},"homepage":"https://github.com/nknapp/line-counter","devDependencies":{"jasmine":"^2.3.1","verb":"^0.7.4"},"gitHead":"fda779a828aa2c6f9487cb70fa52ed0f870b7a14","_id":"line-counter@1.1.0","_shasum":"10df2c046ad3546e724fba55fa72cde18a6a01f3","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"knappi","email":"npm@knappi.org"},"maintainers":[{"name":"knappi","email":"npm@knappi.org"}],"dist":{"shasum":"10df2c046ad3546e724fba55fa72cde18a6a01f3","tarball":"https://registry.npmjs.org/line-counter/-/line-counter-1.1.0.tgz","integrity":"sha512-6bmXJG/pOX5HBb2aIJZrI9CALBgY1VMbS0GPuXfJaT13UEfee/2xxPCsOOJdXLl3KPRyBf2/D+cjiG8hU9S7LA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEC+fCHF1FU4IgfL21GxhGKbCZ+ozfg57TCHJFvPgC2QAiA9Q38dxhP8T/YAiKWXN1Sh1OWthlFF+6zh/qhgSZgs1g=="}]}}},"readme":"# line-counter [![NPM version](https://badge.fury.io/js/line-counter.svg)](http://badge.fury.io/js/line-counter)  [![Build Status](https://travis-ci.org/nknapp/line-counter.svg)](https://travis-ci.org/nknapp/line-counter)  [![Coverage Status](https://img.shields.io/coveralls/nknapp/line-counter.svg)](https://coveralls.io/r/nknapp/line-counter)\n\n> A simple class that allows to count lines while iterating over a string\n\nThis module helps you when you want to output the line-number of certain locations in a string while iterating over the string otherwise.\nFor example, if you want to\n\n## Example\n\nSuppose, we want to extract all occurences of 'sed' and 'ipsum' from the following text:\n\n```txt\nLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor\ninvidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et\naccusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata\nsanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing\nelitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed\ndiam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd\ngubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n```\n\nWe can easily match all the occurences with a regex, but we only get the char-index of each match.\nUsing the `line-counter` module, we can print line-numbers as well:\n\n```js\nvar regex = /sed|ipsum/g;\nvar text = require(\"fs\").readFileSync(\"example.txt\");\n\nvar LineCounter = require(\"line-counter\");\nvar counter = new LineCounter(text);\n\nvar match;\nwhile ((match = regex.exec(text)) !== null) {\n    // Example for .countUpTo()\n    console.log(\n        \"Found '\" + match[0] + \"'\",\n        \"at index\", match.index,\n        \"which is in line \", counter.countUpTo(match.index)\n    );\n    // Example for .locate()\n    console.log(\n        \"Found '\" + match[0] + \"'\",\n        \"at index\", match.index,\n        \"which is at location\", counter.locate(match.index)\n    );\n}\n```\n\n### API\n\n### [LineCounter](index.js#L44)\n\nCreate a new LineCounter instance counting lines in a given string. The class provides a method `countUpTo` that pushes an internal counter to the line of a specified char-index in the string.\n\nExample:\n\n**Params**\n\n* `contents` **{string}**: the string that is parsed (i.e. file contents)\n\n**Example**\n\n```js\nvar LineCounter = require('line-counter');\nvar lc = new LineCounter('abc\\ncde\\nefg');\nlc.countUpTo(0); // == 1\nlc.countUpTo(8); // == 3\n```\n\n### [.countUpTo](index.js#L70)\n\nReturns the line-number of a given char-index within the string.\n\n**Params**\n\n* `upTo` **{number}**: a char-index within the `contents`-string. This char-index must be greater or equal to the line-start of the last char-index passed to the previous call to `countUpTo`\n* `returns` **{number}**: the line-number of this char-index.\n\n### [.locate](index.js#L111)\n\nReturns the location (line-nr and column-nr) of a char index\nwithin the string.\n\n* `returns` **{{column: number, line: number}**: line- and column-index (based off `1`)\n\n## Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm i -d && npm test\n```\n\n## Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/nknapp/line-counter/issues/new)\n\n## Author\n\n**Nils Knappmeier**\n\n+ [github/nknapp](https://github.com/nknapp)\n* [twitter/knappi79](http://twitter.com/knappi79)\n\n## License\n\nReleased under the MIT license.\n\n# Change Log\n\nThis project adheres to [Semantic Versioning](http://semver.org/).\n\n## Upcoming\n\n### Add\n\n* Added `.locate(charIndex)` to return line- and column-index of the char-index location\n\n## v1.0.3 - 2015-05-11\n\n### Fix\n* Issue #1: Endless-Loop calling `.upTo(content.length)` for contents that end with a new-line.\n\n## v1.0.2 - 2015-05-10\n\n### Added\n* Initial version of the line-counter module","maintainers":[{"name":"knappi","email":"npm@knappi.org"}],"time":{"modified":"2022-06-19T12:28:01.076Z","created":"2015-05-10T21:56:30.160Z","1.0.0":"2015-05-10T21:56:30.160Z","1.0.3":"2015-05-11T21:22:58.220Z","1.1.0":"2015-06-05T06:44:23.148Z"},"homepage":"https://github.com/nknapp/line-counter","repository":{"type":"git","url":"https://github.com/nknapp/line-counter.git"},"author":{"name":"Nils Knappmeier"},"bugs":{"url":"https://github.com/nknapp/line-counter/issues"},"license":"MIT","readmeFilename":"README.md"}