Overview
Sorionlib provides a collection of utility functions to simplify common programming tasks. Import them from theutils module.
String utilities
slugify(text)
Converts a string to a URL-friendly slug.
| Parameter | Type | Description |
|---|---|---|
text | string | The text to convert. |
string - The slugified text.
capitalize(text)
Capitalizes the first letter of a string.
| Parameter | Type | Description |
|---|---|---|
text | string | The text to capitalize. |
string - The capitalized text.
truncate(text, length)
Truncates a string to a specified length.
| Parameter | Type | Description |
|---|---|---|
text | string | The text to truncate. |
length | number | Maximum length. |
string - The truncated text with ellipsis if needed.
Array utilities
unique(array)
Removes duplicate values from an array.
| Parameter | Type | Description |
|---|---|---|
array | array | The array to deduplicate. |
array - Array with unique values.
chunk(array, size)
Splits an array into chunks of a specified size.
| Parameter | Type | Description |
|---|---|---|
array | array | The array to split. |
size | number | Size of each chunk. |
array - Array of chunks.
shuffle(array)
Randomly shuffles an array.
| Parameter | Type | Description |
|---|---|---|
array | array | The array to shuffle. |
array - The shuffled array.
Object utilities
deepClone(object)
Creates a deep copy of an object.
| Parameter | Type | Description |
|---|---|---|
object | object | The object to clone. |
object - The cloned object.
merge(target, source)
Deep merges two objects.
| Parameter | Type | Description |
|---|---|---|
target | object | The target object. |
source | object | The source object. |
object - The merged object.
Date utilities
formatDate(date, format)
Formats a date according to a pattern.
| Parameter | Type | Description |
|---|---|---|
date | Date | The date to format. |
format | string | Format pattern. |
string - The formatted date.
timeAgo(date)
Returns a human-readable relative time string.
| Parameter | Type | Description |
|---|---|---|
date | Date | The date to compare. |
string - Relative time string.