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 🙏

© 2025 – Pkg Stats / Ryan Hefner

datatype-validation

v1.3.6

Published

check the data type or change the data type

Readme

Datatype Validation

An npm utility package to make it easier to check data types such as string, number, boolean and more in JavaScript

Installation

Install with npm

npm install datatype-validation

or connect with CDN

https://www.unpkg.com/datatype-validation@latest/datatype.js

Import

With Require

const datatype = require('datatype-validation');

Connect with CDN

<script src="https://www.unpkg.com/datatype-validation@latest/datatype.js" type="text/javascript"></script>

Usage

To use existing functions, use datatype.functionName(value), here is an example of its use:

Check data type

String

datatype.isString("test"); //This will return true, because the value entered is a string

datatype.isString(123); //This will return false, because the value entered is not a string but a number

Number

datatype.isInt(123); //This will return true, because the value entered is a number

datatype.isInt("lol"); //This will return false, because the value entered is a string, not a number

datatype.isInt(123.4); //This will return false, because the value entered is a decimal number, not an integer number


datatype.isFloat(123.4); //This will return true, because the value entered is a decimal number

datatype.isFloat(123); //This will return false, because the value entered is not a decimal number but an integer number

Boolean

datatype.isBoolean(false); //This will return true, because the value entered is a boolean, not a string or number


datatype.isBoolTrue(true); //This will return true, because the value entered is a boolean that contains the value true not false


datatype.isBoolFalse(true); //This will return false, because the value entered is a boolean that contains the value true, not false

DateTime

datatype.isDate("18-11-2023"); //This will return true, because the value entered is in date format

datatype.isDate(18-11-2023); //This will return false, because to do this it must be in string format

//You can do this in any delimiter/combiner for example I used (-) you can also use spaces or whatever you think is suitable

//Example:
datatype.isDate("18 11 2023");
datatype.isDate("18~11~2023");
datatype.isDate("18:11:2023");


datatype.isTime("10:30:58"); //This will return true, because the value entered is in time format

datatype.isTime(10:36:25); //This will return false, because to do this it must be in string format

//You can do this in any delimiter/combiner for example I used (:) you can also use spaces or whatever you think is suitable

//Example:
datatype.isTime("10-38-40"); 
datatype.isTime("10 39 50"); 
datatype.isTime("10|42|30"); 


datatype.isDateTime("18-11-2023 10:45:15"); //This will return true, because the value entered is in date and time format

datatype.isDateTime(18-11-2023 10:48:56); //This will return false, because to do this it must be in string format

//You can do this in any delimiter/combiner for example I used (- and :) you can also use spaces or whatever you think is suitable

//Example:
datatype.isDateTime("18 11 2023 10 57 59");
datatype.isDateTime("18/11/2023 10-58-35");
datatype.isDateTime("18:11:2023 11-14-06");

Other

datatype.isDomain('example.com'); //This will return true, because the value entered is valid domain

datatype.isDomain('https://lol.net'); //This also result the value true

datatype.isDomain('http://lol.xyz'); //This also result the value true

datatype.isDomain('https://blog.lol.com'); //This also result the value true

datatype.isDomain('https://blog.lol.i'); //This will return false, because the domain extension is invalid


datatype.isIPAddress('192.168.1.1'); //This will return true

datatype.isIPAddress(192.168.1.1); //This will return false, because javascript thinks this is a mathematical operation

Change data type

String

datatype.toString(1234); //This will return a value in the form of string "1234"

Number

datatype.toInt("12.5"); //This will convert the string float value to int (12)

datatype.toFloat(25); //This will convert the value int (25) to float (25.0)
Boolean
datatype.toBoolean("lol"); //This will convert or return boolean value true

datatype.toBoolean(""); //This will convert or return boolean value false

datatype.toBoolean(1); //This will convert or return boolean value true, if value number > 0

datatype.toBoolean(0); //This will convert or return boolean value false, if value number < 0

List

| Function | Description | | :--------------------- | :----------------------------------------------- | | isString(value) | to check whether the value entered is a string or not | | isInt(value) | to check whether the value entered is a number or not | | isFloat(value) | to check whether the value entered is a decimal number or not | | isBoolean(value) | to check whether the value entered is a boolean or not | | isBoolTrue(value) | to check whether the value entered is a boolean containing the value true or false | | isBoolFalse(value) | to check whether the value entered is a boolean containing the value false or true | | isDate(value) | to check whether the value entered is dd-mm-yyyy or not | | isTime(value) | to check whether the value entered is hh-mm-ss or not | | isDateTime(value) | to check whether the value entered is dd-mm-yyyy hh-mm-ss or not | | isDomain(value) | to check whether the value entered is valid domain or not | | isIPAddress(value) | to check whether the value entered is valid ipaddress or not | | toString(value) | converts the input value into a string | | toInt(value) | converts the input value into a int | | toFloat(value) | converts the input value into a float | | toBoolean(value) | converts the input value into a boolean value |