Socket
Book a DemoInstallSign in
Socket

slot-finder

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slot-finder

Script for putting things in slots.

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

Build Status

slot-finder

Script for putting things in slots

The slot-finding algorithm will try to place as many things into slots as it can without clashing (priority dictated by the order of the things array), and will try to put the things into their preferred slots (as dictated by the order of the slots array).

Any unfilled slots will retain the value you pass in.

API

type SlotNameType = string;
type ThingNameType = string;

type SlotsType = { [slot: SlotNameType]: any };

type ThingType = {
  name: ThingNameType,
  slots: Array<SlotNameType>,
};

type ThingsType = Array<ThingType>;

export default (slots: SlotsType, things: ThingsType) => { [slot: SlotNameType]: ThingNameType };

Example

import slotFinder from 'slot-finder';

const slots = { left: null, right: null, center: null };

const things = [
  { name: 'first', slots: ['right'] },
  { name: 'second', slots: ['left', 'right'] },
];

const thingsInSlots = slotFinder(slots, things);

console.log(thingsInSlots);
// -> { left: 'second', right: 'first', center: null }

FAQs

Package last updated on 07 Feb 2018

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