This plugin speeds up pdsl
in babelified codebases by pre-compiling p-expressions to predicate function definitions.
This aught to work but should be considered experimental for the time being until we have more tests around it.
Install the plugin with yarn or npm.
yarn add --dev @pdsl/babel-plugin-pdsl
npm install -D @pdsl/babel-plugin-pdsl
Add the plugin to your .bablerc
:
{
"plugins": ["@pdsl/babel-plugin-pdsl"]
}
NOTE: Ensure the plugin is placed before any module resolution plugins.
This plugin parses p-expressions and repaces them with helper function calls in your code:
import p from "pdsl";
const notNil = p`!(null|undefined)`;
const hasName = p`{name}`;
const isTrue = p`true`;
const hasNameWithFn = p`{name:${a => a.length > 10}}`;
import { val, not, or, obj, entry, pred } from "pdsl/helpers";
const notNil = val(not(or(val(null), val(undefined))));
const hasName = val(obj("name"));
const isTrue = val(true);
const hasNameWithFn = val(obj(entry("name", pred(a => a.length > 10))));