// To checks if some value is numeric
is("Number", 1); // true
is("Number", 1.2); // true
is("Number", "1"); // true
is("Number", "1.2"); // true
is("Number", " 1 "); // true
is("Number", ""); // false
is("Number", " "); // false
is("Number", "One"); // false
// To checks if a string is filled
is("Present", "blank"); // true
is("Present", " \n A \t "); // true
is("Present", " "); // false
is("Present", " \n\t "); // false
// If you use an invalid function.
is("Foo", "Bar"); // 0
// Why ZERO?
// Because I haven't any space to return something useful! :p
-
-
Save serradura/2510893 to your computer and use it in GitHub Desktop.
140byt.es -- Click ↑↑ fork ↑↑ to play!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function is(k,v){ | |
return( | |
k == 'Number' ? !isNaN(parseInt(v)) && isFinite(v) : | |
k == 'Present' ? !(v == undefined || v == null) && v.replace(/^\s+|\s+$/g,'') != '' : | |
0 | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function is(k,v){return(k=='Number'?!isNaN(parseInt(v))&&isFinite(v):k=='Present'?!(v==undefined||v==null)&&v.replace(/^\s+|\s+$/g,'')!='':0)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Rodrigo Serradura <http://github.com/serradura> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "is()", | |
"description": "Checks if a value is numeric or is filled string", | |
"keywords": [ | |
"string", | |
"number", | |
"functional" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<title>Foo</title> | |
<div>Expected value: <b>undefined</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
// write a small example that shows off the API for your example | |
// and tests it in one fell swoop. | |
var myFunction = function(){ /* the code here should be identical to the entry. */ } | |
document.getElementById( "ret" ).innerHTML = myFunction() | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure if this is the same in all possible cases but it saves a lot of bytes. Also fixes the problem that your version crashes for
is('Present', 1)
.Edit: Save more bytes. ;-)