1.0.1 • Published 6 years ago

quick-array v1.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

QuickArray

Array extension with custom indexing and quick lookup by element property values.

Installation

$ npm install --save quick-array

Usage

/* first, import */
import QuickArray from 'quick-array'
/* or */
var QuickArray = require('quick-array')

let fruits = [
  { name: "mango", color: "yellow" },
  { name: "durian", color: "yellow-green" },
  { name: "salak", color: "brown" }
]

/* pass original array and indexing key */
let quickFruits = new QuickArray(fruits, 'name')

quickFruits.quickFind("durian")
//=> { name: "durian", color: "yellow-green" }

/* pass original array and indexing function */
quickFruits = new QuickArray(fruits, (element) => element.name.toUpperCase())

quickFruits.quickFind("DURIAN")
//=> { name: "durian", color: "yellow-green" }

/* find original index */
quickFruits.quickFindIndex("DURIAN")
//=> 1

Caveat

IE doesn't support automatic reindexing on array changes.

Why durian?

Because it smells like my code.

1.0.1

6 years ago

1.0.0

6 years ago