MCPcopy Create free account
hub / github.com/ComponentDriven/csf / testValue

Function testValue

src/includeConditionalArg.ts:9–26  ·  view source on GitHub ↗
(cond: Omit<Conditional, 'arg' | 'global'>, value: any)

Source from the content-addressed store, hash-verified

7const count = (vals: any[]) => vals.map((v) => typeof v !== 'undefined').filter(Boolean).length;
8
9export const testValue = (cond: Omit<Conditional, 'arg' | 'global'>, value: any) => {
10 const { exists, eq, neq, truthy } = cond as any;
11 if (count([exists, eq, neq, truthy]) > 1) {
12 throw new Error(`Invalid conditional test ${JSON.stringify({ exists, eq, neq })}`);
13 }
14 if (typeof eq !== 'undefined') {
15 return isEqual(value, eq);
16 }
17 if (typeof neq !== 'undefined') {
18 return !isEqual(value, neq);
19 }
20 if (typeof exists !== 'undefined') {
21 const valueExists = typeof value !== 'undefined';
22 return exists ? valueExists : !valueExists;
23 }
24 const shouldBeTruthy = typeof truthy === 'undefined' ? true : truthy;
25 return shouldBeTruthy ? !!value : !value;
26};
27
28/**
29 * Helper function to include/exclude an arg based on the value of other other args

Callers 2

includeConditionalArgFunction · 0.85

Calls 1

countFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…