1.0.1 • Published 10 months ago

remove-empty-divs v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

remove-empty-divs

A simple utility function to remove empty div elements from the current HTML page. This package is designed for use in web applications where cleaning up empty div elements is needed.

Installation

You can install the package via npm if it's published:

npm install remove-empty-divs

Or, if you're using it locally for development or testing, you can link it:

  1. Navigate to the package directory and run:

    npm link
  2. In your React application directory, run:

    npm link remove-empty-divs

Usage

In a TypeScript React Project

  1. Import the Function

    Import the removeEmptyDivs function into your React component:

    import removeEmptyDivs from "remove-empty-divs";
  2. Use the Function

    Call the function within a useEffect hook to ensure it runs after the component mounts:

    import React, { useEffect } from "react";
    import removeEmptyDivs from "remove-empty-divs";
    
    const App: React.FC = () => {
      useEffect(() => {
        // Call the function to remove empty divs
        removeEmptyDivs();
      }, []);
    
      return (
        <div className="App">
          <div>
            <p>Non-empty div</p>
          </div>
          <div></div>
          <div>
            <span>Another non-empty div</span>
          </div>
          <div></div>
        </div>
      );
    };
    
    export default App;

In a Plain JavaScript Project

  1. Import the Function

    import removeEmptyDivs from "remove-empty-divs";
  2. Use the Function

    Call the function in your JavaScript code:

    document.addEventListener("DOMContentLoaded", () => {
      removeEmptyDivs();
    });

API

removeEmptyDivs()

This function iterates over all div elements in the current HTML page and removes those that do not contain any child nodes.

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes.
  4. Open a pull request with a description of your changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

  • React - For building modern user interfaces.
  • TypeScript - For adding static type checking to JavaScript.

Feel free to modify and extend this README to better fit your project's needs.

Explanation

  • Installation: Instructions for both published and local installations.
  • Usage: How to use the package in a TypeScript React project and a plain JavaScript project.
  • API: Description of the removeEmptyDivs function.
  • Contributing: Guidelines for contributing to the project.
  • License: Licensing information.
1.0.1

10 months ago

1.0.0

12 months ago