96jd-error-handler-utils
v18.0.5
Published
Utility for error handling
Downloads
117
Maintainers
Readme
96jd-error-handler-utils
Installation
NPM
npm install 96jd-error-handler-utils
YARN
yarn add 96jd-error-handler-utils
PNPM
pnpm add 96jd-error-handler-utils
BUN
bun add 96jd-error-handler-utils
Getting started
import {
fieldCanNotBeEmpty,
fieldMustBeAtLeastLength,
fieldMustBeAtMaxLength,
fieldMustBeBetweenLengths,
fieldMustMatchDigitsLength,
formHasErrors,
getErrorMessageByHttpStatus
} from "96jd-error-handler-utils";
console.log(fieldCanNotBeEmpty("First Name"));
console.log(fieldMustMatchDigitsLength("Person Number", 11));
console.log(fieldMustBeAtLeastLength("Description", 50));
console.log(fieldMustBeAtMaxLength("Title", 50));
console.log(fieldMustBeBetweenLengths("Phone number", 8, 20));
console.log(getErrorMessageByHttpStatus(400));
console.log(getErrorMessageByHttpStatus(401, "en"));
console.log(getErrorMessageByHttpStatus(403, "no"));
const errors = {
personNumber: "Error 1",
firstName: "Error 2",
lastName: "Error 3",
phoneNumber: "Error 4",
address: "Error 5",
password: "Error 6",
confirmPassword: "Error 7"
};
formHasErrors(errors) ? console.log(errors) : {};