UNPKG

@iimm/shared

Version:

shared utils on browser and react env

58 lines (57 loc) 2.17 kB
import type { ObjectStyle, HtmlConvertAttributesConfig, HtmlJsonNode } from '../types'; export interface InlineStyleToObjectStyleOptions { /** 转换为驼峰命名? * @default false */ styleCamelCase?: boolean; /** 获得的object样式返回前进一步的转化函数 */ objectStyleConvertFn?: (objectStyle: ObjectStyle) => ObjectStyle; } /** 内联样式转化为对象样式,默认样式的属性名保留原样,不会转化为驼峰式 */ export declare const inlineStyleToObjectStyle: (style?: string, options?: InlineStyleToObjectStyleOptions) => ObjectStyle; export interface HtmlToJsonOptions extends HtmlConvertAttributesConfig { /** * 跳过style标签的解析? * @default false */ skipStyle?: boolean; /** * 在结果中保留原始内联样式文本? * @default false */ keepInlineStyle?: boolean; /** * 跳过script标签内容的解析? * @default false */ skipScript?: boolean; /** * 在结果中移除class?如果保留将将class拆分为字符串数组 * @default false */ skipClass?: boolean; /** * 在结果中跳过注释? * @default true */ skipComment?: boolean; /** 跳过除了style和class的其他属性? * @default false */ skipAttributes?: boolean; /** 过滤tag的属性名 */ attributeNameFilter?: (attributeName: string) => boolean; /** style的属性名转换为驼峰式? * @default false */ styleCamelCase?: boolean; /** 其他属性名转化为驼峰式? * @default false */ attributesCamelCase?: boolean; objectStyleConvertFn?: InlineStyleToObjectStyleOptions['objectStyleConvertFn']; } /** 将html字符串转化成指定格式的js节点对象的数组 */ export declare const htmlToJson: (html: string, options?: HtmlToJsonOptions) => HtmlJsonNode[]; /** 将解析成js节点对象或js节点对象数组的html对象转化成html字符串 */ export declare const jsonToHtml: (json: HtmlJsonNode[] | HtmlJsonNode, options?: HtmlConvertAttributesConfig) => string;