Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

types.js

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

types.js - npm Package Compare versions

Comparing version 1.2.3 to 1.2.4

test/test.coffee

2

package.json
{
"name": "types.js",
"version": "1.2.3",
"version": "1.2.4",
"description": "A tiny Javascript type-check library",

@@ -5,0 +5,0 @@ "main": "types.min.js",

@@ -10,4 +10,4 @@ types.js

`(NaN !== NaN) == true` still freakes me out, I just don't like to see that kind of stuff in my code.
With types.js I can now test NaN with: `Types.isNaN(NaN)` or `Types.typeof( parseInt('Not A Number!') ) === 'nan'`,
Standard Javascript `(NaN !== NaN) == true` still freakes me out, I just don't like to see that kind of stuff in
my code. With types.js I can now test NaN with: `Types.isNaN(NaN)` or `Types.typeof( parseInt('Not A Number!') ) === 'nan'`,
both will return true.

@@ -50,9 +50,10 @@

_.forceString(); // (empty String)
_.forceString( null, 'ok' ); // ok (as String)
_.forceString( null, [1, 2, 3] ); // (empty String (== default literal) )
_.forceString(33); // 33 (as String)
_.forceNumber('35px'); // 35 (as Number)
_.forceNumber( true, function(){} ); // 0 (as Number)
_.forceBoolean('35px'); // false (as Boolean)
var x;
x= _.forceString(); // (empty String)
x= _.forceString( null, 'ok' ); // ok (as String)
x= _.forceString( null, [1, 2, 3] ); // (empty String (== default literal) )
x= _.forceString(33); // 33 (as String)
x= _.forceNumber('35px'); // 35 (as Number)
x= _.forceNumber( true, function(){} ); // 0 (as Number)
x= _.forceBoolean('35px'); // false (as Boolean)

@@ -70,32 +71,32 @@ MyObject= function( data ){

_.forceFunction( invalidMethod, /regexp/ )(); // (default empty/nop function is called)
x= _.forceFunction( invalidMethod, /regexp/ )(); // (default empty/nop function is called)
_.isString( 'Hello types.js!' ); // true
_.isString( 23456 ); // false
_.isBoolean( false ); // true
_.isArray( [1,2,3] ); // true
_.isObject( [1,2,3] ); // false
_.isObject( /myRegExp/g ); // false
_.isNaN( parseInt('generate NaN') ); // true
x= _.isString( 'Hello types.js!' ); // true
x= _.isString( 23456 ); // false
x= _.isBoolean( false ); // true
x= _.isArray( [1,2,3] ); // true
x= _.isObject( [1,2,3] ); // false
x= _.isObject( /myRegExp/g ); // false
x= _.isNaN( parseInt('generate NaN') ); // true
_.notNull(''); // true
_.notUndefined( undefined ); // false
x= _.notNull(''); // true
x= _.notUndefined( undefined ); // false
_.allString( '', " ", 'with text' ); // true
_.allString( '', ' ', 'with text', 123 ); // false
_.allStringOrNumber( '', ' ', 'with text', 123 ); // true
_.allObject( { key: 'nice' }, [], /regexp/ig ); // false
_.allArray( [1,2,3], [{}], new RegExp('stop') ); // false
_.allArray( [1,2,3], [{}], [false, true] ); // true
x= _.allString( '', " ", 'with text' ); // true
x= _.allString( '', ' ', 'with text', 123 ); // false
x= _.allStringOrNumber( '', ' ', 'with text', 123 ); // true
x= _.allObject( { key: 'nice' }, [], /regexp/ig ); // false
x= _.allArray( [1,2,3], [{}], new RegExp('stop') ); // false
x= _.allArray( [1,2,3], [{}], [false, true] ); // true
_.hasString( 123, { value: 'nice' }, ['?'] ); // false
_.hasStringOrNumber( [1,2], /reg/, 'true' ) // true
_.hasFunction( 123, { value: 'nice' }, function(){} ); // true
_.hasUndefined( 'render false!', 123, null ); // false
_.hasUndefined( 'render true!', 123, undefined ); // true
x= _.hasString( 123, { value: 'nice' }, ['?'] ); // false
x= _.hasStringOrNumber( [1,2], /reg/, 'true' ) // true
x= _.hasFunction( 123, { value: 'nice' }, function(){} ); // true
x= _.hasUndefined( 'render false!', 123, null ); // false
x= _.hasUndefined( 'render true!', 123, undefined ); // true
_.typeof( [1,2,3] ); // 'array'
_.typeof( null ); // 'null'
_.typeof( parseInt('generate NaN') ); // 'nan'
_.typeof( new Date() ); // 'date'
x= _.typeof( [1,2,3] ); // 'array'
x= _.typeof( null ); // 'null'
x= _.typeof( parseInt('generate NaN') ); // 'nan'
x= _.typeof( new Date() ); // 'date'
// etc..

@@ -119,2 +120,6 @@ ```

**Types.forceString** **Types.forceNumber** **Types.forceArray** **Types.forceObject** **Types.forceFunction**
> Just like forceBoolean, only applying the type denoted by the method name. See the forceType literals for
> the different methods below.
**Types.typeof**

@@ -170,14 +175,10 @@ > `<String> Types.typeof( value )`

____________________________
**force'Type' and default literals**
**force'Type' method and default literals**
> format: `<string> forceString( <any type> value, <string> replacement )`
> format: `<'Type'> force'Type'( <any type> value, <'Type'> replacement )`
<br/><br/>
> The literals returned by default:
forceBoolean |forceString |forceNumber
---------------|--------------|--------------
Boolean `false`|String `''` |Number `0`
forceObject |forceArray |forceFunction
---------------|--------------|--------------
Object `{}` |Array `[]` |Function `function(){}`
___
forceBoolean |forceString |forceNumber |forceObject |forceArray |forceFunction
---------------|--------------|--------------|---------------|--------------|--------------
`false` |`''` |`0` |`{}` |`[]` |`function(){}`
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