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

raddle

v0.1.1

Published

Extensible document manipulation language for the web

Downloads

5

Readme

Raddle

A minimalist functional language

What?

Raddle is a functional language for manipulating structured documents (XML, HTML, JSON or... Raddle itself).

This library provides only a parser and compiler. It utilizes L3N, a tiny format for encoding the language as a flat stream, and Frink, the core functionality using a reactive approach.

Raddle is inspired by RQL and XQuery.

Getting started

Run npm install to fetch all dependencies. We need them to compile a string of code, for example:

import { parseString, run } from 'raddle';
import { fromStream } from 'l3n';
import * as n from 'frink';

parseString("add(1,2)").pipe(toVNodeStream,$o => run($o,{
	modules:{
		n:n
	}
}));

The parser emits an L3N stream, a flat binary encoding of the program. However, the compiler expects a VNode stream, which wraps the binary data into a more convenient interface. See L3N for more information.

The compiler takes a confuration object with at least the module containing the core functions. The default prefix for this is n, but this may be configured as well in the near future.

Definition Anatomy

The dollar sign provides a context where stuff can be assigned to, and it can be called as a function. So you could write:

$(name[,documentation][,type],body)

Character strings don't have to be written in quotes always. Only in cases where ambiguity with reserved characters would arise, a string should be notated between a pair of (single or double) quotes.

To retrieve the value from the variable, you can call the dollar function with its name:

$(name)

However, you may leave off the parentheses for a shorthand notation:

$name

Lambdas

Functions can be defined in the same way as variables are assigned. Anonymous functions (also known as lambdas) are written within a block of curly brackets. Each parameter of the lambda is referenced numerically, in the order that the function will receive it when it's called, for instance:

{add($1,$2)}

Whenever a new lambda function is created, all previous numbered parameters go out of scope. This way inline functions can also be created. So when a parameter needs to be adressed in a nested lambda, its value should be assigned to a named variable first, since named variables are scoped to the entire block of curly brackets they're in. Example:

{$(x,$1),$(y,$2),add($x,$y)}

Top-level functions

$* declare a module

A module must be explicitly prefixed:

$*(my-module)

$< import a module

$*(other-module,"path")

$> export a constant

$>(my-module:compute,body)

If you don't want to expose the constant, just leave off the > sign.

Types

Types can be provided as function calls:

  • string()
  • number() (Equivalent to double())
  • integer()
  • array()
  • array(T) (T is the type of the items in the array.)
  • map()
  • map(K,V) (K is the type of the key and V is the type of the value.)
  • function() (A function with an unknown number of arguments. This is the default constraint for any lambda.)
  • function(S,R) (S is a sequence of parameter types, and R is the type of the value the function should return.)
  • element(Q) (Q is the qualified name of the XML element)
  • attribute(Q) (Q is the qualified name of the XML attribute)

Partial application

Any function can be partially applied by using a question mark as a placeholder for an unknown parameter:

add(?,4)

The above function call returns a partially applied function that can be called with a single argument.