y2j
v1.0.4
Published
minimal package to convert yaml/yml to json
Downloads
1
Maintainers
Readme
Classes
YamlReader
Class YamlReader offers convenience methods to read and convert YML to JSON.
Kind: global class
YamlReader.parse(input, exceptionOnInvalidType, objectDecoder) ⇒
Parses YML into a JavaScript object. The parse method, when supplied with a YML string, will do its best to convert YML in a file into a JavaScript object.
Kind: static method of YamlReader
Returns: [Object] The YML converted to a JavaScript object
Throw: [ParseError] If the YML is not valid
| Param | Default | | --- | --- | | input | | | exceptionOnInvalidType | false | | objectDecoder | |
Example
myObject = YamlReader.parse('some: yaml');
console.log(myObject);
YamlReader.read(path, callback, exceptionOnInvalidType, objectDecoder) ⇒
Read yml file from path given
Kind: static method of YamlReader
Returns: [Object] The YML converted to a JavaScript object
Throw: [ParseError] If the YML is not valid
| Param | | --- | | path | | callback | | exceptionOnInvalidType | | objectDecoder |
Example
const file = path.resolve(__dirname, filePath);
const ymlStr = YamlReader.read(file);
console.log(ymlStr);
YamlReader.parseFile() ⇒
Kind: static method of YamlReader
Returns: [Object] The YML converted to a JavaScript object or null if the file doesn't exist.
Throw: [ParseError] If the YML is not valid
LineAnalyzer
LineAnalyzer YML parsing
Kind: global class
- LineAnalyzer
- .configure(exceptionOnInvalidType, objectDecoder)
- .parse(value, exceptionOnInvalidType, objectDecoder) ⇒
- .parseScalar(scalar, delimiters, stringDelimiters, context, evaluate) ⇒
- .parseQuotedScalar(scalar, context) ⇒
- .parseSequence(sequence, context) ⇒
- .parseMapping(mapping, context) ⇒
- .evaluateScalar(scalar, context) ⇒
LineAnalyzer.configure(exceptionOnInvalidType, objectDecoder)
Kind: static method of LineAnalyzer
| Param | Default | | --- | --- | | exceptionOnInvalidType | | | objectDecoder | |
LineAnalyzer.parse(value, exceptionOnInvalidType, objectDecoder) ⇒
Converts a YML string to a JavaScript object.
Kind: static method of LineAnalyzer
Returns: [Object] A JavaScript object representing the YML string
Throw: [ParseError]
| Param | Default | | --- | --- | | value | | | exceptionOnInvalidType | false | | objectDecoder | |
LineAnalyzer.parseScalar(scalar, delimiters, stringDelimiters, context, evaluate) ⇒
Parses a scalar to a YML string.
Kind: static method of LineAnalyzer
Returns: [String] A YML string
Throw: [ParseError] When malformed inline YML string is parsed
| Param | Default | | --- | --- | | scalar | | | delimiters | | | stringDelimiters | | | context | | | evaluate | true |
LineAnalyzer.parseQuotedScalar(scalar, context) ⇒
Parses a quoted scalar to YML.
Kind: static method of LineAnalyzer
Returns: [String] A YML string
Throw: [ParseError] When malformed inline YML string is parsed
| Param | | --- | | scalar | | context |
LineAnalyzer.parseSequence(sequence, context) ⇒
Parses a sequence to a YML string.
Kind: static method of LineAnalyzer
Returns: [String] A YML string
Throw: [ParseError] When malformed inline YML string is parsed
| Param | | --- | | sequence | | context |
LineAnalyzer.parseMapping(mapping, context) ⇒
Parses a mapping to a YML string.
Kind: static method of LineAnalyzer
Returns: [String] A YML string
Throw: [ParseError] When malformed inline YML string is parsed
| Param | | --- | | mapping | | context |
LineAnalyzer.evaluateScalar(scalar, context) ⇒
Evaluates scalars and replaces magic values.
Kind: static method of LineAnalyzer
Returns: [String] A YML string
| Param | | --- | | scalar | | context |
Utils
Class A bunch of utility methods
Kind: global class
Utils.trim(str, _char) ⇒
Precompiled date pattern Trims the given string on both sides
Kind: static method of Utils
Returns: [String] A trimmed string
| Param | Default | | --- | --- | | str | | | _char | \s |
Utils.ltrim(str, _char) ⇒
Trims the given string on the left side
Kind: static method of Utils
Returns: [String] A trimmed string
| Param | Default | | --- | --- | | str | | | _char | \s |
Utils.isEmpty(value) ⇒
Checks if the given value is empty (null, undefined, empty string, string '0', empty Array, empty Object)
Kind: static method of Utils
Returns: [Boolean] true if the value is empty
| Param | | --- | | value |
Utils.getStringFromFile(path, callback) ⇒
Reads the data from the given file path and returns the result as string
Kind: static method of Utils
Returns: [String] The resulting data as string
| Param | Default | | --- | --- | | path | | | callback | |
Utils.getFiles(directoryPath) ⇒
listing all files in directoryPath
Kind: static method of Utils
Returns: [Array] Array of files
| Param | | --- | | directoryPath |
Utils.stringToDate(str) ⇒
Returns a parsed date from the given string
Kind: static method of Utils
Returns: [Date] The parsed date or null if parsing failed
| Param | | --- | | str |
Utils.isNumeric(input) ⇒
Returns true if input is numeric
Kind: static method of Utils
Returns: [Boolean] true if input is numeric
| Param | | --- | | input |
Utils.isEmptyObject(value) ⇒
Checks if the given value is an empty object
Kind: static method of Utils
Returns: [Boolean] true if the value is empty and is an object
| Param | | --- | | value |
Utils.isDigits(input) ⇒
Returns true if input is only composed of digits
Kind: static method of Utils
Returns: [Boolean] true if input is only composed of digits
| Param | | --- | | input |
Utils.octDec(input) ⇒
Decode octal value
Kind: static method of Utils
Returns: [Integer] The decoded value
| Param | | --- | | input |
Utils.subStrCount(string, subString, start, length) ⇒
Counts the number of occurences of subString inside string
Kind: static method of Utils
Returns: [Integer] The number of occurences
| Param | | --- | | string | | subString | | start | | length |
Utils.hexDec(input) ⇒
Decode hexadecimal value
Kind: static method of Utils
Returns: [Integer] The decoded value
| Param | | --- | | input |
Utils.utf8chr(c) ⇒
Get the UTF-8 character for the given code point.
Kind: static method of Utils
Returns: [String] The corresponding UTF-8 character
| Param | | --- | | c |
Parser
Class Parser parses YML strings to convert them to JavaScript objects.
Kind: global class
- Parser
- .cleanup(value) ⇒
- .getRealCurrentLineNb() ⇒
- .isNextLineIndented() ⇒
- .getCurrentLineIndentation() ⇒
- .getNextEmbedBlock(indentation, includeUnindentedCollection) ⇒
- .isStringUnIndentedCollectionItem() ⇒
- .isCurrentLineComment() ⇒
- .isCurrentLineBlank() ⇒
- .parseValue(value, exceptionOnInvalidType, objectDecoder) ⇒
- .isNextLineUnIndentedCollection() ⇒
parser.cleanup(value) ⇒
Cleanups a YML string to be parsed.
Kind: instance method of Parser
Returns: [String] A cleaned up YML string
| Param | | --- | | value |
parser.getRealCurrentLineNb() ⇒
Returns the current line number (takes the offset into account).
Kind: instance method of Parser
Returns: [Integer] The current line number
parser.isNextLineIndented() ⇒
Returns true if the next line is indented.
Kind: instance method of Parser
Returns: [Boolean] Returns true if the next line is indented, false otherwise
parser.getCurrentLineIndentation() ⇒
Returns the current line indentation.
Kind: instance method of Parser
Returns: [Integer] The current line indentation
parser.getNextEmbedBlock(indentation, includeUnindentedCollection) ⇒
Returns the next embed block of YML.
Kind: instance method of Parser
Returns: [String] A YML string
Throw: [ParseError] When indentation problem are detected
| Param | Default | | --- | --- | | indentation | | | includeUnindentedCollection | false |
parser.isStringUnIndentedCollectionItem() ⇒
Returns true if the string is un-indented collection item
Kind: instance method of Parser
Returns: [Boolean] Returns true if the string is un-indented collection item, false otherwise
parser.isCurrentLineComment() ⇒
Returns true if the current line is a comment line.
Kind: instance method of Parser
Returns: [Boolean] Returns true if the current line is a comment line, false otherwise
parser.isCurrentLineBlank() ⇒
Returns true if the current line is blank.
Kind: instance method of Parser
Returns: [Boolean] Returns true if the current line is blank, false otherwise
parser.parseValue(value, exceptionOnInvalidType, objectDecoder) ⇒
Parses a YML value.
Kind: instance method of Parser
Returns: [Object] A JavaScript value
Throw: [ParseError] When reference does not exist
| Param | | --- | | value | | exceptionOnInvalidType | | objectDecoder |
parser.isNextLineUnIndentedCollection() ⇒
Returns true if the next line starts unindented collection
Kind: instance method of Parser
Returns: [Boolean] Returns true if the next line starts unindented collection, false otherwise