import { Predicate } from './types'; /** * Checks whether an object satisfies predicates defined in structure * * NOTE: All predicates defined in structure must be satisfied. * If some of the properties are optional use [undefinedOr](#undefinedOr) * * You shouldn't use this function to validate input from the user and expect complex report of what is invalid. * There are few reasons for that: * * it's just a predicate (that always returns only true or false) * * breaks [the design rule](design.md#user-content-defined-and-generated-predicates-will-not-throw-any-errors) * * See examples for inspiration how you can use _structure_ * * @example Structure check * const schema = { * name: String, // only string * phone: is.or(String, Number), // string or number * surname: is.undefinedOr(String) // optional * }, * isPerson = is.structure(schema); * * const person = {name: 'Tommy', phone: 80129292}; * isPerson(person); // true * // same as * is.structure(schema, person); // true * isPerson({name: 'Tommy'}); * * @example filtering * const people = [ * {name: 'Prof. Bend Ovah', age: 55, sex: 'male'}, * {name: 'Dr. Supa Kaki', age: 34, sex: 'female'}, * {name: 'Prof. Anti Santy', age: 46, sex: 'male'} * ]; * * const professors = people.filter(is.structure({ * name: is.startsWith('Prof.') * })); * * // [ * // {name: 'Prof. Bend Ovah', age: 55, sex: 'male'}, * // {name: 'Prof. Anti Santy', age: 46, sex: 'male'} * // ] * * @example duck typing * * const isDuck = is.structure({ * quack: is.function, * walk: is.function * }); * * isDuck({ * say: function() { return 'woof! woof!'; * }}); // not a duck * * isDuck({ * quack: function() { return 'quack!'; }, * walk: function() { return 'tup tup tup'; } * }); // yep, it's a duck * * @throws {TypeError} if structure is not an object */ declare function isStructure(structure: { [name: string]: Predicate | Function; }): Predicate; declare function isStructure(structure: { [name: string]: Predicate | Function; }, value: Object): boolean; export default isStructure;