npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

warning-message

v1.1.0

Published

A declarative way to return warning messages

Downloads

43

Readme

warning-message

Build Status Coverage Status

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.

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!

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.

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!

Advanced example with your own custom warnings

Create file where you export your custom warnings:

Note: the properties: exactly, maxChar, minChar, and not 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:

date

This function returns a warning for a date.

warningMessage().date(); // The input has to be valid date format!
warningMessage().date('custom message'); // custom message

datetime

This function returns a warning for a datetime.

warningMessage().datetime(); // The input has to be valid datetime format!
warningMessage().datetime('custom message'); // custom message

email

This function returns a warning for an email.

warningMessage().email(); // The input has to be an email!
warningMessage().email('custom message'); // custom message

exactly

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

float

This function returns a warning for a float.

warningMessage().float(); // The input has to be a float!
warningMessage().float('custom message'); // custom message

integer

This function returns a warning for an integer.

warningMessage().integer(); // The input has to be an integer!
warningMessage().integer('custom message'); // custom message

maxChar

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

minChar

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

minMaxChar

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

not

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

number

This function returns a warning for a number.

warningMessage().number(); // The input has to be a number!
warningMessage().number('custom message'); // custom message

phonenumber

This function returns a warning for a phonenumber.

warningMessage().phonenumber(); // The input has to be a phonenumber!
warningMessage().phonenumber('custom message'); // custom message

requiredField

This function returns a warning for a required inputfield.

warningMessage().requiredField(); // This field is required!
warningMessage().requiredField('custom message'); // custom message

time

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

url

This function returns a warning for a url.

warningMessage().url(); // The input has to be a valid url!
warningMessage().url('custom message'); // custom message

validation

This function returns a warning for a validation.

warningMessage().validation(); // The input is not valid!
warningMessage().validation('custom message'); // custom message

LICENSE

MIT © Lukas Aichbauer