mapped-file
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

mapped-file

tests coverage version

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 }
// }
diary.txt
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 git@github.com: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



Readme

Keywords

Package Sidebar

Install

npm i mapped-file

Weekly Downloads

122

Version

0.1.1

License

MIT

Unpacked Size

21.2 kB

Total Files

23

Last publish

Collaborators

  • lorean.victor