Created
June 7, 2011 13:27
-
-
Save sapegin/1012250 to your computer and use it in GitHub Desktop.
JavaScript Cookbook
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 formatNumber(value) { | |
| value = value.toString() | |
| .replace(".", ",") | |
| .replace(" ", "") | |
| .replace("-", "−"); | |
| var re = /(\d+)(\d{3})/; | |
| while (re.test(value)) { | |
| value = value.replace(re, "<i>$1</i>$2"); | |
| } | |
| return value; | |
| } |
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 getText(node) { | |
| return node.textContent || node.innerText; | |
| } |
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
| // ['минута', 'минуты', 'минут'][plural(minutes)] | |
| function plural(n) { | |
| return (n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); | |
| } |
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
| if (!String.prototype.trim) { | |
| String.prototype.trim = function() { | |
| return this.replace(/^\s+|\s+$/g, ''); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment