min-dom is a focused and lightweight JavaScript library, currently at version 5.3.0, providing a collection of essential DOM manipulation utilities. It emphasizes a minimal footprint, weighing approximately 2KB gzipped, making it suitable for environments where bundle size is critical. The library maintains an active release cadence, with recent updates ensuring compatibility and minor feature enhancements. Key differentiators include its small size, its inspiration from the `component` project's utilities, and its provision of common helpers like `assignStyle`, `attr`, `classes`, `clear`, `closest`, `delegate`, `domify`, `event`, `matches`, `query`, and `remove`. It is designed to be library-friendly and ships with TypeScript types for improved developer experience in typed projects.
npm install min-domVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating elements with `domify`, querying the DOM using `query`, manipulating CSS classes with `classes`, and handling events with `event.on`/`event.off`.
Review the changelog for `domify@2` and `min-dom@5.0.0` to understand potential impacts. Test your application thoroughly after upgrading. If you had custom shims or overrides for `domify`, they might need adjustments.
Ensure you are calling `event.on`, `event.off`, or `event.bind` rather than attempting to call `on` or `off` directly if you've destructured `event` or are using an incorrect import pattern.
Always validate selector strings before passing them to `query` or `closest`. Ensure they are non-empty and syntactically correct CSS selectors.
Sanitize any user-provided HTML strings before passing them to `domify`. Consider using a dedicated HTML sanitization library or ensuring that only trusted sources provide the HTML content.
Correct your event binding to `import { event } from 'min-dom'; event.on(element, 'event', handler);`Use named imports for all utilities: `import { query, domify } from 'min-dom';`Ensure the selector string is a valid CSS selector and not empty. For example, `closest(element, '.my-class')` is correct, but `closest(element, '')` will fail.