All Projects → vfile → Vfile

vfile / Vfile

Licence: mit
Virtual file format for text processing used in @unifiedjs

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vfile

python-yamlable
A thin wrapper of PyYaml to convert Python objects to YAML and back
Stars: ✭ 28 (-89.93%)
Mutual labels:  file
Mime
.NET wrapper for libmagic
Stars: ✭ 51 (-81.65%)
Mutual labels:  file
github-content
Easily download files from github raw user content.
Stars: ✭ 21 (-92.45%)
Mutual labels:  file
indexed-string-variation
Experimental JavaScript module to generate all possible variations of strings over an alphabet using an n-ary virtual tree
Stars: ✭ 16 (-94.24%)
Mutual labels:  virtual
tmpfile
Alternative to tmpfile() function
Stars: ✭ 22 (-92.09%)
Mutual labels:  file
guess-filename.py
Derive a file name according to old file name cues and/or PDF file content
Stars: ✭ 27 (-90.29%)
Mutual labels:  file
clowdr
Midspace (formerly Clowdr) is a completely open-source virtual conference platform. Host complex events with hundreds of authors and presenters. Midspace includes automated livestreams, video chat, text chat, randomised networking and much more.
Stars: ✭ 48 (-82.73%)
Mutual labels:  virtual
Naza
🍀 Go basic library. || Go语言基础库
Stars: ✭ 253 (-8.99%)
Mutual labels:  file
fs-utils
Generalized file and path utils for Node.js projects.
Stars: ✭ 33 (-88.13%)
Mutual labels:  file
root-file-viewer
View ROOT files directly in VS Code!
Stars: ✭ 20 (-92.81%)
Mutual labels:  file
HXCFE file selector
HxC Floppy Emulator file selector
Stars: ✭ 27 (-90.29%)
Mutual labels:  file
EncrypC
🔑 File Encryption Application using Python.
Stars: ✭ 14 (-94.96%)
Mutual labels:  file
FXFileChooser
Custom JavaFX file chooser which allows quick manual filtering, which allows to add Path predicates as filter and which is testable using TestFX.
Stars: ✭ 22 (-92.09%)
Mutual labels:  file
slackify-markdown
Convert markdown into Slack-specific markdown
Stars: ✭ 80 (-71.22%)
Mutual labels:  unified
logging
Generic file logger for .NET Core (FileLoggerProvider) with minimal dependencies
Stars: ✭ 109 (-60.79%)
Mutual labels:  file
replace-in-files
Replace text in one or more files or globs.
Stars: ✭ 21 (-92.45%)
Mutual labels:  file
ntast
Notion Abstract Syntax Tree specification.
Stars: ✭ 101 (-63.67%)
Mutual labels:  unified
Tableexport
tableExport(table导出文件,支持json、csv、txt、xml、word、excel、image、pdf)
Stars: ✭ 261 (-6.12%)
Mutual labels:  file
Lazer Database
PHP flat file database to store data with JSON
Stars: ✭ 254 (-8.63%)
Mutual labels:  file
magic-bytes
A library for detecting file types.
Stars: ✭ 20 (-92.81%)
Mutual labels:  file

vfile

Build Coverage Downloads Size Sponsors Backers Chat

vfile is a small and browser friendly virtual file format that tracks metadata (such as a file’s path and contents) and messages.

It was made specifically for unified and generally for the common task of parsing, transforming, and serializing data, where vfile handles everything about the document being compiled. This is useful for example when building linters, compilers, static site generators, or other build tools. vfile is part of the unified collective.

vfile is different from the excellent vinyl in that it has a smaller API, a smaller size, and focuses on messages.

Contents

Install

npm:

npm install vfile

Use

var vfile = require('vfile')

var file = vfile({path: '~/example.txt', contents: 'Alpha *braavo* charlie.'})

file.path // => '~/example.txt'
file.dirname // => '~'

file.extname = '.md'

file.basename // => 'example.md'

