benderTheCrime / collections

Helpful collections shamelessly copied from Python and ported to JS: https://docs.python.org/2/library/collections.html#module-collections

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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)

About

Helpful collections shamelessly copied from Python and ported to JS: https://docs.python.org/2/library/collections.html#module-collections


Languages

Language:JavaScript 100.0%