New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

es6-javascript-validators

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-javascript-validators

An ES6 module with various methods and exports for validating variables in JavaScript.

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

es6-javascript-validators

Stop for a second. Do you see this a lot in your code?:

	if (typeof var1 === 'string' && var1.length > 0) {
		// other code here...
	}

I see it all the time -- and in tons of places too. Or, my favorite:

	if (typeof var2 === 'object' && var2 !== null) {
		// but what if it's an empty object?
	}

Well, lets collectively stop that. Lets use simple functions to do that for us! es6-javascript-validators is a collection of functions which will do all of this for you and keep your code consistent and clean.

Available Methods

  • isNullOrUndefined: Is it null or undefined?
  • isStr: Is it a string?
  • isArr: Is it an array?
  • isNum: Is it a number?
  • isObj: Is it an object?
  • isFnc: Is it a function?
  • validStr: Is it a string and not an empty one?
  • validArr: Is it an array and not an empty one?
  • validNum: Is it a number and greater than 0?
  • validObj: Is it an object and not an empty one?
  • ...Or, if you want all of them, just export the default object which contains all of the above.

Import specific functions


	import { isStr, isObj } from 'your/path/to/module.js';

	console.log(isStr('')); // true
	console.log(isStr([])); // false
	console.log(isStr(null)); // false
	console.log(isStr(0)); // false

	console.log(isObj('')); // false
	console.log(isObj([])); // false
	console.log(isObj(null)); // false
	console.log(isObj({})); // true

Import all utils


	import Util from 'your/path/to/module.js';

	console.log(Util.isObj({})); // true
	console.log(Util.validObj({})); // false
	console.log(Util.validObj({ a:1, b:2 })); // true

	console.log(Util.isStr('')); // true
	console.log(Util.validStr('')); // false

	console.log(Util.isArr([])); // true
	console.log(Util.validArr([1, 2, 3])); // true

	//.. and so on

Keywords

FAQs

Package last updated on 03 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc