README
util.toggle
Functions used to toggle strings on/off within a Set
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'}