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

hurml

v1.0.1

Published

Human Readable Markup Language Parser

Downloads

12

Readme

HURML Parser

This module parses files that are formatted using the 'hurml' format, and provides simple tools for working with the resulting data structures. The 'hurml' format is a simple plain-text file format, which is somewhat resilient to human (user) error and is especially useful for configuration files that are meant to be changed by non-developer personnel.

File format

'Hurml' is a line-based file format, with optional blocks that start and end with brackets.

Lines are formatted as follows (whitespace is not important in front of and at the end of lines):

  • Comments start with a # character as the first non-whitespace symbol, and span to the end of the line.
  • Properties are formatted as Name = value, where value can be one of the following:
    • Nothing (or whitespace), resulting in an undefined value;
    • A number (e.g. 1, 100, 100.1, or .1);
    • Boolean literal values true or false;
    • String values using single, double, straight or curly quotes, e.g. "Hello", or “world”;
    • One or more 'tokens' (without any quotes, split on commas and semicolons). These might be assigned special meaning, but can also be converted to a string.
    • A multiline block, starting with an opening bracket (i.e. (), spanning all the way until the line that contains a matching closing bracket. Each block is parsed on its own, and the resulting value, object, or array is used as the property value.
  • Properties can also be written in multiline format, as [Name]. The lines following this line determine what is assigned to this property: an object with further properties, or a list (array).
  • List items start with a dash (-). The value after the dash symbol is parsed in the same way as for property values, and the result is appended to the 'current' array, i.e. either the global result object, an implicit 'list' property, or a list that is assigned to the previous multiline or block property.
  • Single values that are not property assignments or list items are used as the value of a name property, with the exception of tokens, which are assigned to properties that have the same name as the token string.

Examples

A simple object with property values:

# This results in a single object:
foo = "Bar"
number = 123
undef =
cool = true
flags = FOO_ENABLE

An object with a single array property:

# Indentation is not important
list = (
  - one
  - two
  - three
)

The same, using another notation:

[list]
- one
- two
- three

An object with two nested objects:

obj = (
nestedProperty = 123
more = stuff
)
another = (
  # again, indentation doesn't matter
  foo = "BAR"
)

The same, using another notation:

[obj]
nestedProperty = 123
more = stuff

[another]
foo = "BAR"

A nested list:

[ topLevel ]
list = (
  - (
    "First item"
    [config]
    value = 1
  )
  - (
    "Second item"
    [config]
    value = 2
  )
)

The JSON representation of this data structure is:

{"topLevel":{"list":[{"name":"First item","value":1},{"name":"Second item","value":2}]}}

Working with data

The hurml.parse(...) function parses a 'hurml' formatted text, and returns the corresponding data structure. This consists of an object, array, or value (string, number, or boolean), with nested properties or array elements similar to a plain JavaScript data structure. Only tokens have a separate HurmlToken type, which can be converted to a string using the .toString() method.

With this result, the following functions can be used to check and get data:

hurml.find(data, ...path) finds one or more values using (nested, case-insensitive) property names. Any nested arrays are flattened, and do not need to be specified in the property path.

hurml.test(data, ...path) tests whether the given (nested, case-insensitive) propery exists and its value is truethy.

hurml.match(stringOrRegExp, data, ...path) tests whether the given (nested, case-insensitive) property's value matches given string, number, boolean, or regular expression.