String Helpers in Calculators

The calculator has a set of string helper functions under the stringHelper class

Example

let str=stringHelper.capitalize('this is a test');
//results in This Is A Test

stringHelper.clean(s)

Trim and replace multiple spaces with a single space.

stringHelper.capitalize(s)

Converts first letter of the string to uppercase.

stringHelper.count(s, substring)

Returns number of occurrences of substring in string.

stringHelper.startsWith(s, starts, position)

This method checks whether the string begins with starts at position (default: 0).

stringHelper.endsWith(s, ends, position)

This method checks whether the string ends with ends at position (default: string.length).

stringHelper.padLeft(s, length, padStr)

Left-pad a string

stringHelper.padRight(s, length, padStr)

Right pad a string

stringHelper.replaceAll(s, find, replace, ignoreCase)

Replace all characters defined by find with the replace

stringHelper.parseTemplateObject(templateObject, data, options)

Does a dynamic parse of the provided template object. The template object can be a string, array or object. Data is the object to parse in. Options include:

  • copy (default=true) - creates a copy
  • strict (default=false) - throws an exception if a parse path cant be found
  • idCharacter (default=@) - the character that identifies a parse element

A dynamic parse supports handlebars,({{{field}}}), direct replacement({a:“@field”}) and string replacement({@field})

Examples

stringHelper.parseTemplateObject("this is a {{test}}", {test:"abc"})
//results in: this is a abc

stringHelper.parseTemplateObject("this is a {@test}", {test:"abc"})
//results in: this is a abc

stringHelper.parseTemplateObject({a:"@test"}, {test:"abc"})
//results in: {a:“abc”}