Files
Inuka Wijerathna 313cc05608 docs(core): add JSDoc to toArray, coalesce, and trace utilities (#11909)
* docs(core): add JSDoc to toArray utility

* docs(core): add JSDoc to coalesce utility

* docs(core): add JSDoc to trace logging utilities

* fix(docs): remove invalid JSDoc inline tag and add trailing newline in coalesce

* fix(docs): add trailing newline to to-array

* fix(docs): add @param description for options and trailing newline in trace

* fix(docs): ensure LF line endings in coalesce

* fix(docs): ensure LF line endings in to-array

* fix(docs): ensure LF line endings in trace

* fix(docs): insert JSDoc into original trace.js preserving template literals
2026-06-07 10:57:22 +00:00

20 lines
469 B
JavaScript

/**
* Coerces a value to an array.
*
* - Returns an empty array when `val` is `undefined`.
* - Returns `val` unchanged when it is already an array.
* - Otherwise wraps `val` in a single-element array.
*
* @param {*} val - The value to coerce.
* @returns {Array} The resulting array.
*/
export default function toArray(val) {
if (val === undefined) {
return []
} else if (Object(val) instanceof Array) {
return val
} else {
return [val]
}
}