/** * Per-environment configuration for data-* attribute patterns to strip. * Each key is an environment name and its value is a list of glob-style patterns to remove. */ interface IEnvAttrCleanerConfig { /** Map of environment names to lists of data-* attribute patterns to strip. */ environments: Record; } /** * Returns whether a data-* attribute name matches a glob-style pattern. * Supports `*` as a wildcard. * * @param attr - The attribute name to test (e.g. `data-test-id`). * @param pattern - The glob pattern to match against (e.g. `data-test-*`). */ declare function matchPattern(attr: string, pattern: string): boolean; /** * Returns whether a data-* attribute should be stripped, * i.e. whether it matches at least one of the strip patterns. * * @param attr - The attribute name to test. * @param patterns - List of glob patterns marking attributes for removal. */ declare function shouldStrip(attr: string, patterns: string[]): boolean; /** * Strips data-* attributes from an HTML or source code string * when they match one of the given patterns. All other attributes are preserved. * * @param code - The source string to process. * @param stripPatterns - List of glob patterns for attributes to remove. * @returns The processed string with matched data-* attributes removed. */ declare function stripDataAttributes(code: string, stripPatterns: string[]): string; /** Subset of the Bun build API used by the envAttrCleaner plugin. */ interface IBunBuild { onLoad: (options: { filter: RegExp; }, callback: (args: { path: string; }) => Promise<{ contents: string; loader: string; }>) => void; } /** Shape of a Bun bundler plugin. */ interface IBunPlugin { name: string; setup: (build: IBunBuild) => void; } /** * Bun plugin that strips non-allowed data-* attributes from source files at build time, * based on the current `NODE_ENV`. * * @param userConfig - Optional partial configuration to override the default environment patterns. * @returns A Bun plugin object to pass to `Bun.build({ plugins: [...] })`. * * @example * ```ts * import envAttrCleaner from 'env-attr-cleaner-bun' * * await Bun.build({ * entrypoints: ['./src/index.tsx'], * outdir: './dist', * plugins: [envAttrCleaner()] * }) * ``` */ declare function envAttrCleaner(userConfig?: Partial): IBunPlugin; export { envAttrCleaner as default, envAttrCleaner, matchPattern, shouldStrip, stripDataAttributes }; export type { IBunBuild, IBunPlugin, IEnvAttrCleanerConfig };