cluedin-widget
Version:
This is the project for creating and managing widgets in CluedIn.
55 lines (49 loc) • 2.04 kB
JavaScript
var type = require( "./ises/type" ),
is = {
a: {},
an: {},
not: {
a: {},
an: {}
}
};
var ises = {
"arguments": [ "arguments", type( "arguments" ) ],
"array": [ "array", type( "array" ) ],
"boolean": [ "boolean", type( "boolean" ) ],
"date": [ "date", type( "date" ) ],
"function": [ "function", "func", "fn", type( "function" ) ],
"null": [ "null", type( "null" ) ],
"number": [ "number", "integer", "int", type( "number" ) ],
"object": [ "object", type( "object" ) ],
"regexp": [ "regexp", type( "regexp" ) ],
"string": [ "string", type( "string" ) ],
"undefined": [ "undefined", type( "undefined" ) ],
"empty": [ "empty", require( "./ises/empty" ) ],
"nullorundefined": [ "nullOrUndefined", "nullorundefined", require( "./ises/nullorundefined" ) ]
};
Object.keys( ises ).forEach( function( key ) {
var methods = ises[ key ].slice( 0, ises[ key ].length - 1 ),
fn = ises[ key ][ ises[ key ].length - 1 ];
methods.forEach( function( methodKey ) {
is[ methodKey ] = is.a[ methodKey ] = is.an[ methodKey ] = fn;
is.not[ methodKey ] = is.not.a[ methodKey ] = is.not.an[ methodKey ] = function() {
return fn.apply( this, arguments ) ? false : true;
};
} );
} );
module.exports = {
isEmail: function( email ) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test( email );
},
isUrl: function( str ) {
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
return regexp.test( str );
},
is: is,
isValidFileName: function( fileName ) {
var ext = fileName.split( '.' ).pop();
return (ext.toLowerCase() === 'png' || ext.toLowerCase() === 'jpg' || ext.toLowerCase() === 'jpeg' || ext.toLowerCase() === 'gif');
}
};