{"_id":"respect","_rev":"12-e8d9040ee1b625c72f89ad3a2bbb3b16","name":"respect","time":{"modified":"2022-06-26T11:57:40.660Z","created":"2013-11-20T14:15:26.047Z","0.0.0":"2013-11-20T14:15:27.111Z","0.1.0":"2015-03-29T17:02:01.623Z","0.2.0":"2015-04-15T22:25:30.979Z","0.2.1":"2015-04-18T06:56:39.919Z","0.2.2":"2015-06-27T19:56:50.692Z","0.2.3":"2020-02-07T11:23:06.937Z"},"maintainers":[{"name":"sabiwara","email":"sabiwara@gmail.com"}],"dist-tags":{"latest":"0.2.3"},"description":"Comparison plugin for BDD assertion libraries (chai, should)","readme":"# respect.js\n\n[![Build Status](https://travis-ci.org/sabiwara/respect.svg?branch=master)](https://travis-ci.org/sabiwara/respect)\n\nComparison plugin for BDD assertion libraries ([chai](http://chaijs.com/),\n[should](https://www.npmjs.com/package/should))\n\n\n## Installation\n\n### In node.js:\n\n``` bash\n$ npm install respect --save-dev\n```\n\n### In  the browser\n\n```html\n<script src=\"respect.min.js\" type=\"text/javascript\"></script>\n```\n\n## tl;dr\n\nThe philosophy behind `respect.js` is to extend BDD assertions to make quick and comprehensive object comparisons.\nIt extends `should`-like assertions with a `respect` method that takes a specification and checks it matches.\n\n```javascript\nvar record = {\n  _id: '5515ce73959470012aef024a',\n  name: 'Eva Warner',\n  age: 23,\n  lastLogin: new Date('2014-05-20 07:51:36'),\n  particularity: 'Matches this Regex',\n  nestedObj: {\n    nestedArray: [5, '34', null, true]\n  },\n  anotherArray: [{\n    willBeChecked: true\n  }, {\n    willBeChecked: false\n  }],\n  other: 'Not relevant, will be ignored in the test'\n};\nrecord.should.respect({\n  name: 'Eva Warner',\n  age: function(age) {\n    return (age >= 7) && (age <= 77);\n  },\n  lastLogin: Date,\n  particularity: /regex/i,\n  nestedObj: {\n    nestedArray: [5, String, null, Boolean]\n  },\n  anotherArray: {\n    0: {\n      willBeChecked: true\n    },\n    length: 2\n  },\n  unexpectedPropertyThatShouldNotBeHere: undefined\n});\n```\n\nThis flexible approach can make data-comparing unit-tests less heavy and more expressive,\nespecially when it comes to database documents for instance:\n - no need to omit/pick fields before a deep comparison because they are irrelevant or unpredictable (ids, dates...)\n - easy-to-write one-shot comparison that can check an equality, but also a regex match or a constructor...\n\nIn one words, it checks if an object **respects a specification** rather than comparing two objects.\n\n\n## API\n\n\n### Declaration\n\n```javascript\nvar respect = require('respect');\n```\n\n#### With [should](https://www.npmjs.com/package/should)\n\n```javascript\nvar should = require('should');\nshould.use(respect.shouldPlugin());\n```\n\n#### With [chai](http://chaijs.com/)\n\n```javascript\nvar chai = require('chai');\nchai.use(respect.chaiPlugin());\n\n// Then, according to your preferences:\nvar should = chai.should();\n// OR\nvar expect = chai.expect;\n```\n\n\n### Assertions\n\nThe generic syntax is:\n\n```javascript\ndata.should.respect(specifications, options);\n// OR\nexpect(data).to.respect(specifications, options);\n```\n\nNested objects are compared recursively, and arrays are iterated over.\n`options` can be omitted: by default all the following options are set to `true`:\n\n#### `partial`: Ignore un-specified fields\n\n```javascript\nvar record = {\n  notImportant: 'It is here but we do not need to check for it'\n};\nrecord.should.respect({\n  butThisFieldShouldBeAbsent: undefined\n});\n```\n\n*Note:* if the record object does have the `butThisFieldShouldBeAbsent` field, an exception will be raised.\n\nThis behaviour can be deactivated by providing a `{ partial: false }` option.\n\n#### `regex`: Regex shortcuts\n\n```javascript\nvar record = {\n  uuid: 'bbd4e20b-cdd4-5107-ad63-02a2cfc23c5b'\n};\nrecord.should.respect({\n  uuid: /^[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}$/i\n});\n```\n\nThis behaviour can be deactivated by providing a `{ regex: false }` option.\n\n#### `types`: Constructors shortcut\n\n```javascript\nvar record = {\n  name: 'John',\n  age: 55,\n  now: new Date(),\n  pattern: /[aA]bc.\\s/,\n  dateConstructor: Date,\n  regexConstructor: RegExp\n};\nrecord.should.respect({\n  name: String,\n  age: function(age) {\n    return (age >= 7) && (age <= 77);\n  },\n  now: Date,\n  pattern: RegExp,\n  dateConstructor: Date,\n  regexConstructor: RegExp\n});\n```\n\nThis behaviour can be deactivated by providing a `{ types: false }` option.\n\n#### `lambdas`: Lambda evaluation functions shortcut\n\n```javascript\nvar record = {\n  name: 'John',\n  age: 55\n};\nrecord.should.respect({\n  name: 'John',\n  age: function(age) {\n    return (age >= 7) && (age <= 77);\n  }\n});\n```\n\nThis behaviour can be deactivated by providing a `{ lambdas: false }` option.\n\n\n### Override default behaviours\n\n#### On the assertion level:\n\nExample of changing default behaviours:\n\n```javascript\n// will raise assertion multiple errors because of options\nvar record = {\n  description: 'matches the regex but is a string',\n  now: new Date(),\n  fieldThatShouldNotBeHere: true   // will not be accepted because partial=false\n};\nrecord.should.respect({\n  description: /regex/,            // will fail because regex=false\n  now: Date                        // will fail because types=false\n}, {\n  partial: false,\n  regex: false,\n  types: false\n});\n```\n\nIn this extreme example, every option is removed so the comparison ends up to a *deep equal*.\nWhereas it can be necessary to deactivate one given behaviour for specific cases, it is silly to use `respect`\nin place of a deep equal comparator. Just use the already implemented `should.deep.equal`.\n\n\n#### On the plugin level\n\n`chaiPlugin` and `shouldPlugin` both accept an `options` object, which can override the default behaviours for\nall assertions made from this module.\nBesides, for those who prefer to use their own keyword instead of the default `'respect'`,\nyou can easily pick your own alias by providing an `alias` option when generating the plugin.\nYou can even declare several plugins with different options under different aliases.\n\n```javascript\nvar chai = require('chai');\nvar respect = require('respect');\nchai.use(respect.chaiPlugin({ alias: 'matchStrictly', partial: false, types: false }));\nchai.use(respect.chaiPlugin({ alias: 'matchAll', partial: false }));\nchai.use(respect.chaiPlugin({ alias: 'matchPartially' }));\nchai.should();\n\nvar record = {\n  name: 'Jimmy Hudson',\n  age: 54,\n  male: true\n};\n\n// Will fail because of the unactivated `types` option\nrecord.should.matchStrictly({ name: String, age: Number, male: Boolean });\n\n// Will fail because of the unactivated `partial` option and the missing 'male' key\nrecord.should.matchAll({ name: String, age: Number });\n\n// Will succeed\nrecord.should.matchPartially({ name: String, age: Number });\n```\n\n#### Extend the comparison methods\n\n\n```javascript\nvar Comparator = require('respect');\nvar MyComparator = // TODO write extension code (examples to come)\nchai.use(MyComparator.chaiPlugin());\n```\n\n### Comparisons outside of BDD assertions\n\nIf you want to use `respect` as a comparison util outside of BDD assertions, you can simply use its `check()` method.\n\n```javascript\n// respect.check(actual, expected, [options])\nvar record = {\n  name: 'Darth Vader',\n  badass: true\n};\nrespect.check(record, { badass: true });                      // true\nrespect.check(record, { badass: true }, { partial: false });  // false\n```\n\n## Tests\n\n```bash\n$ npm test\n```\n\n## Documentation\n\n```bash\n$ npm run gen-doc\n```\n\n## License\n\nMIT License Copyright (c) 2015 Sabiwara\n","versions":{"0.1.0":{"name":"respect","description":"Comparison plugin for BDD assertion libraries (chai, should)","version":"0.1.0","author":{"name":"Sabiwara","email":"sabiwara@gmail.com"},"license":"MIT","repository":{"type":"git","url":"http://github.com/sabiwara/respect"},"scripts":{"test":"./node_modules/grunt/bin/grunt check","gen-doc":"./node_modules/coffeedoc/bin/coffeedoc src/*.coffee -o doc"},"main":"./lib/respect","devDependencies":{"assert":"^1.3.0","chai":"^2.1.2","coffeedoc":"^0.3.1","grunt":"^0.4.5","grunt-browserify":"^3.6.0","grunt-coffeelint":"0.0.13","grunt-contrib-coffee":"^0.13.0","grunt-contrib-uglify":"^0.8.0","grunt-contrib-watch":"^0.6.1","grunt-githooks":"^0.3.1","grunt-mocha-cov":"^0.3.0","mocha":"^2.2.1","should":"^5.2.0"},"dependencies":{"lodash":"^3.5.0"},"keywords":["bdd","unit test","should","chai","mocha","assertion"],"files":["lib"],"gitHead":"37bbbca7e17492f1185fbe29950d920289204bd1","bugs":{"url":"https://github.com/sabiwara/respect/issues"},"homepage":"https://github.com/sabiwara/respect","_id":"respect@0.1.0","_shasum":"ca1a5762eee130935ae5b6228542157c556a329b","_from":".","_npmVersion":"2.6.0","_nodeVersion":"1.4.1","_npmUser":{"name":"sabiwara","email":"sabiwara@gmail.com"},"maintainers":[{"name":"sabiwara","email":"sabiwara@gmail.com"}],"dist":{"shasum":"ca1a5762eee130935ae5b6228542157c556a329b","tarball":"https://registry.npmjs.org/respect/-/respect-0.1.0.tgz","integrity":"sha512-bqmWC/fyLWJDEbq4jwc3iL+K2UIy24MZLNcay8comEqyynE6Qr5hEnvgMFUvt0packDw9IAeAUTWbn59ijwASA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCxYIa0ri10zPS3swlibzO8buKLiE4rhx1cLAJimH0bOAIgVv97HEaecgnUbBhY0v8lNB7IVvweBAnc2Sz8qsrdsLQ="}]},"directories":{}},"0.2.0":{"name":"respect","description":"Comparison plugin for BDD assertion libraries (chai, should)","version":"0.2.0","author":{"name":"Sabiwara","email":"sabiwara@gmail.com"},"license":"MIT","repository":{"type":"git","url":"http://github.com/sabiwara/respect"},"scripts":{"test":"./node_modules/grunt/bin/grunt check","gen-doc":"./node_modules/coffeedoc/bin/coffeedoc src/*.coffee -o doc"},"main":"./lib/respect","devDependencies":{"assert":"^1.3.0","chai":"^2.1.2","coffeedoc":"^0.3.1","grunt":"^0.4.5","grunt-browserify":"^3.6.0","grunt-coffeelint":"0.0.13","grunt-contrib-coffee":"^0.13.0","grunt-contrib-uglify":"^0.8.0","grunt-contrib-watch":"^0.6.1","grunt-githooks":"^0.3.1","grunt-mocha-cov":"^0.3.0","mocha":"^2.2.1","should":"^5.2.0"},"dependencies":{"lodash":"^3.5.0"},"keywords":["bdd","unit test","should","chai","mocha","assertion","comparison"],"files":["lib"],"gitHead":"890794f4b1f7ab7c181a68cf6c48b64882f4a1dc","bugs":{"url":"https://github.com/sabiwara/respect/issues"},"homepage":"https://github.com/sabiwara/respect","_id":"respect@0.2.0","_shasum":"a3787b14b0c5594f6d8327a52091ac490a1cca7a","_from":".","_npmVersion":"2.7.5","_nodeVersion":"1.6.3","_npmUser":{"name":"sabiwara","email":"sabiwara@gmail.com"},"maintainers":[{"name":"sabiwara","email":"sabiwara@gmail.com"}],"dist":{"shasum":"a3787b14b0c5594f6d8327a52091ac490a1cca7a","tarball":"https://registry.npmjs.org/respect/-/respect-0.2.0.tgz","integrity":"sha512-sOtv8X3uGBBD8U0ZxK17g3l9lD5B5Vtb4HUnPcvF/ehnH018V0SgHkEpiqmNuuNtsK93D7eyxdAZVaEZDmo5gA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCrVlihjg7qWXOpBSYCd9aIVdbxPxMEjf//8Z7qb8ulKQIgClzpVW+So0/2nLrkUaADIRiIi2XR2EAyZhnTaJ311t8="}]},"directories":{}},"0.2.1":{"name":"respect","description":"Comparison plugin for BDD assertion libraries (chai, should)","version":"0.2.1","author":{"name":"Sabiwara","email":"sabiwara@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+ssh://git@github.com/sabiwara/respect.git"},"scripts":{"test":"./node_modules/grunt-cli/bin/grunt check","gen-doc":"./node_modules/coffeedoc/bin/coffeedoc src/*.coffee -o doc"},"main":"./lib/respect","devDependencies":{"chai":"^2.1.2","coffee-script":"^1.9.2","coffeedoc":"^0.3.1","grunt":"^0.4.5","grunt-browserify":"^3.6.0","grunt-cli":"^0.1.13","grunt-coffeelint":"0.0.13","grunt-contrib-coffee":"^0.13.0","grunt-contrib-uglify":"^0.8.0","grunt-contrib-watch":"^0.6.1","grunt-githooks":"^0.3.1","grunt-mocha-cov":"^0.3.0","mocha":"^2.2.1","should":"^5.2.0"},"dependencies":{"lodash":"^3.7.0"},"keywords":["bdd","unit test","should","chai","mocha","assertion","comparison"],"files":["lib"],"engines":{"node":">=1.0","iojs":">=1.0"},"gitHead":"fbf27b1425babd3e25ebac28f8e9e93403e229c0","bugs":{"url":"https://github.com/sabiwara/respect/issues"},"homepage":"https://github.com/sabiwara/respect#readme","_id":"respect@0.2.1","_shasum":"b484067a72491af3c0aa2a732da1f3eba53b0d1c","_from":".","_npmVersion":"2.8.3","_nodeVersion":"0.12.0","_npmUser":{"name":"sabiwara","email":"sabiwara@gmail.com"},"maintainers":[{"name":"sabiwara","email":"sabiwara@gmail.com"}],"dist":{"shasum":"b484067a72491af3c0aa2a732da1f3eba53b0d1c","tarball":"https://registry.npmjs.org/respect/-/respect-0.2.1.tgz","integrity":"sha512-TYSHszCa/z81DoEdCWgyH9CmY53shoZFP3+Ii9145MIWDBSOmOnBPXVsLLuqa8ysWI9AIdl0E8MrU61GiN0RWg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC4/oXqtByPMxKTXQ7blekTOkN4c0uyf+QeJa8UlXvrBwIhAI3tg7rD0/PXYSd+Qq1z3uXxmhEXVihLS4ybUASppWdT"}]},"directories":{}},"0.2.2":{"name":"respect","description":"Comparison plugin for BDD assertion libraries (chai, should)","version":"0.2.2","author":{"name":"Sabiwara","email":"sabiwara@gmail.com"},"license":"MIT","repository":{"type":"git","url":"http://github.com/sabiwara/respect"},"scripts":{"test":"./node_modules/grunt-cli/bin/grunt check","gen-doc":"./node_modules/coffeedoc/bin/coffeedoc src/*.coffee -o doc"},"main":"./lib/respect","devDependencies":{"chai":"^2.1.2","coffee-script":"^1.9.2","coffeedoc":"^0.3.1","grunt":"^0.4.5","grunt-browserify":"^3.6.0","grunt-cli":"^0.1.13","grunt-coffeelint":"0.0.13","grunt-contrib-coffee":"^0.13.0","grunt-contrib-uglify":"^0.8.0","grunt-contrib-watch":"^0.6.1","grunt-githooks":"^0.3.1","grunt-mocha-cov":"^0.3.0","mocha":"^2.2.1","should":"^5.2.0"},"dependencies":{"lodash":"^3.7.0"},"keywords":["bdd","unit test","should","chai","mocha","assertion","comparison"],"files":["lib"],"engines":{"node":">=1.0","iojs":">=1.0"},"gitHead":"e31a012f1dccaf45e28cd8e558eb7dd87d1897d8","bugs":{"url":"https://github.com/sabiwara/respect/issues"},"homepage":"https://github.com/sabiwara/respect","_id":"respect@0.2.2","_shasum":"ab51b6d1c4cc195ac8fd3bfb76d793adf3b1ab83","_from":".","_npmVersion":"2.7.4","_nodeVersion":"1.6.3","_npmUser":{"name":"sabiwara","email":"sabiwara@gmail.com"},"maintainers":[{"name":"sabiwara","email":"sabiwara@gmail.com"}],"dist":{"shasum":"ab51b6d1c4cc195ac8fd3bfb76d793adf3b1ab83","tarball":"https://registry.npmjs.org/respect/-/respect-0.2.2.tgz","integrity":"sha512-NriO6K8eHqUvG6TBwzNnvOOJw76W18ONclBnxH9UABRAuKaKhwdnb1jOE3lzrpu1+l11HHFS0jPaQgZ6mU4T1w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH3xSnlmbJ1JyRRbCTZa0qQcagExJw/YlwAZmGev4l0YAiBffxVSonyrLKj3XurrtSFy4pOKneG5KgroBcsOyGgu0w=="}]},"directories":{}},"0.2.3":{"name":"respect","description":"Comparison plugin for BDD assertion libraries (chai, should)","version":"0.2.3","author":{"name":"Sabiwara","email":"sabiwara@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+ssh://git@github.com/sabiwara/respect.git"},"scripts":{"test":"./node_modules/grunt-cli/bin/grunt check","gen-doc":"./node_modules/coffeedoc/bin/coffeedoc src/*.coffee -o doc"},"main":"./lib/respect","devDependencies":{"chai":"^2.1.2","coffee-script":"^1.9.2","coffeedoc":"^0.3.1","grunt":"^0.4.5","grunt-browserify":"^3.6.0","grunt-cli":"^0.1.13","grunt-coffeelint":"0.0.13","grunt-contrib-coffee":"^0.13.0","grunt-contrib-uglify":"^0.8.0","grunt-contrib-watch":"^0.6.1","grunt-githooks":"^0.3.1","grunt-mocha-cov":"^0.3.0","mocha":"^2.2.1","should":"^5.2.0"},"dependencies":{"lodash":"^4.17.15"},"keywords":["bdd","unit test","should","chai","mocha","assertion","comparison"],"engines":{"node":">=1.0","iojs":">=1.0"},"gitHead":"9c7ba9975dae792d2da1a0f72ba2354e5fc3c024","bugs":{"url":"https://github.com/sabiwara/respect/issues"},"homepage":"https://github.com/sabiwara/respect#readme","_id":"respect@0.2.3","_nodeVersion":"12.10.0","_npmVersion":"6.10.3","dist":{"integrity":"sha512-uIUzk+swDeNg94Zhvq/3Wi6eQf/0rpN0lMmUm7IwjFEyv9nO1//IERWIW7gkjQhmuP9/YP38g22l6/AzCiOiIA==","shasum":"a70d0c18d49c6c4f0695561a59eab86e8c7ce7ed","tarball":"https://registry.npmjs.org/respect/-/respect-0.2.3.tgz","fileCount":5,"unpackedSize":18376,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJePUibCRA9TVsSAnZWagAAxw8QAJoNn0irzeT5/m9CnNrJ\nNqwmGlsi7fP7DU9W7pJiYWjOLEeXd8MFkvNOoDUBG/eF5VBuEPqVjN0FUL4b\nhOi/J+TyM0qK/QkqJF6A6XpSpJPZsONNvcow2UBS7RpK3yDPDZIxkw5g5kD8\n3wRfOPeeQkXFc+ciNPmRfXIzKrVz5QWexTwwPH51v8j7BlTccFbb3GkEt2xC\nz7cWihfldIWNKRtM0RaMV9AYC1EmVvQ4DMIyD4cXAjjiRsdZrBv50vXy6ea6\nUQKFMwv/n3SEUsa1yXcfxhD+OwmIQx9+Fwu/gZ4N98fJ3SfXh/IoH3KXXeTP\nWhB48uPUtyzBvR5fqWrUyftXP8FB7f6a+jkYPfmET6uPBFGiSU94xO/q7vW1\np5vnL3Jm8j5z76+xyvzttubpbLM/el0klzbfbD3Zx/lzr6Nd4Hxc1nLEctZ+\nnXLEzqKOV4ih++Ngjx1lu5D0NZqbNmdChuMyMPaM6tRCjV8oo5L/QlHK6Dam\n2ZDk+omkHQ7AbQN23b3Uc4jbCPJlmULJAtj/X5DdOVjCE4mze9YbSx1YeCBI\njsY4V7XBR1AO3e5/eNha9LW/G4C2YJdkPqeNtULiGvn6HOa4gKxXXJO3afj1\nVF37LNUcyfMtH2n5SrK+qS0ftF0B3EsrCozbBHJADNp42Z045jJ00UjaA8Ze\nrwfe\r\n=zd/5\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBKT7Ho5cHOSBQEZorIrh2S2sGOmt5JtWjUL5LkO7WyiAiEAwD/1b0szB7FYybTHC6uTvDPAsjJurMHp3+OneZmn6bY="}]},"maintainers":[{"name":"sabiwara","email":"sabiwara@gmail.com"}],"_npmUser":{"name":"sabiwara","email":"sabiwara@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/respect_0.2.3_1581074586833_0.06693620286675817"},"_hasShrinkwrap":false}},"homepage":"https://github.com/sabiwara/respect#readme","keywords":["bdd","unit test","should","chai","mocha","assertion","comparison"],"repository":{"type":"git","url":"git+ssh://git@github.com/sabiwara/respect.git"},"author":{"name":"Sabiwara","email":"sabiwara@gmail.com"},"bugs":{"url":"https://github.com/sabiwara/respect/issues"},"license":"MIT","readmeFilename":"Readme.md"}