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

gt-helpers

v0.0.4

Published

some tools to help parse and generate GuidedTrack programs

Downloads

1

Readme

gt-helpers is a set of tools for creating GuidedTrack programs. Its main use is compiling GT programs in Liquid template form into finished GT programs, though it has a few other little tools as well.

Installation

To use in Node:

npm install --save @jrc03c/gt-helpers

To use in the browser:

  1. Clone this repo
  2. Attach the dist/gt-helpers.js script to a web page, which will make the gt object accessible as a global variable

Examples

To compile a simple Liquid template, start with a GT program that mixes in Liquid templating syntax:

-- template.gt
This is a GT program!

{% for question in questions %}
*question: {{ question.text }}
	*answers: {{ question.options }}
{% endfor %}

Create a JS file that handles the build process:

// build.js
const gt = require("gt-helpers")
const fs = require("fs")

const template = fs.readFileSync("template.gt", "utf8")

const data = {
	questions: [
		{
			text: "Why?",
			options: JSON.stringify(["Because.", "Why not?", "I said so."]),
		},
		{
			text: "How much?",
			options: JSON.stringify(["A lot.", "A little.", "None."]),
		},
		{
			text: "When?",
			options: JSON.stringify(["Now.", "Never."]),
		},
	],
}

gt.template.liquidBuild(template, data).then(final => {
	fs.writeFileSync("final.gt", final, "utf8")
})

And then invoke the JS file:

node build.js

This produces:

-- template.gt
This is a GT program!


*question: Why?
	*answers: ["Because.","Why not?","I said so."]

*question: How much?
	*answers: ["A lot.","A little.","None."]

*question: When?
	*answers: ["Now.","Never."]

NOTE: Since GT syntax relies on using tabs for indentation, make sure that both your GT template and your JS file uses tabs to avoid ending up with a compiled GT program that uses spaced indentation!

I've also added some little utility functions that make it easy to:

  • convert a JSON object to a GT association
  • convert a JS Date object to a GT datetime object

So, for example:

const gt = require("gt-helpers")

const object = { name: "Josh", position: { x: 5, y: 7 } }
const association = gt.object.toAssociation(object)
console.log(association)
// '{"name"->"Josh","position"->{"x"->5,"y"->7}}'

const date = new Date("December 10, 2019 10:30:00")
const gtDate = gt.date.toGTDateObject(date)
console.log(gtDate)
// '{"year"->2019,"month"->12,"day"->10,"hour"->10,"minute"->30}'

It's also possible (but highly experimental) to extract questions from the text of a GT program like this:

// NOTE: Remember that GT programs must be indented with tabs!

const program = `
	*question: How old are you?
		*type: number
		*save: age

	*question: What is your name?
		*save: name

	*question: Which of these is your favorite ice cream flavor?
		*tip: If these aren't your favorites, then just pick which one of the three you like best.
		Chocolate
		Vanilla
		Strawberry
`

const questionData = gt.program.extractQuestions(program)
questionData.print()

The returned data is a js-math-tools DataFrame. Additionally, the demo page that accompanies this repo offers the ability to download the data in CSV or JSON formats.

By the way, you'll notice in the picture above that values in the "answers" column are stored as strings. That's because the DataFrame class intentionally does not allow storage of arrays as values. But the string values are created by JSON.stringify and should therefore be easily parseable as JSON (e.g., with JSON.parse in JS or json.loads in Python).