contentful-rich-text-html-parser
Version:
Convert any HTML to the Contentful Rich Text format
35 lines • 1.32 kB
JavaScript
import { BLOCKS, TOP_LEVEL_BLOCKS, } from "@contentful/rich-text-types";
import { BLOCK_TYPES, INLINE_TYPES, MARK_TYPES } from "./constants.js";
export const isNotNull = (value) => value !== null;
export const isWhiteSpace = (content) => /^\s*$/.test(content);
export const getAsList = (value) => {
if (Array.isArray(value)) {
return value;
}
return [value];
};
export const isBlockType = (nodeType) => BLOCK_TYPES.includes(nodeType);
export const isInlineType = (nodeType) => INLINE_TYPES.includes(nodeType);
export const isMarkType = (nodeType) => MARK_TYPES.includes(nodeType);
export const isTopLevelBlock = (nodeType) => TOP_LEVEL_BLOCKS.includes(nodeType);
export const isNodeTypeBlock = (node) => isBlockType(node.nodeType);
export const isNodeTypeTopLevelBlock = (node) => isTopLevelBlock(node.nodeType);
export const isNodeTypeInline = (node) => isInlineType(node.nodeType);
export const isNodeTypeMark = (node) => {
return isMarkType(node.type);
};
export const isNodeTypeText = (node) => {
if (isNodeTypeMark(node)) {
return false;
}
if (node.nodeType === "text") {
return true;
}
return false;
};
export const createDocumentNode = (content, data = {}) => ({
nodeType: BLOCKS.DOCUMENT,
data,
content,
});
//# sourceMappingURL=utils.js.map