Skip to content

Releases: trojs/validator

Publish package to GitHub

24 Nov 18:01
Compare
Choose a tag to compare
2.1.5

Publish to GitHub

Add url and date validation

24 Nov 10:42
bca39cd
Compare
Choose a tag to compare
Merge pull request #51 from hckrnews/feature/add-url-validation

Add url and date validation

Invalid fields

01 Apr 05:58
Compare
Choose a tag to compare

You can now find the wrong fields with .errors

Optional key can be set to the key

01 Apr 05:56
229e390
Compare
Choose a tag to compare

You can set the question mark at the key, so more options are possible with the types, e.g. if the type definition isn't a string.

{
    first: String,
    "?second": String,
}

You can also validate an array of items

19 Feb 20:47
2dd1ee8
Compare
Choose a tag to compare

Example usage:

const persons = [
    {
        name: "James",
        age: 25,
        siblings: ["Johnnathan"],
        metaData: {},
        active: true,
        address: {
            street: "Streetname",
            number: 1,
            postalCode: "1234AB",
            city: "City",
            country: "Somewehere"
        },
        companies: [
            { name: "Example company 1", website: "https://hckr.news" }
            { name: "Example company 2" }
        ]
    }
];

validator.validateAll(persons);

Now you can add sub array's with objects

19 Feb 19:36
99a0913
Compare
Choose a tag to compare

Example multi level schema:

const personSchema = {
    name: "string",
    age: "number",
    siblings: "array",
    metaData: "?object",
    active: "boolean",
    address: {
        street: "string",
        number: "number",
        postalCode: "string",
        city: "string",
        country: "string"
    },
    companies:  {
        name: "string",
        website: "?string"
    }
};

Example valid data for the person schema:

const personObj = {
    name: "James",
    age: 25,
    siblings: ["Johnnathan"],
    metaData: {},
    active: true,
    address: {
        street: "Streetname",
        number: 1,
        postalCode: "1234AB",
        city: "City",
        country: "Somewehere"
    },
    companies: [
        { name: "Example company 1", website: "https://hckr.news" }
        { name: "Example company 2" }
    ]
}