1.0.6 • Published 5 years ago

@sharyn/util.toggle v1.0.6

Weekly downloads
10
License
MIT
Repository
github
Last release
5 years ago

🌹 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
1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago