מחבר:
הפנו את עוזר ה-AI המועדף עליכם למסמך הזהChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Init history"v5.5.1029.6.2025
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתעריכת המסמך הזה
אם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודנוצר:2025-08-23עדכון אחרון:2026-09-27
העתקה
העתקת ה-Markdown של המסמך ללוח
Documentation: getEnumeration Function in intlayer
Description
The getEnumeration function (also aliased as enu) 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.
For more details on how to declare enumerations, see the Enumeration documentation.
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
typescript
העתקת קוד
העתקת הקוד ללוח
import { getEnumeration } from "intlayer";
const content = getEnumeration(
{
"<=-2.3": "You have less than -2.3",
"<1": "You have less than one",
"2": "You have two",
">=3": "You have three or more",
},
2
);
console.log(content); // Output: "You have two"
Priority of Conditions
typescript
העתקת קוד
העתקת הקוד ללוח
import { getEnumeration } from "intlayer";
const content = getEnumeration(
{
"<4": "You have less than four",
"2": "You have two",
},
2
);
console.log(content); // Output: "You have less than four"
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 behavior.
- 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.
