@janiscommerce/superstruct
v1.2.2
Published
 [](https://coveralls.io/github/janis-commerce/superst
Readme
superstruct
The following package complements the superstruct package, the same adds some methods to easily validate different types of data
Installation
npm install @janiscommerce/superstructAvailable custom structs types
The custom types that you can use in addition to the superstruct are:
emailThis type checks if is a valid emailURLThis type checks if is a valid URLemptyThis type checks if it's an empty string, array or a falsy value!emptyThis type checks if it's not an empty string, array or a falsy valuelowercaseThis type checks if is a valid lowercase stringuppercaseThis type checks if is a valid uppercase stringcamelcaseThis type checks if is a valid camelcase stringnumericThis type checks if is a valid numeric valuemd5This type checks if is a valid md5 hashJSONThis type checks if is a valid JSONISODateThis type checks if is a valid ISO DateintegerThis type checks if is a integer numberpositiveThis type checks if is a positive numberpositiveOrZeroThis type checks if is a positive number or zeroobjectIdThis type checks if is a ObjectId with 24 charactersUUIDThis type checks if is a V4 UUIDhexColorThis type checks if is a Hexadecimal Color
Usage
const { struct } = require('@janiscommerce/superstruct');
const userStruct = struct({
name: 'string',
email: 'email',
age: 'number',
password: 'md5',
image: 'URL',
mainColor: 'hexColor
});
const userData = {
name: 'John Doe',
email: '[email protected]',
age: 28,
password: 'be5b0158b79c90c8358990f34ec18d43',
image: 'https://gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8?s=200',
hexColor: '#123456'
};
userStruct(userData);