Utilities
Estimated reading time: 5 minutesOverview
The framework provides a complete set of utility functions, globally mounted on window, available anywhere in mod development.
These functions cover data handling, random generation, conditionals, string conversion, numeric clamping, image loading, and more, to reduce boilerplate and improve mod development efficiency.
All utilities can be called directly:
Function List
Data Utilities
Deep Clone (clone)
Deep clones common objects, including:
- Plain objects, arrays
Date,RegExpMap,SetArrayBuffer,DataView, TypedArray
Params: source, opt.deep (default true), opt.proto (default true)
Returns: Cloned object
Deep Compare (equal)
Deep compares two values; uses lodash deep-equal logic internally.
Params: a, b
Returns: true or false
Recursive Merge (merge)
Mutates the target object and recursively merges sources.
Modes: replace (replace arrays, default), concat (concatenate arrays), merge (merge by index)
Params: target, ...sources, mode, filterFn
Returns: Merged target
Array Contains (contains)
Supports single/multiple values, deep compare, case-insensitive, custom comparator.
Modes: all (all exist), any (any exists), none (none exist)
Params: arr, value (single value or array), mode, opt.case, opt.compare, opt.deep
Returns: Boolean
Random Utilities
Random Number (random)
Generates random integers or floats.
Params: min, max, float; or config object { min, max, float }
Returns: Random number
Random Pick (either)
Supports array/args form, weights, and null option.
Params: itemsOrA (array or first item), ...rest, weights, null (allow null)
Returns: Randomly selected value
Conditional Utilities
SelectCase
For multi-branch conditions, range matching, regex, and custom predicates.
Methods: .case(), .casePredicate(), .caseRange(), .caseIn(), .caseIncludes(), .caseRegex(), .caseCompare(), .else(), .match()
Returns: match() returns first matching result; otherwise else() default
String Utilities
Convert (convert)
Supports common naming style conversion; title mode can preserve acronyms.
Modes: lower, upper, capitalize, title, camel, pascal, snake, kebab, constant
Params: str, mode (default 'lower'), opt.delimiter, opt.acronym
Returns: Converted string
Numeric Utilities
Clamp / Round (number)
Converts any input to a valid number with:
- Fallback for invalid values
- Min/max range
- Rounding modes (floor, ceil, round, trunc)
- Step snapping
- Percent output
- Loop/cyclic range
Params: value, fallback (default 0), min, max, mode, opt.step, opt.percent, opt.loop
Returns: Clamped number; when opt.percent is true, returns 0–100 percent
Resource Utilities
Load Image (loadImage)
Checks if image exists and returns loadable result.
Params: src (image path)
Returns: Sync: string or boolean; async: Promise
