@torba/mojang-rules
v1.0.13
Published
Pure platform and feature rule evaluation. No side effects, no I/O — just POJOs and functions.
Readme
@torba/mojang-rules
Pure platform and feature rule evaluation. No side effects, no I/O — just POJOs and functions.
Install
npm install @torba/mojang-rules zodConcepts
A Rule either allows or disallows based on OS constraints, feature flags, or unconditionally:
type Rule =
| { action: 'allow' | 'disallow'; os: OsConstraint }
| { action: 'allow' | 'disallow'; features: FeatureConstraint }
| { action: 'allow' | 'disallow' };A Ruleset is an array of rules. All rules must be satisfied for the ruleset to pass.
API
satisfiesRuleset(ruleset, os, feats?)
Returns true if every rule in ruleset is satisfied for the given OS and feature set.
import { satisfiesRuleset } from '@torba/mojang-rules';
const passes = satisfiesRuleset([{ action: 'allow', os: { name: 'linux' } }], {
name: 'linux',
version: '6.12',
arch: 'x86_64',
});
// trueCompact "shorthand" parsing of rules lives in @torba/core.
Ruleset helpers
import { emptyRuleset, allowOsRuleset } from '@torba/mojang-rules';
emptyRuleset(); // []
allowOsRuleset('linux'); // [{ action: 'allow', os: { name: 'linux' } }]Zod schemas
import { RuleSchema, RulesetSchema } from '@torba/mojang-rules';
const rule = RuleSchema.parse({ action: 'allow', os: { name: 'osx' } });
const rules = RulesetSchema.parse([...]);