warning-message
A declarative way to return warning messages
Why?
Almost any project needs a warning messages. This package simplifies your workflow.
Installation
npm i -S warning-message
or
yarn add warning-message
Usage
After installation you can import the package to your project and use a declarative way return warning messages.
The return value is always a string
.
You can use the default warning messages or create your own custom warning messages.
Simple example with default warning messages
If a function takes no parameter it returns the standard message. If a function takes an parameter, it simple returns this string.
; // standard message; // The input has to be an email!// custom message // Not an email!
Advanced example with default warning messages
Some functions have 2 or more parameters. The last parameter is always a function that takes the previous parameters. You can use this function to create a custom string.
; // standard message; // The input has to be at least 3 and maximum 6 letters!// custom message; // input should have min: 3 and max: 6 letters!
Advanced example with your own custom warnings
Create file where you export your custom warnings:
Note: the properties:
exactly
,maxChar
,minChar
, andnot
can have a__VAR1__
Not: the property:
minMaxChar
can have a__VAR1__
and a__VAR2__
__VAR1__
& __VAR2__
are the additional values passed to the function. you can add them if you want but you dont have to.
const customWarnings = date: 'Custom warning: date format!' datetime: 'Custom warning: datetime format!' email: 'Custom warning: email!' exactly: 'Custom warning: exactly __VAR1__!' float: 'Custom warning: float!' integer: 'Custom warning: integer!' maxChar: 'Custom warning: max. __VAR1__ letters!' minChar: 'Custom warning: min. __VAR1__ letters!' minMaxChar: 'Custom warning: min. __VAR1__ and max. __VAR2__ letters!' not: 'Custom warning: not __VALUE__!' number: 'Custom warning: number!' phonenumber: 'Custom warning: phonenumber!' requiredField: 'Custom warning: required!' time: 'Custom warning: time format!' url: 'Custom warning: url!' validation: 'Custom warning: not valid!'; ;
In you file where you would use the warnings you can use your custom warnings like that:
;; // __VAR1__ is the first function argument// __VAR2__ is the second function argument; // Custom warning: min. 3 and max. 5 letters! ; // Custom warning: phonenumber! // __VAR1__ is the first function argument; // Custom warning: not this!
Functions:
- date
- datetime
- exactly
- float
- integer
- maxChar
- minChar
- minMaxChar
- not
- number
- phonenumber
- requiredField
- time
- url
- valid
date
This function returns a warning for a date.
; // The input has to be valid date format!; // custom message
datetime
This function returns a warning for a datetime.
; // The input has to be valid datetime format!; // custom message
This function returns a warning for an email.
; // The input has to be an email!; // custom message
exactly
This function returns a warning for an value that do not match exactly a target.
; // The input has to be exactly like target!; // custom message target
float
This function returns a warning for a float.
; // The input has to be a float!; // custom message
integer
This function returns a warning for an integer.
; // The input has to be an integer!; // custom message
maxChar
This function returns a warning for a value that exceeds a target.
; // The input has to be max. 6 letters!; // custom message 6
minChar
This function returns a warning for a value that has less character than a target.
; // The input has to be min. 3 letters!; // custom message 3
minMaxChar
This function returns a warning for a value that has less character than a target and eceeds a second target.
; // The input has to be min. 3 and max. 6 letters!; // custom message 3 and 6
not
This function returns a warning for a value that is not alowed.
; // The input is not allowed to be: value!; // custom message value
number
This function returns a warning for a number.
; // The input has to be a number!; // custom message
phonenumber
This function returns a warning for a phonenumber.
; // The input has to be a phonenumber!; // custom message
requiredField
This function returns a warning for a required inputfield.
; // This field is required!; // custom message
time
This function returns a warning for a time.
; // The input has to be a valid time format!; // custom message
url
This function returns a warning for a url.
; // The input has to be a valid url!; // custom message
validation
This function returns a warning for a validation.
; // The input is not valid!; // custom message
LICENSE
MIT © Lukas Aichbauer