StructureJS
0.14.1A class based utility library for building modular and scalable web platform applications. Features opt-in classes and utilities which provide a solid foundation and toolset to build your next project.
The StringUtil...
createUUID
()
String
public
static
Creates a universally unique identifier.
StringUtil.createUUID();
// 'a95d7134-3342-4001-bcea-cc0371b70dec'
format
str
...rest
Replaces each format item in a specified string with the text equivalent of a corresponding object's value.
str
String
...rest
Array. StringUtil.format('Robert is {0}. Very {0} and {1}!', 'cool', 'smart');
// 'Robert is cool. Very cool and smart!'
getExtension
filename
withDot
Gets the extension name off the string being passed in.
filename
String
withDot
Boolean
If you want the period to be included in the extension name.
StringUtil.getExtension('file.exe');
// 'exe'
StringUtil.getExtension('file.exe', true);
// '.exe'
paramReplace
queryString
name
value
Updates a value in the query string by its key name.
queryString
Object
name
Object
value
Object
StringUtil.paramReplace('?name=Robert&age=23&gender=male', 'gender', 'female');
// '?name=Robert&age=23&gender=female'
queryStringToObject
queryString
[useParseFloat=false]
Converts a query string to an object.
queryString
String
[useParseFloat=false]
Boolean
optional
If true converts strings to numbers.
StringUtil.queryStringToObject('?name=Robert&age=23&gender=male');
// {name: 'Robert', age: '23', gender: 'male'}
StringUtil.queryStringToObject('?name=Robert&age=23&gender=male', true);
// {name: 'Robert', age: 23, gender: 'male'}
removeAllWhitespace
str
Remove all whitespace from the string passed in.
str
String
let str = ' a b c d e f g ';
StringUtil.removeAllWhitespace(str);
// 'abcdefg'
removeLeadingTrailingWhitespace
str
Remove leading and trailing whitespace.
str
String
let str = ' a b c d e f g ';
StringUtil.removeLeadingTrailingWhitespace(str);
// 'a b c d e f g'
toCamelCase
str
Converts a string to a camel case string.
str
String
StringUtil.toCamelCase("liveDown_by-the.River");
// 'liveDownByTheRiver'
toConstantCase
str
Converts a string to a constant case string.
str
String
StringUtil.toConstantCase("liveDown_by-the.River");
// 'LIVE_DOWN_BY_THE_RIVER'
toPascalCase
str
Converts a hyphen string to a pascal case string.
str
String
StringUtil.toPascalCase("liveDown_by-the.River");
// 'LiveDownByTheRiver'
toQueryString
obj
Converts a query string to an object.
obj
Object
StringUtil.toQueryString({name: 'Robert', age: '23', gender: 'male'});
// name=Robert&age=23&gender=male'
toSentence
str
[separator]
Converts a string to a sentence case string.
str
String
[separator]
String
optional
Can be any string you want to use as a separator.
StringUtil.toSentence("liveDown_by-the.River");
// 'live down by the river'
StringUtil.toSentence("liveDown_by-the.River", '-');
// 'live-down-by-the-river'
StringUtil.toSentence("liveDown_by-the.River", '_');
// 'live_down_by_the_river'
StringUtil.toSentence("liveDown_by-the.River", '/');
// 'live/down/by/the/river'
truncate
text
length
indicator
text
String
length
Int
indicator
String
StringUtil.truncate('Robert is cool and he likes bruschetta.', 14));
// 'Robert is cool...'
StringUtil.truncate('Robert is cool and he likes bruschetta.', 14, '!!!'));
// 'Robert is cool!!!'