@achmadeko003/validate
v1.0.6
Published
validate
Downloads
13
Readme
Validate
A package for validate.
Feature
Installation
$ npm i @achmadeko003/validate
A function for validate email with a custom format.
usage:
import { isEmail } from "@achmadeko003/validate/index";
isEmail("[email protected]"); // Basic usage
// true
isEmail("[email protected]", {
gmail: true,
outlook: true,
yahoo: true,
hotmail: true,
}); // Famous email domain
// true
isEmail("[email protected]", { custom: "madko.com" }); // Custom email domain
// true
isEmail("[email protected]", { firstLetter: 3, mask: "*" }); // Mask email
// Pur******@madko.com
String
A function for validate string.
usage:
import { isString } from "@achmadeko003/validate/index";
new isString("pururu").check(); // Basic usage for validate value type is string or not
new isString("pururu!").useSymbols().check(); // Add useSymbols() for excluded symbols
new isString("pururu2").useNumber().check(); // Add useNumber() for excluded symbols
new isString("pururu").useSymbols().useNumber().check(); // or add useSymbols() and useNumber() for exluded character symbols and number
new isString("pururu2").maxLength(3); // Add maxLength() for check string length
new isString("https://example.com").checkLinkURL(); // checkLinkURL() for validate if string is https:// or http:// URL
Object
A function for validate value is object or not.
usage:
import { isObject } from "@achmadeko003/validate/index";
const profile = {
id: 10,
name: "Pururu",
phone: null,
email: "[email protected]",
address: null,
};
new isObject(profile).check(); // Basic usage
// true
new isObject(profile).valueNull(); // Validate object key values
// {
// status: true,
// detail: [
// 'phone value is null or undefined',
// 'address value is null or undefined'
// ]
// }
new isObject(profile).setKeys(["phone", "email"]).valueNull(); // Validate specific object key values
// {
// status: true,
// detail: [
// 'phone value is null or undefined'
// ]
// }
Empty
A function for validate field null or undefined.
usage:
import { isEmpty } from "@achmadeko003/validate/index";
const phoneNumber = null;
isEmpty(phoneNumber); // Basic usage that return true if value null or undefined