This file contains 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
/** | |
* Author: Alex Chao([email protected]) | |
* Date: 2014-08-01 | |
*/ | |
/** | |
* Note: You can choose the other polyfill which is compatible with ECMA-262, 5th edition | |
* Url: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | |
*/ |
This file contains 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
/** | |
* Author: Alex Chao([email protected]) | |
* Date: 2014-08-02 | |
*/ | |
/** | |
* Note: You can choose the other polyfill which is compatible with ECMA-262, 5th edition | |
* Url: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach | |
*/ |
This file contains 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
// Check if a string consists of the digit characters (0-9) | |
function isDigit(str) { | |
return str && !/[^\d]/.test(str); | |
} |
This file contains 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
/* | |
* Ref: http://stackoverflow.com/questions/1353684/detecting-an-invalid-date-date-instance-in-javascript | |
*/ | |
function isValidDate(d) { | |
return Object.prototype.toString.call(d) === '[object Date]' && !isNaN(d.valueOf()); | |
} |
This file contains 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
/* | |
* Ref: http://stackoverflow.com/questions/154059/how-do-you-check-for-an-empty-string-in-javascript | |
*/ | |
// `str` must be a string | |
function isEmpty(str) { | |
return !!str.length; | |
} | |
// check if the `str` is empty, null or undefined (`str` may be 0 or false) |
This file contains 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
/* | |
* Ref: http://stackoverflow.com/questions/154059/how-do-you-check-for-an-empty-string-in-javascript | |
*/ | |
function isBlank(str) { | |
return !str || !/\S/.test(str); | |
} |
This file contains 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
// when you need a range, you'd better use comparison operators | |
function isFullYear(year) { | |
return !/^\d{4}$/.test(year); | |
} |
This file contains 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
/** | |
* Description: Count a string (mixing English and Chinese characters) length. | |
* A basic and rough function. | |
* | |
* Performance: | |
* Multiple methods performance test on http://jsperf.com/count-string-length. | |
* You can see that using regexp to check range is very slow from the above test page. | |
*/ | |
function strLen(str) { | |
var count = 0; |
This file contains 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
// Check if a value is falsy. This is, its value is one of undefined, null, false, 0, NaN or an empty string "". | |
// Also, you can use the Boolean function to convert the value. | |
function isFalsy(o) { | |
return !o; | |
} |
This file contains 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
// Check if a value is truthy. The word truthy means the value is not one of undefined, null, false, 0, NaN or an empty string "". | |
// Also, you can use the Boolean function to convert the value. | |
function isTruthy(o) { | |
return !!o; | |
} |
OlderNewer