@sharyn/util.toggle
v1.0.6
Published
<!-- This file is auto-generated, don't modify it. Modify the JSDoc instead. -->
Downloads
11
Readme
🌹 toggle
toggle
: Toggles between two values, and defaults to the first one.
Installation
npm i @sharyn/util.toggle
# or
yarn add @sharyn/util.toggle
You can alternatively install the @sharyn/util package, or the entire sharyn library.
Arguments
currentValue (any): The current value.
firstValue (any): The first value.
secondValue (any): The second value.
Returns
any: The other option.
Example
toggle(current, 'a', 'b') // if current === 'a', returns 'b'
toggle(current, 'a', 'b') // if current === 'b', returns 'a'
toggle(current, 'a', 'b') // if current === 'x', returns 'a'
Deep equality is supported:
cycle({ a: 1 }, { a: 1 }, { a: 2 }) // { a: 2 }
Imports
Depending on the package you are using, you can import
or require
toggle
in the following ways:
// If you installed @sharyn/util.toggle
import toggle from '@sharyn/util.toggle' // smaller size, better for client bundles
// If you installed @sharyn/util
import toggle from '@sharyn/util/toggle' // smaller size, better for client bundles
import { toggle } from '@sharyn/util' // more convenient in Node environments
// If you installed sharyn
import toggle from 'sharyn/util/toggle' // smaller size, better for client bundles
import { toggle } from 'sharyn/util' // more convenient in Node environments