SFormat
The SFormat is a super BFormat. It provides additional features to navigate through components & relations, read tags, modify text (escape, substring, etc) and so on.
A SFormat is defined by a chain of characters between curly brackets { } and is a succession of functions used to build the result. Unlike the BFormat, the SFormat result can be a component or any object (while BFormat can only result in a String).
Example: {parent.relations('out','b:isIn').item(1).%displayName%} -> Take the parent, then follow its outbound relations b:isIn, then take the second element (because there might be several relations) and then apply the BFormat to get the displayName.
Functions in a SFormat can take parameters between parenthesis and separated by a coma. It can take one of the following parameters depending on the function:
String: 'param'
Number: 3 or 6.4
Boolean: true or false
SFormat is used in Active components such as InfoSource, HistoryDisplayName management and is mainly used in Strategies.
Example: {parent.inRel('b:isIn')}
Classic BFormat can be defined between %...% (as usual). It can be introduced after the definition of a component by SFormat functions or directly at the root as a classic BFormat.
Example: {parent.inRel('b:isIn').%displayName%}
If you want to avoid interpretation of SFormat, you can use [...], so the format will not be resolved.
Example: station:|slot:|bql:select slotPathOrd, displayName, [btibCore:BqlLib.sFormat('{origin.inRel(b:strSourceOf).parent.%slotPathOrd%}')] from btibStructure:Node where b:floor = '{origin.%displayName%}' will result in: station:|slot:|bql:select slotPathOrd, displayName, btibCore:BqlLib.sFormat('{origin.inRel(b:strSourceOf).parent.%slotPathOrd%}') from btibStructure:Node where b:floor = 'Floor 1'
Here is the list of the functions currently implemented by the SFormat.
Recently added functions are highlighted in blue.
Name | Description | Base Type | Parameters | Return Type |
|---|---|---|---|---|
parent | Get the parent of a component. | Component | - | Component |
children | Get the children of a component. | Component | - | Array |
slot | Get a slot of a component. | Component |
| Object |
child | Deprecated. This function is now called 'slot'. | Component |
| Object |
length | Get the size of an array or of a String. | Array | - | Number |
item | Get the item of an array at a given index. Index starts at 0. | Array |
| Object |
first | Get the first item of an array. | Array | - | Object |
last | Get the last item of an array. | Array | - | Object |
removeFirst | Remove the first item of the array return the array. | Array | - | Array |
removeLast | Remove the last item of the array return the array. | Array | - | Array |
removeDuplicates | Remove the duplicates from an array. | Array | - | Array |
filter | Filter the values of an array. Value is valid if equals to the given String, boolean or double. | Array |
| Array |
display | Convert an array into a String using a format. Format is applied to each value of the array. Use [] to protect SFormat from resolve. Use \n for line break. | Array |
| String |
ord | Execute a query: slotPathOrd, bql or neql. Base: absolute or relative. | Component |
| Array |
escape | Escape a String. | String | - | String |
unescape | Unescape a String. | String | - | String |
toFriendly | Convert a String to friendly case. | String | - | String |
fromFriendly | Convert a String from friendly case. | String | - | String |
fileName | Replace special chars (including accents) by _ | String | - | String |
safeName | Stripe accents and replace special chars by _ | String | - | String |
substring | Reduce a String between two indexes. | String |
| String |
substringFromEnd | Remove x characters from a String, starting at the end. | String |
| String |
indexOf | Return the index of an input String. | String |
| Number |
replace | Replace an input String in the base. | String |
| String |
prefix | Will return the prefix followed by the base if the base is not null or empty. | String |
| String |
suffix | Will return the base followed by the suffix if the base is not null or empty. | String |
| String |
split | Split a String depending on a sequence of chars. | String |
| Array |
splitRegex | Split a String depending on a regex. | String |
| Array |
orEmpty | Will return the base if the base is not null or empty. | String | - | Boolean |
toDynamicEnum | Convert an array into a value to a dynamic enum. | Array | - | DynamicEnum |
toDynamicEnums | Convert an array of x elements into an array of x enums with only one value. | Array | - | DynamicEnums |
toString | Convert the base in a String. | Object | - | String |
toInt | Convert the base in an integer. | Object | - | Number |
toDouble | Convert the base in a double. | Object | - | Number |
toOrd | Convert the base in an ord. | Object | - | Ord |
toBrush | Convert the base in a brush. | Object | - | Brush |
toTag | Get the tag of the value of an enum. | Object | - | String |
toDisplayTag | Get the display tag of the value of an enum. | Object | - | String |
toSimple | Convert the base in a Simple. | Object |
| Simple |
add | Add a number to another. | Number |
| Number |
subtract | Subtract a number to another. | Number |
| Number |
multiply | Multiply a number to another. | Number |
| Number |
divide | Divide a number to another. | Number |
| Number |
pxView | Get the ord of the file of a pxView. | Component |
| Ord |
isType | Return whether a component is from the given type or not. | Component |
| Boolean |
checkType | Return the base if it's from the given type. | Component |
| Boolean |
makeType | Create a new instance of a type. | Component |
| Object |
exists | Return whether an object/slot exists, i.e. is not null. | Object | - | Boolean |
isNull | Return whether an object is null. Also see isInvalid() function. | Object | - | Boolean |
isEmpty | Return whether an array is empty. | Array | - | Boolean |
isInvalid | Return whether an object is null or a String is equals to "null", is empty or contains "err:". | String | - | Boolean |
property | Get a property of a component identified by its name. Property includes name, value, flags and facets. | Component |
| Object |
properties | Get all the properties of a component. Property includes name, value, flags and facets. | Component | - | Array |
frozenProperties | Get all the frozen properties of a component. Property includes name, value, flags and facets. | Component | - | Array |
dynamicProperties | Get all the dynamic properties of a component. Property includes name, value, flags and facets. |