state-toggle
Advanced tools
Comparing version 1.0.3 to 2.0.0
26
index.js
@@ -1,11 +0,18 @@ | ||
'use strict' | ||
module.exports = factory | ||
// Construct a state `toggler`: a function which inverses `property` in context | ||
// based on its current value. | ||
// The by `toggler` returned function restores that value. | ||
function factory(key, state, 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. | ||
* | ||
* @param {string} key | ||
* @param {boolean} state | ||
* @param {*} ctx | ||
* @returns {() => Function} | ||
*/ | ||
export function stateToggle(key, state, ctx) { | ||
return enter | ||
/** | ||
* Bound enter function to set `state` as `key` on `ctx`. | ||
* @returns {() => void} | ||
*/ | ||
function enter() { | ||
@@ -19,2 +26,5 @@ var context = ctx || this | ||
/** | ||
* Configured exit function to revert setting `state` as `key` on `ctx`. | ||
*/ | ||
function exit() { | ||
@@ -21,0 +31,0 @@ context[key] = current |
{ | ||
"name": "state-toggle", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"description": "Enter/exit a state", | ||
@@ -21,23 +21,27 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"browserify": "^16.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.0.0", | ||
"xo": "^0.25.0" | ||
"c8": "^7.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.38.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s stateToggle -o state-toggle.js", | ||
"build-mangle": "browserify . -s stateToggle -p tinyify -o state-toggle.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"prepublishOnly": "npm run build", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"prebuild": "rimraf \"*.d.ts\"", | ||
"build": "tsc", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
@@ -64,9 +68,3 @@ }, | ||
] | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
} | ||
} |
@@ -21,6 +21,6 @@ # state-toggle | ||
```js | ||
var toggle = require('state-toggle') | ||
import {stateToggle} from 'state-toggle' | ||
var ctx = {on: false} | ||
var enter = toggle('on', ctx.on, ctx) | ||
var enter = stateToggle('on', ctx.on, ctx) | ||
var exit | ||
@@ -39,2 +39,5 @@ | ||
`state-toggle` exports the following identifier: `stateToggle`. | ||
There is no default export. | ||
### `toggle(key, initial[, ctx])` | ||
@@ -73,5 +76,5 @@ | ||
[build-badge]: https://img.shields.io/travis/wooorm/state-toggle.svg | ||
[build-badge]: https://github.com/wooorm/state-toggle/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/wooorm/state-toggle | ||
[build]: https://github.com/wooorm/state-toggle/actions | ||
@@ -78,0 +81,0 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/state-toggle.svg |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5788
5
40
99
Yes