Skip to content

reergymerej/list-tweaker

Repository files navigation

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

Releases

No releases published

Packages

No packages published