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

fluxduct

v0.5.0

Published

A low-level JSON-safe programming language

Downloads

1

Readme

Fluxduct npm version

A basic JSON-safe programming language

Overview

A compact object format programming language with 4 basic operations (at the moment).

Use Case

Let's say you have an API, and you're looking for a method by which you can increase performance of your app via doing transformations of the data directly in the API. In this scenario, you would middleman the API returned data through a Fluxduct parser in order to get the data in the format you would like. An important distinction to be made here is that you are not changing the raw output of your API, but rather defining explicit values which you would like back in the app.

These values are much more versatile than a pure API response as well, as they can be compounded with operators and conditionals to return computed values not otherwise returned in your API. Even more, the number of fields is completely up to you! If you only want 3 fields, foo, bar, and baz, on an API endpoint that returns more than just those 3 fields, you can explicitly only request those fields back.

As icing on the cake; Fluxduct is made from plain javascript, which allows for implementation either server-side or client-side, on top of this, Fluxduct is JSON-safe, meaning all transformations can exist as JSON, making these transformations able to be stored in most databases without the need for any additional transformations.

Usage

Input

This package exports a single function, parse, which accepts two arguments; firstly, a dictionary of variables and their respective values, which will be expected to match the paths passed in the object being parsed, secondly, the object to be parsed.

Output

Parse returns a single value or an array of values providing there are multiple expressions provided.

Examples

Addition

Simple

{ add: [{ path: ['a'] }, { path: ['b'] }] }

Nested

{ add: [{ multiply: [{ path: ['a'] }, { path: ['b'] }] }, { path: ['b'] }] }

Subtraction

Simple

{ subtract: [{ path: ['a'] }, { path: ['b'] }] }

Nested

{ subtract: [{ multiply: [{ path: ['a'] }, { path: ['b'] }] }, { path: ['b'] }] }

Multiply

Simple

{ multiply: [{ path: ['a'] }, { path: ['b'] }] }

Nested

{ multiply: [{ add: [{ path: ['a'] }, { path: ['b'] }] }, { path: ['b'] }] }

Divide

Simple

{ divide: [{ path: ['a'] }, { path: ['b'] }] }

Nested

{ divide: [{ add: [{ path: ['a'] }, { path: ['b'] }] }, { path: ['b'] }] }

Any one of these variables can be substituted for a IF condition, as shown below

{ add: [{ if: [{ path: ['a'] }, { path: ['b'] }, { path: ['c'] }] }, { path: ['d'] }] } -> If c is a boolean of value true then b will be used, else c.

Any variable above can be further nested with any combination of the operators and IF conditions

Errors

Invalid Parse Arguments (obj is not an object)

"The second argument provided "{a json stringified version of the provided argument}", is not an object."

A final, resolved value as an argument in a operation does not have a path key

"No path key present in argument "{a json stringified version of the provided argument}"."

No key present in dictionary for a given argument's path

"No value present in dictionary "{json stringified dictionary}" for path "{json stringified path}"."

Resolved value in dictionary does not meet expected type

"Expected {expectedType, defaulted to number} value at path "{json stringified path}" in dictionary "{json stringified dictionary}", received "{typeof resolvedValue}"."