fk-react-ui-components
Version:
Step 1 : Create a file in [ Seeds / Plants / Trees ] <br> Step 2 : It should export an Object with component name and story Component [Refer other components] <br> Step 3 : Story Component should return a react component <br> Step 3 : Created file should
48 lines (39 loc) • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _valid = require('valid.js');
var validators = _interopRequireWildcard(_valid);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
// Please refer https://github.com/dleitee/valid.js for documentation
var isNil = function isNil(value) {
return !value;
};
validators.validate = function () {
for (var _len = arguments.length, fnArr = Array(_len), _key = 0; _key < _len; _key++) {
fnArr[_key] = arguments[_key];
}
return function (value) {
var errorObj = {
isValid: true,
message: ''
};
if (!value) {
value = '';
}
return fnArr.reduce(function (acc, x) {
if (isNil(x.fn)) {
throw new Error('The function for validation is null or undefined.');
} else {
if (acc.isValid && !x.fn(value)) {
return {
isValid: false,
message: x.message || 'Validation Failure'
};
}
return acc;
}
}, errorObj, fnArr);
};
};
exports.default = validators;