New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

repartitor

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

repartitor

A package to make repartition easier on an array of objects

latest
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

repartitor

An algorithm to make an equal repartition of an array of objects depending on one of the fields

See example 3 for the auto-filling repartion use case you are probably looking for

Installation

npm install repartitor --save

Example uses

  • Select a # of objects

Given an array of objects with a field color and an id, I want to get an array with an equal repartition of occurences of a given field.

const Repartitor = require('repartitor');

const myObjects = [
    {
        id: 1,
        color: 'blue'
    }, {
        id: 2,
        color: 'blue'
    }, {
        id: 3,
        color: 'blue'
    }, {
        id: 4,
        color: 'yellow'
    }, {
        id: 5,
        color: 'yellow'
    }, {
        id: 6,
        color: 'red'
    },
];

Get one of each, exclude no color value.

const results = new Repartitor({ targetArray: myObjects, field: 'color', useAllPropertiesValues: true, stackSize: 1 }).run();
/*
[
    {
        id: 1,
        color: 'blue'
    } {
        id: 4,
        color: 'yellow'
    }, {
        id: 6,
        color: 'red'
    },
]
*/
  • Exclusion of values

Get one of each but exlude the yellow.

const results = new Repartitor({ targetArray: myObjects }).run('color', ['red', 'blue'], 1);
/*
[
    {
        id: 6,
        color: 'red'
    }, {
        id: 1,
        color: 'blue'
    }
]
*/
  • Auto-fill with other values as equally as possible

Get two of each and exclude yellow colors(here the red is filled with a blue instead);

const results = new Repartitor({ targetArray: myObjects }).run('color', ['red', 'blue'], 2);

Keywords

repartition

FAQs

Package last updated on 06 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts