{"id":15699021,"url":"https://github.com/pgilad/get-line-from-pos","last_synced_at":"2025-05-09T02:15:50.708Z","repository":{"id":20955702,"uuid":"24244334","full_name":"pgilad/get-line-from-pos","owner":"pgilad","description":"Get the line number of a string using index or position","archived":false,"fork":false,"pushed_at":"2015-05-31T08:25:07.000Z","size":172,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-09T02:15:48.079Z","etag":null,"topics":["javascript","line","lookup","position","utility"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pgilad.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-19T20:24:24.000Z","updated_at":"2017-02-21T07:03:50.000Z","dependencies_parsed_at":"2022-07-30T02:37:58.022Z","dependency_job_id":null,"html_url":"https://github.com/pgilad/get-line-from-pos","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Fget-line-from-pos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Fget-line-from-pos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Fget-line-from-pos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgilad%2Fget-line-from-pos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgilad","download_url":"https://codeload.github.com/pgilad/get-line-from-pos/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253176442,"owners_count":21866143,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","line","lookup","position","utility"],"created_at":"2024-10-03T19:37:28.852Z","updated_at":"2025-05-09T02:15:50.676Z","avatar_url":"https://github.com/pgilad.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# get-line-from-pos\n\u003e Get the line number of a string using index or position\n\n[![NPM Version](http://img.shields.io/npm/v/get-line-from-pos.svg?style=flat)](https://npmjs.org/package/get-line-from-pos)\n[![NPM Downloads](http://img.shields.io/npm/dm/get-line-from-pos.svg?style=flat)](https://npmjs.org/package/get-line-from-pos)\n[![Build Status](http://img.shields.io/travis/pgilad/get-line-from-pos.svg?style=flat)](https://travis-ci.org/pgilad/get-line-from-pos)\n\nLookup a line number in a string using an index or position.\n\nUseful if you want to get a line number of a position or index from a regex match, but can\nalso be used in other situations.\n\n- Allows using negative positions to lookup line number.\n- Supported by CommonJS, AMD and browser.\n- Supports Regular line ending style (`\\n`) and MacOS line ending style (`\\r`).\n\n#### Installation\n\n```bash\n$ npm install --save get-line-from-pos\n```\n\n## Usage\n\n### CommonJS\n\n```js\nvar getLineFromPos = require('get-line-from-pos');\n\nvar str = 'string with \\n multiple \\n lines';\nconsole.log(getLineFromPos(str, /multiple/g.exec(str)));\n// -\u003e 2\n```\n\n### AMD\n\n```js\ndefine(['getLineFromPos'], function(getLineFromPos){\n    var pos = getLineFromPos(multipleLineStr, index);\n    console.log(pos);\n    //-\u003e line number that index is on\n});\n```\n\n### Browser\n\nLoad the script:\n```html\n\u003cscript src=\"../get-line-from-pos/index.js\"\u003e\u003c/script\u003e\n```\n\nThen when you need to use it:\n```js\nconsole.log(getLineFromPos(someStr, -1));\n//-\u003e Will output the number of lines in someStr\n```\n\n## API\n\n`getLineFromPos(inputStr, index)`\n\nBoth parameters are required.\n\n### inputStr\n\nType: `String`\n\n**Required**\n\nString to do the lookup for line number.\n\n### index\n\nType: `Number`\n\n**Required**\n\nThe index or position to lookup the line number.\n\n## License\n\nMIT ©[Gilad Peleg](http://giladpeleg.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgilad%2Fget-line-from-pos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgilad%2Fget-line-from-pos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgilad%2Fget-line-from-pos/lists"}