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

json2text

v0.0.5

Published

Generate free-format text from JSON templates

Downloads

8

Readme

json2text

json2text generate free-format text from JSON templates (e.g. HTML generation).

Install package globally:

npm install json2text -g

Tools

  • j2t [EXTENSION]: compile templates
  • j2n FILE: generate template stubs from FILE
  • j2f FILE [EXTENSION]: convers _text fields from FILE to _file fields.

How to use example

1. Define template elements

Create file with .j2.node.json extension (e.g. elements.j2.node.json). Include the following text:

[
	{
		"_name": "list",
		"style": "disc",
		"_text": "<ul style='list-style-type:%%style%%'>\n%%_text%%</ul>"
	}, {
		"_name": "item",
		"_text": "<li> %%_text%% </li>\n"
	}
]

JSON fields:

  • _name: node(s) names.
  • _text: node's templating string.
  • OPTIONAL: other fileds represent arguments with default values (e.g. style)

2. Define template layout

Create file with .j2.json extension (e.g. layout.j2.json). Include the following text:

{
	"_node": "list",
	"style": "circle",
	"_child": [
		{"_node": "item", "_child": "list item #1"},
		{"_node": "item", "_child": "list item #2"}
	]
}

JSON fields:

  • _node: element name
  • _child: (string|object|list): node content
  • OPTIONAL: other fileds represent arguments values (e.g. style = circle)

3. Compile template

Run:

j2t html

This command will search current work directory file-tree for .j2.node.json and .j2.json files and would compile .html output files (.out by default):

<ul style='list-style-type:circle'>
<li> list item #1 </li>
<li> list item #2 </li>
</ul>

Features and info

  • Each .j2.node.json and .j2.json change leads to output file(s) regeneration
  • JSON fields starts with _ (underscore) (e.g. _node, _name) are reserved for json2text future use, don't use them for attributes

TODO

  • Replace fsmonitor. Updates detection on Mac is reported to be slow. Copy & paste does not detected
  • Add flag to generate ones and exit
  • Color console print