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

@jdlien/validator-utils

v1.2.7

Published

Validation and sanitization functions used by @jdlien/Validator.

Downloads

23

Readme

Validator Utils

Introduction

This package is a library of utility functions that can be used for validating and sanitizing strings and numbers, especially for use in forms. This package is the dependency for the @jdlien/validator package.

This package was separated from Validator so that it could be used in other projects without pulling in the entire Validator package if you only need some of its validation and parsing functions without the form validation and error message functionality.

Installation

npm install @jdlien/validator-utils

# or

yarn add @jdlien/validator-utils

Utility Functions

Validator includes several utility functions that may be useful in your own code, so they are exported as part of the module. If you wish to use these, you may import the functions directly from the module as an object that contains all the functions:

import * as validatorUtils from '@jdlien/validator'
// you could assign the functions you need to more convenient variables
const { dateFormat, formatDateTime } = validatorUtils

Here is a list of the utility functions:

  • isFormControl: Determines if an element is an HTML input, select, or textarea element.
  • isType: Checks if an element has a type or data-type attribute matching one of the passed values.
  • momentToFPFormat: Converts a moment.js-style format string to the flatpickr format.
  • monthToNumber: Converts month string or number to a zero-based month number (January == 0).
  • yearToFull: Converts a year string or number to a 4-digit year.
  • parseDate: Parses a date string or Date object into a Date object.
  • parseTime: Parses a time string into an object with hour, minute, and second properties.
  • parseTimeToString: Parses a time string into a formatted string.
  • formatDateTime: Formats a date string or Date object into a string with a specified format.
  • parseDateToString: Parses a date string or Date object into a formatted string with the specified moment.js-style date format.
  • isDate: Determines if a value is a valid date.
  • isDateInRange: Determines if a date falls within a specified range (either past or future).
  • isTime: Determines if a value is a valid time.
  • isEmail: Determines if a value is a valid email address.
  • parseNANPTel: Parses a North American phone number string into a standardized format.
  • isNANPTel: Determines if a value is a valid North American phone number.
  • parseInteger: Parses an integer string into a standardized format.
  • isNumber: Determines if a value is a valid number.
  • parseNumber: Parses a number string into a standardized format.
  • isInteger: Determines if a value is a valid integer.
  • parseUrl: Parses a URL string into a standardized format.
  • isUrl: Determines if a value is a valid URL.
  • parseZip: Parses a zip code string into a standardized format.
  • isZip: Determines if a value is a valid zip code.
  • parsePostalCA: Parses a Canadian postal code string into a standardized format.
  • isPostalCA: Determines if a value is a valid Canadian postal code.
  • isColor: Determines if a value is a valid color.
  • parseColor: Parses a color string into a standardized format.
  • normalizeValidationResult: Normalizes a validation result (like a boolean or string) into an object with a valid property and a messages array of strings.

Contributing

Install dev dependencies:

npm install

When running Vite, you may get an error like

Module did not self-register: '...\node_modules\canvas\build\Release\canvas.node'

If that happens, you need to install the canvas module manually: bash npm rebuild canvas --update-binary