{"_id":"@abneroliveira/business-rules-engine","_rev":"3-f5a03ca3a4ea6f4e3f5ddc06d00e1e79","name":"@abneroliveira/business-rules-engine","description":"business rules engine","dist-tags":{"latest":"1.3.0"},"versions":{"1.3.0":{"name":"@abneroliveira/business-rules-engine","version":"1.3.0","description":"business rules engine","main":"dist/businessRulesEngine.js","typings":"dist/src/index.d.ts","files":["dist/**/*.*","src/**/*.*"],"scripts":{"test":"grunt ci"},"repository":{"type":"git","url":"git+https://github.com/abner/business-rules-engine.git"},"keywords":["business rules","validation","form"],"author":{"name":"abner","email":"abner.silva@gmail.com"},"license":"BSD-3-Clause","bugs":{"url":"https://github.com/abner/business-rules-engine/issues"},"dependencies":{"axios":"^0.3.1","core-js":"^2.4.1","hashmap":"^1.1.0","moment":"^2.15.1","q":"1.0.1","underscore":"^1.8.3","underscore.string":"^2.4.0"},"devDependencies":{"@types/axios":"^0.9.32","@types/hashmap":"^2.0.29","@types/moment":"^2.13.0","@types/q":"0.0.31","@types/underscore":"^1.7.33","@types/underscore.string":"0.0.30","awesome-typescript-loader":"^2.2.4","expect.js":"~0.2.0","grunt":"~0.4.1","grunt-cli":"~0.1.9","grunt-complexity":"~0.1.3","grunt-contrib-commands":"^0.1.6","grunt-contrib-concat":"^0.5.0","grunt-contrib-copy":"^0.5.0","grunt-contrib-jshint":"~0.6.4","grunt-contrib-uglify":"^0.5.1","grunt-contrib-watch":"~0.5.3","grunt-docular":"^0.1.2","grunt-mocha-cli":"^1.9.0","grunt-ngdocs":"^0.2.2","grunt-run":"^0.2.3","grunt-typedoc":"^0.1.1","grunt-typescript":"^0.3.8","sinon":"^1.12.1","tslint":"^3.15.1","typedoc":"^0.1.1","typescript":"^2.0.3","webpack":"^1.13.2"},"gitHead":"55c180ab20791e657aa52a50112a1d137d058631","homepage":"https://github.com/abner/business-rules-engine#readme","_id":"@abneroliveira/business-rules-engine@1.3.0","_shasum":"2c2c0bcb4ef1b03b718b4ee0d4017c915e85e851","_from":".","_npmVersion":"3.10.7","_nodeVersion":"6.3.0","_npmUser":{"name":"abneroliveira","email":"abner.silva@gmail.com"},"dist":{"shasum":"2c2c0bcb4ef1b03b718b4ee0d4017c915e85e851","tarball":"https://registry.npmjs.org/@abneroliveira/business-rules-engine/-/business-rules-engine-1.3.0.tgz","integrity":"sha512-w/b7KIPXKbSfHoOtyqFhE9lwYnaHU1clZVI5GGaOZDtB2vw+HNQLkx7yRgAYZ/CXPlALMXGmsckLWQiiiGJc2w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAvhWGRX7QNCCwi8mobKEL698AITl4RsuF82VmxcDIumAiBS75Tbt0tCTxLfVRD96zv+7CU0xkAGtmX/qE7NLbZSQA=="}]},"maintainers":[{"name":"abneroliveira","email":"abner.silva@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/business-rules-engine-1.3.0.tgz_1475095848469_0.3631571710575372"}}},"readme":"# Business rules engine\n\n![logo](https://github.com/rsamec/form/blob/master/form_logo.jpg)\n\nBusiness rules engine is a lightweight JavaScript library for easy business rules definition of the product, the contract, the form etc.\n\n## Key features\nThe main benefit is that business rules engine is not tight to HTML DOM or any other UI framework.\nThis validation engine is **UI agnostic** and that is why it can be used as **an independent representation of business rules** of a product, contract, etc.\nIt can be easily reused by different types of applications, libraries.\n\n+   It enables to decorate custom objects and its properties with validation rules.\n+   It supports declarative and imperative validation rules definition\n    +  declarative [JSON schema](http://json-schema.org/) with validation keywords [JSON Schema Validation](http://json-schema.org/latest/json-schema-validation.html)\n    +  declarative raw JSON data  annotated with meta data - using keywords from [JQuery validation plugin](http://jqueryvalidation.org/)\n    +  imperative - [validation API](http://rsamec.github.io/business-rules-engine/docs/modules/_validation_validation_.html)\n+   It supports composition of validation rules, that enables to validate custom object with nested structures.\n+   It is ease to create your own custom validators.\n+   It supports asynchronous validation rules (uses promises).\n+   It supports shared validation rules.\n+   It supports assigning validation rules to collection-based structures - arrays and lists.\n+   It supports notification of errors changed via ErrorChanged dispatch event.\n+   It supports dot syntax to access to nested rules.\n+   It supports localization of error messages with TranslateArgs.\n+   It deploys as AMD, CommonJS or plain script module pattern.\n+   It offers basic build-in constrains validators. See list [basic build-in constraints](http://rsamec.github.io/business-rules-engine/docs/modules/_validation_basicvalidators_.html)\n+   Other custom validators can be find in extensible repository of custom validators (work in progress).\n\n## Installation\n\nThis module is installed:\n\n+   Node.js\n   +    npm install business-rules-engine\n   +    use require('business-rules-engine');\n+   Bower\n   +   bower install business-rules-engine\n   +   Require.js - require([\"business-rules-engine/amd/Validation\"], ...\n   +   Script tag -> add reference to business-rules-engine/module/Validation.js file.\n\n## Example Usage\n\nThere are 3 ways how to define validation rules\n\n+  declarative [JSON schema](http://json-schema.org/) with validation keywords [JSON Schema Validation](http://json-schema.org/latest/json-schema-validation.html)\n+  declarative raw JSON data  annotated with meta data - using keywords from [JQuery validation plugin](http://jqueryvalidation.org/)\n+  imperative - [validation API](http://rsamec.github.io/business-rules-engine/docs/modules/_validation_validation_.html)\n\n\n### JSON Schema Validation\n\n``` js\n    {\n        FirstName: {\n            type: \"string\",\n            title: \"First name\",\n            required: \"true\",\n            maxLength: 15\n        },\n        LastName: {\n            type: \"string\",\n            \"title\": \"Last name\",\n            required: true,\n            maxLength: 15\n        },\n        Contacts: {\n            type: \"array\",\n            maxItems: 4,\n            minItems: 2,\n            items: {\n                type: \"object\",\n                properties: {\n                    Email: {\n                        type: \"string\",\n                        title: \"Email\",\n                        default: '',\n                        required: true,\n                        maxLength: 100,\n                        pattern: \"S*@S*\" },\n                    Mobile: {\n                        type: \"object\",\n                        properties: {\n                            CountryCode: {\n                                type: \"string\",\n                                title: \"Country code\",\n                                required: true,\n                                maxLength: 3,\n                                enum: [\"FRA\", \"CZE\", \"USA\", \"GER\"]\n                            },\n                            Number: {\n                                type: \"string\",\n                                title: \"Phone number\",\n                                required: true,\n                                maxLength: 9\n                            }\n                        }\n                    },\n                    FixedLine: {\n                        type: \"object\",\n                        properties: {\n                            CountryCode: {\n                                type: \"string\",\n                                title: \"Country code\",\n                                required: true,\n                                maxLength: 3,\n                                enum: [\"FRA\", \"CZE\", \"USA\", \"GER\"]\n                            },\n                            Number: {\n                                type: \"string\",\n                                title: \"Phone number\",\n                                required: true,\n                                maxLength: 9\n                            }\n                        }\n                    }\n                }\n            }\n        }\n    }\n```\n\n```js\nvar rules = new FormSchema.JsonSchemaRuleFactory(json).CreateRule(\"Main\");\n```\n\n### JSON data annotated with meta data \n\n``` js\n// define data structure + validation rules meta data\n  {\n        FirstName: {\n            rules: {required: true, maxlength: 15}},\n        LastName: {\n            rules: {required: true, maxlength: 15}},\n        Contacts: [\n            {\n                Email: {\n                    rules: {\n                        required: true,\n                        maxlength: 100,\n                        email: true\n                    }\n                },\n                Mobile: {\n                    CountryCode: {\n                        rules: {required: true, maxlength: 3, enum: [\"FRA\", \"CZE\", \"USA\", \"GER\"] }\n                    },\n                    Number: {\n                        rules: {required: true, maxlength: 9 }\n                    }\n                },\n                FixedLine: {\n                    CountryCode: {\n                        rules: {required: true, maxlength: 3, enum: [\"FRA\", \"CZE\", \"USA\", \"GER\"] }\n                    },\n                    Number: {\n                        rules: {required: true, maxlength: 9 }\n                    }\n                }\n            },{maxItems: 4, minItems: 2}\n        ]\n    }\n```\n\n```js\nvar rules = new FormSchema.JQueryValidationRuleFactory(json).CreateRule(\"Main\");\n```\n### Imperative definition - using API\n\nTo define business rules for some object, you have to create abstract validator.\n``` js\n          //create new validator for object with structure<IPerson>\n          var personValidator = new Validation.AbstractValidator();\n\n          //basic validators\n          var required = new Validators.RequiredValidator();\n          var maxLength = new Validators.MaxLengthValidator(15);\n\n          //assigned validators to property\n          personValidator.RuleFor(\"FirstName\", required);\n          personValidator.RuleFor(\"FirstName\",maxLength);\n\n          //assigned validators to property\n          personValidator.RuleFor(\"LastName\", required);\n          personValidator.RuleFor(\"LastName\",maxLength);\n          \n          ...\n\n```\n\nTo use business rules and execute them on particular data\n```js\n          //create test data\n          var data = {\n                Person1:\n                {\n                    FirstName:'John',\n                    LastName: 'Smith'\n                },\n                Person2:{}\n\n          }\n\n          //create concrete rule\n          var person1Validator = personValidator.CreateRule(\"Person 1\");\n\n          //execute validation\n          var result = person1Validator.Validate(this.Data.Person1);\n\n          //verify results\n          if (result.HasErrors){\n              console.log(result.ErrorMessage);\n          }\n          //---------\n          //--outputs\n          //---------\n\n          //create concrete rule\n          var person2Validator = personValidator.CreateRule(\"Person 2\");\n\n          //execute validation\n          var result = person2Validator.Validate(this.Data.Person1);\n\n           //verify results\n          if (result.HasErrors){\n              console.log(result.ErrorMessage);\n          }\n\n          //---------\n          //--outputs\n          //---------\n          // FirstName: Field is required.\n          // LastName: Field is required.\n\n```\n\n## Additional information\n\n+ Business rules engine\n    + [Business rules engine - Tutorial] (https://github.com/rsamec/business-rules-engine/wiki)\n    + [Business rules engine - API] (http://rsamec.github.io/business-rules-engine/docs/index.html)\n\n+ Examples - rules\n    + [Business rules repository - sources] (https://github.com/rsamec/business-rules)\n    + [Business rules repository - API] (http://rsamec.github.io/business-rules/docs/index.html)\n\n+ Examples - UI with rules\n    + Polymer example\n        + [demo](http://polymer-formvalidation.rhcloud.com/)\n        + [sources](https://github.com/rsamec/clever-form-demo)\n        + [tutorial] (http://rsamec.github.io/lessons/2014/10/19/the-fastest-way-to-create-clever-application)\n    + NodeJS Example\n        + [sources] (https://github.com/rsamec/node-form-app)\n    + AngularJS Example\n        + [sources] (https://github.com/rsamec/angular-form-app)\n        + [demo -forms app] (http://nodejs-formvalidation.rhcloud.com/)\n        + [demo - vacation Request form] (http://nodejs-formvalidation.rhcloud.com/#/vacationApproval/new)\n        + [demo - hobbies form] (http://nodejs-formvalidation.rhcloud.com/#/hobbies/new)\n        + [demo - hobbies form - try it in plunkr] (http://embed.plnkr.co/vbp9aFw7Lc2EyNyhUf5y/preview)\n\n+ [author blog] (http://rsamec.github.io/)\n\n## Source code\n\nAll code is written in typescript.\n\n``` bash\nnpm install -g typescript\n```\n\nTo compile to javascript.\n\n``` bash\ntsc src/validation/Validation.ts --target ES5 --module commonjs\n```\n\n## Tests\n\n``` bash\nnpm install -g mocha\nnpm install -g expect.js\n```\n\nTo run tests\n\n``` bash\nmocha test\n```\n\n\n## Grunt automatization\n\n### Basic steps\n\n+ git clone https://github.com/rsamec/business-rules-engine\n+ npm install - get npm packages\n+ tsd update - get external typings definition\n+ grunt typings - create node-form typings definition - used by custom validators\n\nTo build all sources to dist folder (generates AMD, CommonJS and module pattern)\n``` bash\n$ grunt dist\n```\n\nTo run code analyze - complexity + jshint.\n``` bash\n$ grunt ci\n```\n\nTo generate api documentation.\n``` bash\n$ grunt document\n```\n\nTo generate typings -> typescript definition files.\n``` bash\n$ grunt typings\n```\n\nTo run tests\n``` bash\n$ grunt test\n```\n\n## Roadmap\n\nPriority\n\n+ Refactor validation API - simplify and better naming\n+ Support for changes notification -> partially done, but consider to use framework like ObserveJs or similer notification frameworks\n+ Refactor implemenation\n    +   use depedency injection for managing dependencies among internal components\n    +   remove depedencies or make them optional - Q, underscore, moment, axiom\n    +   lazy loading + consider better data structure for composite \n\nOthers\n\n+ Add validation groups to shared validation rules\n+ Separate ValidationResult from execution of validation rules\n+ Improve documentation + more examples\n\n## License\n\nThe MIT License (MIT)\n","maintainers":[{"name":"abneroliveira","email":"abner.silva@gmail.com"}],"time":{"modified":"2022-06-12T14:14:32.340Z","created":"2016-09-28T20:50:48.701Z","1.3.0":"2016-09-28T20:50:48.701Z"},"homepage":"https://github.com/abner/business-rules-engine#readme","keywords":["business rules","validation","form"],"repository":{"type":"git","url":"git+https://github.com/abner/business-rules-engine.git"},"author":{"name":"abner","email":"abner.silva@gmail.com"},"bugs":{"url":"https://github.com/abner/business-rules-engine/issues"},"license":"BSD-3-Clause","readmeFilename":"README.md"}