{"name":"parameter","version":"1.0.0","description":"A parameter verify tools.","main":"index.js","scripts":{"test":"mocha --check-leaks -R spec -t 1000 test/*.test.js","test-cov":"node node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- --check-leaks -t 1000 test/*.test.js","test-travis":"node node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly -- --check-leaks -t 1000 test/*.test.js","jshint":"jshint .","autod":"autod -w --prefix '~'","cnpm":"npm install --registry=https://registry.npm.taobao.org","contributors":"contributors -f plain -o AUTHORS"},"dependencies":{},"devDependencies":{"beautify-benchmark":"~0.2.4","benchmark":"*","contributors":"~0.5.0","istanbul-harmony":"*","mocha":"*","should":"*"},"repository":{"type":"git","url":"git://github.com/node-modules/parameter.git"},"keywords":["parameter","verify","univ"],"engines":{"node":">= 0.10.0"},"author":{"name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","contributors":[{"name":"dead-horse","email":"dead-horse@qq.com","url":"https://github.com/dead-horse"},{"name":"fengmk2","email":"fengmk2@gmail.org","url":"https://github.com/fengmk2"}],"gitHead":"5488371cea4dce7a8214da0861bd0aad0f84f03c","bugs":{"url":"https://github.com/node-modules/parameter/issues"},"homepage":"https://github.com/node-modules/parameter","_id":"parameter@1.0.0","_shasum":"430deba512c92f60db1c71115a6258060b7b0578","_from":".","_npmVersion":"2.1.6","_nodeVersion":"0.11.14","_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"}],"dist":{"shasum":"430deba512c92f60db1c71115a6258060b7b0578","tarball":"http://registry-npm.ywwl.com/parameter/download/parameter-1.0.0.tgz","integrity":"sha512-aIimpfBqIf0NZoBJ4zEUxdOCBgMAvDtH0tBG9RQQ6JuxvySPvTa38yWKtbuZSKlVWMBSy/zS8a6sm0M+Lg0OvQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCi6Ofz5I29XZQU4QLBekqjvjasT5aZII0km1HZAj72mAIgV4od/2OfgD0KCAPw5+eSHkDDPvPEWy7bME7IEYdJQ/M="}],"size":5435,"noattachment":false,"key":"/parameter/-/parameter-1.0.0.tgz"},"directories":{},"readme":"parameter\n=======\n\n[![NPM version][npm-image]][npm-url]\n[![Node.js CI](https://github.com/node-modules/parameter/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/parameter/actions/workflows/nodejs.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/parameter.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/parameter\n[codecov-image]: https://codecov.io/github/node-modules/parameter/coverage.svg?branch=master\n[codecov-url]: https://codecov.io/github/node-modules/parameter?branch=master\n[download-image]: https://img.shields.io/npm/dm/parameter.svg?style=flat-square\n[download-url]: https://npmjs.org/package/parameter\n\nA parameter verify tools.\n\n## Install\n\n```bash\n$ npm install parameter --save\n```\n\n## Usage\n\n### API\n\n`Parameter` Class\n\n- `constructor([options])` - new Class `Parameter` instance\n  - `options.translate` - translate function\n  - `options.validateRoot` - config whether to validate the passed in value must be a object, default to `false`.\n  - `options.convert` - convert primitive params to specific type, default to `false`.\n  - `options.widelyUndefined` - convert empty string(`''`), NaN, Null to undefined, this option can make `rule.required` more powerful, default to `false`.__This may change the original input params__.\n- `validate(rule, value)` - validate the `value` conforms to `rule`. return an array of errors if break rule.\n- `addRule(type, check)` - add custom rules.\n   - `type` - rule type, required and must be string type.\n   - `check` - check handler. can be a `function` or a `RegExp`.\n\n__Note: when `options.convert` enabled, all built-in rules check for primitive input param and convert it to rule's default `convertType`(which defined below), you can also enable this feature for specific rule by `convertType` options in each rule definition.__\n\n### Example\n\n```js\nvar Parameter = require('parameter');\n\nvar parameter = new Parameter({\n  translate: function() {\n    var args = Array.prototype.slice.call(arguments);\n    // Assume there have I18n.t method for convert language.\n    return I18n.t.apply(I18n, args);\n  },\n  validateRoot: true, // restrict the being validate value must be a object\n});\n\nvar data = {\n  name: 'foo',\n  age: 24,\n  gender: 'male'\n};\n\nvar rule = {\n  name: 'string',\n  age: 'int',\n  gender: ['male', 'female', 'unknown']\n};\n\nvar errors = parameter.validate(rule, data);\n```\n\n#### [complex example](example.js)\n\n### Rule\n\n#### common rule\n\n- `required` - if `required` is set to false, this property can be null or undefined. default to `true`.\n- `type` - The type of property, every type has it's own rule for the validate.\n- `convertType` - Make parameter convert the input param to the specific type, support `int`, `number`, `string` and `boolean`, also support a function to customize your own convert method.\n- `default` - The default value of property, once the property is allowed non-required and missed, parameter will use this as the default value. __This may change the original input params__.\n- `widelyUndefined` - override `options.widelyUndefined`\n\n__Note: you can combile require and type end with a notation `?` like: `int?` or `string?` to specific both type and non-required.__\n\n#### int\n\nIf type is `int`, there has tow addition rules:\n\n- `max` - The maximum of the value, `value` must <= `max`.\n- `min` - The minimum of the value, `value` must >= `min`.\n\nDefault `convertType` is `int`.\n\n__Note: default `convertType` will only work when `options.convert` set to true in parameter's constructor.__\n\n#### integer\n\nAlias to `int`.\n\n#### number\n\nIf type is `number`, there has tow addition rules:\n\n- `max` - The maximum of the value, `value` must <= `max`.\n- `min` - The minimum of the value, `value` must >= `min`.\n\nDefault `convertType` is `number`.\n\n#### date\n\nThe `date` type want to match `YYYY-MM-DD` type date string.\n\nDefault `convertType` is `string`.\n\n#### dateTime\n\nThe `dateTime` type want to match `YYYY-MM-DD HH:mm:ss` type date string.\n\nDefault `convertType` is `string`.\n\n#### datetime\n\nAlias to `dateTime`.\n\n#### id\n\nThe `id` type want to match `/^\\d+$/` type date string.\n\nDefault `convertType` is `string`.\n\n#### boolean\n\nMatch `boolean` type value.\n\nDefault `convertType` is `boolean`.\n\n#### bool\n\nAlias to `boolean`\n\n#### string\n\nIf type is `string`, there has four addition rules:\n\n- `allowEmpty`(alias to `empty`) - allow empty string, default to false. If `rule.required` set to false, `allowEmpty` will be set to `true` by default.\n- `format` - A `RegExp` to check string's format.\n- `max` - The maximum length of the string.\n- `min` - The minimum length of the string.\n- `trim` - Trim the string before check, default is `false`.\n\nDefault `convertType` is `string`.\n\n#### email\n\nThe `email` type want to match [RFC 5322](http://tools.ietf.org/html/rfc5322#section-3.4) email address.\n\n- `allowEmpty` - allow empty string, default is false.\n\nDefault `convertType` is `string`.\n\n#### password\n\nThe `password` type want to match `/^$/` type string.\n\n- `compare` - Compare field to check equal, default null, not check.\n- `max` - The maximum length of the password.\n- `min` - The minimum length of the password, default is 6.\n\nDefault `convertType` is `string`.\n\n#### url\n\nThe `url` type want to match [web url](https://gist.github.com/dperini/729294).\n\nDefault `convertType` is `string`.\n\n#### enum\n\nIf type is `enum`, it requires an addition rule:\n\n- `values` - An array of data, `value` must be one on them. ___this rule is required.___\n\n#### object\n\nIf type is `object`, there has one addition rule:\n\n- `rule` - An object that validate the properties ot the object.\n\n#### array\n\nIf type is `array`, there has four addition rule:\n\n- `itemType` - The type of every item in this array.\n- `rule` - An object that validate the items of the array. Only work with `itemType`.\n- `max` - The maximum length of the array.\n- `min` - The minimum lenght of the array.\n\n#### abbr\n\n- `'int'` => `{type: 'int', required: true}`\n- `'int?'` => `{type: 'int', required: false }`\n- `'integer'` => `{type: 'integer', required: true}`\n- `'number'` => `{type: 'number', required: true}`\n- `'date'` => `{type: 'date', required: true}`\n- `'dateTime'` => `{type: 'dateTime', required: true}`\n- `'id'` => `{type: 'id', required: true}`\n- `'boolean'` => `{type: 'boolean', required: true}`\n- `'bool'` => `{type: 'bool', required: true}`\n- `'string'` => `{type: 'string', required: true, allowEmpty: false}`\n- `'string?'` => `{type: 'string', required: false, allowEmpty: true}`\n- `'email'` => `{type: 'email', required: true, allowEmpty: false, format: EMAIL_RE}`\n- `'password'` => `{type: 'password', required: true, allowEmpty: false, format: PASSWORD_RE, min: 6}`\n- `'object'` => `{type: 'object', required: true}`\n- `'array'` => `{type: 'array', required: true}`\n- `[1, 2]` => `{type: 'enum', values: [1, 2]}`\n- `/\\d+/` => `{type: 'string', required: true, allowEmpty: false, format: /\\d+/}`\n\n### `errors` examples\n\n#### `code: missing_field`\n\n```js\n{\n  code: 'missing_field',\n  field: 'name',\n  message: 'required'\n}\n```\n\n#### `code: invalid`\n\n```js\n{\n  code: 'invalid',\n  field: 'age',\n  message: 'should be an integer'\n}\n```\n\n## License\n\n[MIT](LICENSE.txt)\n\n<!-- GITCONTRIBUTOR_START -->\n\n## Contributors\n\n|[<img src=\"https://avatars.githubusercontent.com/u/156269?v=4\" width=\"100px;\"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/985607?v=4\" width=\"100px;\"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/5518?v=4\" width=\"100px;\"/><br/><sub><b>huacnlee</b></sub>](https://github.com/huacnlee)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/143572?v=4\" width=\"100px;\"/><br/><sub><b>hotoo</b></sub>](https://github.com/hotoo)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/2039144?v=4\" width=\"100px;\"/><br/><sub><b>sang4lv</b></sub>](https://github.com/sang4lv)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/471928?v=4\" width=\"100px;\"/><br/><sub><b>ghostoy</b></sub>](https://github.com/ghostoy)<br/>|\n| :---: | :---: | :---: | :---: | :---: | :---: |\n[<img src=\"https://avatars.githubusercontent.com/u/12657964?v=4\" width=\"100px;\"/><br/><sub><b>beliefgp</b></sub>](https://github.com/beliefgp)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/5825244?v=4\" width=\"100px;\"/><br/><sub><b>taylorharwin</b></sub>](https://github.com/taylorharwin)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/3199140?v=4\" width=\"100px;\"/><br/><sub><b>tomowang</b></sub>](https://github.com/tomowang)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/11374721?v=4\" width=\"100px;\"/><br/><sub><b>hdumok</b></sub>](https://github.com/hdumok)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/7971415?v=4\" width=\"100px;\"/><br/><sub><b>paranoidjk</b></sub>](https://github.com/paranoidjk)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/30565051?v=4\" width=\"100px;\"/><br/><sub><b>zcxsythenew</b></sub>](https://github.com/zcxsythenew)<br/>\n\nThis project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Apr 05 2022 10:44:22 GMT+0800`.\n\n<!-- GITCONTRIBUTOR_END -->\n","publish_time":1420770791968,"_cnpm_publish_time":1420770791968,"dist-tags":{"latest":"3.7.0"}}