2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-15 10:32:24 +03:00
Files
vue-meta/src/shared/ensure.js
T
2019-02-23 12:33:30 +01:00

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)
}