@nacelle/rich-text-utils
Version:
A set of Typescript types and helpers to work with Rich Text fields.
57 lines • 1.9 kB
JavaScript
import { headingNodeType, spanNodeType, rootNodeType, paragraphNodeType, listNodeType, listItemNodeType, blockquoteNodeType, blockNodeType, codeNodeType, linkNodeType, entryLinkNodeType, inlineEntryNodeType, inlineNodeTypes, thematicBreakNodeType, } from './definitions';
export function hasChildren(node) {
return 'children' in node;
}
export function isInlineNode(node) {
return inlineNodeTypes.includes(node.type);
}
export function isHeading(node) {
return node.type === headingNodeType;
}
export function isSpan(node) {
return node.type === spanNodeType;
}
export function isRoot(node) {
return node.type === rootNodeType;
}
export function isParagraph(node) {
return node.type === paragraphNodeType;
}
export function isList(node) {
return node.type === listNodeType;
}
export function isListItem(node) {
return node.type === listItemNodeType;
}
export function isBlockquote(node) {
return node.type === blockquoteNodeType;
}
export function isBlock(node) {
return node.type === blockNodeType;
}
export function isCode(node) {
return node.type === codeNodeType;
}
export function isLink(node) {
return node.type === linkNodeType;
}
export function isEntryLink(node) {
return node.type === entryLinkNodeType;
}
export function isInlineEntry(node) {
return node.type === inlineEntryNodeType;
}
export function isThematicBreak(node) {
return node.type === thematicBreakNodeType;
}
export function isRichText(
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
obj) {
return obj && 'value' in obj && isDocument(obj.value);
}
export function isDocument(
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
obj) {
return obj && 'schema' in obj && 'document' in obj;
}
//# sourceMappingURL=guards.js.map