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

layered-text

v0.1.11

Published

layered text tool

Downloads

5

Readme

layered-text

layered text tool

Install

npm install layered-text

Usage


var layered_text = require("layered-text");

function cmp_json(value, expect) {
	return JSON.stringify(value) === JSON.stringify(expect);
}

//.format() for object
cmp_json(layered_text(["abc"]), ["abc"]) &&
//parse string then .format() for string
cmp_json(layered_text('["abc"]'), ["abc"]) &&

//.format/compact/normalize/parse()
cmp_json(layered_text.format('["abc"]'), ['["abc"]']) &&
cmp_json(layered_text.compact('["abc"]'), ['["abc"]']) &&
cmp_json(layered_text.normalize('["abc"]'), ['["abc"]', 0, 0]) &&
cmp_json(layered_text.parse('["abc"]'), ["abc"])

Document

Definition of Layered-Text v0.0.4

* Definition 

	layered-text ::= [ ] | [ text (, property)? (, subordinate)? (, text (, property)? (, subordinate)? )* ]

		A JSON Array (refer to JSON, https://www.json.org/ );
		Started with \[;

		text
			A JSON String (refer to JSON);
			Started with \";

		property
			A JSON Object (refer to JSON);
			Started with \{;

		subordinate ::= layered-text

	normalized-layered-text ::= [ ] | [ text, property, subordinate (, text, property, subordinate)* ]

* Examples

	//text
	["abc"]
	["this is a string \nwith line break"]
	["abc", "def"] //2 items

	//property 
	["abc", {"id": 1}] //1 items with property
	["abc", {}] := ["abc"] //empty property
	["abc", {"id": 1}, "def", {"id": 2}] //2 items with properties

	//subordinate
	["abc", ["def"]] //1 item and sub
	["abc", []] := ["abc"] //empty sub
	["abc", {"id": 1}, ["def"]] //1 item and property and sub
	["abc", ["def"], "ghi"] //2 items
	["abc", ["def"], "ghi", ["jkl"]] //2 items

* Normalizing process
	* transfer layered-text to normalized-layered-text , a fixed 3-items-group array;
		["abc", "def"] := ["abc", {}, [], "def", {}, []]

	* accepted abnormal formats;

		* multiple properties will be combined to a single property ; the later items will cover the former items;
			["abc", {"id": 1, "name": "a"}, {"id": 2}] := ["abc", {"id": 2, "name": "a"}]

		* multiple subordinates will be concatenated to a single subordinate;
			["abc", ["def"], ["ghi"]] := ["abc", ["def", "ghi"]]

		* empty property / subordinate can be 0/null/undefined;
			["abc", {}, []] := ["abc", 0, 0] := ["abc"]

		* if the 1st item of layered-text is another layered-text , the 1st item will be flattened to the main.
			[["abc", "def"], ["ghi"]] := ["abc", "def", ["ghi"]]
			[[["abc", "def"], ["ghi"]], "jkl"] := ["abc", "def", ["ghi"], "jkl"]

* Compacting process

	* empty property {} and empty subordinate [], will be removed;
		["abc", {}, []] := ["abc"]
		["abc", {"id": 1}, []] := ["abc", {"id": 1}]
		["abc", {}, ["def"]] := ["abc", ["def"]]