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

calyx

v0.17.0

Published

Generative grammars for creative coding

Downloads

33

Readme

Calyx

A JavaScript port of Calyx, a Ruby based generative grammar tool.

Status

npm github

Install

npm install calyx

Usage

Most of the existing documentation is for the Ruby version, but some brief usage notes are included below.

ESM

import calyx from "calyx"

const hello = calyx.grammar({
  "start": "Hello world."
})

CommonJS

const calyx = require("calyx")

const hello = calyx.grammar({
  "start": "Hello world."
})

Generator API

Call generate on a grammar instance to generate a random text based on your configured rules.

const result = hello.generate()

generate returns a Result type which allows you to access the generated text as a string or an s-expression tree of arrays.

result.text
result.tree

Example Usage

Every grammar feature documented for the Ruby version should work here (if not, please raise a bug report).

The main difference between the Ruby and JavaScript implementations is the class-based Ruby DSL for defining grammar rules. This doesn’t exist in the JavaScript version which only supports definitions in the object-literal format with string keys for rule names.

import { grammar } from "calyx"

const companyNames = grammar({
  "start": ["{web_two_punkt_oh} {ext}", "{acme_variations} {ext}"],
  "ext": ["LLC", "Ltd", "Limited", "Pty Ltd"],
  "web_two_punkt_oh": ["{punktrs}r", "{punktrs}zy"],
  "punktrs": ["Lick", "Stick", "Brick", "Syntax", "Relax", "Back"],
  "acme_variations": "Acme {acme_noun}",
  "acme_noun": ["Products", "Industries", "Goods", "Holdings", "Services"]
})

const company = companyNames.generate()

console.log(company.text)

Syntax

See more details here.

License

This package is copyright 2017-2022 Mark Rickerby and distributed freely under the terms of the MIT License. See the LICENSE file packaged with this software distribution.