Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
This doc is out of date, the base version has been updated on 23 August 2025.
Go to English docVersion History
- "Init history"v5.5.1029/06/2025
The content of this page was translated using an AI.
See the last version of the original content in EnglishIf you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Documentation: getEnumeration Function in intlayer
Description
The getEnumeration function retrieves content corresponding to a specific quantity based on predefined conditions in an enumeration object. The conditions are defined as keys, and their priority is determined by their order in the object.
Parameters
enumerationContent: QuantityContent<Content>- Description: An object where keys represent conditions (e.g.,
<=,<,>=,=) and values represent the corresponding content. The order of keys defines their matching priority. - Type:
QuantityContent<Content>Contentcan be any type.
- Description: An object where keys represent conditions (e.g.,
quantity: number- Description: The numeric value used to match against the conditions in
enumerationContent. - Type:
number
- Description: The numeric value used to match against the conditions in
Returns
- Type:
Content - Description: The content corresponding to the first matching condition in the
enumerationContent. If no match is found, it defaults to handling based on the implementation (e.g., error or fallback content).
Example Usage
Basic Usage
Priority of Conditions
Edge Cases
No Matching Condition:
- If no condition matches the provided quantity, the function will either return
undefinedor handle the default/fallback scenario explicitly.
- If no condition matches the provided quantity, the function will either return
Ambiguous Conditions:
- If conditions overlap, the first matching condition (based on object order) takes precedence.
Invalid Keys:
- The function assumes that all keys in
enumerationContentare valid and parsable as conditions. Invalid or improperly formatted keys may lead to unexpected behaviour.
- The function assumes that all keys in
TypeScript Enforcement:
- The function ensures that the
Contenttype is consistent across all keys, allowing for type safety in the retrieved content.
- The function ensures that the
Notes
- The
findMatchingConditionutility is used to determine the appropriate condition based on the given quantity.