Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
warning-message
Advanced tools
Readme
A declarative way to return warning messages
Almost any project needs a warning messages. This package simplifies your workflow.
npm i -S warning-message
or
yarn add warning-message
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.
If a function takes no parameter it returns the standard message. If a function takes an parameter, it simple returns this string.
import warningMessage from 'warning-message';
// standard message
warningMessage().email(); // The input has to be an email!
// custom message
warningMessage().email('Not an email!') // Not an email!
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.
import warningMessage from 'warning-message';
// standard message
warningMessage().minMaxChar(3, 6); // The input has to be at least 3 and maximum 6 letters!
// custom message
warningMessage().minMaxChar(3, 6, (min, max) => `input should have min: ${min} and max: ${max} letters`); // input should have min: 3 and max: 6 letters!
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!',
};
export default customWarnings;
In you file where you would use the warnings you can use your custom warnings like that:
import warningMessage from 'warning-message';
import customWarnings from 'path/to/your/customWarnings';
// __VAR1__ is the first function argument
// __VAR2__ is the second function argument
warningMessage(customWarnings).minMaxChar(3, 5); // Custom warning: min. 3 and max. 5 letters!
warningMessage(customWarnings).phonenumber(); // Custom warning: phonenumber!
// __VAR1__ is the first function argument
warningMessage(customWarnings).not('this'); // Custom warning: not this!
Functions:
This function returns a warning for a date.
warningMessage().date(); // The input has to be valid date format!
warningMessage().date('custom message'); // custom message
This function returns a warning for a datetime.
warningMessage().datetime(); // The input has to be valid datetime format!
warningMessage().datetime('custom message'); // custom message
This function returns a warning for an email.
warningMessage().email(); // The input has to be an email!
warningMessage().email('custom message'); // custom message
This function returns a warning for an value that do not match exactly a target.
warningMessage().exactly('target'); // The input has to be exactly like target!
warningMessage().exactly('target', (target) => `custom message ${target}`); // custom message target
This function returns a warning for a float.
warningMessage().float(); // The input has to be a float!
warningMessage().float('custom message'); // custom message
This function returns a warning for an integer.
warningMessage().integer(); // The input has to be an integer!
warningMessage().integer('custom message'); // custom message
This function returns a warning for a value that exceeds a target.
warningMessage().macChar(6); // The input has to be max. 6 letters!
warningMessage().maxChar(6, (max) => `custom message ${mex}`); // custom message 6
This function returns a warning for a value that has less character than a target.
warningMessage().minChar(3); // The input has to be min. 3 letters!
warningMessage().minChar(3, (min) => `custom message ${min}`); // custom message 3
This function returns a warning for a value that has less character than a target and eceeds a second target.
warningMessage().minMaxChar(3, 6); // The input has to be min. 3 and max. 6 letters!
warningMessage().minMaxChar(3, 6, (min, max) => `custom message ${min} and ${max}`); // custom message 3 and 6
This function returns a warning for a value that is not alowed.
warningMessage().not('value'); // The input is not allowed to be: value!
warningMessage().not('value', (value) => `custom message ${value}`); // custom message value
This function returns a warning for a number.
warningMessage().number(); // The input has to be a number!
warningMessage().number('custom message'); // custom message
This function returns a warning for a phonenumber.
warningMessage().phonenumber(); // The input has to be a phonenumber!
warningMessage().phonenumber('custom message'); // custom message
This function returns a warning for a required inputfield.
warningMessage().requiredField(); // This field is required!
warningMessage().requiredField('custom message'); // custom message
This function returns a warning for a time.
warningMessage().time(); // The input has to be a valid time format!
warningMessage().time('custom time warning message'); // custom message
This function returns a warning for a url.
warningMessage().url(); // The input has to be a valid url!
warningMessage().url('custom message'); // custom message
This function returns a warning for a validation.
warningMessage().validation(); // The input is not valid!
warningMessage().validation('custom message'); // custom message
MIT © Lukas Aichbauer
FAQs
A declarative way to return warning messages
We found that warning-message demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).