XMD User-Defined Functions - Practical Examples
XMD User-Defined Functions - Practical Examples
This document showcases real-world examples of user-defined functions in XMD, demonstrating the shell-style syntax and practical use cases.
Basic Function Examples
Simple Calculator Functions
<!-- Define basic arithmetic functions -->
<!-- Use the functions -->
**Calculations:**
- 5 + 3 =
- 4 × 7 =
- 8² =
- (5 + 3) × 2 =
String Processing Functions
<!-- Use string functions -->
>
Web Development Examples
HTML Generation Functions
<!-- Generate HTML -->
Check out !
CSS Class Helpers
<!-- Generate styled elements -->
Important text
Data Processing Examples
Array Processing Functions
**Fruit List:**
**Numbers:**
Template Functions
<!-- Generate user profiles -->
<!-- Generate code examples -->
Documentation Generation
API Documentation Functions
<!-- Generate API docs -->
**Parameters:**
Table Generation Functions
<!-- Generate tables -->
Content Management Examples
Blog Post Functions
<!-- Generate blog post -->
Navigation Functions
**Navigation:**
-
-
-
Advanced Pattern Examples
Conditional Content Functions
Configuration-Based Functions
<div class="">
Content with theme-based styling
</div>
Function Composition Examples
Chaining Functions
<!-- Chain functions together -->
Data Transformation Pipeline
<!-- Transform data through pipeline -->
Best Practices Demonstrated
1. Descriptive Function Names
- Use clear, action-oriented names:
greet,calculateTotal,formatDate - Avoid abbreviations:
formatUserProfilenotfmtUsrProf
2. Parameter Clarity
- Use meaningful parameter names:
name,email,startDate - Keep parameter count reasonable (2-4 parameters ideal)
3. Single Responsibility
- Each function should do one thing well
- Compose complex behavior from simple functions
4. Consistent Return Types
- Functions should return predictable data types
- Document expected return values in comments
5. Error Handling
- Use conditional returns for edge cases
- Provide sensible defaults when possible
Integration with XMD Features
Working with Variables
Working with Imports
API Endpoint:
Working with Command Execution
**Repository Status:**
**JavaScript Files:** files found
These examples demonstrate the power and flexibility of XMD’s user-defined functions. The shell-style syntax makes them easy to write and read, while the integration with XMD’s existing features provides powerful content generation capabilities.