mirror of
https://github.com/badges/shields.git
synced 2026-11-21 16:06:35 +03:00
* 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
20 lines
469 B
JavaScript
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]
|
|
}
|
|
}
|