MCPcopy Index your code
hub / github.com/OpenCoworkAI/open-codesign / validateEntry

Function validateEntry

packages/shared/src/editmode.ts:254–288  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

252}
253
254function validateEntry(value: unknown): TokenSchemaEntry | null {
255 if (!isPlainObject(value)) return null;
256 const kind = value['kind'];
257 if (kind === 'color' || kind === 'boolean') {
258 return { kind };
259 }
260 if (kind === 'number') {
261 const min = optionalNumber(value, 'min');
262 const max = optionalNumber(value, 'max');
263 const step = optionalNumber(value, 'step');
264 if (min === null || max === null || step === null) return null;
265 if (hasOwn(value, 'unit') && typeof value['unit'] !== 'string') return null;
266 const out: TokenSchemaEntry = { kind: 'number' };
267 if (min !== undefined) out.min = min;
268 if (max !== undefined) out.max = max;
269 if (step !== undefined) out.step = step;
270 if (typeof value['unit'] === 'string') out.unit = value['unit'];
271 return out;
272 }
273 if (kind === 'enum') {
274 const options = value['options'];
275 if (!Array.isArray(options)) return null;
276 if (options.length === 0 || !isStringArray(options)) {
277 return null;
278 }
279 return { kind: 'enum', options };
280 }
281 if (kind === 'string') {
282 if (hasOwn(value, 'placeholder') && typeof value['placeholder'] !== 'string') return null;
283 const out: TokenSchemaEntry = { kind: 'string' };
284 if (typeof value['placeholder'] === 'string') out.placeholder = value['placeholder'];
285 return out;
286 }
287 return null;
288}
289
290export function parseTweakSchema(source: string): TweakSchema | null {
291 const block = findMarkerBlock(source, 'TWEAK-SCHEMA');

Callers 1

parseTweakSchemaFunction · 0.85

Calls 4

isPlainObjectFunction · 0.85
optionalNumberFunction · 0.85
hasOwnFunction · 0.85
isStringArrayFunction · 0.85

Tested by

no test coverage detected