datocms-structured-text-utils
Advanced tools
Comparing version 2.0.3 to 2.0.4
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isDocument = exports.isStructuredText = exports.isThematicBreak = exports.isInlineItem = exports.isItemLink = exports.isLink = exports.isCode = exports.isBlock = exports.isBlockquote = exports.isListItem = exports.isList = exports.isParagraph = exports.isRoot = exports.isSpan = exports.isHeading = exports.isInlineNode = exports.hasChildren = void 0; | ||
exports.isEmptyDocument = exports.isDocument = exports.isStructuredText = exports.isThematicBreak = exports.isInlineItem = exports.isItemLink = exports.isLink = exports.isCode = exports.isBlock = exports.isBlockquote = exports.isListItem = exports.isList = exports.isParagraph = exports.isRoot = exports.isSpan = exports.isHeading = exports.isInlineNode = exports.hasChildren = void 0; | ||
var definitions_1 = require("./definitions"); | ||
@@ -77,2 +77,24 @@ function hasChildren(node) { | ||
exports.isDocument = isDocument; | ||
function isEmptyDocument( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types | ||
obj) { | ||
if (!obj) { | ||
return true; | ||
} | ||
var document = isStructuredText(obj) | ||
? obj.value | ||
: isDocument(obj) | ||
? obj | ||
: null; | ||
if (!document) { | ||
throw new Error('Passed object is neither null, a Structured Text value or a DAST document'); | ||
} | ||
return (document.schema === 'dast' && | ||
document.document.children.length === 1 && | ||
document.document.children[0].type === 'paragraph' && | ||
document.document.children[0].children.length === 1 && | ||
document.document.children[0].children[0].type === 'span' && | ||
document.document.children[0].children[0].value === ''); | ||
} | ||
exports.isEmptyDocument = isEmptyDocument; | ||
//# sourceMappingURL=guards.js.map |
@@ -19,1 +19,2 @@ import { Root, List, Blockquote, Block, Link, ItemLink, InlineItem, Code, ListItem, Paragraph, Heading, Node, Span, WithChildrenNode, InlineNode, Record, StructuredText, ThematicBreak, Document } from './types'; | ||
export declare function isDocument(obj: any): obj is Document; | ||
export declare function isEmptyDocument(obj: any): boolean; |
@@ -57,2 +57,23 @@ import { headingNodeType, spanNodeType, rootNodeType, paragraphNodeType, listNodeType, listItemNodeType, blockquoteNodeType, blockNodeType, codeNodeType, linkNodeType, itemLinkNodeType, inlineItemNodeType, inlineNodeTypes, thematicBreakNodeType, } from './definitions'; | ||
} | ||
export function isEmptyDocument( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types | ||
obj) { | ||
if (!obj) { | ||
return true; | ||
} | ||
var document = isStructuredText(obj) | ||
? obj.value | ||
: isDocument(obj) | ||
? obj | ||
: null; | ||
if (!document) { | ||
throw new Error('Passed object is neither null, a Structured Text value or a DAST document'); | ||
} | ||
return (document.schema === 'dast' && | ||
document.document.children.length === 1 && | ||
document.document.children[0].type === 'paragraph' && | ||
document.document.children[0].children.length === 1 && | ||
document.document.children[0].children[0].type === 'span' && | ||
document.document.children[0].children[0].value === ''); | ||
} | ||
//# sourceMappingURL=guards.js.map |
@@ -19,1 +19,2 @@ import { Root, List, Blockquote, Block, Link, ItemLink, InlineItem, Code, ListItem, Paragraph, Heading, Node, Span, WithChildrenNode, InlineNode, Record, StructuredText, ThematicBreak, Document } from './types'; | ||
export declare function isDocument(obj: any): obj is Document; | ||
export declare function isEmptyDocument(obj: any): boolean; |
{ | ||
"name": "datocms-structured-text-utils", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "A set of Typescript types and helpers to work with DatoCMS Structured Text fields.", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "364675f62d3aa0b4a0d859d27da6d34615407cfe" | ||
"gitHead": "dc132d64b36fd4cf7bb0ff7688ad21d55bbd4c0c" | ||
} |
@@ -114,1 +114,31 @@ import { | ||
} | ||
export function isEmptyDocument( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types | ||
obj: any, | ||
): boolean { | ||
if (!obj) { | ||
return true; | ||
} | ||
const document = isStructuredText(obj) | ||
? obj.value | ||
: isDocument(obj) | ||
? obj | ||
: null; | ||
if (!document) { | ||
throw new Error( | ||
'Passed object is neither null, a Structured Text value or a DAST document', | ||
); | ||
} | ||
return ( | ||
document.schema === 'dast' && | ||
document.document.children.length === 1 && | ||
document.document.children[0].type === 'paragraph' && | ||
document.document.children[0].children.length === 1 && | ||
document.document.children[0].children[0].type === 'span' && | ||
document.document.children[0].children[0].value === '' | ||
); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108348
2540