Comparing version 1.5.3 to 1.6.0
{ | ||
"name": "types.js", | ||
"version": "1.5.3", | ||
"description": "A tiny (~2kb) Javascript type checker/enforcer library", | ||
"version": "1.6.0", | ||
"description": "A tiny (~2.5kb) Javascript type checker/enforcer library", | ||
"main": "types.min.js", | ||
@@ -18,4 +18,4 @@ "scripts": { | ||
"validation", | ||
"validate", | ||
"check", | ||
"checking", | ||
"force", | ||
@@ -22,0 +22,0 @@ "is", |
types.js | ||
======== | ||
<br/> | ||
A tiny (~2kB) Javascript type checker/enforcer library. | ||
A tiny (~2.5kB) Javascript type checker/enforcer library. | ||
@@ -289,2 +289,15 @@ - fixes NaN, array, null, etc.. | ||
``` | ||
**Types.logForce** | ||
> `<undefined> logForce( <Function> logger )` | ||
You can call Types.logForce(); to turn on console logging for failed conversions of forceTypes. If you prefer a more advanced logger than the basic provided console.log, you can simply pass that logger as argument. | ||
```javascript | ||
types.logForce(); | ||
var result= types.forceString( [], 'ok' ); | ||
// types.js - forceString, cannot convert type 'array' to String, trying replacement value now | ||
console.log( result ); | ||
// ok | ||
``` | ||
___ | ||
@@ -420,2 +433,3 @@ **Types.intoArray** | ||
forceFunction | function(){} | ||
forceRegExp | /(?:)/ | ||
___ | ||
@@ -425,2 +439,15 @@ change log | ||
**1.6.0** | ||
- adds forceRegExp | ||
- adds logForce, now we can show a log when forceTypes encounters a type mismatch | ||
- updates readme | ||
___ | ||
**1.5.3** | ||
adds getFirst<Type>, returning the first found argument of a specific type | ||
___ | ||
**1.5.1** | ||
@@ -427,0 +454,0 @@ |
41
types.js
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
"use strict"; | ||
var LITERALS, TYPES, Types, _, breakIfEqual, createForce, instanceOf, testValues, typeOf, | ||
var LITERALS, TYPES, Types, breakIfEqual, createForce, instanceOf, log, logPrefix, testValues, typeOf, types, | ||
slice = [].slice; | ||
log = function() {}; | ||
logPrefix = 'types.js - force'; | ||
instanceOf = function(type, value) { | ||
@@ -29,3 +33,4 @@ return value instanceof type; | ||
return number; | ||
})() | ||
})(), | ||
'RegExp': new RegExp | ||
}; | ||
@@ -76,4 +81,12 @@ | ||
Types = _ = { | ||
parseIntBase: 10 | ||
Types = types = { | ||
parseIntBase: 10, | ||
logForce: function(logger) { | ||
if (types.isFunction(logger)) { | ||
return log = logger; | ||
} | ||
if (types.isObject(console)) { | ||
return log = types.forceFunction(console.log); | ||
} | ||
} | ||
}; | ||
@@ -86,3 +99,3 @@ | ||
case 'Number': | ||
if ((_.isNumber(value = parseInt(value, _.parseIntBase))) && !value["void"]) { | ||
if ((types.isNumber(value = parseInt(value, types.parseIntBase))) && !value["void"]) { | ||
return value; | ||
@@ -92,3 +105,3 @@ } | ||
case 'String': | ||
if (_.isStringOrNumber(value)) { | ||
if (types.isStringOrNumber(value)) { | ||
return value + ''; | ||
@@ -104,8 +117,16 @@ } | ||
return function(value, replacement) { | ||
var replacementType, valueType; | ||
valueType = types["typeof"](value); | ||
if ((value != null) && void 0 !== (value = convertType(value))) { | ||
return value; | ||
} | ||
if ((replacement != null) && void 0 !== (replacement = convertType(replacement))) { | ||
return replacement; | ||
log(logPrefix + type + ': invalid first argument with type: \'' + valueType + '\''); | ||
if (types.isDefined(replacement)) { | ||
replacementType = types["typeof"](replacement); | ||
if ((replacement != null) && void 0 !== (replacement = convertType(replacement))) { | ||
return replacement; | ||
} | ||
log(logPrefix + type + ': invalid second argument with type: \'' + replacementType + '\''); | ||
} | ||
log(logPrefix + type + ': forcing return value to type ' + type); | ||
return LITERALS[type]; | ||
@@ -172,5 +193,5 @@ }; | ||
if (args.length < 2) { | ||
if (_.isString(args[0])) { | ||
if (types.isString(args[0])) { | ||
args = args.join('').replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ').split(' '); | ||
} else if (_.isArray(args[0])) { | ||
} else if (types.isArray(args[0])) { | ||
args = args[0]; | ||
@@ -177,0 +198,0 @@ } |
@@ -1,1 +0,1 @@ | ||
(function(){"use strict";var n,r,e,t,u,i,o,f,c,a=[].slice;o=function(n,r){return r instanceof n},c=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 c(n,"function")},Boolean:function(n){return c(n,"boolean")},String:function(n){return c(n,"string")},Array:function(n){return c(n)&&o(Array,n)},RegExp:function(n){return c(n)&&o(RegExp,n)},Date:function(n){return c(n)&&o(Date,n)},Number:function(n){return c(n,"number")&&n===n||c(n)&&o(Number,n)},Object:function(n){return!(!c(n)||null===n||o(Boolean,n)||o(Number,n)||o(Array,n)||o(RegExp,n)||o(Date,n))},NaN:function(n){return c(n,"number")&&n!==n},Defined:function(n){return void 0!==n}},r.StringOrNumber=function(n){return r.String(n)||r.Number(n)},e=t={parseIntBase:10},i=function(r){var u;return u=function(n){switch(r){case"Number":if(t.isNumber(n=parseInt(n,t.parseIntBase))&&!n["void"])return n;break;case"String":if(t.isStringOrNumber(n))return n+"";break;default:if(e["is"+r](n))return n}},function(e,t){return null!=e&&void 0!==(e=u(e))?e:null!=t&&void 0!==(t=u(t))?t:n[r]}},f=function(n,e,t){var u,i,o;if(null==t&&(t=[]),t.length<1)return n===r.Undefined;for(u=0,i=t.length;i>u;u++)if(o=t[u],n(o)===e)return e;return!e},u=!0,function(){var t,o,c;c=[];for(t in r)o=r[t],c.push(function(r,t){return e["is"+r]=t,e["not"+r]=function(n){return!t(n)},e["has"+r]=function(){return f(t,u,arguments)},e["all"+r]=function(){return f(t,!u,arguments)},r in n&&(e["force"+r]=i(r)),e["getFirst"+r]=function(){var n,t,u,i;for(i=1<=arguments.length?a.call(arguments,0):[],n=0,t=i.length;t>n;n++)if(u=i[n],e["is"+r](u))return u}}(t,o));return c}(),e.intoArray=function(){var n;return n=1<=arguments.length?a.call(arguments,0):[],n.length<2&&(t.isString(n[0])?n=n.join("").replace(/^\s+|\s+$/g,"").replace(/\s+/g," ").split(" "):t.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 module&&(module.exports=e),"undefined"!=typeof window&&(window.Types=e)}).call(this); | ||
(function(){"use strict";var n,e,r,t,u,i,o,f,c,a,l,s=[].slice;o=function(){},f="types.js - force",i=function(n,e){return e instanceof n},a=function(n,e){return null==e&&(e="object"),typeof n===e},n={Boolean:!1,String:"",Object:{},Array:[],Function:function(){},Number:function(){var n;return n=new Number,n["void"]=!0,n}(),RegExp:new RegExp},e={Undefined:function(n){return void 0===n},Null:function(n){return null===n},Function:function(n){return a(n,"function")},Boolean:function(n){return a(n,"boolean")},String:function(n){return a(n,"string")},Array:function(n){return a(n)&&i(Array,n)},RegExp:function(n){return a(n)&&i(RegExp,n)},Date:function(n){return a(n)&&i(Date,n)},Number:function(n){return a(n,"number")&&n===n||a(n)&&i(Number,n)},Object:function(n){return!(!a(n)||null===n||i(Boolean,n)||i(Number,n)||i(Array,n)||i(RegExp,n)||i(Date,n))},NaN:function(n){return a(n,"number")&&n!==n},Defined:function(n){return void 0!==n}},e.StringOrNumber=function(n){return e.String(n)||e.Number(n)},r=l={parseIntBase:10,logForce:function(n){return l.isFunction(n)?o=n:l.isObject(console)?o=l.forceFunction(console.log):void 0}},u=function(e){var t;return t=function(n){switch(e){case"Number":if(l.isNumber(n=parseInt(n,l.parseIntBase))&&!n["void"])return n;break;case"String":if(l.isStringOrNumber(n))return n+"";break;default:if(r["is"+e](n))return n}},function(r,u){var i,c;if(c=l["typeof"](r),null!=r&&void 0!==(r=t(r)))return r;if(o(f+e+": invalid first argument with type: '"+c+"'"),l.isDefined(u)){if(i=l["typeof"](u),null!=u&&void 0!==(u=t(u)))return u;o(f+e+": invalid second argument with type: '"+i+"'")}return o(f+e+": forcing return value to type "+e),n[e]}},c=function(n,r,t){var u,i,o;if(null==t&&(t=[]),t.length<1)return n===e.Undefined;for(u=0,i=t.length;i>u;u++)if(o=t[u],n(o)===r)return r;return!r},t=!0,function(){var i,o,f;f=[];for(i in e)o=e[i],f.push(function(e,i){return r["is"+e]=i,r["not"+e]=function(n){return!i(n)},r["has"+e]=function(){return c(i,t,arguments)},r["all"+e]=function(){return c(i,!t,arguments)},e in n&&(r["force"+e]=u(e)),r["getFirst"+e]=function(){var n,t,u,i;for(i=1<=arguments.length?s.call(arguments,0):[],n=0,t=i.length;t>n;n++)if(u=i[n],r["is"+e](u))return u}}(i,o));return f}(),r.intoArray=function(){var n;return n=1<=arguments.length?s.call(arguments,0):[],n.length<2&&(l.isString(n[0])?n=n.join("").replace(/^\s+|\s+$/g,"").replace(/\s+/g," ").split(" "):l.isArray(n[0])&&(n=n[0])),n},r["typeof"]=function(n){var r,t;for(r in e)if(t=e[r],t(n)===!0)return r.toLowerCase()},"undefined"!=typeof define&&null!==define&&"function"==typeof define&&define.amd&&define("types",[],function(){return r}),"undefined"!=typeof module&&(module.exports=r),"undefined"!=typeof window&&(window.Types=r)}).call(this); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
524
67561
7
203