1.0.4 โ€ข Published 7 months ago

find_all_data v1.0.4

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

๐Ÿ“ฆ Data Manipulation Module

Documentation en francais

The ๐Ÿ“ฆ data manipulation module is a library that simplifies the manipulation and analysis of data arrays. Whether your data is raw or you need to perform complex operations like sorting, searching ๐Ÿ•ต๏ธโ€โ™‚๏ธ, or calculations ๐Ÿ“Š, this module can make your task easier.

Why Use This Module? ๐Ÿคทโ€โ™‚๏ธ

Data Structuring ๐Ÿ—๏ธ

One of the essential aspects of data manipulation is having well-structured data. This module allows you to take an existing data array and add a unique 'id' property to each object. It also ensures that all objects in the array have the same keys, ensuring a consistent structure.

Data Exploration ๐Ÿ”

You can easily explore your data by extracting essential information. The module provides methods for searching for specific objects by their 'id' or filtering data based on specific criteria. This allows you to quickly answer questions like "What items match a particular criterion?"

Data Aggregation ๐Ÿ“Š

If you need to aggregate or summarize data, this module allows you to calculate statistics such as sum, maximum, and minimum values for any numeric key. This enables you to obtain valuable insights from your data quickly.

Data Pagination ๐Ÿ“„

To handle large amounts of data, the module offers a pagination function. You can specify the page number and the number of items per page, and the module will return the corresponding data range. This makes it easy to create paginated views in your application.

Text Search ๐Ÿ”Ž

Another powerful feature of this module is text search. You can perform case-insensitive searches without considering accents. This allows you to search for objects containing specific terms within a given key, thereby improving the user-friendliness of your application.

How to Use This Module? ๐Ÿ› ๏ธ

Table of Contents ๐Ÿ“œ

  1. Installation
  2. Creating the Module Instance
  3. Data Structure
  4. Data Exploration
  5. Data Aggregation
  6. Data Pagination
  7. Text Search
  8. Functions

1. Installation ๐Ÿš€

To use the data manipulation module, you need to install it in your Node.js project using npm. Run the following command in your project directory:

npm i find_all_data

2. Creating the Module Instance ๐Ÿญ

After installing the module, you can import it into your JavaScript code as follows:

const findData = require("find_all_data");

Then, create an instance of the module by passing your data array (data) as an argument:

const user = findData(data);

3. Data Structure ๐Ÿงฑ

The module ensures a consistent data structure by adding a unique 'id' property to each object in the array. It also verifies that all objects have the same keys. Here's how it works:

const data = require("./user.json");
const findData = require("findData");

const user = findData(data);

console.log(user.all());

In the above example, user.all() will return your data array with the 'id' added.

4. Data Exploration ๐Ÿ”

Searching by 'id' ๐Ÿ”Ž

You can search for an object by its 'id' using the findById method. For example:

const myUser = user.findById(1);
console.log(myUser);

Data Filtering ๐Ÿงน

The findAll method allows you to search for objects in a data set using various filtering and sorting options. This method is particularly useful for extracting specific data from a collection.

Signature ๐Ÿ–‹๏ธ

findAll(params);

Parameters ๐ŸŽ›๏ธ

  • params (object): An object containing search and filtering options.

params Options ๐Ÿ“ฆ

  • params.where (array of functions): An array of functions to filter objects based on return values.
  • params.order (array of two strings): An array containing the name of the sorting key and the sorting order ("ASC" for ascending or "DESC" for descending).
  • params.limit (array of two numbers): An array containing the limit of items to return, with an offset value first and a limit value second.

Return ๐Ÿš€

  • An array of objects that match the specified search criteria.

Usage Examples ๐Ÿ› ๏ธ

  1. Filtering by a Single Key ๐ŸŽฏ
const newData = user.findAll({
  where: [
    user => user.age <= 10
  ]
});
console.log(newData);
  1. Sorting in Ascending Order ๐Ÿ”„
const newData = user.findAll({
  order: ['age', 'ASC']
});
console.log(newData);
  1. Sorting in Descending Order ๐Ÿ”„
const newData = user.findAll({
  order: ['age', 'DESC']
});
console.log(newData);
  1. Limiting Results with an Offset ๐Ÿ“ƒ
const newData = user.findAll({
  limit: [5, 10], // Return 10 results starting from the 6th result
});
console.log(newData);
  1. Combining Multiple Options ๐ŸŒŸ
const newData = user.findAll({
  where: [
    user => user.age <= 10,
    user => user.isAdmin === true,
  ],
  order: ['age', 'DESC'],
  limit: [5, 10],
});
console.log(newData);

5. Data Aggregation ๐Ÿ“Š

You can perform several aggregation operations on your data, such as calculating the sum, finding the maximum and minimum values for a numeric key. Here are some examples:

Sum of Values ๐Ÿ“ˆ

const sum = user.sum("age");
console.log(sum);

Maximum Value ๐Ÿš€

const maxValue = user.max("age");
console.log(maxValue);

Minimum Value ๐Ÿ“‰

const minValue = user.min("age");
console.log(minValue);

6. Data Pagination ๐Ÿ“„

Pagination allows you to manage large amounts of data by retrieving only a portion of the results at a time. Here's how to paginate your data:

const [offset, limit] = user.page(2, 10); // Page 2, 10 items per page
const newData = user.findAll(
  {
    limit: user.page(2, 10)
  });

console.log(newData);

7. Text Search ๐Ÿ”

You can perform case-insensitive and accent-insensitive text searches on a specific key. For example, to search for objects containing the term "apple" in the 'description' key:

const newData = user.findAll(
  {
    where: [
      user.search('description', 'apple')
    ]
  });

console.log(newData);

8. Functions ๐Ÿ› ๏ธ

It provides several useful functions for working with data sets. Here's a description of the key functions of the module.

keys Function ๐Ÿ—๏ธ

The keys function returns an array of keys (property names) of the objects in the data array. This allows you to understand the structure of objects and the properties you can access.

const keys = user.keys();
console.log(keys); // Displays an array of keys

distinct Function ๐ŸŒŸ

The distinct function takes a key as input and returns an array of unique values for that key in the data array. It's useful for obtaining unique values from a specific column.

const uniqueValues = user.distinct('age');
console.log(uniqueValues); // Displays an array of unique values

type Function ๐Ÿ“

The type function takes a key as input and returns the data type (string, number, boolean, etc.) of the associated property in the objects of the data array.

const propertyType = user.type('age');
console.log(propertyType); // Displays the data type

reset Function ๐Ÿ”„

The reset function resets the temporary data array to the original data. This cancels all previous filtering, sorting, or pagination operations applied.

user.reset(); // Resets the temporary data

These functions allow you to better understand the structure of your data, extract unique values, and determine the data types associated with your objects' properties. You can also reset temporarily modified data at any time using the reset function.

This documentation covers the main features of the data manipulation module. You can now use these tools to explore, filter, aggregate, and paginate your data with ease in your JavaScript projects. Feel free to experiment further with these functions to master them better. ๐Ÿš€

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago