Constructors

  • Create a new virtual file.

    options is treated as:

    • string or Uint8Array{value: options}
    • URL{path: options}
    • VFile — shallow copies its data over to the new file
    • object — all fields are shallow copied over to the new file

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

    You cannot set dirname or extname without setting either history, path, basename, or stem too.

    Parameters

    Returns VFile

    New instance.

Properties

cwd: string

Base of path (default: process.cwd() or '/' in browsers).

Place to store custom info (default: {}).

It’s OK to store custom data directly on the file but moving it to data is recommended.

history: string[]

List of file paths the file moved between.

The first is the original path and the last is the current path.

map: undefined | null | Map

Source map.

This type is equivalent to the RawSourceMap type from the source-map module.

messages: VFileMessage[]

List of messages associated with the file.

result: unknown

Custom, non-string, compiled, representation.

This is used by unified to store non-string results. One example is when turning markdown into React nodes.

stored: boolean

Whether a file was saved to disk.

This is used by vfile reporters.

value: Value

Raw value.

Accessors

  • get basename(): undefined | string
  • Get the basename (including extname) (example: 'index.min.js').

    Returns undefined | string

    Basename.

  • set basename(arg): void
  • Set basename (including extname) ('index.min.js').

    Cannot contain path separators ('/' on unix, macOS, and browsers, '\' on windows). Cannot be nullified (use file.path = file.dirname instead).

    Parameters

    • arg: undefined | string

    Returns void

    Nothing.

  • get dirname(): undefined | string
  • Get the parent path (example: '~').

    Returns undefined | string

    Dirname.

  • set dirname(arg): void
  • Set the parent path (example: '~').

    Cannot be set if there’s no path yet.

    Parameters

    • arg: undefined | string

    Returns void

    Nothing.

  • get extname(): undefined | string
  • Get the extname (including dot) (example: '.js').

    Returns undefined | string

    Extname.

  • set extname(arg): void
  • Set the extname (including dot) (example: '.js').

    Cannot contain path separators ('/' on unix, macOS, and browsers, '\' on windows). Cannot be set if there’s no path yet.

    Parameters

    • arg: undefined | string

    Returns void

    Nothing.

  • get path(): string
  • Get the full path (example: '~/index.min.js').

    Returns string

    Path.

  • set path(arg): void
  • Set the full path (example: '~/index.min.js').

    Cannot be nullified. You can set a file URL (a URL object with a file: protocol) which will be turned into a path with url.fileURLToPath.

    Parameters

    • arg: string

    Returns void

    Nothing.

  • get stem(): undefined | string
  • Get the stem (basename w/o extname) (example: 'index.min').

    Returns undefined | string

    Stem.

  • set stem(arg): void
  • Set the stem (basename w/o extname) (example: 'index.min').

    Cannot contain path separators ('/' on unix, macOS, and browsers, '\' on windows). Cannot be nullified (use file.path = file.dirname instead).

    Parameters

    • arg: undefined | string

    Returns void

    Nothing.

Methods

  • Serialize the file.

    Note: which encodings are supported depends on the engine. For info on Node.js, see: https://nodejs.org/api/util.html#whatwg-supported-encodings.

    Parameters

    • Optional encoding: null | string

      Character encoding to understand value as when it’s a Uint8Array (default: 'utf-8').

    Returns string

    Serialized file.