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. | Component | - | Array |
| tagProperties | Get all the properties with a metadata flag of a component. Property includes name, value, flags and facets. | Component | - | Array |
| number | Extract a number at the end of a String. | String |
| String |
| addFacets | Concatenates facets. | BFacets |
| BFacets |
| removeFacets | Remove a key from facets. | BFacets |
| BFacets |
| format | Resolve a BFormat or BSFormat slot on the last base. | Component |
| Object |
| method | Call a method on the base with the given parameters. | Object |
| Object |
| methodWithCx | Call a method on the base with the given parameters and the context. | Object |
| Object |
| json | Extract a value from a json. See JsonFormat documentation: JSON Key Selector | Json | See JsonFormat documentation | Json / Primitive |
| equals | Return whether a member is equal to an other. | String / Double / Boolean |
| Boolean |
| like | Return whether a String is like an other. | String |
| Boolean |
| lessThan | Return whether a number is less than an other. | Number |
| Boolean |
| greaterThan | Return whether a number is greater than an other. | Number |
| Boolean |
| and | Return true if both conditions are valid. | Boolean |
| Boolean |
| or | Return true if at least one of the conditions is valid. | Boolean |
| Boolean |
| not | Return true if the base is false and false if the base is true. | Boolean | - | Boolean |
| node | Get the first node of the results. See nodes() method. | Node / InfoSource |
| Node |
| nodes | For infoSources: get the nodes from which the component is source of on the given aspect. For nodes: get the ascendants node of a given level. | Node / InfoSource |
| Node |
| infoSource | Get the infoSource of a source. | Component | - | InfoSource |
| tag | Get the value of a tag. | Component |
| Object |
| inRel | Get the endpoint of the first inbound relation with the given id. | Component |
| Component |
| outRel | Get the endpoint of the first outbound relation with the given id. | Component |
| Component |
| rel | Get the endpoint of the first relation with the given id in the given direction. | Component |
| Component |
| relations | Get the endpoints of all the relations with the given id in the given direction. | Component |
| Array |
| inLink | Get the endpoint of the first inbound link on the given slot. | Component |
| Component |
| outLink | Get the endpoint of the first outbound link on the given slot. | Component |
| Component |
| link | Get the endpoint of the first link on the given slot in the given direction. | Component |
| Component |
| links | Get the endpoints of all the links on the given slot in the given direction. | Component |
| Array |
| category | Get a category created with a CategoryBlock. | Component | - | Category |
| hasCategory | Check if a component has the given category. | Component |
| Boolean |
| hasExactCategory | Check if a component has only the given category. | Component |
| Boolean |
| hasCategories | Check if a component has the given categories. | Component |
| Boolean |
| hasExactCategories | Check if a component has the only given categories. | Component |
| Boolean |
| widget | Get a widget identified by an id. | Base |
| Widget |
| column | Get a column of a table. Column can be identified by name or index. Index is starting at 0. Index 0 is often timestamp, 1 is often status. | Table |
| Column |
| columns | Get all the columns of a table | Table | - | Array |