// trim white-space(s)
function trim(text) {
return text.replace(/^\s+|\s+$/g, "");
}
function ltrim(text) {
return text.replace(/^\s+/, "");
}
function rtrim(text) {
return text.replace(/\s+$/, "");
}
// find min and max value in array
function array_min(arr) {
return Math.min.apply({}, arr);
}
function array_max(arr) {
return Math.max.apply({}, arr);
}
// type check
function is_set(x) {
return typeof x !== "undefined";
}
function is_array(x) {
return typeof x === "object";
}
function is_string(x) {
return typeof x === "string";
}
function is_number(x) {
return typeof x === "number";
}
function is_function(x) {
return typeof x === "function";
}
// capitalize text
function caputalize(text) {
return text.toLowerCase().replace(/(^|\s)([a-z])/g, function(a, b, c) {
return b + c.toUpperCase();
});
}
// strip tags
function strip_tags(text) {
return text.replace(/<.*?>/g, "");
}
Some of them come from PHP, and they are very handy.
4 Responses
Example: Spanish name: "marco ñuñez", results into "Marco ñUñez".
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.