rower
v1.0.5
Published
Simple API for array of objects
Downloads
4
Readme
Rower is a simple interface for your array of objects which always return a new array.
What you can do with rower?
import rower from 'rower'
let ducks = rower([
{ id: 0, name: 'Igor' },
{ id: 1, name: 'Anastasia' },
{ id: 2, name: 'Gloria' },
])
Find
ducks
.where(duck => duck.name == 'Anastasia')
.where(duck => duck.name == 'Gloria')
.find()
// [
// { id: 1, name: 'Anastasia' },
// { id: 2, name: 'Gloria' },
// ]
Update
ducks
.where(duck => duck.name == 'Igor')
.update({ name: 'Cinderella' })
// [
// { id: 0, name: 'Cinderella' },
// { id: 1, name: 'Anastasia' },
// { id: 2, name: 'Gloria' },
// ]
Delete
ducks
.where(duck => duck.id > 0)
.where(duck => duck.id < 2)
.delete()
// [
// { id: 0, name: 'Cinderella' },
// { id: 2, name: 'Gloria' },
// ]
Create
ducks
.where(duck => duck.id > 0)
.create((duck) => {
return `Hello! I'm ${duck.name}`
})
// [
// "Hello! I'm Anastasia",
// "Hello! I'm Gloria",
// ]
Sort
ducks
.sort((a, b) => { return b.id - a.id })
// [
// { id: 2, name: 'Gloria' },
// { id: 1, name: 'Anastasia' },
// { id: 0, name: 'Igor' },
// ]
Toggle
ducks
.toggle({ id: [0, 1], name: ['Igor', 'Anastasia'] })
// [
// { id: 1, name: 'Anastasia' },
// { id: 0, name: 'Igor' },
// { id: 2, name: 'Gloria' },
// ]
Pluck
ducks
.where(duck => duck.id > 0)
.pluck('id')
// [ 1, 2 ]