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

livesey-validation

v1.0.2

Published

A lightweight and simple validation module for JavaScript, providing essential utilities for data validation.

Downloads

65

Readme

🧙‍♂️ livesey-validation 🧙‍♂️

Build Status License Version

🖊️ Description

livesey-validation is a lightweight and simple JavaScript module designed for data validation. It provides essential utilities for validating common data types such as booleans, dates, numbers, and strings. Ideal for environments where data validation is crucial, such as form validation or data processing tasks.

📌 Table of Contents

  1. Installation
  2. Usage
  3. API Documentation
  4. Contributing
  5. License
  6. Authors and Contacts

Installation

To install the livesey-validation module, use npm:

npm install livesey-validation

Usage

Booleans

import { Booleans } from 'livesey-validation';

try {
  console.log(Booleans.parseEnvValue('true').isBoolean().isTrue().getValue()); // true
} catch (error) {
  console.error(error.message);
}

Dates

import { Dates } from 'livesey-validation';

try {
  console.log(Dates.parseEnvValue('2024-08-30').isValidDate().isFormat('YYYY-MM-DD').getValue()); // '2024-08-30'
} catch (error) {
  console.error(error.message);
}

Numbers

import { Numbers } from 'livesey-validation';

try {
  console.log(Numbers.parseEnvValue('42').isInt().isNonNegative().getValue()); // 42
} catch (error) {
  console.error(error.message);
}

Strings

import { Strings } from 'livesey-validation';

try {
  console.log(Strings.isEmail('[email protected]').max(30).getValue()); // Pass: Valid email
} catch (error) {
  console.error(error.message);
}

API Documentation

Booleans

  • Booleans.parseEnvValue(value: string): Booleans

    Parses a string value to a boolean. Throws an error if the value is not "true" or "false".

  • isBoolean(): Boolean

    Validates that the internal value is a boolean.

  • isTrue(): Booleans

    Validates that the internal value is true.

  • isFalse(): Booleans

    Validates that the internal value is false.

  • getValue(): boolean

    Returns the internal boolean value.

Dates

  • Dates.parseEnvValue(value: string, format: string = 'YYYY-MM-DD'): Dates

    Parses a string value into a date and checks it against the specified format.

  • isValidDate(): Dates

    Validates that the internal value is a valid date.

  • isFormat(format: string): Dates

    Validates that the date matches the specified format.

  • isBefore(date: string): Dates

    Validates that the internal date is before the specified date.

  • isAfter(date: string): Dates

    Validates that the internal date is after the specified date.

  • isInRange(startDate: string, endDate: string): Dates

    Validates that the internal date is within the specified date range.

  • getValue(): string

    Returns the internal date string.

Numbers

  • Numbers.parseEnvValue(value: string | number): Numbers

    Parses a value to a number. Throws an error if the value cannot be parsed.

  • isInt(): Numbers

    Validates that the internal value is an integer.

  • isBigInt(): Numbers

    Validates that the internal value is a BigInt.

  • isFloat(): Numbers

    Validates that the internal value is a floating-point number.

  • isPositive(): Numbers

    Validates that the internal number is positive.

  • isNonNegative(): Numbers

Validates that the internal number is non-negative.

  • isNegative(): Numbers

Validates that the internal number is negative.

  • isNonPositive(): Numbers

Validates that the internal number is non-positive.

  • isNaN(): Numbers

Validates that the internal value is NaN.

  • isInfinity(): Numbers

Validates that the internal value is Infinity.

  • getValue(): number

Returns the internal number value.

Strings

  • Strings.isString(value: string): Strings

Validates that the value is a string.

  • min(length: number): Strings

Validates that the string's length is at least the specified length.

  • max(length: number): Strings

Validates that the string's length is no more than the specified length.

  • exactly(length: number): Strings

Validates that the string's length is exactly the specified length.

  • isEmail(value: string): Strings

Validates that the string is a valid email address.

  • isUrl(value: string): Strings

Validates that the string is a valid URL.

  • isIp(value: string): Strings

Validates that the string is a valid IP address.

  • isPhone(value: string): Strings

Validates that the string is a valid phone number.

  • isUUID(value: string): Strings

Validates that the string is a valid UUID.

  • isTime(value: string): Strings

Validates that the string is a valid time in the format HH.

  • getValue(): string

Returns the internal string value.

Contributing

We welcome contributions! If you encounter any bugs or have suggestions for improvements, please open an issue on GitHub.

Reporting Issues

If you find a bug, please report it by opening an issue here.

Code of Conduct

Please adhere to our Code of Conduct when contributing.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Authors and Contacts

  • Heorhii Huziuk - Lead Developer - [email protected]

    Special thanks to everyone who contributed to this project!❤️