mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-15 10:32:24 +03:00
20 lines
351 B
JavaScript
20 lines
351 B
JavaScript
import isArray from './isArray'
|
|
import { isObject } from './typeof'
|
|
|
|
export function ensureIsArray(arg, key) {
|
|
if (!key || !isObject(arg)) {
|
|
return isArray(arg) ? arg : []
|
|
}
|
|
|
|
if (!isArray(arg[key])) {
|
|
arg[key] = []
|
|
}
|
|
return arg
|
|
}
|
|
|
|
export function ensuredPush(object, key, el) {
|
|
ensureIsArray(object, key)
|
|
|
|
object[key].push(el)
|
|
}
|