Parses an object in string format to a javascript object
Parses values of type boolean, strings, numbers, undefined, null, array and object. Regex to do at a later time.
Comments and whitespace in the string are ignored.
Two apis
a) stringToObject / stringToAny
stringToObject is to be used if you expect the string to only be an object. It will throw an error with message 'String is not an object' if not an object.
;
stringToAny will work with any allowed type represented as a string. It will throw error with message 'Malformed' if malformed.
b) StringToObjectParser
This works a character at a time returning a ProcessResult.
If malformed will return ProcessResult.Break
When completed call complete.
Do not pass the first {
enum ProcessResult{Continue,Completed,Break}
const stringToObjectParser = new StringToObjectParser();
stringToObjectParser.process('h'); // ProcessResult.Continue
stringToObjectParser.process('i'); // ProcessResult.Continue
stringToObjectParser.process(':'); // ProcessResult.Continue
stringToObjectParser.process('"'); // ProcessResult.Continue
stringToObjectParser.process('w'); // ProcessResult.Continue
stringToObjectParser.process('o'); // ProcessResult.Continue
stringToObjectParser.process('r'); // ProcessResult.Continue
stringToObjectParser.process('l'); // ProcessResult.Continue
stringToObjectParser.process('d'); // ProcessResult.Continue
stringToObjectParser.process('"'); // ProcessResult.Continue
stringToObjectParser.process('}'); // ProcessResult.Completed
expect(stringToObjectParser.getCompleted()).toEqual({hi:'world'});