state-toggle
Advanced tools
+16
-38
@@ -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 | ||
| } | ||
| } | ||
| } |
+34
-32
| { | ||
| "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": "*" | ||
| } | ||
| } | ||
| } |
+11
-12
| # 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 |
| <!--remark setext--> | ||
| <!--lint disable no-multiple-toplevel-headings --> | ||
| 1.0.0 / 2016-07-16 | ||
| ================== |
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
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
-20%4730
-12.02%4
-20%17
-56.41%83
-1.19%