Closed Mr-M1M3 closed 2 years ago
Hi @Mr-M1M3 — if you're still curious — the first param acts as a human-readable label for the Struct you are creating. You can see it in error messages.
For example:
import isUuid from 'is-uuid'
const uuid = define('uuid', (value) => isUuid.v4(value)); // The label is set to `uuid`
const [error, value] = validate("Z2C46V", uuid);
console.log(error.message) // Prints: 'Expected a value of type `uuid`, but received: `"Z2C46V"`'
Hope this helps!
Thanks @arturmuller. I get it now!!!
Ho there, while reading docs, I came to know that we can define our own custom types using
define()
function. However, I couldn't find any explanation of the parameters it takes. It would be a great help if you tell me about the parameter.