Last active
September 19, 2022 20:02
Revisions
-
blizzrdof77 revised this gist
Sep 19, 2022 . 1 changed file with 10 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,12 +6,12 @@ */ /* Easier way to check if a string contains a substring */ String.prototype.contains = String.prototype.contains || function(search) { return (this.indexOf(search) !== -1); }; /* Check if a string contains any substring within an array of passed strings */ String.prototype.containsAny = String.prototype.containsAny || function(arr) { for (var i = 0; i < arr.length; i++) { if (this.indexOf(arr[i]) > -1) { return true; @@ -20,7 +20,7 @@ String.prototype.containsAny = function(arr) { return false; }; String.prototype.replaceAll = String.prototype.replaceAll || function(find, replacement) { return this.replace(new RegExp(find, 'g'), replacement); }; @@ -30,34 +30,34 @@ String.prototype.replaceAll = function(find, replacement) { * @type String * @return String */ String.prototype.toTitleCase = String.prototype.toTitleCase || function() { return this.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); }; String.prototype.camelCaseToDashed = String.prototype.camelCaseToDashed || function() { return this.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); }; String.prototype.toProperCase = String.prototype.toProperCase || function() { return this.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); }; String.prototype.toCamelCase = String.prototype.toCamelCase || function() { return this.replaceAll('-', '_').replaceAll('_', ' ').replace(/(?:^\w|\-[A-Z]|\b\w)/g, function(letter, index) { return index == 0 ? letter.toLowerCase() : letter.toUpperCase(); }).replace(/\s+/g, '').replace('-', ''); }; String.prototype.toKebabCase = String.prototype.toKebabCase || function(uppercase = false) { let str = this.toCamelCase().camelCaseToDashed(); return (uppercase ? str.toUpperCase() : str); }; String.prototype.toSnakeCase = String.prototype.toSnakeCase || function(capitalize = false) { let str = this.toKebabCase().replaceAll('-', '_'); return (capitalize ? str.replaceAll('_', ' ').toTitleCase().replaceAll(' ', '_') : str); }; -
blizzrdof77 revised this gist
Sep 19, 2022 . 1 changed file with 16 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,12 +6,12 @@ */ /* Easier way to check if a string contains a substring */ String.prototype.contains = function(search) { return (this.indexOf(search) !== -1); }; /* Check if a string contains any substring within an array of passed strings */ String.prototype.containsAny = function(arr) { for (var i = 0; i < arr.length; i++) { if (this.indexOf(arr[i]) > -1) { return true; @@ -20,7 +20,7 @@ String.prototype.containsAny = String.prototype.containsAny || function(arr) { return false; }; String.prototype.replaceAll = function(find, replacement) { return this.replace(new RegExp(find, 'g'), replacement); }; @@ -30,28 +30,34 @@ String.prototype.replaceAll = String.prototype.replaceAll || function(find, repl * @type String * @return String */ String.prototype.toTitleCase = function() { return this.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); }; String.prototype.camelCaseToDashed = function() { return this.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); }; String.prototype.toProperCase = function() { return this.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); }; String.prototype.toCamelCase = function() { return this.replaceAll('-', '_').replaceAll('_', ' ').replace(/(?:^\w|\-[A-Z]|\b\w)/g, function(letter, index) { return index == 0 ? letter.toLowerCase() : letter.toUpperCase(); }).replace(/\s+/g, '').replace('-', ''); }; String.prototype.toKebabCase = function(uppercase = false) { let str = this.toCamelCase().camelCaseToDashed(); return (uppercase ? str.toUpperCase() : str); }; String.prototype.toSnakeCase = function(capitalize = false) { let str = this.toKebabCase().replaceAll('-', '_'); return (capitalize ? str.replaceAll('_', ' ').toTitleCase().replaceAll(' ', '_') : str); }; -
blizzrdof77 revised this gist
Jul 18, 2018 . 1 changed file with 20 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,11 +4,23 @@ * @param String search * @return Bool */ /* Easier way to check if a string contains a substring */ String.prototype.contains = String.prototype.contains || function(search) { return (this.indexOf(search) !== -1); }; /* Check if a string contains any substring within an array of passed strings */ String.prototype.containsAny = String.prototype.containsAny || function(arr) { for (var i = 0; i < arr.length; i++) { if (this.indexOf(arr[i]) > -1) { return true; } } return false; }; String.prototype.replaceAll = String.prototype.replaceAll || function(find, replacement) { return this.replace(new RegExp(find, 'g'), replacement); }; @@ -18,28 +30,28 @@ String.prototype.replaceAll = function(find, replacement) { * @type String * @return String */ String.prototype.toTitleCase = String.prototype.toTitleCase || function() { return this.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); }; String.prototype.camelCaseToDashed = String.prototype.camelCaseToDashed || function() { return this.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); }; String.prototype.toProperCase = String.prototype.toProperCase || function() { return this.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); }; String.prototype.toCamelCase = String.prototype.toCamelCase || function() { return this.replace(/(?:^\w|\-[A-Z]|\b\w)/g, function(letter, index) { return index == 0 ? letter.toLowerCase() : letter.toUpperCase(); }).replace(/\s+/g, '').replace('-', ''); }; String.prototype.toDashedCase = String.prototype.toDashedCase || function() { return this.toCamelCase().camelCaseToDashed(); }; -
blizzrdof77 revised this gist
Jan 5, 2018 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /** * Helper String Methods/Extensions to the JS String Object * * @param String search * @return Bool @@ -8,6 +8,16 @@ String.prototype.contains = function(search) { return (this.indexOf(search) !== -1); }; String.prototype.replaceAll = function(find, replacement) { return this.replace(new RegExp(find, 'g'), replacement); }; /** * Case conversion helper methods * * @type String * @return String */ String.prototype.toTitleCase = function() { return this.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); -
blizzrdof77 created this gist
Jan 4, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ /** * Check if string contains a provided substring * * @param String search * @return Bool */ String.prototype.contains = function(search) { return (this.indexOf(search) !== -1); }; String.prototype.toTitleCase = function() { return this.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); }; String.prototype.camelCaseToDashed = function() { return this.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); }; String.prototype.toProperCase = function() { return this.replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); }; String.prototype.toCamelCase = function() { return this.replace(/(?:^\w|\-[A-Z]|\b\w)/g, function(letter, index) { return index == 0 ? letter.toLowerCase() : letter.toUpperCase(); }).replace(/\s+/g, '').replace('-', ''); }; String.prototype.toDashedCase = function() { return this.toCamelCase().camelCaseToDashed(); };