mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-13 01:02:24 +03:00
2231ec1aa1
* feat: try to detect global mixins adding meta info * fix: add find polyfill for ie * fix: only detect global mixins when Vue.devtools: true
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
/*
|
|
* To reduce build size, this file provides simple polyfills without
|
|
* overly excessive type checking and without modifying
|
|
* the global Array.prototype
|
|
* The polyfills are automatically removed in the commonjs build
|
|
* Also, only files in client/ & shared/ should use these functions
|
|
* files in server/ still use normal js function
|
|
*/
|
|
|
|
// this const is replaced by rollup to true for umd builds
|
|
// which means the polyfills are removed for other build formats
|
|
const polyfill = process.env.NODE_ENV === 'test'
|
|
|
|
export function find (array, predicate, thisArg) {
|
|
if (polyfill && !Array.prototype.find) {
|
|
// idx needs to be a Number, for..in returns string
|
|
for (let idx = 0; idx < array.length; idx++) {
|
|
if (predicate.call(thisArg, array[idx], idx, array)) {
|
|
return array[idx]
|
|
}
|
|
}
|
|
return
|
|
}
|
|
return array.find(predicate, thisArg)
|
|
}
|
|
|
|
export function findIndex (array, predicate, thisArg) {
|
|
if (polyfill && !Array.prototype.findIndex) {
|
|
// idx needs to be a Number, for..in returns string
|
|
for (let idx = 0; idx < array.length; idx++) {
|
|
if (predicate.call(thisArg, array[idx], idx, array)) {
|
|
return idx
|
|
}
|
|
}
|
|
return -1
|
|
}
|
|
return array.findIndex(predicate, thisArg)
|
|
}
|
|
|
|
export function toArray (arg) {
|
|
if (polyfill && !Array.from) {
|
|
return Array.prototype.slice.call(arg)
|
|
}
|
|
return Array.from(arg)
|
|
}
|
|
|
|
export function includes (array, value) {
|
|
if (polyfill && !Array.prototype.includes) {
|
|
for (const idx in array) {
|
|
if (array[idx] === value) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
return array.includes(value)
|
|
}
|