{"_id":"linenumber","_rev":"5-ad9f8656d8591606d72d4eb4b9bca8a8","name":"linenumber","description":"Get the line number of one or more matches in a file","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"linenumber","version":"1.0.0","description":"Get the line number of one or more matches in a file","main":"lib/linenumber.js","scripts":{"test":"grunt"},"repository":{"type":"git","url":"https://github.com/tandrewnichols/linenumber.git"},"keywords":["index","line","number","file"],"author":{"name":"Andrew Nichols","email":"tandrewnichols@gmail.com","url":"www.tandrewnichols.me"},"license":"MIT","bugs":{"url":"https://github.com/tandrewnichols/linenumber/issues"},"homepage":"https://github.com/tandrewnichols/linenumber","devDependencies":{"chai":"^3.2.0","coffee-script":"^1.9.3","grunt":"^0.4.5","grunt-contrib-clean":"^0.6.0","grunt-contrib-copy":"^0.8.1","grunt-contrib-jshint":"^0.11.2","grunt-contrib-testem":"^0.5.16","grunt-contrib-uglify":"^0.9.2","grunt-contrib-watch":"^0.6.1","grunt-mocha-test":"^0.12.7","grunt-open":"^0.2.3","grunt-simple-istanbul":"0.0.1","grunt-travis-matrix":"0.0.5","jshint-stylish":"^2.0.1","mocha":"^2.2.5","mocha-given":"^0.1.3","proxyquire":"^1.7.1","sinon":"^1.16.1","task-master":"^2.2.1"},"gitHead":"7db04458438294b631df36c09106fbf7f01e25af","_id":"linenumber@1.0.0","_shasum":"1011b0b064c4f1b4061127a6a73b0d720e272ea3","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"tandrewnichols","email":"tandrewnichols@gmail.com"},"maintainers":[{"name":"tandrewnichols","email":"tandrewnichols@gmail.com"}],"dist":{"shasum":"1011b0b064c4f1b4061127a6a73b0d720e272ea3","tarball":"https://registry.npmjs.org/linenumber/-/linenumber-1.0.0.tgz","integrity":"sha512-YopY5aBhep/dtZgpcBtYSasG5uA+jfcsHw/cvmRofEBf6yHMMmh1T6LvY4zdil1G9OGINYvpD9uPh2iGh34a6A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD61QzJfEFgz6KULnX4CHcEM4bzlbc+Dl0GpYkLqJ85tAIhAKj4YE9DlBUv2QvmuFPG+z/BWw3YayTtdfoQmJWh/TCY"}]},"directories":{}},"1.0.1":{"name":"linenumber","version":"1.0.1","description":"Get the line number of one or more matches in a file","main":"lib/linenumber.js","scripts":{"test":"grunt"},"repository":{"type":"git","url":"git+https://github.com/tandrewnichols/linenumber.git"},"keywords":["index","line","number","file"],"author":{"name":"Andrew Nichols","email":"tandrewnichols@gmail.com","url":"www.tandrewnichols.me"},"license":"MIT","bugs":{"url":"https://github.com/tandrewnichols/linenumber/issues"},"homepage":"https://github.com/tandrewnichols/linenumber","devDependencies":{"chai":"^3.2.0","coffee-script":"^1.9.3","grunt":"^0.4.5","grunt-contrib-clean":"^0.6.0","grunt-contrib-copy":"^0.8.1","grunt-contrib-jshint":"^0.11.2","grunt-contrib-testem":"^0.5.16","grunt-contrib-uglify":"^0.9.2","grunt-contrib-watch":"^0.6.1","grunt-mocha-test":"^0.12.7","grunt-open":"^0.2.3","grunt-simple-istanbul":"0.0.1","grunt-travis-matrix":"0.0.5","jshint-stylish":"^2.0.1","mocha":"^2.2.5","mocha-given":"^0.1.3","proxyquire":"^1.7.1","sinon":"^1.16.1","task-master":"^2.2.1"},"gitHead":"6d2878a7be6e420b21e5bc15a924eb2723caaa64","_id":"linenumber@1.0.1","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"tandrewnichols","email":"tandrewnichols@gmail.com"},"dist":{"integrity":"sha512-g7x+bxzGaJ7yUk1chFXmY4NT1oIiSQREUs33M29cjDPFUP1W/dlM3YGD1cR7qeSehp5TEpxAFP0L+Rpk3nUKzw==","shasum":"e45aba6ee50ec01626773c89224a8b46d0b2d77d","tarball":"https://registry.npmjs.org/linenumber/-/linenumber-1.0.1.tgz","fileCount":29,"unpackedSize":32443,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc3WUdCRA9TVsSAnZWagAAf5QP/3H7elQPu5E7h1ZmK9Jj\nLv+HvCM/GAhisib+Xw3PUL7PX0C2a41Ro0qxXrMAXeFOqGpwznGFZC5bIAdQ\nXC2p42M9NTmlJH89vNkATW80+zJ1WtRtcS3ogYQMbQyTbGOMjs5zY1SrlVcG\nCQ1ZECxHQh05blbZtwV8G8NHOUIyL+ToxtfYbL02UmVl9WX4hbnGB+xT+DOP\nOYTUX4E5Ynxu1zrxgAOPrvliGwrabD4LXEj9EdE3IXwSLnS3DkcVnvjzWL/K\nFWJlHNCGyXYRNR5Exuz3lmfeNXAbeH9egZBT1Y1AHT70s1+wiW8qTAwaKynL\nF2BSJay2czzqHMQ82MPzbfteic0baHnsCa+i+0lg1VyUuFMGdpoiG3QJ8qX8\nhFMGM2oatS1ibkYxYo5NjN+FeUAJI5m/t7ajxdymWk/LVWXz8GH/HqxE2PwM\ncgh1OqnpEb5qaF3GwwxnuELRPC8UYkRrDYzqX9WeqYVMNtiMAxDrxJL3zG/e\n82KtiFcKgxbvELHzNybx4H9tt8pw+W3ODN4K3kNtLN6X1st1syifug4+uoR8\n3qzcseLBXZjRK+0VPwVQq6SUsOPdskEBBJNo1YpmU3ayBm7HdThb4O1j+roP\na10/DMI+xlTM3EJX0WxQvBzZy/WxdqJxLYKCP3lhSJdbelH4UKajhPmNczL7\nvvMJ\r\n=ha/4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCnpzYEXi4GbjNZ7AGWaL7Y5QmNJQpV49QETgnvmQlOagIgC8DtLP91QJPgtkXVbw/zrVjTzUuVhtwInz42l01RE5M="}]},"maintainers":[{"name":"tandrewnichols","email":"tandrewnichols@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/linenumber_1.0.1_1558013212785_0.7602317902738247"},"_hasShrinkwrap":false}},"readme":"[![Build Status](https://travis-ci.org/tandrewnichols/linenumber.png)](https://travis-ci.org/tandrewnichols/linenumber) [![downloads](http://img.shields.io/npm/dm/linenumber.svg)](https://npmjs.org/package/linenumber) [![npm](http://img.shields.io/npm/v/linenumber.svg)](https://npmjs.org/package/linenumber) [![Code Climate](https://codeclimate.com/github/tandrewnichols/linenumber/badges/gpa.svg)](https://codeclimate.com/github/tandrewnichols/linenumber) [![Test Coverage](https://codeclimate.com/github/tandrewnichols/linenumber/badges/coverage.svg)](https://codeclimate.com/github/tandrewnichols/linenumber) [![dependencies](https://david-dm.org/tandrewnichols/linenumber.png)](https://david-dm.org/tandrewnichols/linenumber) ![Size](https://img.shields.io/badge/size-1.25kb-brightgreen.svg)\n\n# linenumber\n\nGet the line number of one or more matches in a file\n\n## Installation\n\n`npm install --save linenumber`\n\n## Summary\n\nPass in the contents of a file or a filename, along with a pattern and an optional callback, and get back an array that includes the line numbers of any matches in that file.\n\n## Usage\n\nPass the content to search (which can also be a filename) and the string or regular expression pattern to search for to linenumber, along with an optional callback.\n\nFor example, given _lib/foo.json_,\n\n```js\n{\n  \"foo\": 1,\n  \"bar\": true,\n  \"baz\": \"a string\"\n}\n```\n\nany of the following will work:\n\n```js\n/**\n * SYNC\n */\nvar linenumber = require('linenumber');\n\n// With string content and query\nlinenumber('Foo\\nbar\\nbaz', 'bar'); // [{ line: 2, match: 'bar' }]\n\n// With a filename\nlinenumber('lib/foo.json', 'bar'); // [{ line: 3, match: 'bar', file: 'lib/foo.json' }]\n\n// With a regular expression\nlinenumber('lib/foo.json', /ba./g); // [{ line: 3, match: 'bar', file: 'lib/foo.json' }, { line: 4, match: 'baz', file: 'lib/foo.json' }]\n\n// Without a match\nlinenumber('lib/foo.json', 'hello'); // null\n\n/**\n * ASYNC\n */\n// The other versions above will also work asynchronously if a callback is passed\nlinenumber('lib/foo.json', 'bar', function(err, results) { /*...*/ }); // results = [{ line: 3, match: 'bar', file: 'lib/foo.json' }]\n```\n\nBy default, `linenumber` will use `fs.readFile` and `fs.readFileSync` to read in the contents of a file, but you can set it up to use a different file loader if desired. For instance, since our examples above use a `.json` file, we can make `linenumber` use `require` as the loader instead.\n\n```js\nlinenumber.loaderSync(require);\nlinenumber('lib/foo.json', 'bar');\n```\n\n If you are using `linenumber` on the client-side, these defaults obviously will not work, so you will have to load your own. There are too many client side libraries and frameworks to try to establish a reasonable default.\n\nA note on async usage: `linenumber` looks at your callback length to try to determine whether to return `null, results` or just `results`. `fs` and many other node-based modules use the standard error-then-everything-else signature, but on the client-side that may not be the case. `linenumber` assumes that if a callback accepts only one parameter, it's the content, _not_ an error (which makes sense).\n\n## Custom Loaders\n\nAs above, you can provide custom loaders for reading the contents of a \"file\" (which could really mean anything). There are several ways to do this.\n\n### Sync loader only\n\nCall `linenumber.loaderSync` and pass the function.\n\n```js\nlinenumber.loaderSync(require);\n```\n\n### Async loader only\n\nCall `linenumber.loader` and pass the function.\n\n```js\n// Contrived example\nlinenumber.loader(function(file, done) {\n  fs.readFile(file, { encoding: 'utf8' }, function(err, contents) {\n    done(null, contents.replace('hello', 'goodbye'));\n  });\n});\n```\n\n### Provide both sync and async loaders\n\nYou can call _either_ `loader` or `loaderSync` with an array or object to replace both the sync and async loaders.\n\n```js\nlinenumber.loader([sync, async]);\n// or\nlinenumber.loader({ sync: sync, async: async });\n```\n\n### Args\n\nYou can also provide arguments to be passed to loader functions.\n\n```js\n// someSyncFunction will be invoked with the filename, 'foo', and 'bar'\nlinenumber.loaderSync(someSyncFunction, 'foo', 'bar');\n```\n\n### Context\n\nYou can even set the context of the `this` object for the loader function:\n\n```\nlinenumber.loader.apply(this, asyncFunc);\n```\n\nIn this case, `linenumber` will store the `this` context and apply it whenever the loader is called.\n\n### Reset the loaders\n\nIf for some reason, you need to restore the original loaders, just call `linenumber.reset()`.\n\n## Browser\n\nUse whatever serving mechanism you prefer and serve `dist/linenumber.js` or `dist/linenumber.min.js`, then access it globally with `linenumber`.\n\n```html\n<script src=\"/dist/linenumber.js\"></script>\n<script>\n  var matches = linenumber('Foo\\nbar\\nbaz', 'bar');\n</script>\n```\n\n## Contributing\n\nPlease see [the contribution guidelines](CONTRIBUTING.md).\n","maintainers":[{"name":"tandrewnichols","email":"tandrewnichols@gmail.com"}],"time":{"modified":"2022-06-19T12:31:36.223Z","created":"2015-10-01T17:49:58.179Z","1.0.0":"2015-10-01T17:49:58.179Z","1.0.1":"2019-05-16T13:26:52.954Z"},"homepage":"https://github.com/tandrewnichols/linenumber","keywords":["index","line","number","file"],"repository":{"type":"git","url":"git+https://github.com/tandrewnichols/linenumber.git"},"author":{"name":"Andrew Nichols","email":"tandrewnichols@gmail.com","url":"www.tandrewnichols.me"},"bugs":{"url":"https://github.com/tandrewnichols/linenumber/issues"},"license":"MIT","readmeFilename":"README.md"}