UNPKG

@curvenote/cli-plugin

Version:
30 lines (29 loc) 1.29 kB
import { u } from 'unist-builder'; export function validateStringOptions(vfile, fieldName, field, validValues) { const notString = typeof field !== 'string'; const invalidValues = validValues && typeof field === 'string' && !validValues.includes(field); if (notString) vfile.message(`Invalid ${fieldName} supplied.`); if (invalidValues) vfile.message(`Invalid ${fieldName} supplied must be one of (${validValues.join(' | ')}).`); } export function makePlaceholder(data, description) { const optionList = data.options ? [ u('ul', Object.entries(data.options)?.map(([key, value]) => u('listItem', [u('inlineCode', key), u('text', `: ${String(value)}`)])) ?? []), ] : []; return [ u('admonition', { kind: 'important' }, [ u('admonitionTitle', [u('inlineCode', [u('text', data.name)])]), u('block', [ u('text', 'This block will be replaced with '), u('strong', [u('text', description)]), u('text', ' when deployed to '), u('link', { url: 'https://curvenote.com' }, [u('text', 'Curvenote')]), u('text', '.'), ]), u('block', [u('text', 'Options:'), ...optionList]), ]), ]; }