.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / state-toggle / readme.md
1 # state-toggle
2
3 [![Build][build-badge]][build]
4 [![Coverage][coverage-badge]][coverage]
5 [![Downloads][downloads-badge]][downloads]
6 [![Size][size-badge]][size]
7
8 Enter/exit a state.
9
10 ## Install
11
12 [npm][]:
13
14 ```sh
15 npm install state-toggle
16 ```
17
18 ## Use
19
20 ```js
21 var toggle = require('state-toggle')
22
23 var ctx = {on: false}
24 var enter = toggle('on', ctx.on, ctx)
25 var exit
26
27 // Entering:
28 exit = enter()
29 console.log(ctx.on) // => true
30
31 // Exiting:
32 exit()
33 console.log(ctx.on) // => false
34 ```
35
36 ## API
37
38 ### `toggle(key, initial[, ctx])`
39
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.
43
44 ###### Returns
45
46 `Function` — [`enter`][enter].
47
48 ### `enter()`
49
50 Enter the state.
51
52 ###### Context
53
54 If no `ctx` was given to `toggle`, the context object (`this`) of `enter()` is
55 used to toggle.
56
57 ###### Returns
58
59 `Function` — [`exit`][exit].
60
61 ### `exit()`
62
63 Exit the state, reverting `key` to the value it had before entering.
64
65 ## License
66
67 [MIT][license] © [Titus Wormer][author]
68
69 <!-- Definitions -->
70
71 [build-badge]: https://img.shields.io/travis/wooorm/state-toggle.svg
72
73 [build]: https://travis-ci.org/wooorm/state-toggle
74
75 [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/state-toggle.svg
76
77 [coverage]: https://codecov.io/github/wooorm/state-toggle
78
79 [downloads-badge]: https://img.shields.io/npm/dm/state-toggle.svg
80
81 [downloads]: https://www.npmjs.com/package/state-toggle
82
83 [size-badge]: https://img.shields.io/bundlephobia/minzip/state-toggle.svg
84
85 [size]: https://bundlephobia.com/result?p=state-toggle
86
87 [npm]: https://docs.npmjs.com/cli/install
88
89 [license]: license
90
91 [author]: https://wooorm.com
92
93 [enter]: #enter
94
95 [exit]: #exit