1.1.5 • Published 4 years ago

ez-validation v1.1.5

Weekly downloads
560
License
-
Repository
github
Last release
4 years ago

badge NPM version NPM downloads overall NPM package size

License: MIT semantic-release

Validation made Ez

Who said Validation has to be hard and annoying!

https://medium.com/@27amad27/validation-made-ez-50e72d6a0b29

FunctionParamsDescription
requirederrorMessagechecks if value is empty or not
isStringerrorMessagechecks if value is a STRING
isBooleanerrorMessagechecks if value is a BOOLEAN
isNumbererrorMessagechecks if value is a INT
isWholeNumbererrorMessagechecks if value is a Whole Number
isObjecterrorMessagechecks if value is an OBJECT
isEmptyerrorMessagechecks if value is an EMPTY
isAlphanumericerrorMessagechecks if value is Alphanumeric
isEmailerrorMessagechecks if value is valid Email
isPhoneNumbererrorMessagechecks if value is valid Phone Number
isUSAZipCodeerrorMessagechecks if value is valid USA Zip Code
maxLengthmaxNumber, errorMessagechecks if value exceeds max length
minLengthminNumber, errorMessagechecks if value is below min length
maxValuemaxNumber, errorMessagechecks if value exceeds max number value
minValueminNumber, errorMessagechecks if value is below min number value
customRegex regex, errorMessagepass in a custom regex
customValidation cb, errorMessagepass in a custom call back that returns a Boolean False if there is an error True is there is not an error
import { EzValidation } from "ez-validation";

val = "asdf";
EzValidation(val).customValidation(
  val => (val == "asdf" ? false : true),
  "Please enter valid response"
).errorMessage;
// output = "Please enter valid response"

val = 123;
EzValidation(val)
  .isNumber("I am not a number")
  .maxValue(100, "Too large").errorMessage;
// output = "Too large"

val = "I am a large string";
EzValidation(val)
  .isString()
  .maxLength(4)
  .required().errorMessage;
// output = "Exceeds maximum length of  4"

val = "I am a large string";
EzValidation(val, "DEFAULT ERROR")
  .isString()
  .maxLength(4)
  .required().errorMessage;
// output = "DEFAULT ERROR"
import { schemaValidation } from "ez-validations";

const values = {
  noValidation: "hi",
  email: "fake-email",
  name: "im a cow"
};

const schema = {
  email: (val: string) =>
    EzValidation(val)
      .isEmail()
      .required().errorMessage,
  name: (val: string) => EzValidation(val).maxLength(2).errorMessage
};
schemaValidation(values, validationSchema);
/* output: {
  email: "not a valid email",
  name: "name length too long"
}
*/
import { schemaValidation } from "ez-validations";

const values = {
  noValidation: "hi",
  email: "fake-email",
  name: "im a cow"
};

const schema = {
  email: {
    validate: (val: string) =>
      EzValidation(val)
        .isEmail()
        .required().errorMessage
  },
  name: {
    validate: (val: string) => EzValidation(val).maxLength(2).errorMessage
  }
};
schemaValidation(values, schema, "validate");
/* output: {
  email: "not a valid email",
  name: "name length too long"
}
*/
import { EZValidationAPI } from "ez-validation";

class CustomEzValidation extends EZValidationAPI {
  customMethod() {
    if (this.validating == 0) {
      this._returnError("value can't be 0");
    }
    return this;
  }
}
new CustomEZValidation(0).customMethod().errorMessage;
// "value can't be 0"
1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.11

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago