0.8.1 • Published 3 years ago
@uppercod/schema v0.8.1
@uppercod/schema
declare validations, filters or transformers in a simple and functional.
install
npm install @uppercod/schema
Usage
Simple
import { schema, error } from "@uppercod/schema";
const transform = schema({
age: Number,
email: (value) => {
if (/\w+@\w+.\w+$/.test(value)) {
return value;
}
throw "invalid email";
},
});
transform({ age: "20" }).then(
(valid) => console.log("valid: ", valid),
(invalid) => console.log("invalid: ", invalid)
);
multiple validations in per field
const min = (minValue) => (value) =>
minValue <= value ? error`The ${value} is less than ${minValue}` : value;
const transform = schema({
age: [Number, min(3)],
});
nested
const trim = (value) => value.trim();
const user = schema({
id: Number,
userName: trim,
});
const data = schema({
user: user,
});
context
const user = schema({
firstName: String,
lastName: String,
fullName: (value, prop, { fistName, lastName }) =>
fistName + " " + lastName,
});
filters
import is from "is_js";
import { schema } from "@uppercod/schema";
import { filter, date, options } from "@uppercod/schema/filter";
schema({
email: filter(is.email),
date: date({ min: new Date("01-02-2020") }),
status: options("active", "inactive"),
});
Api 2
import { schema, optional, use } from "@uppercod/schema";
schema({
id: (value, field, context) => {},
firstName : minLength(3)
fullName: () => {
const {firstName,lastName} = use("valid");
return firstName + " "+ lastName;
},
});
0.8.1
3 years ago
0.8.0
3 years ago
0.7.1
3 years ago
0.7.0
3 years ago
0.6.0
3 years ago
0.5.0
3 years ago
0.4.7
3 years ago
0.4.6
3 years ago
0.4.5
3 years ago
0.4.4
3 years ago
0.4.1
3 years ago
0.4.3
3 years ago
0.4.2
3 years ago
0.4.0
3 years ago
0.3.7
3 years ago
0.3.6
3 years ago
0.3.5
3 years ago
0.3.4
3 years ago
0.3.3
3 years ago
0.3.2
3 years ago
0.3.1
3 years ago
0.3.0
3 years ago
0.1.0
3 years ago
0.0.0
3 years ago