state-toggle
Advanced tools
Comparing version 1.0.0 to 1.0.1
54
index.js
@@ -1,45 +0,23 @@ | ||
/** | ||
* @author Titus Wormer | ||
* @copyright 2016 Titus Wormer | ||
* @license MIT | ||
* @module state-toggle | ||
* @fileoverview Enter/exit a state. | ||
*/ | ||
'use strict' | ||
'use strict'; | ||
module.exports = factory | ||
/* eslint-env commonjs */ | ||
/* Expose. */ | ||
module.exports = factory; | ||
/** | ||
* Construct a state `toggler`: a function which inverses | ||
/* Construct a state `toggler`: a function which inverses | ||
* `property` in context based on its current value. | ||
* The by `toggler` returned function restores that value. | ||
* | ||
* @param {string} key - Property to toggle. | ||
* @param {boolean} state - Default state. | ||
* @param {Object?} [ctx] - Context object. | ||
* @return {Function} - Enter. | ||
*/ | ||
* The by `toggler` returned function restores that value. */ | ||
function factory(key, state, ctx) { | ||
/** | ||
* Enter a state. | ||
* | ||
* @return {Function} - Exit state. | ||
*/ | ||
return function () { | ||
var context = ctx || this; | ||
var current = context[key]; | ||
return enter | ||
context[key] = !state; | ||
function enter() { | ||
var context = ctx || this | ||
var current = context[key] | ||
/** | ||
* Cancel state to its value before entering. | ||
*/ | ||
return function () { | ||
context[key] = current; | ||
}; | ||
}; | ||
context[key] = !state | ||
return exit | ||
function exit() { | ||
context[key] = current | ||
} | ||
} | ||
} |
{ | ||
"name": "state-toggle", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Enter/exit a state", | ||
@@ -11,6 +11,3 @@ "license": "MIT", | ||
], | ||
"files": [ | ||
"index.js" | ||
], | ||
"repository": "https://github.com/wooorm/state-toggle", | ||
"repository": "wooorm/state-toggle", | ||
"bugs": "https://github.com/wooorm/state-toggle/issues", | ||
@@ -21,32 +18,49 @@ "author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
], | ||
"files": [ | ||
"index.js" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"browserify": "^13.0.1", | ||
"browserify": "^16.0.0", | ||
"esmangle": "^1.0.1", | ||
"nyc": "^7.0.0", | ||
"remark-cli": "^1.0.0", | ||
"remark-comment-config": "^4.0.0", | ||
"remark-github": "^5.0.0", | ||
"remark-lint": "^4.0.0", | ||
"remark-validate-links": "^4.0.0", | ||
"nyc": "^11.0.0", | ||
"prettier": "^1.12.1", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.16.0" | ||
"xo": "^0.20.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . --quiet --frail", | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"build-bundle": "browserify index.js --bare -s stateToggle > state-toggle.js", | ||
"build-mangle": "esmangle < state-toggle.js > state-toggle.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"prettier": true, | ||
"esnext": false, | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
}, | ||
"ignores": [ | ||
"state-toggle.js", | ||
"state-toggle.min.js" | ||
"state-toggle.js" | ||
] | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
] | ||
}, | ||
"nyc": { | ||
@@ -57,15 +71,3 @@ "check-coverage": true, | ||
"branches": 100 | ||
}, | ||
"remarkConfig": { | ||
"output": true, | ||
"plugins": [ | ||
"comment-config", | ||
"github", | ||
"lint", | ||
"validate-links" | ||
], | ||
"settings": { | ||
"bullet": "*" | ||
} | ||
} | ||
} |
# state-toggle [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
<!--lint disable heading-increment no-duplicate-headings--> | ||
Enter/exit a state. | ||
@@ -9,3 +7,3 @@ | ||
[npm][npm-install]: | ||
[npm][]: | ||
@@ -19,14 +17,15 @@ ```bash | ||
```javascript | ||
var toggle = require('state-toggle'); | ||
var ctx = {on: false}; | ||
var enter = toggle('on', ctx.on, ctx); | ||
var exit; | ||
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 | ||
exit = enter() | ||
console.log(ctx.on) // => true | ||
// Exiting: | ||
exit(); | ||
console.log(ctx.on); // false | ||
exit() | ||
console.log(ctx.on) // => false | ||
``` | ||
@@ -77,3 +76,3 @@ | ||
[npm-install]: https://docs.npmjs.com/cli/install | ||
[npm]: https://docs.npmjs.com/cli/install | ||
@@ -80,0 +79,0 @@ [license]: LICENSE |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
8
4730
4
17
83