list-tweaker

1.0.0 • Public • Published

list-tweaker

Build Status

Easily modify items in an array

remove

import { remove } from 'list-tweaker'
const list = [
  { id: 'a' },
  { id: 'b' },
  { id: 'c' },
]

remove(list, { id: 'b' })

// [
//   { id: 'a' },
//   { id: 'c' },
// ]

replace

import { replace } from 'list-tweaker'

const list = [
  { id: 'a' },
  { id: 'b' },
  { id: 'c' },
]

replace(list, { id: 'b', suprise: 'clown!' })

// [
//   { id: 'a' },
//   { id: 'b', suprise: 'clown!' },
//   { id: 'c' },
// ]

update

import { update } from 'list-tweaker'

const list = [{
  id: 'a',
  oldField: 'Kevin Bacon',
  color: 'green',
}]

update(list, {
  id: 'a',
  newField: 'Kevin Costner',
  color: 'chartreuse',
})

// [{
//   id: 'a',
//   oldField: 'Kevin Bacon',
//   color: 'chartreuse',
//   newField: 'Kevin Costner',
// }]

kickstarted by npm-boom

Package Sidebar

Install

npm i list-tweaker

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • reergymerej