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

vdck

v1.3.0

Published

Vdck is a TypeScript/CJS library providing validation functions for various primitive data types

Downloads

109

Readme

VDCK

Vdck is a TypeScript/CJS package that providing primitive data validation functions. Its key features includes:

  • Comprehensive Validation: Check arrays, strings, numbers, objects, keys' values, and handle null/undefined values.
  • Time-Saving: Simplifies type checking in TypeScript, reducing development time.
  • Efficient: Lightweight utility with a minimal footprint of just 26.0 KB.
  • Compatibility: Fully compatible with Node.js versions >= 6.0.0.

Summary

Updates

v 1.3:

  • isKeyInObject function's parameters fixed, null/undefined/empty values are now excluded

v 1.2:

  • isObject type check error fixed, null is now excluded

v 1.1:

  • Added the isEmail function to validate email addresses
  • Delete unnecessary arrays check on isKeyInObject
  • Added another param to to isNumber => 'a' => it checks that is a number without a specific tag (int or float)
  • Edit/delete comments and README.md

Install

To get started with vdck, simply install the npm package:

npm i vdck

Import

It can be imported both as ES6 or as CommonJS module

// Node > ES6
import vdck from 'vdck';

// Node > CommonJS
const vdck = require('vdck');

Functions

The following is a brief description of which functions vdck contains:

isArray

Check if the given input is a valid array based on function's parameters:

  • value {any} - Any value to check.
  • minLength {number} - (default: 0) - Minimum array length.
  • maxLength {number} - (default: 5000) - Maximum array length.
  • showErrors {boolean} - (default: false) - Should it prints error message on the CLI?
// Node > CommonJS
vdck.isArray(["Hello", " world", "!"]);

// Node > ES6
isArray(["Hello", " world", "!"]);

isString

Check if the given input is a valid string based on function's parameters:

  • value {any} - Any value to check.
  • trim {boolean} - (default: true) - Should it trims the given value before checking it?
  • minLength {number} - (default: 0) - Minimum string length.
  • maxLength {number} - (default: 5000) - Maximum string length.
  • regex {RegExp | null} - (default: null) - Check regular expression to validate the string.
  • showErrors {boolean} - (default: false) - Should it prints error message on the CLI?
// Node > CommonJS
vdck.isString("Ciao!", true, 0, 100, /^[a-zA-Z0-9]+$/gm);

// Node > ES6
isString("Ciao!", true, 0, 100, /^[a-zA-Z0-9]+$/gm);

isEmail

Check if the given input is a valid email address based on function's parameters:

  • value {any} - Any value to check.
  • trim {boolean} - (default: true) - Should it trims the given value before checking it?
  • regex {RegExp | null} - (default: null) - Check regular expression to validate the email address.
  • showErrors {boolean} - (default: false) - Should it prints error message on the CLI?
// Node > CommonJS
vdck.isEmail("[email protected]");

// Node > ES6
isEmail("[email protected]");

isKeyInObject

isKeyInObject function has default values for its options' parameters:
maxLength: number = 40000;
minLength: number = 0;
regx: RegExp | null = null;
type: -1 | 0 | 1 = 0;
trim: boolean = true;

Check if the given key exists within the given object and its value's type based on function's parameters:

  • value {Obj extends Record<string, any>} - Any value to check.
  • key {string} - Given object's key.
  • keyValueType {string} - Given object's key value.
  • options {object | null} - (default: null) - Value's key options for every type.
  • options.maxLength {undefined | number} - Value's key options for maximum length types.
  • options.minLength {undefined | number} - Value's key options for minimum length.
  • options.numberType {undefined | string} - Value's key options for number's type types.
  • options.regx {undefined | RegExp | null} - Value's key options for regexp types.
  • options.type {undefined | number} - Value's key options for type's types.
  • options.trim {undefined | boolean} - Value's key options for trim types.
  • showErrors {boolean} - (default: false) - Should it prints error message on the CLI?
// Node > CommonJS
vdck.isKeyInObject({ "Hi": 2 }, 'Hi', 'n');

// Node > ES6
isKeyInObject({ "Hi": 2 }, 'Hi', 'n');

isNotUndefinedNull

Check if the given input is not undefined nor null based on function's parameter:

  • value {any} - Any value to check.
// Node > CommonJS
vdck.isNotUndefinedNull(false);

// Node > ES6
isNotUndefinedNull(false);

isNumber

Check if the given input is a valid number based on function's parameters:

  • value {any} - Any value to check.
  • numberType {number} - (default: 'i') - Should it be an int or a float? 'a' -> all | 'i' -> int | 'f' -> float.
  • type {number} - (default: 0) - Should it be a real number, a positive number, or a negative number?
  • showErrors {boolean} - (default: false) - Should it prints error message on the console?
// Node > CommonJS
vdck.isNumber(21, 'i', 1);

// Node > ES6
isNumber(21, 'i', 1);

isObject

Check if the given input is a valid object based on function's parameters:

  • value {any} - Any value to check.
  • minLength {number} - (default: 0) - Minimum keys length.
  • maxLength {number} - (default: 5000) - Maximum keys length.
  • showErrors {boolean} - (default: false) - Should it prints error message on the console?
// Node > CommonJS
vdck.isObject({}, 0, 1, true);

// Node > ES6
isObject({}, 0, 1, true);

Funding

If you liked this package, consider funding it at @PayPal (the link is within package.json too)

Author

Frash | Francesco Ascenzi (@fra.ascenzi on IG)

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.