JavaScripTools Manual

Parsers

Other parsers

Aditionally to the main NumberParser, DateParser and CustomParser, there are other parsers included on the Parsers script. They are:

BooleanParser

A parser for boolean values. The constructor arguments / properties are:

Examples:

var parser = new BooleanParser("yes", "no");
parser.parse("yes") -> true
parser.format(false) -> "no"

var parser2 = new BooleanParser("false", "true", false);
parser.parse("true") -> false (if useBooleanValue was true, would return true)
parser.format(false) -> "true"

MapParser

A parser that uses a Map. The format method returns the value associated with the given key, while parse returns the first key associated with the given value. Examples:

var map = new Map();
map.put(1, "One");
map.put(2, "Two");
var parser = new MapParser(map);
parser.parse("One") -> 1
parser.format(2) -> "Two"

StringParser

Simply transforms the value to strings on both format and parse methods. Examples:

var parser = new StringParser();
parser.format(1) -> "1";
parser.parse(1) -> "1";

EscapeParser

A parser that uses the escapeCharacters to format and unescapeCharacters function to the values. Two contructor arguments are accepted, extraChars and onlyExtra, and they are passed to those functions. See their api reference for more details. Examples:

var parser = new EscapeParser();
parser.format("abc\ndef") -> "abc\\ndef"
parser.parse("123\\t456\\n789") -> "123\t456\n789"



Previous:
Using the WrapperParser
Table of Contents Next:
Introduction to InputMask