Skip to content
This repository has been archived by the owner on Aug 31, 2019. It is now read-only.

Latest commit

 

History

History
150 lines (116 loc) · 4.22 KB

api.md

File metadata and controls

150 lines (116 loc) · 4.22 KB

Modules

vuegister

The require hook for load SFC (single-file component or *.vue) files.

Classes

Location

Class for calculation of the line numbers.

vuegister

The require hook for load SFC (single-file component or *.vue) files.

extract(buf, tags) ⇒ array

Extracts SCF sections (inner text and all tag attributes) specified by tags argument, low level API.

Parameters

  • buf: string - Content of the SFC file.
  • tags: array - List of sections to be extracted.

Returns: array - Returns extracted sections, each section is an object of the following format:

{
  tag: string,    // name of the tag
  text: string,   // inner text, content of the tag
  attrs: object,  // key-value pairs, attributes of the tag
  offset: number, // line number where the tag begins in the SCF minus
                  // one or zero for external file
}

Kind: Exported function

load(buf, [file], [cfg]) ⇒ string

Parses SFC, high level API.

Parameters

  • buf: string - Content of the SFC file.
  • [file]: string - Full path to the SFC.
  • [cfg]: object - Options, an object of the following format:
{
  maps: boolean,   // false, provide source map
  lang: object,    // {}, default language for tag without lang attribute,
                   // for example:
                   // {
                   //   {script: 'js'}
                   // }
  plugins: object, // {}, user configuration for the plugins, for example:
                   // {
                   //   babel: {
                   //     babelrc: true,
                   //   },
                   // }
}

Returns: string - Returns ready-to-use JavaScript with injected template.
Kind: Exported function

register([options]) ⇒ boolean

Setups hook on require *.vue extension.

Parameters

  • [options]: object - Available options are:
{
  maps: boolean,   // false, provide source map
  lang: object,    // {}, default language for tag without lang attribute,
                   // for example:
                   // {
                   //   {script: 'js'}
                   // }
  plugins: object, // {}, user configuration for the plugins, for example:
                   // {
                   //   babel: {
                   //     babelrc: true,
                   //   },
                   // }
}

Returns: boolean - Returns true on success.
Kind: Exported function

unregister() ⇒ array

Removes requre hook.

Returns: array - Returns list of unloaded modules.
Kind: Exported function

Location

Class for calculation of the line numbers.

Kind: global class

new Location(buf)

Create class instance.

Parameters

  • buf: string - Raw text.

Example

let data = fs.readFileSync(file, 'utf8');
let loc = new Location(data);

location.getLine(index) ⇒ number

Get line number.

Parameters

  • index: number - the 0-based index.

Returns: number - Returns 0-based line number for given index.
Kind: instance method of Location