String manipulation

lowerCase( )

Lower case all letters.

Examples

'My Car':lowerCase() // "my car"
'my car':lowerCase() // "my car"
null:lowerCase() // null
1203:lowerCase() // 1203

upperCase( )

Upper case all letters.

Examples

'My Car':upperCase() // "MY CAR"
'my car':upperCase() // "MY CAR"
null:upperCase() // null
1203:upperCase() // 1203

ucFirst( )

Upper case first letter.

Examples

'My Car':ucFirst() // "My Car"
'my car':ucFirst() // "My car"
null:ucFirst() // null
undefined:ucFirst() // undefined
1203:ucFirst() // 1203

ucWords( )

Upper case the first letter of all words.

Examples

'my car':ucWords() // "My Car"
'My cAR':ucWords() // "My CAR"
null:ucWords() // null
undefined:ucWords() // undefined
1203:ucWords() // 1203
  • "catch all formatter"

  • always returns the same message if called

ParametersDescriptionType

message

text to print

string

Examples

'My Car':print('hello!') // "hello!"
'my car':print('hello!') // "hello!"
null:print('hello!') // "hello!"
1203:print('hello!') // "hello!"

convEnum( type )

  • converts user-defined enums to human readable values

  • user-defined enums must be passed in options of carbone.render

ParametersDescriptionType

type

enum name passed in options of carbone.render(data, options)

string

Examples

// with options = {
//   "enum": {
//     "ORDER_STATUS": [
//       "pending",
//       "sent",
//       "delivered"
//     ]
//   }
// }
0:convEnum('ORDER_STATUS') // "pending"
1:convEnum('ORDER_STATUS') // "sent"
5:convEnum('ORDER_STATUS') // 5
// with options = {
//   "enum": {
//     "YES_NO": {
//       "true": "Yes",
//       "false": "No"
//     }
//   }
// }
false:convEnum('YES_NO') // "No"
true:convEnum('YES_NO') // "Yes"
null:convEnum('YES_NO') // null
3:convEnum('UNKNOWN_ENUM') // 3

unaccent( )

Removes accents from text.

Examples

'crème brulée':unaccent() // "creme brulee"
'CRÈME BRULÉE':unaccent() // "CREME BRULEE"
'être':unaccent() // "etre"
'éùïêèà':unaccent() // "euieea"

convCRLF( )

Renders carriage return \r and line feed into documents instead of printing them as a string.

  • supported file formats: DOCX, PDF, ODT, ODS

    • ODS support is experimental

  • use the :convCRLF formatter before :html to convert to <br> tags

    • example: {d.content:convCRLF:html}

Examples

// with options = {
//   "extension": "odt"
// }
'my blue \n car':convCRLF() // "my blue <text:line-break/> car"
'my blue \r\n car':convCRLF() // "my blue <text:line-break/> car"
// with options = {
//   "extension": "docx"
// }
'my blue \n car':convCRLF() // "my blue </w:t><w:br/><w:t> car"
'my blue \r\n car':convCRLF() // "my blue </w:t><w:br/><w:t> car"

substr( begin, end )

Slices a string with a begin and an end.

ParametersDescriptionType

begin

Zero-based index at which to begin extraction.

integer

end

Zero-based index before which to end extraction

integer

Examples

'foobar':substr(0, 3) // "foo"
'foobar':substr(1) // "oobar"
'foobar':substr(-2) // "ar"
'foobar':substr(2, -1) // "oba"

padl( targetLength, padString )

Pads the string from the start with another string.

ParametersDescriptionType

targetLength

The length of the resulting string once the string has been padded. If the value is less than string length, then string is returned as-is.

number

padString

The string to pad the current str with. If padString is too long to stay within the targetLength, it will be truncated from the end. The default value is " "

string

Examples

'abc':padl(10) // "       abc"
'abc':padl(10, 'foo') // "foofoofabc"
'abc':padl(6, '123465') // "123abc"
'abc':padl(8, '0') // "00000abc"
'abc':padl(1) // "abc"

padr( targetLength, padString )

Pads the string from the end with another string.

ParametersDescriptionType

targetLength

The length of the resulting string once the string has been padded. If the value is less than string length, then string is returned as-is.

number

padString

The string to pad the current str with. If padString is too long to stay within the targetLength, it will be truncated from the end. The default value is " "

string

Examples

'abc':padr(10) // "abc       "
'abc':padr(10, 'foo') // "abcfoofoof"
'abc':padr(6, '123465') // "abc123"
'abc':padr(8, '0') // "abc00000"
'abc':padr(1) // "abc"

len( )

Returns the length of a string or array.

Examples

'Hello World':len() // 11
'':len() // 0
[1,2,3,4,5]:len() // 5
[1,'Hello']:len() // 2

Last updated