vfile
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@types/unist | 2.0.10 | 2.5 kB | MIT | prod | |
is-buffer | 2.0.5 | 2.04 kB | MIT | prod | |
unist-util-stringify-position | 3.0.3 | 4.2 kB | MIT | prod | |
vfile-message | 3.1.4 | 5.66 kB | MIT | prod |
Vfile is a small and browser-friendly virtual file format that tracks metadata about files such as its path and value, as well as lint messages. This package offers a useful API for accessing file value, path, and metadata, and it is specifically designed to support attaching lint messages and errors to specific parts of these files. It is especially useful when dealing with a concept of files in situations where you may not be able to access the file system. It is designed for the unified ecosystem, but can also be used in other projects which deal with parsing, transforming, and serializing data, for example, to create linters, compilers, static site generators, and other building tools.
To use Vfile, you will need to install it. In Node.js (version 16+), it can be installed via npm:
npm install vfile
You can utilize VFile in your JavaScript code:
import {VFile} from 'vfile'
const file = new VFile({
path: '~/example.txt',
value: 'Alpha *braavo* charlie.'
})
//You can manipulate and access file properties such as path, dirname, and basename:
console.log(file.path) // => '~/example.txt'
console.log(file.dirname) // => '~'
file.extname = '.md'
console.log(file.basename) // => 'example.md'
file.basename = 'index.text'
console.log(file.history) // => ['~/example.txt', '~/example.md', '~/index.text']
//You can also add lint messages to the file:
file.message('Unexpected unknown word `braavo`, did you mean `bravo`?', {
place: {line: 1, column: 8},
source: 'spell',
ruleId: 'typo'
})
console.log(file.messages)
The Vfile documentation can be found at this GitHub link. The readme at the provided location is very detailed, containing installation instructions, various usability examples, and a detailed API reference.