entity-checker

1.0.3 • Public • Published

entity-checker

npm version License: MIT

A lightweight utility for handling 'not found' scenarios in JavaScript applications. This library provides helper method to determine if a given entity is null, undefined, an empty array, or an empty object, simplifying the process of checking for missing or empty data. Enhance your code readability and maintainability by encapsulating the logic for common 'not found' checks.

Installation

You can install the library via npm:

npm install entity-checker

Usage

const notFoundUtil = require('entity-checker');

// Example usage
class Library {
  constructor() {
    this.data = [];
  }

  fetchData() {
    // Fetch data logic
    return this.data;
  }

  processData() {
    const data = this.fetchData();

    if (notFoundUtil.isNotFound(data)) {
      console.log('Data not found or empty.');
    } else {
      console.log('Data found:', data);
    }
  }
}

API

isNotFound(entity)

Check if the provided entity is null, undefined, an empty array, or an empty object.

  • Parameters:

    • entity (any): The entity to check.
  • Returns:

    • true if the entity is null, undefined, an empty array, or an empty object.
    • false otherwise.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

License

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

Package Sidebar

Install

npm i entity-checker

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

6.65 kB

Total Files

5

Last publish

Collaborators

  • muhammadhassanahmed4269