���� JFIF �� � ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /var/www/html/video/layout/js/node_modules/option-validator/ |
# option-validator [](https://travis-ci.com/zhw2590582/option-validator)    [](https://www.npmjs.com/package/option-validator) [](https://david-dm.org/zhw2590582/option-validator) > A simple option validator ## Install ``` $ npm install option-validator ``` ```js import optionValidator from 'option-validator'; ``` OR umd builds are also available ```html <script src="path/to/option-validator.js"></script> ``` Will expose the global variable to `window.optionValidator`. ## Usage - Only one api is to receive a option object and a scheme. - If the verification is passed, the original option object will be returned. - If the verification fails, an exception will be thrown. - Support all js type detection [JS Types](./__test__/testData.js) - Support for custom validator functions ```js const option = { a: 1, b: '2', c: { d: () => null, }, g: { h: new Error('error'), }, i: [1, '2', () => 3], j: [1, 2, 3, 4, 5, 6], k: '123456', }; const scheme = { // Shallow verification a: 'number', b: 'string', // Deep verification c: { d: 'function', }, // Validator functions g: { h: (value, type, path) => { // value --> new Error('error') // type --> 'error' // path --> ['option', 'g', 'h'] // Returns string mean validation failed, and the string will thrown return 'I will throw an exception'; // Returns error also mean validation failed, and the error will thrown return new Error('I will throw an exception'); // Returns true mean verification passed return type === 'error'; }, }, // Verify array elements i: ['number', 'string', 'function'], // If there is no corresponding validator, the first one is taken by default. j: ['number'], // Verify one of them k: 'number|string', }; optionValidator(option, scheme); ``` ## License MIT © [Harvey Zack](https://sleepy.im/)