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

ds-validator-toolkit

v1.0.31

Published

<p align="center"> <img src="https://raw.githubusercontent.com/daniseifeddine/Ds-Validator-Toolkit/main/media/logo.png" alt="Logo" width="450"> </p>

Downloads

14

Readme

Validator Toolkit

A comprehensive toolkit for data validation in JavaScript.

Description

Validator Toolkit provides a set of tools and utilities to validate various types of data, including strings, numbers, arrays, and objects. Whether you're building a web application, API, or any other software that deals with user input, Validator Toolkit can help ensure that your data meets the required criteria.

Installation and Usage

Server-side

To install Validator Toolkit using npm, run the following command:

npm install ds-validator-toolkit

Browser Usage (ESM)

You can use Validator Toolkit directly in the browser without installing it by importing the desired functions from the unpkg.com CDN:

<script type="module">
  // inporting package from the URL
  import { VALIDATE_STRING } from "https://unpkg.com/ds-validator-toolkit/dist/index.mjs";

  let name = VALIDATE_STRING.validateString("Mareline", {
    // options...
  });

  console.log(name);
</script>

ES6 Modules

If you're using ES6 modules in your project, you can import the desired functions from the package:

import {
  _STR_,
  VALIDATE_STRING,
} from "./node_modules/ds-validator-toolkit/dist/index.mjs";

Add this line in your html file

<script src="./app.js" type="module"></script>

Webpack Integration

If you're using Webpack, you can easily integrate Validator Toolkit into your project. Follow these steps:

1- Initialize a new npm project using:

npm init -y

2- Install the required dependencies:

npm install webpack webpack-cli babel-loader @babel/core @babel/preset-env --save-dev

3-Create a webpack.config.js file with the following configuration:


const path = require('path');

module.exports = {
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js',
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env'],
                    },
                },
            },
        ],
    },
};

</script>

4- Create a src folder and an index.js file within it. You can import the desired functions from the package in this file:

import { _STR_, VALIDATE_STRING } from "ds-validator-toolkit";

5- In your HTML file, include the bundled JavaScript file:

<script src="./dist/bundle.js" type="module"></script>

6- Run npm run build to generate the bundled JavaScript file (dist/bundle.js).

With these steps, you should be able to use Validator Toolkit in your Webpack project.

Example 1: Using VALIDATE_STRING

Here's an example demonstrating the VALIDATE_STRING function with various options:

const name = "Chloe";
const result = VALIDATE_STRING(name, {
  // Options
  isRequired: true,
  minStringLength: 10,
  maxStringLength: 20,
  // ...

  // Error Messages
  isStringError: "Input must be a string.",
  lengthError: "Input length must be between 10 and 20 characters.",
  // ...
});

console.log(result); // { isValid: false, message: "Input length must be between 10 and 20 characters." }

This example showcases the VALIDATE_STRING function with the specified options and custom error messages.

Example 2: Using STR Class

const name = "flower";

// Check if the string is required
_STR_.isRequired(name, true);

// Check if the string contains blacklisted words
const result = _STR_.containsBlacklistedWord(name, ["flower", "garden"]);

console.log(result); // { isValid: false, message: "Name contains blacklisted words." }

The STR class provides various functions for string validation, making it easy to perform specific checks on strings.

What's New

available options:

isRequired, maxValue, minValue, isInteger, allowNegative = true, allowPositive = true, allowZero = true, onlyDecimal, maxDecimalPlaces, minDecimalPlaces, allowExponent, onlyBinary thousandSeperator customThousandSeperator customValidationFn (NEW!!!)

Future

allowCurrencySymbol

Validators

Here is a list of the validators currently available.

| Validator | Description | | --------------------------------------- | ----------------------------------------------- | | VALIDATE_STRING(string, option= {}) | validate string based on built in option | | STR : class | a class that provide String validation function | | | | | VALIDATE_NUMBER(string, option= {}) | validate number based on built in option | | NUM : class | a class that provide number validation function |