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

check-modify

v1.0.3

Published

Simple text checkers and modifiers for forms

Downloads

8

Readme

check-modify

Simple text checkers and modifiers for forms.

Build Status

Installation

npm install --save check-modify

If you are using React

You may be interested in using these checkers/modifiers with the validating higher order component from the react-validating-controlled NPM package.

Using both, you can quickly create custom components for text inputs/areas, selects, radios, and checkboxes, as well as more complicated custom components.

What's a checker/modifier?

Checkers and modifiers are function generators of functions that take a single String argument (the text to check or modify).

Checkers generate functions that return a Boolean value indicating whether the String argument passes some criterion.

Validators generate functions that return a String value transformation of the String argument

Function signatures

Checker: function(any) --> function(String) --> Boolean

Modifier: function(any) --> function(String) --> String

Example

import { CharacterLimitChecker, CharacterLimitModifier } from 'check-modify';

const checker = CharacterLimitChecker(5);
console.log( checker("abc")     ); // prints "true"
console.log( checker("abcdefg") ); // prints "false"

const modifier = CharacterLimitModifier(5);
console.log( modifier("abc")     ); // prints "abc"
console.log( modifier("abcdefg") ); // prints "abcde"

Note: Currently, there is no option to reference a minified version directly. Rather, import/require the modules you need.

Quick reference

Composition

You can compose any number of checkers and modifiers, including with checkers and modifiers you write yourself. What is actually composed is the generated functions, not the function generators.

Composing checkers

import { composeCheckers, CharacterLimitChecker, MinimumCharacterLimitChecker } from 'check-modify';

const upperChecker = CharacterLimitChecker(8);
const lowerChecker = MinimumCharacterLimitChecker(4);
const composed = composeCheckers(upperChecker, lowerChecker);

console.log( composed("abc")        ); // prints "false"
console.log( composed("abcde")      ); // prints "true"
console.log( composed("abcdefghij") ); // prints "false"

Composing modifiers

import { composeModifiers, CharacterLimitModifier } from 'check-modify';

const Repeater = function() {
  return function(text) {
    return text + text;
  };
};
const truncator = CharacterLimitModifier(2);
const composed = composeModifiers(truncator, Repeater(), Repeater());

console.log( composed("abcdefghij") ); // prints "abababab"

Note: Composed modifiers are applied in order.

Provided checkers and modifiers

For more details about each provided checker and modifier, check the tests accompanying each.

| Checker name (and arguments) | Description
| -------------------------------------- | --------------------------------------------------------------- | CharacterLimitChecker(limit) | Is text shorter than limit characters? | MinimumCharacterLimitChecker(limit) | Is text longer than limit characters? | CurrencyChecker() | Does text have only currency characters (numbers, commas, periods, spaces)? | EmailChecker() | * Is text a valid email? | KeywordCountChecker(countLimit) | Are there fewer than countLimit comma separated phrases? | KeywordLengthChecker(characterLimit) | * Is each comma separated phrase shorter than characterLimit? | LinkChecker() | * Is text a valid HTTP(S) link? | ShortenedLinkChecker() | * Is text NOT a shortened link (e.g. t.co/...)? | PasswordChecker() | * Does text have at least 8 characters, containing at least one letter and number? | PhoneNumberChecker() | * Is text a valid 10 digit phone number? | ZipCodeChecker() | * Is text a valid 5 digit zip code?

Checkers whose description begins with * are intended to be used as a final check on input values just before form submission. The rest are intended to be used to check whether text changes in an input should be allowed to happen.

| Modifier name (and arguments) | Description
| ---------------------------------- | --------------------------------------------------------------- | CharacterLimitModifier(limit) | Truncates text to limit characters | CurrencyOnChangeModifier() | Places commas in correct locations, and enforces max 2 decimal digits | CurrencyOnBlurModifier(maxValue) | Adds a decimal point if needed, fills out any missing zeros, and limits value to maxValue | KeywordOnChangeModifier() | Strips all characters except letters, numbers, ",", "-", and " " | KeywordOnBlurModifier() | Reformats valid keywords with ", " separator | PhoneNumberOnChangeModifier() | Strips all characters except numbers, "-", " ", "(", and ")" | PhoneNumberOnBlurModifier() | Formats 10 digit phone numbers like (123) 456-7890 | ZipCodeOnChangeModifier() | Strips all characters except numbers and "-" | ZipCodeOnBlurModifier() | Keeps up to 5 numeric characters preceeding the first "-"

Modifer names sometimes include either OnChange or OnBlur to indicate the intended use of the modifier with text inputs.

Contributing

Setup

You will want to clone the repository and npm install.

Testing

npm test: Tests all modules

Branch pushes to Github will trigger CI tests on CircleCI.

Building lib

The lib directory contains transpiled code that is gets shipped. To update this directory, npm run build and commit changes.