UNPKG

@antv/t8

Version:

T8 is a text visualization solution for unstructured data within the AntV technology stack, and it is a declarative JSON Schema syntax that can be used to describe the content of data interpretation reports.

50 lines (47 loc) 2.44 kB
import { isObject, isString } from '../../utils/isType.js'; import 'clarinet'; import { ParagraphType } from '../paragraph.js'; import { PhraseType, EntityType } from '../phrase.js'; function isCustomSection(spec) { return isObject(spec) && 'customType' in spec; } function isCustomParagraph(spec) { return isObject(spec) && 'customType' in spec; } function isStandardSection(spec) { return isObject(spec) && 'paragraphs' in spec && Array.isArray(spec === null || spec === void 0 ? void 0 : spec.paragraphs); } function isTextParagraph(spec) { return isObject(spec) && (spec === null || spec === void 0 ? void 0 : spec.type) === ParagraphType.NORMAL && Array.isArray(spec === null || spec === void 0 ? void 0 : spec.phrases); } function isBulletParagraph(spec) { return isObject(spec) && (spec === null || spec === void 0 ? void 0 : spec.type) === ParagraphType.BULLETS && Array.isArray(spec === null || spec === void 0 ? void 0 : spec.bullets); } function isHeadingParagraph(spec) { if (isObject(spec) && 'type' in spec && isString(spec.type)) { var weight = getHeadingWeight(spec === null || spec === void 0 ? void 0 : spec.type); return spec.type.startsWith('heading') && !Number.isNaN(weight); } return false; } function isCustomPhrase(spec) { var _a; return spec.type === PhraseType.CUSTOM && !!((_a = spec === null || spec === void 0 ? void 0 : spec.metadata) === null || _a === void 0 ? void 0 : _a.customType); } function isEntityPhrase(spec) { var _a, _b; return (spec.type === PhraseType.ENTITY && !!((_a = spec === null || spec === void 0 ? void 0 : spec.metadata) === null || _a === void 0 ? void 0 : _a.entityType) && EntityType.includes((_b = spec === null || spec === void 0 ? void 0 : spec.metadata) === null || _b === void 0 ? void 0 : _b.entityType)); } function isTextPhrase(spec) { return spec.type === PhraseType.TEXT; } function getHeadingWeight(pType) { if (pType === null || pType === void 0 ? void 0 : pType.startsWith('heading')) { var weight = Number(pType === null || pType === void 0 ? void 0 : pType.slice(-1)); if (weight >= 1 && weight <= 6) return weight; } return NaN; } export { getHeadingWeight, isBulletParagraph, isCustomParagraph, isCustomPhrase, isCustomSection, isEntityPhrase, isHeadingParagraph, isStandardSection, isTextParagraph, isTextPhrase }; //# sourceMappingURL=isSpecType.js.map