UNPKG

@curvenote/schema

Version:

Schema and markdown parser for @curvenote/editor

25 lines 824 B
import { customAlphabet } from 'nanoid'; export function clamp(val, min, max) { return Math.min(Math.max(val, min), max); } const az = 'abcdefghijklmnopqrstuvwxyz'; const alpha = az + az.toUpperCase(); const numbers = '0123456789'; const nanoidAZ = customAlphabet(alpha, 1); const nanoidAZ9 = customAlphabet(alpha + numbers, 9); export function createId() { return nanoidAZ() + nanoidAZ9(); } export function findChildrenWithName(parent, nodeName) { const predicate = typeof nodeName === 'string' ? (n) => n.type.name === nodeName : (n) => nodeName.includes(n.type.name); const result = []; parent.descendants((child, pos) => { if (predicate(child)) result.push({ node: child, pos }); return true; }); return result; } //# sourceMappingURL=index.js.map