A simple utility library for filtering and aggregating JSON data arrays in JavaScript. This package provides easy-to-use functions to help developers manage and analyze data efficiently in their applications.
- Filter Data: Filter an array of objects based on matching properties.
- Aggregate Data: Sum up numerical properties of objects in an array, grouped by a specified key.
Install json-data-toolkit
via npm:
npm install json-data-toolkit
Importing the module:
const { filterData, aggregateData } = require('json-data-toolkit');
To filter data based on properties, you can use the filterData function:
const data = [
{ name: "Alice", age: 25, occupation: "Engineer" },
{ name: "Bob", age: 30, occupation: "Designer" },
{ name: "Alice", age: 28, occupation: "Designer" }
];
const filtered = filterData(data, { name: "Alice" });
console.log(filtered);
// Output: [{ name: "Alice", age: 25, occupation: "Engineer" }, { name: "Alice", age: 28, occupation: "Designer" }]
To aggregate data by a property and sum another property, use the aggregateData function:
const employees = [
{ department: "Sales", salary: 1000 },
{ department: "Engineering", salary: 2000 },
{ department: "Sales", salary: 1500 }
];
const aggregated = aggregateData(employees, "department", "salary");
console.log(aggregated);
// Output: [{ key: "Sales", sum: 2500 }, { key: "Engineering", sum: 2000 }]
Contributions are always welcome! Please fork the repository and submit a pull request with your new features or fixes.
This project is licensed under the MIT License - see the LICENSE file for details.