AgnosticWipe is a utility function that safely removes all child nodes of a given DOM element, avoiding the use of innerHTML to clear content. It includes configurable debugging capabilities (log and warn), similar to other Agnostic modules, to assist with troubleshooting during development.
- Safely wipes the content of a DOM element without using
innerHTML. - Configurable debugging for logging and warnings.
- Simple, clean, and secure DOM manipulation.
You can install AgnosticWipe via npm:
npm install agnostic-wipe
To use agnosticWipe, first import it and configure the debugging options globally. You can then wipe the content of elements without needing to reconfigure debugging for every call.
import { agnosticWipe } from 'agnostic-wipe'; // Configure AgnosticWipe with debug options globally window.agnosticWipe = agnosticWipe({ debugLog: true, debugWarn: true });
Once agnosticWipe is configured globally, you can call it directly to wipe the content of any element by providing the target selector:
// Wipe content of an element with the ID '#myElement' window.agnosticWipe('#myElement');
This will safely remove all the child nodes of the selected element.
If you don't need to configure debugging, you can use agnosticWipe without setting the options:
// Wipe content of an element without configuring debugging agnosticWipe()('#myElement');
The agnosticWipe function can be configured to show logs and warnings:
debugLog: Controls the appearance of informational messages (console.log). It can be set totrueorfalse.debugWarn: Controls the appearance of warning messages (console.warn). It can be set totrueorfalse.
By default, both flags are set to false.
Show only warnings in the console:
window.agnosticWipe = agnosticWipe({ debugLog: false, debugWarn: true });
Show both logs and warnings:
window.agnosticWipe = agnosticWipe({ debugLog: true, debugWarn: true });
Show nothing:
window.agnosticWipe = agnosticWipe;
-or-
window.agnosticWipe = agnosticWipe({ debugLog: false, debugWarn: false });
AgnosticHTML is licensed under the MIT License. See the LICENSE file for details.
If you encounter any issues, feel free to report them here.