1.0.9 • Published 3 years ago

utilizes.toggle v1.0.9

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

toggle

Toggle property truthines. if the value is falsy set it to true, otherwise set it to false.

The third parameter is the values to toggle between. default to "true, false".

Return the toggled value.

Usage: toggle<I>(object, path: keyof object, values?: Array<I>): I | boolean

import { toggle } from 'utilizes.toggle'

const object = {
  foo: {
    bar: false
  },
  num: 0
}

toggle(object, `foo.bar`)
// Output: true
toggle(object, `num`, [1, 0]) // or "toggle(object, `num`, 1, 0)"
// Output: 1

This module exported from utilizes project.