├── .editorconfig ├── .gitattributes ├── .gitignore ├── .jshintrc ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | end_of_line = lf 7 | charset = utf-8 8 | indent_size = 2 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | insert_final_newline = false 15 | 16 | [{,test/}{actual,fixtures}/**] 17 | trim_trailing_whitespace = false 18 | insert_final_newline = false 19 | 20 | [templates/**] 21 | trim_trailing_whitespace = false 22 | insert_final_newline = false 23 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.sublime-* 3 | _gh_pages 4 | bower_components 5 | node_modules 6 | npm-debug.log 7 | actual 8 | test/actual 9 | temp 10 | tmp 11 | TODO.md 12 | vendor 13 | .idea 14 | benchmark 15 | coverage 16 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "asi": false, 3 | "boss": true, 4 | "curly": false, 5 | "eqeqeq": true, 6 | "eqnull": true, 7 | "esnext": true, 8 | "immed": true, 9 | "latedef": false, 10 | "laxbreak": true, 11 | "laxcomma": false, 12 | "mocha": true, 13 | "newcap": true, 14 | "noarg": true, 15 | "node": true, 16 | "sub": true, 17 | "undef": true, 18 | "unused": true 19 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "stable" 4 | - "0.12" 5 | - "0.10" 6 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | # {%= name %} {%= badge("fury") %} 2 | 3 | > {%= description %} 4 | 5 | ## Install 6 | {%= include("install-npm", {save: true}) %} 7 | 8 | ## Usage 9 | 10 | Returns true if a property is strictly `true` or its inverse is strictly `false`. The inverse of `a` is `noa`, the inverse of `b` is `nob`, and so on. 11 | 12 | ```js 13 | var isTrue = require('{%= name %}'); 14 | 15 | isTrue({a: true}, 'a'); 16 | //=> true 17 | 18 | isTrue({noa: false}, 'a'); 19 | //=> true 20 | ``` 21 | 22 | If a property and it's inverse both exist, both must evaluate to the same result, or `false` is returned. 23 | 24 | **Examples** 25 | 26 | ```js 27 | isTrue({noa: false, a: true}, 'a'); 28 | //=> true 29 | 30 | isTrue({noa: false, a: false}, 'a'); 31 | //=> false 32 | 33 | isTrue({noa: true, a: true}, 'a'); 34 | //=> false 35 | ``` 36 | 37 | ## Related projects 38 | {%= related(verb.related.list) %} 39 | 40 | ## Running tests 41 | {%= include("tests") %} 42 | 43 | ## Contributing 44 | {%= include("contributing") %} 45 | 46 | ## Author 47 | {%= include("author") %} 48 | 49 | ## License 50 | {%= copyright() %} 51 | {%= license() %} 52 | 53 | *** 54 | 55 | {%= include("footer") %} 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015, Jon Schlinkert. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # is-true [![NPM version](https://badge.fury.io/js/is-true.svg)](http://badge.fury.io/js/is-true) 2 | 3 | > Returns `true` if the value of an object's property is strictly true, or it's inverse is false. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/) 8 | 9 | ```sh 10 | $ npm i is-true --save 11 | ``` 12 | 13 | ## Usage 14 | 15 | Returns true if a property is strictly `true` or its inverse is strictly `false`. The inverse of `a` is `noa`, the inverse of `b` is `nob`, and so on. 16 | 17 | ```js 18 | var isTrue = require('is-true'); 19 | 20 | isTrue({a: true}, 'a'); 21 | //=> true 22 | 23 | isTrue({noa: false}, 'a'); 24 | //=> true 25 | ``` 26 | 27 | If a property and it's inverse both exist, both must evaluate to the same result, or `false` is returned. 28 | 29 | **Examples** 30 | 31 | ```js 32 | isTrue({noa: false, a: true}, 'a'); 33 | //=> true 34 | 35 | isTrue({noa: false, a: false}, 'a'); 36 | //=> false 37 | 38 | isTrue({noa: true, a: true}, 'a'); 39 | //=> false 40 | ``` 41 | 42 | ## Related projects 43 | 44 | * [is-false](https://www.npmjs.com/package/is-false): Returns false if the value of a property is either strictly false, or it's inverse… [more](https://www.npmjs.com/package/is-false) | [homepage](https://github.com/jonschlinkert/is-false) 45 | * [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object) 46 | * [is-primitive](https://www.npmjs.com/package/is-primitive): Returns `true` if the value is a primitive. | [homepage](https://github.com/jonschlinkert/is-primitive) 47 | * [is-true](https://www.npmjs.com/package/is-true): Returns `true` if the value of an object's property is strictly true, or it's inverse… [more](https://www.npmjs.com/package/is-true) | [homepage](https://github.com/jonschlinkert/is-true) 48 | * [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject) 49 | 50 | ## Running tests 51 | 52 | Install dev dependencies: 53 | 54 | ```sh 55 | $ npm i -d && npm test 56 | ``` 57 | 58 | ## Contributing 59 | 60 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-true/issues/new). 61 | 62 | ## Author 63 | 64 | **Jon Schlinkert** 65 | 66 | + [github/jonschlinkert](https://github.com/jonschlinkert) 67 | + [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 68 | 69 | ## License 70 | 71 | Copyright © 2015 Jon Schlinkert 72 | Released under the MIT license. 73 | 74 | *** 75 | 76 | _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on November 01, 2015._ -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * is-true 3 | * 4 | * Copyright (c) 2015, Jon Schlinkert. 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var isObject = require('isobject'); 11 | 12 | module.exports = function is(o, key) { 13 | if (!isObject(o)) { 14 | throw new TypeError('is-true expects the first argument to be an object.'); 15 | } 16 | if (typeof key !== 'string') { 17 | throw new TypeError('is-true expects the second argument to be a string.'); 18 | } 19 | 20 | var inverse = 'no' + key; 21 | if (o.hasOwnProperty(key) && o.hasOwnProperty(inverse)) { 22 | return o[key] === true && o[inverse] === false; 23 | } 24 | 25 | return o[key] === true || o[inverse] === false; 26 | }; 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-true", 3 | "description": "Returns `true` if the value of an object's property is strictly true, or it's inverse is false.", 4 | "version": "0.1.1", 5 | "homepage": "https://github.com/jonschlinkert/is-true", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "jonschlinkert/is-true", 8 | "bugs": { 9 | "url": "https://github.com/jonschlinkert/is-true/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js" 14 | ], 15 | "engines": { 16 | "node": ">=0.10.0" 17 | }, 18 | "scripts": { 19 | "test": "mocha" 20 | }, 21 | "dependencies": { 22 | "isobject": "^2.0.0" 23 | }, 24 | "devDependencies": { 25 | "mocha": "*" 26 | }, 27 | "keywords": [ 28 | "boolean", 29 | "check", 30 | "is", 31 | "object", 32 | "property", 33 | "value" 34 | ], 35 | "verb": { 36 | "related": { 37 | "description": "", 38 | "list": [ 39 | "is-true", 40 | "is-false", 41 | "is-plain-object", 42 | "isobject", 43 | "is-primitive" 44 | ] 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * is-true 3 | * 4 | * Copyright (c) 2015 Jon Schlinkert. 5 | * Licensed under the MIT license. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | /* deps:mocha */ 11 | var assert = require('assert'); 12 | var isTrue = require('./'); 13 | 14 | describe('isTrue', function () { 15 | it('should return false if the value is not strictly true:', function () { 16 | assert.equal(isTrue({a: false}, 'a'), false); 17 | assert.equal(isTrue({a: 'false'}, 'a'), false); 18 | assert.equal(isTrue({a: 'true'}, 'a'), false); 19 | assert.equal(isTrue({a: 5}, 'a'), false); 20 | assert.equal(isTrue({a: []}, 'a'), false); 21 | }); 22 | 23 | it('should return true if the value is strictly true:', function () { 24 | assert.equal(isTrue({a: true}, 'a'), true); 25 | }); 26 | 27 | it('should return false if the inverse is not strictly false:', function () { 28 | assert.equal(isTrue({noa: true}, 'a'), false); 29 | assert.equal(isTrue({noa: 'false'}, 'a'), false); 30 | assert.equal(isTrue({noa: 'true'}, 'a'), false); 31 | assert.equal(isTrue({noa: 5}, 'a'), false); 32 | assert.equal(isTrue({noa: []}, 'a'), false); 33 | }); 34 | 35 | it('should return true if the inverse is strictly false:', function () { 36 | assert.equal(isTrue({noa: false}, 'a'), true); 37 | }); 38 | 39 | it('should return true if the value is true and the inverse is false:', function () { 40 | assert.equal(isTrue({noa: false, a: true}, 'a'), true); 41 | assert.equal(isTrue({noa: false, a: false}, 'a'), false); 42 | assert.equal(isTrue({noa: true, a: true}, 'a'), false); 43 | }); 44 | 45 | it('should throw an error when the first argument is not an object:', function () { 46 | assert.throws(function () { 47 | isTrue(null); 48 | }, 'is-true expects the first argument to be an object.'); 49 | 50 | assert.throws(function () { 51 | isTrue(''); 52 | }, 'is-true expects the first argument to be an object.'); 53 | }); 54 | 55 | it('should throw an error when the second argument is not a string:', function () { 56 | assert.throws(function () { 57 | isTrue({}); 58 | }, 'is-true expects the second argument to be a string.'); 59 | 60 | assert.throws(function () { 61 | isTrue({}, {}); 62 | }, 'is-true expects the second argument to be a string.'); 63 | 64 | assert.throws(function () { 65 | isTrue({}, null); 66 | }, 'is-true expects the second argument to be a string.'); 67 | }); 68 | }); 69 | --------------------------------------------------------------------------------