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.4.42 to 1.5.0

4

package.json
{
"name": "types.js",
"version": "1.4.42",
"description": "A tiny (1.9kb), essential Javascript type-check library",
"version": "1.5.0",
"description": "A tiny (1.9kb) Javascript type checker/enforcer library",
"main": "types.min.js",

@@ -6,0 +6,0 @@ "scripts": {

types.js
========
<br/>
A tiny(1.9Kb), essential Javascript type checking library.
A tiny (2.2Kb) Javascript type checker/enforcer library.

@@ -21,2 +21,4 @@ - fixes NaN, array, null, etc..

_.forceNumber( 'use next arg..', 123 ); // 123
_.intoArray( '1 2 3' ); // ['1', '2', '3']
_.intoArray( '1', '2', '3' ); // ['1', '2', '3']
_.allDefined( 'good', false, 0 ); // true

@@ -34,20 +36,24 @@ _.hasObject( 'not', 'really' ); // false

```javascript
var left= '500px';
var callback= null;
if ( typeof left !== 'number' ){
left= parseInt( left, 10 );
}
var left = '500px'
,callback = null
;
if ( typeof left !== 'number' )
left= parseInt( left, 10 );
// check for parseInt returning NaN..
if ( left !== left || typeof left !== 'number' ){
if ( left !== left || typeof left !== 'number' )
left= 100;
}
// be safe before calling the function
if ( typeof callback !== 'function' ){
if ( typeof callback !== 'function' )
callback= function(){}
}
// now we can call safely
callback( left );
// now with force, exactly the same result:
// 2 lines with force, exactly the same result:
left= _.forceNumber( left, 100 );
_.forceFunction( callback )( left );
// see below for more examples

@@ -90,3 +96,3 @@ ```

**some more examples:**
**more examples:**
```javascript

@@ -97,2 +103,3 @@ var _= Types; // browser

var x;
// initialize a variable and be sure what type it will have in any case:

@@ -109,2 +116,3 @@ _.forceString(); // '' (empty String)

var func= null;
// call a function that might not exist anymore:

@@ -117,3 +125,3 @@ _.forceFunction( func )( 'arguments for func, or replacement' );

_.isString( 'Hello types.js!' ); // true
_.isString( 23456 ); // false
_.isString( 23456 ); // false
_.isBoolean( false ); // true

@@ -148,2 +156,3 @@ _.isArray( [1,2,3] ); // true

_.typeof( new Date() ); // 'date'
// etc..

@@ -279,2 +288,37 @@ ```

___
**Types.intoArray**
> `<array> Types.intoArray( <any type> arg1, ..., argN )`
intoArray is a convenience method I use mostly for flexible arguments passing, but can also be used to split
space delimited strings into an array in a non-sparse way (destructing spaces).
It accepts 3 kinds of arguments:
kind |input |result
------------------------|-----------------------------|--------------
space delimited strings |'This is intoArray!' |['This', 'is', 'intoArray!']
multiple arguments |'This', 'is', 'intoArray!' |['This', 'is', 'intoArray!']
array |['This', 'is', 'intoArray!'] |['This', 'is', 'intoArray!']
All generating the same forced array.
```javascript
function testArgs( arg1, ..., argN ){
// need to .apply with context for all arguments to pass
var array= _.intoArray.apply( this, arguments );
console.log( array );
}
testArgs( 'This', 'is', 'intoArray!' );
// [ 'This', 'is', 'intoArray!' ]
testArgs( ['This', 'is', 'intoArray!'] );
// [ 'This', 'is', 'intoArray!' ]
testArgs( 'This is intoArray!' );
// [ 'This', 'is', 'intoArray!' ]
```
For space delimited string parsing, all strings are trimmed and reduced to one consecutive space
to avoid a sparse array.
___
**Types.typeof**

@@ -377,2 +421,8 @@ > `<String> Types.typeof( value )`

==========
**1.5.0**
Added .intoArray method.
___
**1.4.4**

@@ -379,0 +429,0 @@

@@ -1,5 +0,5 @@

// Generated by CoffeeScript 1.8.0
(function() {
"use strict";
var LITERALS, TYPES, Types, breakIfEqual, createForce, instanceOf, testValues, typeOf, _;
var LITERALS, TYPES, Types, breakIfEqual, createForce, instanceOf, testValues, typeOf, _,
__slice = [].slice;

@@ -152,2 +152,15 @@ instanceOf = function(type, value) {

Types.intoArray = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (args.length < 2) {
if (_.isString(args[0])) {
args = args.join('').replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ').split(' ');
} else if (_.isArray(args[0])) {
args = args[0];
}
}
return args;
};
Types["typeof"] = function(value) {

@@ -154,0 +167,0 @@ var name, predicate;

@@ -1,1 +0,1 @@

(function(){"use strict";var n,r,e,t,u,i,o,f,c;i=function(n,r){return r instanceof n},f=function(n,r){return null==r&&(r="object"),typeof n===r},n={Boolean:!1,String:"",Object:{},Array:[],Function:function(){},Number:function(){var n;return n=new Number,n["void"]=!0,n}()},r={Undefined:function(n){return void 0===n},Null:function(n){return null===n},Function:function(n){return f(n,"function")},Boolean:function(n){return f(n,"boolean")},String:function(n){return f(n,"string")},Array:function(n){return f(n)&&i(Array,n)},RegExp:function(n){return f(n)&&i(RegExp,n)},Date:function(n){return f(n)&&i(Date,n)},Number:function(n){return f(n,"number")&&n===n||f(n)&&i(Number,n)},Object:function(n){return!(!f(n)||null===n||i(Boolean,n)||i(Number,n)||i(Array,n)||i(RegExp,n)||i(Date,n))},NaN:function(n){return f(n,"number")&&n!==n},Defined:function(n){return void 0!==n}},r.StringOrNumber=function(n){return r.String(n)||r.Number(n)},e=c={parseIntBase:10},u=function(r){var t;return t=function(n){switch(r){case"Number":if(c.isNumber(n=parseInt(n,c.parseIntBase))&&!n["void"])return n;break;case"String":if(c.isStringOrNumber(n))return n+"";break;default:if(e["is"+r](n))return n}},function(e,u){return null!=e&&void 0!==(e=t(e))?e:null!=u&&void 0!==(u=t(u))?u:n[r]}},o=function(n,e,t){var u,i,o;if(null==t&&(t=[]),t.length<1)return n===r.Undefined;for(i=0,o=t.length;o>i;i++)if(u=t[i],n(u)===e)return e;return!e},t=!0,function(){var i,f,c;c=[];for(i in r)f=r[i],c.push(function(r,i){return e["is"+r]=i,e["not"+r]=function(n){return!i(n)},e["has"+r]=function(){return o(i,t,arguments)},e["all"+r]=function(){return o(i,!t,arguments)},r in n?e["force"+r]=u(r):void 0}(i,f));return c}(),e["typeof"]=function(n){var e,t;for(e in r)if(t=r[e],t(n)===!0)return e.toLowerCase()},"undefined"!=typeof define&&null!==define&&"function"==typeof define&&define.amd?define("types",[],function(){return e}):"undefined"!=typeof window?window.Types=e:"undefined"!=typeof module&&(module.exports=e)}).call(this);
(function(){"use strict";var n,r,e,t,u,i,o,f,c,a=[].slice;i=function(n,r){return r instanceof n},f=function(n,r){return null==r&&(r="object"),typeof n===r},n={Boolean:!1,String:"",Object:{},Array:[],Function:function(){},Number:function(){var n;return n=new Number,n["void"]=!0,n}()},r={Undefined:function(n){return void 0===n},Null:function(n){return null===n},Function:function(n){return f(n,"function")},Boolean:function(n){return f(n,"boolean")},String:function(n){return f(n,"string")},Array:function(n){return f(n)&&i(Array,n)},RegExp:function(n){return f(n)&&i(RegExp,n)},Date:function(n){return f(n)&&i(Date,n)},Number:function(n){return f(n,"number")&&n===n||f(n)&&i(Number,n)},Object:function(n){return!(!f(n)||null===n||i(Boolean,n)||i(Number,n)||i(Array,n)||i(RegExp,n)||i(Date,n))},NaN:function(n){return f(n,"number")&&n!==n},Defined:function(n){return void 0!==n}},r.StringOrNumber=function(n){return r.String(n)||r.Number(n)},e=c={parseIntBase:10},u=function(r){var t;return t=function(n){switch(r){case"Number":if(c.isNumber(n=parseInt(n,c.parseIntBase))&&!n["void"])return n;break;case"String":if(c.isStringOrNumber(n))return n+"";break;default:if(e["is"+r](n))return n}},function(e,u){return null!=e&&void 0!==(e=t(e))?e:null!=u&&void 0!==(u=t(u))?u:n[r]}},o=function(n,e,t){var u,i,o;if(null==t&&(t=[]),t.length<1)return n===r.Undefined;for(i=0,o=t.length;o>i;i++)if(u=t[i],n(u)===e)return e;return!e},t=!0,function(){var i,f,c;c=[];for(i in r)f=r[i],c.push(function(r,i){return e["is"+r]=i,e["not"+r]=function(n){return!i(n)},e["has"+r]=function(){return o(i,t,arguments)},e["all"+r]=function(){return o(i,!t,arguments)},r in n?e["force"+r]=u(r):void 0}(i,f));return c}(),e.intoArray=function(){var n;return n=1<=arguments.length?a.call(arguments,0):[],n.length<2&&(c.isString(n[0])?n=n.join("").replace(/^\s+|\s+$/g,"").replace(/\s+/g," ").split(" "):c.isArray(n[0])&&(n=n[0])),n},e["typeof"]=function(n){var e,t;for(e in r)if(t=r[e],t(n)===!0)return e.toLowerCase()},"undefined"!=typeof define&&null!==define&&"function"==typeof define&&define.amd?define("types",[],function(){return e}):"undefined"!=typeof window?window.Types=e:"undefined"!=typeof module&&(module.exports=e)}).call(this);

Sorry, the diff of this file is not supported yet

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