mapped-file
v0.1.1
Published
A utility for working with files using source mapped locations
Downloads
476
Readme
mapped-file
A simple utility for working with files using source mapped (line, character) locations.
npm i mapped-file
Usage
import { readFile } from 'fs/promises'
import { File } from 'mapped-file'
const filename = 'diary.txt'
const contents = await readFile(filename, 'utf8')
const file = new File(filename, contents)
console.log(file.range({
start: { line: 3, character: 5 },
end: { line: 5, character: 2 }
}, {
surrounding: 1,
highlight: s => `*${s}*`
})
// {
// '2': { content: 'And I do weird stuff in my free time.', surround: true },
// '3': { content: 'I als*o like anime.*', surround: false },
// '4': { content: '*And coding fun stuff.*', surround: false },
// '5': { content: '*I *work in IT.', surround: false },
// '6': { content: 'And I hate all other departments.', surround: true }
// }
Hellow world!
My name is jack
And I do weird stuff in my free time.
I also like anime.
And coding fun stuff.
I work in IT.
And I hate all other departments.
I have no idea why. They are nice people.
Maybe I should talk to my therapist about it?
But I hate her as well.
⚠️⚠️ Line numbers and characters are zero based! ⚠️⚠️
Contribution
Be nice and respectful to other people. Make sure all checks are passing when creating a PR (tests, coverage and linter). Here are some useful commands for development:
git clone [email protected]:loreanvictor/ts-inference-check.git # 👉 clone the code (generally fork it before cloning though)
npm i # 👉 install all dependencies
npm test # 👉 run the tests
npm run coverage # 👉 check code coverage
npm run lint # 👉 check code style
npm run lint:fix # 👉 fix trivial stylistic issues
TODO
- [ ] Write full documentation of all features