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

neon-js

v1.1.2

Published

NEON decoder and encoder for JavaScript

Downloads

6,978

Readme

NEON-JS - NEON decoder and encoder for JavaScript

Build Status NPM version

NEON is very similar to YAML.The main difference is that the NEON supports "entities" (so can be used e.g. to parse phpDoc annotations) and tab characters for indentation. NEON syntax is a little simpler and the parsing is faster.

Example of Neon code:

# my web application config

php:
	date.timezone: Europe/Prague
	zlib.output_compression: yes  # use gzip

database:
	driver: mysql
	username: root
	password: beruska92

users:
	- Dave
	- Kryten
	- Rimmer

Installation:

NEON module for node.js

npm install neon-js

CLI executable is not available yet.

NEON for browser

You can create browser compatible library using browserify.

npm install browserify
browserify -r neon-js -s neon

You can found precompiled browserifed version in repository matej21/neon-js-dist.

<script src="dist/neon.js"></script>
<script type="text/javascript">
var data = neon.decode("hello: world")
</script>

API

var neon = require('neon-js');

try {
	var result = neon.decode("foo: {bar: 123}")
} catch (e) {
	if (e instanceof neon.Error) {
		console.log(e.message);
	}
	throw e;
}

decode(input)

Decodes input NEON string.

var result = neon.decode(input);

encode(var[, options])

Encodes javascript to NEON.

var data = {foo: "bar"}
var result = neon.encode(data);
//or you can use block mode
var result = neon.encode(data, neon.BLOCK);

Entity

Class representing NEON entity.

var entity = neon.decode("Foo(bar)");
entity.value; "Foo";
entity.attributes// neon.Map instance, see bellow

Map

NEON was originally written for PHP where all NEON array-like structures (lists, objects or mixed) were converted to the PHP array. And arrays in PHP are very powerful - they can be treated as a list, hash table and more. neon.Map is trying to keep the very basic of this behaviour - items are ordered (list) and can have string key (hash table). Therefore all NEON array-like structures are mapped to the neon.Map.

#example neon
foo: bar
- lorem
ipsum: dolor
- sit
var map = neon.decode(input);
//map instanceof neon.Map

Map.get(key)

Returns value by the key.

map.get("foo"); // bar
map.get(0); // lorem
map.get("xxx"); //throws an Error

Map.has(key)

Checks if the given key exists in the map.

map.has("foo"); // true
map.has("xxx"); // false

Map.forEach(callable)

Calls provided function for every item in the map. Key is passed as a first argument, value as a second argument.

map.forEach(function (key, value) {

});

Map.isList()

Checks if Map is a list. That means the map doesn't contain any string keys and numeric keys are in range 0..(length-1).

map.isList(); //false

Map.values()

Returns values as an array.

var values = map.values();
// ["bar", "lorem", "dolor", "sit"]

Map.keys()

Returns keys as an array.

var keys = map.keys();
// ["foo", 0, "ipsum", 1]

Map.items()

Returns items structure. This structure is an array where every item is object with properties key and value.

var items = map.items();

// [{key: "foo", value: "bar"}, ...]

Map.toObject([deep])

Converts Map to javascript object. Items order may be lost.

var obj = map.toObject();
// {foo: "bar", 0: "lorem", ipsum: "dolor", 1: sit}

Dumper.toText(data)

Dumps decoded structure into simple text output as you can see in the demo.

var text = neon.Dumper.toText(data)`;

Links: