{"_id":"monocart-locator","_rev":"4-08aa791ead07461e1a558ae2ac6deb90","name":"monocart-locator","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"monocart-locator","version":"1.0.0","license":"MIT","_id":"monocart-locator@1.0.0","maintainers":[{"name":"cenfun","email":"cenfun@qq.com"}],"dist":{"shasum":"7ff2c9cc1391a60b03ccbc1a5c5d162ba41de065","tarball":"https://registry.npmjs.org/monocart-locator/-/monocart-locator-1.0.0.tgz","fileCount":12,"integrity":"sha512-qIHJ7f99miF2HbVUWAFKR93SfgGYpFPUCQPmW9q1VXU9onxMUFJxhQDdG3HkEteogUbsKB7Gr5MRgjzcIxwTaQ==","signatures":[{"sig":"MEQCIHJymFVH3KhGrHHCRsaHCaRLU4ZNdQeF7BW8Wkv1/RlIAiA+t+LSiU89UkgVWFeqDor3mnb3PL0CpTeG6a88nZ1YOQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14088},"main":"./lib/index.js","types":"./lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/index.mjs","default":"./lib/index.js","require":"./lib/index.js"},"./package.json":"./package.json"},"gitHead":"cf1b60f6e740ae6da4b7aa82ecabd0eda30fb1b2","scripts":{"test":"mocha","patch":"npm run test && sf publish patch"},"_npmUser":{"name":"cenfun","email":"cenfun@qq.com"},"_npmVersion":"10.5.0","description":"Monocart Locator","directories":{},"_nodeVersion":"20.12.0","_hasShrinkwrap":false,"devDependencies":{"mocha":"^10.4.0","eslint":"^8.57.0","console-grid":"^2.2.2","eight-colors":"^1.3.0","eslint-config-plus":"^1.0.6"},"_npmOperationalInternal":{"tmp":"tmp/monocart-locator_1.0.0_1711884407531_0.29877490434216947","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"monocart-locator","version":"1.0.1","license":"MIT","_id":"monocart-locator@1.0.1","dist":{"shasum":"fd41853ccb6c762c202d377e7c52a4d806b4c54d","tarball":"https://registry.npmjs.org/monocart-locator/-/monocart-locator-1.0.1.tgz","fileCount":12,"integrity":"sha512-EiTMab4QPeNrD+qshDoRepBRCxUUgpp0YIFE9faES9WY7y+BxivI95oZOduI46dHax9r1mQnordHuRrIKiMCBQ==","signatures":[{"sig":"MEYCIQDVVCSfAI5IW2HFcdRr6DKiQ88No7o2s48S1/NVHHEpTQIhAIcIhORYTiETQGrj4ysfgZkhk6K8aHdtgYCqnSTbRPLw","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14272},"main":"./lib/index.js","types":"./lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/index.mjs","default":"./lib/index.js","require":"./lib/index.js"},"./package.json":"./package.json"},"gitHead":"705ee34f592b0f9d1ffa18dd95d4c38a3e35a893","scripts":{"test":"mocha","patch":"npm run test && sf publish patch"},"_npmUser":{"name":"cenfun","email":"cenfun@qq.com"},"_npmVersion":"10.7.0","description":"Monocart Locator","directories":{},"_nodeVersion":"20.15.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^10.5.2","eslint":"^9.6.0","console-grid":"^2.2.2","eight-colors":"^1.3.0","eslint-config-plus":"^2.0.2"},"_npmOperationalInternal":{"tmp":"tmp/monocart-locator_1.0.1_1719805014599_0.5694552910853938","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"monocart-locator","version":"1.0.2","license":"MIT","_id":"monocart-locator@1.0.2","maintainers":[{"name":"cenfun","email":"cenfun@qq.com"}],"dist":{"shasum":"0149c0eec9c2b724b77853d4bf0feedd7517fc61","tarball":"https://registry.npmjs.org/monocart-locator/-/monocart-locator-1.0.2.tgz","fileCount":9,"integrity":"sha512-v8W5hJLcWMIxLCcSi/MHh+VeefI+ycFmGz23Froer9QzWjrbg4J3gFJBuI/T1VLNoYxF47bVPPxq8ZlNX4gVCw==","signatures":[{"sig":"MEQCIBwbYaPCAl4tcIsCarXpL9F3K1WzfwDCYcKCrCn9BQdzAiBmocwIS7f1fxa+0lqppe1KY2X4GJugnvmRt+zpZ7rBFg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":12163},"main":"./lib/index.js","types":"./lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/index.mjs","default":"./lib/index.js","require":"./lib/index.js"},"./package.json":"./package.json"},"gitHead":"bfdea12a579614ba1b233546d15e057dd38b88b1","scripts":{"test":"mocha","patch":"npm run test && sf publish patch"},"_npmUser":{"name":"cenfun","email":"cenfun@qq.com"},"_npmVersion":"10.7.0","description":"Monocart Locator","directories":{},"_nodeVersion":"20.15.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^10.5.2","eslint":"^9.6.0","console-grid":"^2.2.2","eight-colors":"^1.3.0","eslint-config-plus":"^2.0.2"},"_npmOperationalInternal":{"tmp":"tmp/monocart-locator_1.0.2_1719969037402_0.526088075999013","host":"s3://npm-registry-packages"}},"1.0.3":{"name":"monocart-locator","version":"1.0.3","description":"A lightweight source code position locator for converting between offset and line/column, with built-in line and comment parsing","main":"./lib/index.js","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/index.mjs","require":"./lib/index.js","default":"./lib/index.js"},"./package.json":"./package.json"},"types":"./lib/index.d.ts","scripts":{"test":"mocha","patch":"npm run test && sf publish patch"},"keywords":["locator","source","position","offset","line","column","comment","parser"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/cenfun/monocart-locator.git"},"dependencies":{},"devDependencies":{"console-grid":"^2.2.4","eight-colors":"^1.3.3","eslint":"^10.2.0","eslint-config-plus":"^2.0.4","mocha":"^11.7.5"},"gitHead":"1f45e0391b3d236f7a14b517f734e9a08ffa9fe6","_id":"monocart-locator@1.0.3","bugs":{"url":"https://github.com/cenfun/monocart-locator/issues"},"homepage":"https://github.com/cenfun/monocart-locator#readme","_nodeVersion":"24.14.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-pe29W2XAoA1WQmZZqxXoP7s06ZEXUhcb81086v68cqjk1HnVL7Q/iU/WJnnetxjPcLqwb4qG8vaSGUOMQU602g==","shasum":"476ddc4956efcfbda5470bb1c8b986a54b68307a","tarball":"https://registry.npmjs.org/monocart-locator/-/monocart-locator-1.0.3.tgz","fileCount":9,"unpackedSize":16953,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICF3ejT8Gs6N0NdZKReooyOUHCaqaKw0O0aP72Tr68C7AiA8A9Si8bzQsyo9fwvlsSKENsELN/doXmcyVdhk6u2k6w=="}]},"_npmUser":{"name":"cenfun","email":"cenfun@qq.com"},"directories":{},"maintainers":[{"name":"cenfun","email":"cenfun@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/monocart-locator_1.0.3_1775902565339_0.330562583507773"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-31T11:26:47.531Z","modified":"2026-04-11T10:16:05.609Z","1.0.0":"2024-03-31T11:26:47.674Z","1.0.1":"2024-07-01T03:36:54.828Z","1.0.2":"2024-07-03T01:10:37.567Z","1.0.3":"2026-04-11T10:16:05.498Z"},"license":"MIT","description":"A lightweight source code position locator for converting between offset and line/column, with built-in line and comment parsing","maintainers":[{"name":"cenfun","email":"cenfun@qq.com"}],"readme":"# Monocart Locator\r\n[![](https://img.shields.io/npm/v/monocart-locator)](https://www.npmjs.com/package/monocart-locator)\r\n[![](https://badgen.net/npm/dw/monocart-locator)](https://www.npmjs.com/package/monocart-locator)\r\n![](https://img.shields.io/github/license/cenfun/monocart-locator)\r\n\r\n> A lightweight source code position locator for converting between offset and line/column, with built-in line and comment parsing. Zero dependencies.\r\n\r\n## Features\r\n- Convert between offset and line/column positions\r\n- Parse source code into lines with metadata (length, indent, blank, comment)\r\n- Detect line comments (`//`) and block comments (`/* */`) with template literal (`${}`) support\r\n- O(log n) position lookups via binary search\r\n\r\n## Install\r\n```sh\r\nnpm i monocart-locator\r\n```\r\n\r\n## Usage\r\n\r\n### Locator\r\nThe main API for source code position conversion.\r\n```js\r\nconst { Locator } = require('monocart-locator');\r\n// or\r\n// import { Locator } from 'monocart-locator';\r\n\r\nconst locator = new Locator(source);\r\n\r\n// Convert 1-based line/column to offset\r\nconst offset = locator.locationToOffset({ line: 2, column: 5 });\r\n\r\n// Convert offset to 1-based location\r\nconst loc = locator.offsetToLocation(100);\r\n// { line, column, length, indent, start, end, blank, comment, text }\r\n\r\n// Get source substring\r\nconst slice = locator.getSlice(0, 10);\r\n\r\n// Get line info by 1-based line number\r\nconst lineInfo = locator.getLine(1);\r\n\r\n// Access all parsed lines and comments\r\nconsole.log(locator.lines);     // LineItem[]\r\nconsole.log(locator.comments);  // CommentItem[]\r\n```\r\n\r\n### LineParser\r\nParse source code into lines with metadata.\r\n```js\r\nconst { LineParser } = require('monocart-locator');\r\n\r\nconst lineParser = new LineParser(source);\r\n\r\nconsole.log(lineParser.lines);     // LineItem[]\r\nconsole.log(lineParser.comments);  // CommentItem[]\r\n\r\n// Find line by offset\r\nconst lineInfo = lineParser.findLine(100);\r\n```\r\n\r\n### CommentParser\r\nDetect all line and block comments in source code.\r\n```js\r\nconst { CommentParser } = require('monocart-locator');\r\n\r\nconst commentParser = new CommentParser(source);\r\n\r\nconsole.log(commentParser.comments);  // CommentItem[]\r\n\r\n// Check if a range is inside a comment\r\nconst isComment = commentParser.isComment(start, end);\r\n```\r\n\r\n## API\r\n\r\n### `Locator`\r\n| Property / Method | Description |\r\n|---|---|\r\n| `source` | Original source string |\r\n| `lines` | `LineItem[]` - all parsed lines |\r\n| `comments` | `CommentItem[]` - all parsed comments |\r\n| `locationToOffset({ line, column })` | Convert 1-based line and column to offset |\r\n| `offsetToLocation(offset)` | Convert offset to `LocationItem` (1-based line and column) |\r\n| `getSlice(start, end)` | Get source substring by offsets |\r\n| `getLine(line)` | Get `LineItem` by 1-based line number |\r\n\r\n### `LineItem`\r\n| Property | Type | Description |\r\n|---|---|---|\r\n| `line` | `number` | 0-based line number |\r\n| `length` | `number` | Line length (excluding newline) |\r\n| `indent` | `number` | Leading whitespace count |\r\n| `start` | `number` | Start offset in source |\r\n| `end` | `number` | End offset in source |\r\n| `blank` | `boolean` | Whether line has no non-whitespace content |\r\n| `comment` | `boolean` | Whether first non-whitespace is inside a comment |\r\n| `text` | `string` | Line text (excluding newline) |\r\n\r\n### `LocationItem`\r\nReturned by `offsetToLocation()`. Extends `LineItem` with 1-based position:\r\n| Property | Type | Description |\r\n|---|---|---|\r\n| `line` | `number` | 1-based line number |\r\n| `column` | `number` | 0-based column offset |\r\n\r\n### `CommentItem`\r\n| Property | Type | Description |\r\n|---|---|---|\r\n| `block` | `boolean` | `true` for block comments (`/* */`), `false` for line comments (`//`) |\r\n| `start` | `number` | Start offset in source |\r\n| `end` | `number` | End offset in source |\r\n| `text` | `string` | Comment text including delimiters |\r\n\r\n## License\r\nMIT","readmeFilename":"README.md","homepage":"https://github.com/cenfun/monocart-locator#readme","keywords":["locator","source","position","offset","line","column","comment","parser"],"repository":{"type":"git","url":"git+https://github.com/cenfun/monocart-locator.git"},"bugs":{"url":"https://github.com/cenfun/monocart-locator/issues"}}