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

fpjson-lang

v0.1.5

Published

![](./assets/cover.png)

Downloads

20

Readme

FPJSON

FPJSON is a programming language agnostic JSON-based functional programming language.

  • The whole code is just a JSON array
  • Functional Programming
  • No overhead due to programming language implementation details

In other words, you don't have to worry about any programming language specifications.

Instead you can just focus on building pure logics for data manipuration.

Since it's just a JSON array, it can be ported to any programming language environment.

Some Examples

/* add */
["add", 1, 2] // = 3

/* difference */
["difference", [1, 2, 3], [3, 4, 5]] = [1, 2]

/* map */
[["map", ["inc"]], [1, 2, 3]] // = [4, 5, 6]

/* compose */
[["compose", ["map", ["inc"]], ["difference"]], [1, 2, 3], [3, 4, 5]] // = [2, 3]

There are more than 250 pre-defined functions. And you can further extend that library.

Install

For now the parser is only implemented in JavaScript and it borrows heavily from Ramda.js.

In fast, you can use most of the functions in Ramda with FPJSON.

yarn add fpjson-lang

Usage

It couldn't be simpler.

import fpjson from "fpjson-lang"

const one_plus_two = fpjson(["add", 1, 2]) // = 3

Syntax

You should familiarize yourself with Ramda which enables Haskell-like functional programming with JS. You can use most of the powerful ramda functions with point-free style in JSON.

The first element in an array is a function.

["add", 1, 2] // add(1, 2)

To curry a function, nest it.

[["add", 1], 2] // add(1)(2)

A function always needs to be wrapped with [] and to be the first element in the array.

[["map", ["inc"]], [1, 2, 3]] // map(inc)([1, 2, 3])

This is an error because inc is imterpreted as String.

[["map", "inc"], [1, 2, 3]] // map("inc")([1, 2, 3])

Point-free style means you cannot write something like this with the JSON format.

sortBy((v)=> v.age)(people) // ramdajs

It's because you cannot write arbitrary JS lines such as (v)=> v.age.

Instead, you can achieve the same using another ramda funciton prop.

sortBy(prop("age"), people) // ramdajs
["sortBy",["prop", "age"], people] // FPJSON

Reserved First Words

By placing a reserved word in the first spot of an array, you can access the pre-built features.

There are just 6 of them.

"[]"

To create an array of functions without executing them, place "[]" in the first spot, otherwise the ["lte", 2] function will be executed with ["gt", 2] before -3 is passed.

[["anyPass", ["[]", ["lte", 2], ["gt", 2]]], -3] // anyPass(lte(2), gt(2))(-3)

"typ"

To create a type object such as Number, Boolean, String, Array, and Object.

["is", ["typ", "String"], "abc"] // is(String, "abc")

"reg"

To create a RegExp.

["test", ["reg", "a", "i"], "ABC"] // test(new RegExp("a", "i"), "ABC")

"let"

Pure functional programming without any side-effects is easy to get extremely complex and entangled even for simple logics.

"let" inserts global variables to ease up the unnecessary complexisities.

["let", "num1", 1] // let var1 = 1

"$"

To access previously defined variables, use "$".

["add", ["var", "num1"], 1] // add(num1, 1)

In practice, you need to use "let" and "$" in the same array.

[["pipe", ["add", 1], ["let", "num1"], ["$", "num1"]], 1]) // = 2

Or you can pass a store object as the second argument to fpjson.

let vars = {}
fpjson(["let", "num1", 1], vars) // vars = { "num1" : 1 }
fpjson(["add", ["$", "num1"], 1], vars) // 2

"var"

var works just like $ except that var needs another argument to invoke.

The last argument can be anything since it will be ignored.

Note that you cannot access a new value within the same composition where it was defined.

let vars = {}
fpjson(["let", "num1", 1], vars) // vars = { "num1" : 1 }
fpjson(["add", ["var", "num1", true], 1], vars) // 2

Dynamic Variables

Variable names can be dinamically specified with $dynamic_path.

let vars = {}
fpjson(["let", "num1", 1], vars) // vars = { "num1" : 1 }
fpjson(["let", "ln", "num1"], vars) // vars = { "num1" : 1, "ln" : "num1" }
fpjson(["add", ["$, "$ln"], 1], vars) // 2

Dot Notation

Nested fields can be accessed with ..

let vars = {}
fpjson(["let", "o", { num: 1 }], vars) // vars = { "o" : { "num": 1 } }
fpjson(["var", "o.num", true ], vars) // 1

Who is Using FPJSON?

FPJSON is used to define access control rules and cron jobs in WeaveDB - Arweave-based decentralized NoSQL Database. FPJSON allows super rich and complex programming logics to be stored as JSON data on smart contracts, which opens up a whole new pradigm to dapp development.

FPJSON is also to be used for natural language generation algorithms, which will lead to the next-gen AI paradigm to revolutionize the human languages.

Tutorials

Learning functional programming is pretty challenging. So we created interactive tutorials and an exam to make sure you can familiarize yourself with all the core functions with ease!

Going through the tutorials will install a new framework in your brain and make you a better programmer in general even if you never need FPJSON.

It's not so much about languages, but about how your brain agnostically operates on data structures.