@janiscommerce/superstruct
v1.2.1
Published
![Build Status](https://github.com/janis-commerce/superstruct/workflows/Build%20Status/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/janis-commerce/superstruct/badge.svg?branch=master)](https://coveralls.io/github/janis-commerce/superst
Downloads
1,697
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/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: '[email protected]',
age: 28,
password: 'be5b0158b79c90c8358990f34ec18d43',
image: 'https://gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8?s=200',
hexColor: '#123456'
};
userStruct(userData);