file.basename = 'index.text'

file.history // => ['~/example.txt', '~/example.md', '~/index.text']

file.message('`braavo` is misspelt; did you mean `bravo`?', {
  line: 1,
  column: 8
})

console.log(file.messages)

Yields:

[ { [~/index.text:1:8: `braavo` is misspelt; did you mean `bravo`?]
    message: '`braavo` is misspelt; did you mean `bravo`?',
    name: '~/index.text:1:8',
    file: '~/index.text',
    reason: '`braavo` is misspelt; did you mean `bravo`?',
    line: 1,
    column: 8,
    location: { start: [Object], end: [Object] },
    ruleId: null,
    source: null,
    fatal: false } ]

API

VFile(options?)

Create a new virtual file. If options is string or Buffer, treats it as {contents: options}. If options is a VFile, returns it. All other options are set on the newly created vfile.

Path related properties are set in the following order (least specific to most specific): history, path, basename, stem, extname, dirname.

It’s not possible to set either dirname or extname without setting either history, path, basename, or stem as well.

Example
vfile()
vfile('console.log("alpha");')
vfile(Buffer.from('exit 1'))
vfile({path: path.join(__dirname, 'readme.md')})
vfile({stem: 'readme', extname: '.md', dirname: __dirname})
vfile({other: 'properties', are: 'copied', ov: {e: 'r'}})

vfile.contents

Buffer, string, null — Raw value.

vfile.cwd

string — Base of path. Defaults to process.cwd().

vfile.path

string? — Path of vfile. Cannot be nullified.

vfile.basename

string? — Current name (including extension) of vfile. Cannot contain path separators. Cannot be nullified either (use file.path = file.dirname instead).

vfile.stem

string? — Name (without extension) of vfile. Cannot be nullified, and cannot contain path separators.

vfile.extname

string? — Extension (with dot) of vfile. Cannot be set if there’s no path yet and cannot contain path separators.

vfile.dirname

string? — Path to parent directory of vfile. Cannot be set if there’s no path yet.

vfile.history

Array.<string> — List of file-paths the file moved between.

vfile.messages

Array.<VMessage> — List of messages associated with the file.

vfile.data

Object — Place to store custom information. It’s OK to store custom data directly on the vfile, moving it to data gives a little more privacy.

VFile#toString(encoding?)

Convert contents of vfile to string. When contents is a Buffer, encoding is a character encoding to understand doc as (string, default: 'utf8').

VFile#message(reason[, position][, origin])

Associates a message with the file, where fatal is set to false. Constructs a new VMessage and adds it to vfile.messages.

Returns

VMessage.

VFile#info(reason[, position][, origin])

Associates an informational message with the file, where fatal is set to null. Calls #message() internally.

Returns

VMessage.

VFile#fail(reason[, position][, origin])

Associates a fatal message with the file, then immediately throws it. Note: fatal errors mean a file is no longer processable. Calls #message() internally.

Throws

VMessage.

List of utilities

The following list of projects includes tools for working with virtual files. See unist for projects that work with nodes.

Reporters

The following list of projects show linting results for given virtual files. Reporters must accept Array.<VFile> as their first argument, and return string. Reporters may accept other values too, in which case it’s suggested to stick to vfile-reporters interface.

Contribute

See contributing.md in vfile/.github for ways to get started. See support.md for ways to get help. Ideas for new utilities and tools can be posted in vfile/ideas.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

Sponsor

Support this effort and give back by sponsoring on OpenCollective!

Gatsby 🥇

Vercel 🥇

Netlify

Holloway

ThemeIsle

Boost Hub

Expo


You?

Acknowledgments

The initial release of this project was authored by @wooorm.

Thanks to @contra, @phated, and others for their work on Vinyl, which was a huge inspiration.

Thanks to @brendo, @shinnn, @KyleAMathews, @sindresorhus, and @denysdovhan for contributing commits since!

License

MIT © Titus Wormer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].