1.0.0 • Published 4 years ago

@benderthecrime/collections v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
4 years ago

Collections

Helpful collections shamelessly copied from Python and ported to JS.

Installation

npm i @benderthecrime/collections

Usage

DefaultObject

const collections = require('@benderthecrime/collections')
const {DefaultObject} = collections

const collector = DefaultObject(Number)
const values = ['a', 'b', 'c', 'd', 'a']

for (const value in values) {
    // No need to check to see if the value already exists in the collection.
    collector[value] += 1
}

// Works with scalar values too!
const defaulter = DefaultObject(null)

// And custom classes!
const defaulter = DefaultObject(Test, 'some argument', 'another argument')

// You can even make a DefaultObject inside a DefaultObject!
const collectoe = DefaultObject(DefaultObject, String)