如何克隆一个express-validator
链并使其成为可选,而不影响原始链?例如,考虑这个例子:
var checkPassword = body('password').trim().isLength({min: 10});
var checkPasswordOptional = checkPassword.optional();
// Creates an account.
router.post('/accounts', checkPassword, createAccount);
// Updates an account. Only provided fields are updated.
router.put('/accounts/:id', checkPasswordOptional, updateAccount);
但有了这个,两者都checkPassword
成为checkPasswordOptional
可选的。