StructureJS

0.15.2

A 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.

StringUtil Class

Module: util
Parent Module: StructureJS

The StringUtil...

Index

Show:

Methods

createUUID () String public static

Creates a universally unique identifier.

Returns:

Example:

 StringUtil.createUUID();
 // 'a95d7134-3342-4001-bcea-cc0371b70dec'

format
(
  • str
  • ...rest
)
String public static

Replaces each format item in a specified string with the text equivalent of a corresponding object's value.

Parameters:

Returns:

Example:

 StringUtil.format('Robert is {0}. Very {0} and {1}!', 'cool', 'smart');
 // 'Robert is cool. Very cool and smart!'

getExtension
(
  • filename
  • withDot
)
String public static

Gets the extension name off the string being passed in.

Parameters:

  • filename String
  • withDot Boolean

    If you want the period to be included in the extension name.

Returns:

Example:

 StringUtil.getExtension('file.exe');
 // 'exe'

 StringUtil.getExtension('file.exe', true);
 // '.exe'

paramReplace
(
  • queryString
  • name
  • value
)
String | Void

Updates a value in the query string by its key name.

Parameters:

Returns:

String | Void:

Example:

 StringUtil.paramReplace('?name=Robert&age=23&gender=male', 'gender', 'female');
 // '?name=Robert&age=23&gender=female'

queryStringToObject
(
  • queryString
  • [useParseFloat=false]
)
Object | Null public static

Converts a query string to an object.

Parameters:

  • queryString String
  • [useParseFloat=false] Boolean optional

    If true converts strings to numbers.

Returns:

Object | Null:

Example:

 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
)
String public static

Remove all whitespace from the string passed in.

Parameters:

Returns:

Example:

 let str = '   a b    c d e f g ';
 StringUtil.removeAllWhitespace(str);
 // 'abcdefg'

removeLeadingTrailingWhitespace
(
  • str
)
String public static

Remove leading and trailing whitespace.

Parameters:

Returns:

Example:

 let str = '   a b    c d e f g ';
 StringUtil.removeLeadingTrailingWhitespace(str);
 // 'a b    c d e f g'

toCamelCase
(
  • str
)
String public static

Converts a string to a camel case string.

Parameters:

Returns:

Example:

 StringUtil.toCamelCase("liveDown_by-the.River");
 // 'liveDownByTheRiver'

toConstantCase
(
  • str
)
String public static

Converts a string to a constant case string.

Parameters:

Returns:

Example:

 StringUtil.toConstantCase("liveDown_by-the.River");
 // 'LIVE_DOWN_BY_THE_RIVER'

toPascalCase
(
  • str
)
String public static

Converts a hyphen string to a pascal case string.

Parameters:

Returns:

Example:

 StringUtil.toPascalCase("liveDown_by-the.River");
 // 'LiveDownByTheRiver'

toQueryString
(
  • obj
)
public static

Converts a query string to an object.

Parameters:

Example:

 StringUtil.toQueryString({name: 'Robert', age: '23', gender: 'male'});
 // name=Robert&age=23&gender=male'

toSentence
(
  • str
  • [separator]
)
String public static

Converts a string to a sentence case string.

Parameters:

  • str String
  • [separator] String optional

    Can be any string you want to use as a separator.

Returns:

Example:

 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
)
String public static

Parameters:

Returns:

Example:

  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!!!'

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index