yopl is an ES6 mini-library that implements a Prolog-style logic solver in JavaScript. It provides:
A small core solver with multiple driver styles: callback, generator, async callback, async generator.
A built-in rule library: helpers and control predicates, comparisons, arithmetic, bitwise, boolean logic, and JS-native bridges (Array / Map / Set / Date).
A rule compiler with two tagged-template front-ends — a per-clause DSL (clause\...`) and a strict-Prolog whole-program parser (prolog`...``) — write rules declaratively, catch arity drift at compile time.
Its only runtime dependency is deep6, itself a zero-dependency library that provides the unification engine.
What it does and when to use it
yopl lets you describe a problem as a set of rules over JavaScript values and ask the solver to find values that satisfy them. You write declarative rules; the engine handles search, unification, and backtracking. You stay inside JavaScript — there is no embedded DSL to parse, no separate Prolog runtime, and rules can call back into plain JS (sync or async) whenever a piece of logic is easier to express that way.
It is useful when a problem is awkward to express as straight-line code but natural to express as constraints or relations:
Pattern matching and shape validation against deeply nested data, where you also want to extract values during the match.
Searching configurations, dependency graphs, or rule sets for combinations that satisfy several conditions at once.
Type-inference-like or tag-propagation passes over an AST or IR.
Small expert systems, planners, permission/policy checks, and "find me an X such that Y" queries embedded inside a larger JS app.
Test fixtures and property-style checks that need to enumerate all values matching a spec.
If you only need single-direction pattern matching, a regex or a destructuring assignment is simpler. Reach for yopl when you need bidirectional matching (unification), backtracking across alternative rules, or enumeration of all solutions — and you want all of that without leaving your JavaScript codebase.