How to use @humanwhocodes/object-schema - 2 common examples

To help you get started, we’ve selected a few @humanwhocodes/object-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eslint / eslint / lib / simpleconfig / config-schema.js View on Github external
}
            }

            return Object.assign({}, value1, value2);
        },
        validate(value) {
            assertIsObject(value);
        }
    }
});

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------

module.exports = new ObjectSchema({
    files: {
        required: false,
        merge() {
            return undefined;
        },
        validate(value) {
            if (value !== undefined) {

                // assertIsArrayOfStrings(value);
            }
        }
    },
    ignores: {
        required: false,
        requires: ["files"],
        merge() {
github eslint / eslint / lib / simpleconfig / config-schema.js View on Github external
function assertIsObject(value, name) {
    if (value == null || typeof value !== "object") {
        throw new TypeError(`Expected value to be an object.`);
    }

}

function assertIsArrayOfStrings(value, name) {
    assertIsArray(value, name);

    if (value.some(item => typeof item !== "string")) {
        throw new TypeError(`Expected array to only contain strings.`);
    }
}

const defsSchema = new ObjectSchema({
    ruleNamespaces: {
        required: false,
        merge(value1, value2) {
            if (value1 == undefined) {
                return value2;
            }

            if (value2 == undefined) {
                return value1;
            }

            for (const key of Object.keys(value1)) {
                if (key in value2 && !Object.is(value2[key], value1[key])) {
                    throw new Error(`Rule namespace "${key}" is already defined and cannot be redefined.`);
                }
            }

@humanwhocodes/object-schema

An object schema merger/validator

BSD-3-Clause
Latest version published 7 months ago

Package Health Score

55 / 100
Full package analysis

Popular @humanwhocodes/object-schema functions