Files
node/tools/node_modules/eslint/node_modules/state-toggle
Ruben Bridgewater 8845a77f74 tools: update eslint
PR-URL: https://github.com/nodejs/node/pull/27670
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Refael Ackermann (רפאל פלחי) <refack@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
2019-06-11 15:59:17 +02:00
..
2019-06-11 15:59:17 +02:00
2019-06-11 15:59:17 +02:00
2019-06-11 15:59:17 +02:00
2019-06-11 15:59:17 +02:00

state-toggle

Build Coverage Downloads Size

Enter/exit a state.

Installation

npm:

npm install state-toggle

Usage

var toggle = require('state-toggle')

var ctx = {on: false}
var enter = toggle('on', ctx.on, ctx)
var exit

// Entering:
exit = enter()
console.log(ctx.on) // => true

// Exiting:
exit()
console.log(ctx.on) // => false

API

toggle(key, initial[, ctx])

Create a toggle, which when entering toggles key on ctx (or this, if ctx is not given) to !initial, and when exiting, sets key on the context back to the value it had before entering.

Returns

Function — enter.

enter()

Enter the state.

Context

If no ctx was given to toggle, the context object (this) of enter() is used to toggle.

Returns

Function — exit.

exit()

Exit the state, reverting key to the value it had before entering.

License

MIT © Titus Wormer