New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

array-driver

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-driver

'useful custom array methods'

latest
Source
npmnpm
Version
2.1.0
Version published
Maintainers
1
Created
Source

array-driver

A simple utility package for manipulating arrays. This package contains some useful methods that can save a lot of time during development.

Installation

You can install array-driver using NPM:

npm install array-driver

Usage

First configure the package

const arrayDriver = require('array-driver');
arrayDriver.config();

Then start using the functions

Examples


// Example usage
const students = [
  { id: 1, name: 'Alice', grade: 'A' },
  { id: 2, name: 'Bob', grade: 'B' },
  { id: 3, name: 'Charlie', grade: 'C' },
  { id: 4, name: 'David', grade: 'B' },
  { id: 5, name: 'Eve', grade: 'A' },
];

// Define the search criteria callback function
const searchCriteria = (value) => value.grade === 'B';

// Define the update criteria callback function
const updateCriteria = (element) => {
  element.grade = 'A+';
};

// Call the updateMany function
const updatedStudents = students.updateMany(searchCriteria, updateCriteria);
console.log(updatedStudents);
/*
Output:
[
  { id: 2, name: 'Bob', grade: 'A+' },
  { id: 4, name: 'David', grade: 'A+' }
]
*/

const data = [
  { name: "Alice", city: "New York", age: 25 },
  { name: "Bob", city: "New York", age: 30 },
  { name: "Charlie", city: "San Francisco", age: 25 },
  { name: "Dave", city: "San Francisco", age: 30 },
];
const example1 = data.groupBy('city');
// Output:
// {
//   "New York": [
//       { name: "Alice", city: "New York", age: 25 },
//       { name: "Bob", city: "New York", age: 30 }
//   ],
//   "San Francisco": [
//       { name: "Charlie", city: "San Francisco", age: 25 },
//       { name: "Dave", city: "San Francisco", age: 30 }
//   ]
// }


const arr = [
  { name: "Charlie", age: 35 },
  { name: "David", age: 40 },
  { name: "Eve", age: 45 }
];

arr.deleteAllWhere(obj => obj.name == 'Charlie');
console.log(arr);
//  [
//   { name: "David", age: 40 },
//   { name: "Eve", age: 45 }
// ];

types of methods

  • aggregationMethods
  • deleteMethods
  • filterMethods
  • selectionMethods
  • updateMethods
  • validateMethods

see all the methods available here

Contributions

  • If you wish to contribute on this package, kindly fork and make a pull request.
  • Ideas for more utility functions are welcome.

License

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

Keywords

array

FAQs

Package last updated on 17 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts