1
0
Fork 0
mirror of synced 2024-07-05 14:31:17 +12:00
budibase/packages/builder/scripts/jestSetup.js

27 lines
669 B
JavaScript
Raw Normal View History

2020-08-27 21:34:44 +12:00
// Array.flat needs polyfilled in < Node 11
2020-08-27 21:20:01 +12:00
if (!Array.prototype.flat) {
Object.defineProperty(Array.prototype, "flat", {
configurable: true,
value: function flat() {
var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0])
return depth
? Array.prototype.reduce.call(
this,
function(acc, cur) {
if (Array.isArray(cur)) {
acc.push.apply(acc, flat.call(cur, depth - 1))
} else {
acc.push(cur)
}
return acc
},
[]
)
: Array.prototype.slice.call(this)
},
writable: true,
})
}