API Docs for: 0.0.1
Show:

ProParser Class

Extends StringParser
Defined in: lib/parsers/pro.js:40
Module: niviz

Snowpack PRO file parser. A PRO file is parsed line by line in a single pass (supports streamed data).

Constructor

ProParser

()

Methods

check

(
  • against
)
Boolean
Returns true if the next line starts with the given string against.

Parameters:

Returns:

convert

(
  • id
  • value
)
Moment | Array | Object private

Looks up the converter for type of id and converts the value; throws an error if there is no suitable converter available.

Parameters:

Returns:

Moment | Array | Object:

The converted value.

end

() chainable

Inherited from Parser: lib/parser.js:176

This method must be called by the parsing methods when the parsing has finished.

getcodes

() Object static

Get the conversion table which is a key/value object, key being the PRO file code and the value being the property name used within niViz.

Returns:

next

() String | Undefined
Returns the next line/token; updates the parser's current position pointer and line number as a side effect.

Returns:

String | Undefined: The next token.

parse

(
  • [callback]
)
Object

Inherited from Parser but overwritten in lib/parser.js:130

Starts the parsing process; in sync mode this method blocks until the parsing has finished, otherwise it should return immediately! If given a callback, it must be bound to the end and error events.

Parameters:

Returns:

Object: The parse result.

parse_data

() private chainable

Parses profile data and adds it to the station.

This method consumes lines until a property id repeats or the following line does not start with an id.

parse_header

(
  • id
  • type
  • description
)
private chainable

Parses a profile header line and registers the property and the corresponding value converter function in properties.

Note: Since header definitions can span multiple lines, this method peeks ahead and consumes subsequent indented lines!

Parameters:

parse_line

(
  • line
)
private

Inherited from StringParser but overwritten in lib/parsers/pro.js:355

Lexically analyses a line and parses it accordingly.

Note: When strict parsing is active (default), this method will reject out-of-section lines even if they are syntactically correct (e.g., header definitions outside of a header section).

Parameters:

parse_parameter

() private chainable

pause

()
Resumes _parse method after a short timeout; these small timeouts effectively give the browser more time to breathe and are a remedy for the 'long running script' warnings in Firefox.

peek

() String

Returns:

String: The next k characters.

restrict

(
  • mode
)
Boolean private

Ensure that the current mode is mode; throws an Error otherwise.

Note: Does not throw if .strict is set to false.

Parameters:

Returns:

Boolean:

Whether or not mode is current.

sanitize

(
  • tops
)
Object private

Take all the layer tops and create three arrays: one with all the layer bottoms, one with all the tops above ground, and one with all the bottoms above ground.

Parameters:

  • tops Array

    The layer tops

Returns:

Object:

Object with three arrays: bottoms, above0 and bottoms0

skip

(
  • [until]
)
String | Undefined

Inherited from StringParser but overwritten in lib/parsers/pro.js:578

Returns the next line that is not a blank line or comment; if given, the next line that starts with until is treated like EOD.

Parameters:

Returns:

String | Undefined:

The next line.

verify

() chainable

Inherited from Parser: lib/parser.js:165

Verify that all syntactic and semantic requirements are met by the parsed entity.

Properties

_parse

Unknown

code

Object static

The conversion table for PRO property codes to names used by Niviz.

codes

Config static

Default conversion table for PRO property codes to names used by Niviz. Editable by the user.

converter

Object static

Type converter functions for PRO data values.

data

Object

Inherited from Parser: lib/parser.js:50

dates

Array static

A list of date/time formats recognized by the parser.

delimiter

String
The token delimiter; defaults to a newline.

done

Boolean
Whether or not all data has been parsed.

lines

Number private
The number of lines/tokens parsed so far.

mode

String

The current parsing mode. The mode corresponds to the different sections in a PRO file:

  • 'station_parameters'
  • 'header'
  • 'data'

position

Number private
The current position in the input data.

properties

Object

Contains the parsed property headers.

result

Object

Inherited from Parser: lib/parser.js:56

station

Station

The snow station instance; the instance should be populated by the parsing methods and represents the parse result.

strict

Boolean

When true (default), the parser will only accept lines in their respective sections.

trim

String
The token trim value; defaults to a carriage return. If present, this value will be cut off at the end of each token during parsing.

types

Array static

A list of all known data value types. For each type, there is a corresponding parser/converter in .converters.

version

Number

The current PRO version used. Niviz supports 1.0 and 1.4