superstruct
![npm version](https://badge.fury.io/js/%40janiscommerce%2Fsuperstruct.svg)
The following package complements the superstruct package, the same adds some methods to easily validate different types of data
Installation
npm install @janiscommerce/superstruct
Available custom structs types
The custom types that you can use in addition to the superstruct are:
email
This type checks if is a valid emailURL
This type checks if is a valid URLempty
This type checks if it's an empty string, array or a falsy value!empty
This type checks if it's not an empty string, array or a falsy valuelowercase
This type checks if is a valid lowercase stringuppercase
This type checks if is a valid uppercase stringcamelcase
This type checks if is a valid camelcase stringnumeric
This type checks if is a valid numeric valuemd5
This type checks if is a valid md5 hashJSON
This type checks if is a valid JSONISODate
This type checks if is a valid ISO Dateinteger
This type checks if is a integer numberpositive
This type checks if is a positive numberpositiveOrZero
This type checks if is a positive number or zeroobjectId
This type checks if is a ObjectId with 24 charactersUUID
This type checks if is a V4 UUIDhexColor
This 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: 'emai@asd.com',
age: 28,
password: 'be5b0158b79c90c8358990f34ec18d43',
image: 'https:
hexColor: '#123456'
};
userStruct(userData);