MCPcopy
hub / github.com/thesysdev/openui / parseRule

Function parseRule

packages/lang-core/src/utils/validation.ts:15–23  ·  view source on GitHub ↗
(rule: string)

Source from the content-addressed store, hash-verified

13const NUMERIC_RULES = new Set(["min", "max", "minLength", "maxLength"]);
14
15export function parseRule(rule: string): ParsedRule {
16 const colonIdx = rule.indexOf(":");
17 if (colonIdx === -1) return { type: rule };
18
19 const type = rule.slice(0, colonIdx);
20 const rawArg = rule.slice(colonIdx + 1);
21 const arg = NUMERIC_RULES.has(type) && !Number.isNaN(Number(rawArg)) ? Number(rawArg) : rawArg;
22 return { type, arg };
23}
24
25export function parseRules(rules: unknown): ParsedRule[] {
26 if (!Array.isArray(rules)) return [];

Callers

nothing calls this directly

Calls 1

hasMethod · 0.80

Tested by

no test coverage detected