A basic JSON-safe programming language
A compact object format programming language with 10 basic operations (at the moment).
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.
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.
Parse returns a single value or an array of values providing there are multiple expressions provided.
- Note: Examples do not include additional operators added in >0.5.0 (or, and, concat, power, equal)
{ add: [{ path: ['a'] }, { path: ['b'] }] }
{ add: [{ multiply: [{ path: ['a'] }, { path: ['b'] }] }, { path: ['b'] }] }
{ subtract: [{ path: ['a'] }, { path: ['b'] }] }
{ subtract: [{ multiply: [{ path: ['a'] }, { path: ['b'] }] }, { path: ['b'] }] }
{ multiply: [{ path: ['a'] }, { path: ['b'] }] }
{ multiply: [{ add: [{ path: ['a'] }, { path: ['b'] }] }, { path: ['b'] }] }
{ divide: [{ path: ['a'] }, { path: ['b'] }] }
{ 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
"The second argument provided "{a json stringified version of the provided argument}", is not an object."
"No path key present in argument "{a json stringified version of the provided argument}"."
"No value present in dictionary "{json stringified dictionary}" for path "{json stringified path}"."
"Expected {expectedType, defaulted to number} value at path "{json stringified path}" in dictionary "{json stringified dictionary}", received "{typeof resolvedValue}"."