_str is a chainable library which aim to simplify string manipulation and handling. _str will also keep an history of all the modification it has made so it is easy to rollback any changes. It is also possible to store manipulation state which can later be retrieved individually or as a all (useful if you can have one chain for all your changes but need multiple formatted version of the original strings.
var str;
str = _str('example').prepend('this is an ').append('.').upFirst().end();
console.log(str);
// str => "This is an example."
str = _str(' email@test.com bla bla bla http://google.com').emailsToLinks().urlsToLinks().end();
console.log(str);
// str => "<a href="mailto:email@test.com">email@test.com</a> <a href="http://google.com">http://google.com</a>"
str = _str('abcd').set('original').reverse().set('reverse').set('custom','data').get();
console.log(str);
// str => {original:'abcd', reverse: 'dcba', custom:'data'}
var tpl = 'My name is {firstName} {lastName}.';
str = _str(tpl).replace(['{firstName}', '{lastName}'],['Gilles', 'Cochez']).end();
console.log(str);
// str => "My name is Gilles Cochez."
str = _str(tpl).replace({'{firstName}': 'Gilles', '{lastName}': 'Cochez'}).end();
console.log(str);
// str => "My name is Gilles Cochez."
Function used internally to do all API calls and handle string versioning
Reverse the string to the last modification recorded.
1 argument: Store the current string state to a given reference
2 arguments: Store a value for a given reference
1 argument: Return a state of string matching the given reference.
Return the history object
String.indexOf wrapper
String.lastIndexOf wrapper
String.match wrapper
String.search wrapper
String.slice wrapper
1 argument: Argument is used as end limiter and 0 is used as start
2 arguments: Both start and end are set by the arguments
String.split wrapper
0 argument: seperator default to " "
1 argument: seperator = argument
Document.write(current_string) wrapper
Return the current string length
Return the current string
String.charAt wrapper
String.charCodeAt wrapper
String.substr wrapper
Replace a substring of the current string with another string
Returns the number of times the needle substring occurs in the haystack string. Please note that needle is case sensitive.
Compares the current string from position offset with str up to length characters.
String.toLowerCase() wrapper
Lower the case of the first charater for the current string
Lower the first character of every words inside the current string
String.toUpperCase() wrapper
Up the case of the first character of the current string
Up the case of the first character of every words in the current string
Remove all spaces from the right of the current string
Remove all spaces from the left of the current string
Remove all spaces from the left and the right of the current string
Reverse the order of characters in the current string
Replace strings with other strings. Can take string, arrays and objects as argument. Set all to true to replace each instances of a string instead of the first one found.
Same as above, actually call the method above but always passing all as true.
Remove a given string from the current string, if all is true all occurence will be removed instead of the first one found.
Same as above but always replace all occurences.
Wraps buffer to selected number of characters using string break character
Append one or multiple string(s) to the current string
Escapes single quote, double quotes and backslash characters in current string with backslashes
1 argument: Append and prepend start to the current string
2 arguments: Prepend start and append end to the current string
Add a given at the end of the current string
Add a given string at the beginning of the current string
Convert return carriage to BR element
Remove all tags from the current string
Remove all slashes from the current string
Create a link using the current string
Convert URLs found in the current string into HTML hyperlinks
Convert emails found in the current string into HTML hyperlinks
Encode entities in the current string
Decode entities in the current string
Encode HTML special characters in the current string
Decode HTML special characters in the current string
Structure is inspired by jQuery (http://jquery.com) and strings manipulation methods are inspired and/or partially taken from phpjs (http://phpjs.org).
Thanks to both projects for their amazing work.