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

sonjs

v0.3.4

Published

A scenario-based programming language

Downloads

192

Readme

Son

A scenario-based programming language

Description

Son is an experimental programming language designed as a subset of JavaScript. It simplifies programming by eliminating complex constructs like branching and loops, allowing only linear algorithms. In Son, each procedure is represented as a set of plots, which are individual units of logic. A plot is a scenario that depicts one possible path through the algorithm. The language’s transpiler automatically combines these plos to build the full procedure.

One key advantage of Son is that scenarios are easy to test in isolation, making debugging and verification straightforward. Additionally, anyone with basic JavaScript knowledge can quickly start using Son, thanks to its familiar syntax and streamlined approach.

Installation

npm install --global sonjs

Examples

This file defines a function called fizzbuzz that takes a single argument, number. The function's name is derived from the filename.

fizzbuzz.js

fun(number)

plot("divisible by 3 - Fizz")
yes(number % 3 === 0)
no(number % 5 === 0)
return "Fizz"


plot("divisible by 5 - Buzz")
no(number % 3 === 0)
yes(number % 5 === 0)
return "Buzz"

plot("divisible by 3 and 5 - FizzBuzz")
yes(number % 3 === 0)
yes(number % 5 === 0)
return "FizzBuzz"

A Son file consists of one or more sections. Each section can include optional shared code and may contain one or more plots. The fizzbuzz.js file contains only one, default section.

A plot can include both rules and actions. Actions are written in plain JavaScript, while rules are defined using the functions yes() and no().

At runtime, only one plot from each section is executed.

A return or throw statement terminates the function. In such a case, all remaining sections are skipped.

The matching rules for all plots within a section must be mutually exclusive, meaning only the rules of one plot can be true at a time.

The order in which the matching rules are evaluated is important, so ensure they are arranged correctly.

Additionally, the matching rules should contain pure functions, meaning they must not produce any side effects.

fibonacci.js

fun(ordinal) 

section("The first two elements")
plot()
yes(ordinal <= 1)
return ordinal

section("The main algorithm")
return fibonacci(ordinal - 2) + fibonacci(ordinal - 1)

Usage

A single function

Compile the examples/myModule/fibonacci.js function into JavaScript and save the generated fibonacci.js file in the dist folder. The dist folder must exist.

Be careful to not to overwrite the source file. Specify a different output folder since the output filename will be the same as the source filename.

sonjs --output dist examples/myModule/fibonacci.js

One project

Read the Son project from the examples/myModule/myModule.son file and include all function, property, and plain JavaScript files from the examples/myModule/ folder and its subfolders. Write the generated myModule.js file to the dist folder in the CommonJS format. The dist folder must exist.

sonjs --output dist --commonjs examples/myModule/myModule.son

Many projects in several subfolders

Find the .son module files located in the examples/myModule folder or its subfolders and compile the modules into .js files. Write the .js files to the dist folder in the ECMAScript format. The dist folder must exist.

sonjs --output dist --es examples/myModule

Code generation

The Son transpiler generates JavaScript code in multiple formats: browser, ES (ECMAScript), and CommonJS.

The generated functions can either be grouped together in an object (similar to a class) or written individually in a procedural style.