npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

y2j

v1.0.4

Published

minimal package to convert yaml/yml to json

Downloads

9

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)

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) ⇒

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