0.0.21 • Published 6 years ago

util.toggle v0.0.21

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

util.toggle

Functions used to toggle strings on/off within a Set

build analysis code style: prettier testing NPM

Installation

This module uses yarn to manage dependencies and run scripts for development.

To install as an application dependency:

$ yarn add --dev util.toggle

To build the app and run all tests:

$ yarn run all

Overview

A set of functions used to toggle strings on/off within a Set of strings. The use case for this is managing the set of class descriptors programatically on a React component.

Usage

Toggle string on/off

import {toggle} from 'util.toggle';

const x: Set<string> = new Set<string>();

x.add('abc');
x.add('def');

// x => {'abc', 'def'}

toggle(x)(
	'abc'
);

// x => {'def'}

toggle(x)(
	'abc'
);

// x => {'abc', 'def'}

toggle(x)(
	'abc',
	'def'
);

// x => {}

Toggle string based on predicate

import {toggleIf} from 'util.toggle';

const x: Set<string> = new Set<string>();

x.add('abc');
x.add('def');

// x => {'abc', 'def'}

toggleIf(x, false)(
	'abc'
);

// x => {'abc', 'def'}

toggle(x, true)(
	'abc'
);

// x => {'def'}

Toggle string on based on if/else predicate

import {toggleOnIfElse} from 'util.toggle';

const x: Set<string> = new Set<string>();

x.add('abc');

// x => {'abc'}

toggleOnIfElse(x, false)(
	'abc'
)(
	'def'
);

// x => {'abc', 'def'}

x.delete('abc');

// x => {'def'}

toggleOnIfElse(x, true)(
	'abc'
)(
	'ghi'
);

// x => {'abc', 'def'}

API

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago