3 [![Build][build-badge]][build]
4 [![Coverage][coverage-badge]][coverage]
5 [![Downloads][downloads-badge]][downloads]
6 [![Size][size-badge]][size]
15 npm install state-toggle
21 var toggle = require('state-toggle')
24 var enter = toggle('on', ctx.on, ctx)
29 console.log(ctx.on) // => true
33 console.log(ctx.on) // => false
38 ### `toggle(key, initial[, ctx])`
40 Create a toggle, which when entering toggles `key` on `ctx` (or `this`, if `ctx`
41 is not given) to `!initial`, and when exiting, sets `key` on the context back to
42 the value it had before entering.
46 `Function` — [`enter`][enter].
54 If no `ctx` was given to `toggle`, the context object (`this`) of `enter()` is
59 `Function` — [`exit`][exit].
63 Exit the state, reverting `key` to the value it had before entering.
67 [MIT][license] © [Titus Wormer][author]
71 [build-badge]: https://img.shields.io/travis/wooorm/state-toggle.svg
73 [build]: https://travis-ci.org/wooorm/state-toggle
75 [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/state-toggle.svg
77 [coverage]: https://codecov.io/github/wooorm/state-toggle
79 [downloads-badge]: https://img.shields.io/npm/dm/state-toggle.svg
81 [downloads]: https://www.npmjs.com/package/state-toggle
83 [size-badge]: https://img.shields.io/bundlephobia/minzip/state-toggle.svg
85 [size]: https://bundlephobia.com/result?p=state-toggle
87 [npm]: https://docs.npmjs.com/cli/install
91 [author]: https://wooorm.com