1.1.2 • Published 4 months ago

array-device v1.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

Handle your array objects with ease

Install it

pnpm install array-device

Specific usage:

Array object deduplication

import { reduce } from 'array-device';
const arr = [
  {
    id: 1,
    name: 'noah',
    age: 18
  },
  {
    id: 1,
    name: 'mark',
    age: 18
  }
];
console.log(reduce(arr, 'id'));
//[{id: 1, name: 'noah', age: 18]

Add the selected field to the matching array, suitable for all selections and half selections

import { all } from 'array-device';
let a = [
  { id: 1, a: 123, b: 1234 },
  { id: 2, a: 123, b: 1234 }
];
let c = [1, 4];
console.log(all(a, c, 'id', 'boo'));
//[{id: 1, a: 123, b: 1234, boo: true},{id: 2, a: 123, b: 1234, boo: false}]

Filter out the array of objects that meet the criteria

import { part } from 'array-device';
let b = [
  { id: 1, a: 123, b: 1234 },
  { id: 2, a: 123, b: 1234 },
  { id: 3, a: 123, b: 1234 },
  { id: 4, a: 123, b: 1234 }
];
let c = [1, 4];
console.log(part(b, c, 'id'));
//[{id: 1, a: 123, b: 1234},{id: 4, a: 123, b: 1234}]

Filter out an array of objects that do not meet the criteria

import { other } from 'array-device';
let b = [
  { id: 1, a: 123, b: 1234 },
  { id: 2, a: 123, b: 1234 },
  { id: 3, a: 123, b: 1234 },
  { id: 4, a: 123, b: 1234 }
];
let c = [1, 4];
console.log(other(b, c, 'id'));
//[{id: 2, a: 123, b: 1234},{id: 3, a: 123, b: 1234}]

Find the intersection of two arrays of objects

import { intersection } from 'array-device';
let a = [
  { id: 1, a: 123, b: 1234 },
  { id: 2, a: 123, b: 1234 }
];
let b = [
  { id: 1, a: 123, b: 1234 },
  { id: 2, a: 123, b: 1234 },
  { id: 3, a: 123, b: 1234 },
  { id: 4, a: 123, b: 1234 }
];
console.log(intersection(a, b, 'id'));
//[{"id":1,"a":123,"b":1234},{"id":2,"a":123,"b":1234}]

Find the difference of two arrays of objects

import { difference } from 'array-device';
let a = [
  { id: 1, a: 123, b: 1234 },
  { id: 2, a: 123, b: 1234 }
];
let b = [
  { id: 1, a: 123, b: 1234 },
  { id: 2, a: 123, b: 1234 },
  { id: 3, a: 123, b: 1234 },
  { id: 4, a: 123, b: 1234 }
];
console.log(difference(b, a, 'id'));
//[{"id":3,"a":123,"b":1234},{"id":4,"a":123,"b":1234}]
1.1.1

4 months ago

1.1.0

4 months ago

1.0.9

4 months ago

1.1.2

4 months ago

1.0.8

4 months ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago