node-file-parser by Skelware

API Docs for: 2.2.2
Show:

FileParser

Module: Main

Summary

The FileParer class is an abstract class that need to be extended. If this class is used directly, it will return the contents of a file without parsing them.

Methods

decode

Syntax

decode

(
  • [data]
)
Object | String

Summary

Decodes the data, turning a String that is read from a file to an Object usable by JavaScript.

Parameters:

  • [data] String optional

Returns:

Object | String:

encode

Syntax

encode

(
  • [data]
)
String

Summary

Encodes the data, turning an Object into a String that can be written to a file.

Parameters:

  • [data] Object | String optional

Returns:

String:

FileParser

Syntax

FileParser

(
  • file
)

Summary

Creates a new FileParser.

Parameters:

  • file String

    The location of the file.

getContent

Syntax

getContent

() String | Object

Summary

Gets the (cached) parsed content of the file, when it was last read.

Returns:

String | Object:

The content of the file, after being parsed by the subclass.

getFile

Syntax

getFile

() String

Summary

Gets the file, but not the content.

Returns:

String:

The file location that was supplied to the constructor.

getRawContent

Syntax

getRawContent

() String

Summary

Gets the (cached) raw content of the file, when it was last read.

Returns:

String:

The content of the file, without being parsed.

modify

Syntax

modify

(
  • [watcher]
)
chainable

Summary

Adds a callback function to the parser, so that each entry can be modified to tailor specific needs. Only one callback can be active at any given time.

Parameters:

  • [watcher] Function optional

    The callback that should be called by the parser, or undefined if the callback should be cleared.

read

Syntax

read

(
  • callback
)
chainable

Summary

Reads the file into the current raw content and then parses it.

Parameters:

  • callback Object

setContent

Syntax

setContent

(
  • [content]
)
chainable

Summary

Sets the content of this file, but does not yet write to the file.

Parameters:

  • [content] Object optional

write

Syntax

write

() chainable

Summary

Writes or updates the file with the current parsed content.