-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #480 from marcodejongh/remove_stringjs
Remove stringjs dependency
- Loading branch information
Showing
9 changed files
with
79 additions
and
972 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Tinytest.add("Humanize - Should humanize a string", function (test) { | ||
test.equal(humanize('super_snake_case'), 'Super snake case') | ||
test.equal(humanize('capitalizedCamelCase'), 'Capitalized camel case') | ||
test.equal(humanize('hyphen-case'), 'Hyphen case') | ||
test.equal(humanize('no-extensions-here.md'), 'No extensions here') | ||
test.equal(humanize('lower cased phrase'), 'Lower cased phrase') | ||
test.equal(humanize(' so many spaces '), 'So many spaces') | ||
test.equal(humanize(123), '123') | ||
test.equal(humanize(''), '') | ||
test.equal(humanize(null), '') | ||
test.equal(humanize(undefined), '') | ||
}); |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Code source: | ||
https://github.com/jxson/string-humanize | ||
https://github.com/jxson/string-capitalize | ||
*/ | ||
|
||
function capitalize(string){ | ||
string = string || ''; | ||
string = string.trim(); | ||
|
||
if (string[0]) { | ||
string = string[0].toUpperCase() + string.substr(1).toLowerCase(); | ||
} | ||
|
||
return string; | ||
} | ||
|
||
humanize = function humanize(string){ | ||
string = string || ''; | ||
string = string.toString(); // might be a number | ||
string = string.trim(); | ||
string = string.replace(extname(string), ''); | ||
string = underscore(string); | ||
string = string.replace(/[\W_]+/g, ' '); | ||
|
||
return capitalize(string); | ||
} | ||
|
||
|
||
function underscore(string){ | ||
string = string || ''; | ||
string = string.toString(); // might be a number | ||
string = string.trim(); | ||
string = string.replace(/([a-z\d])([A-Z]+)/g, '$1_$2'); | ||
string = string.replace(/[-\s]+/g, '_').toLowerCase(); | ||
|
||
return string; | ||
} | ||
|
||
function extname(string){ | ||
var index = string.lastIndexOf('.'); | ||
var ext = string.substring(index, string.length); | ||
|
||
return (index === -1) ? '' : ext; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
if (!String.prototype.startsWith) { | ||
String.prototype.startsWith = function(searchString, position) { | ||
position = position || 0; | ||
return this.indexOf(searchString, position) === position; | ||
}; | ||
} | ||
|
||
if (!String.prototype.trim) { | ||
String.prototype.trim = function () { | ||
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); | ||
}; | ||
} |
Oops, something went wrong.