@maizzle/framework
Version:
Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.
54 lines (53 loc) • 2.07 kB
TypeScript
import { ChildNode } from "domhandler";
//#region src/transformers/removeAttributes.d.ts
/**
* Single attribute-removal rule.
*/
interface RemoveAttributeRule {
/** Attribute name to match. */
name: string;
/**
* Match condition for the attribute's value:
* - `string` — remove when the value matches exactly.
* - `RegExp` — remove when the value matches the regex.
* - `boolean` / omitted — remove when the value is empty.
*/
value?: string | RegExp | boolean;
}
/**
* Entry passed to {@link removeAttributes}. A bare string targets the named
* attribute and removes it when its value is empty.
*/
type RemoveAttributeOption = string | RemoveAttributeRule;
/**
* Remove HTML attributes from elements.
*
* Empty `style` and `class` attributes are always stripped, regardless of
* what you pass. Your entries are appended to those defaults.
*
* - `'data-src'` — remove when the value is empty.
* - `{ name: 'id', value: 'test' }` — remove when the value matches exactly.
* - `{ name: 'data-id', value: /\d/ }` — remove when the value matches the regex.
*
* @param html HTML string to transform.
* @param attributes Additional attribute-removal rules to apply on top of the defaults.
* @returns The transformed HTML string.
*
* @example
* import { removeAttributes } from '@maizzle/framework'
*
* const out = removeAttributes('<p style="" data-x="">x</p>', [
* 'data-x',
* { name: 'role', value: 'none' },
* ])
*/
declare function removeAttributes(html: string, attributes?: RemoveAttributeOption[]): string;
/**
* DOM-form of {@link removeAttributes} used by the internal transformer
* pipeline. Takes a parsed DOM, returns a parsed DOM — avoids redundant
* serialize/parse round-trips when chained with other transformers.
*/
declare function removeAttributesDom(dom: ChildNode[], attributes?: RemoveAttributeOption[]): ChildNode[];
//#endregion
export { RemoveAttributeOption, RemoveAttributeRule, removeAttributes, removeAttributesDom };
//# sourceMappingURL=removeAttributes.d.ts.map