Skip to content

Commit a4bfc56

Browse files
authored
grammer.ne: add polyfill for Array.flat (#43)
* restore node 10 testing.
1 parent bb0a1b3 commit a4bfc56

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.github/workflows/ci-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [ ubuntu-latest ]
14-
node-version: [12.x, 14.x]
14+
node-version: [10.x, 12.x, 14.x]
1515
fail-fast: false
1616

1717
steps:

grammar.ne

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
main -> Mailbox | Path
22

33
@{%
4+
// from https://github.com/jonathantneal/array-flat-polyfill
5+
if (!Array.prototype.flat) {
6+
Object.defineProperty(Array.prototype, 'flat', {
7+
configurable: true,
8+
value: function flat () {
9+
var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0]);
10+
11+
return depth ? Array.prototype.reduce.call(this, function (acc, cur) {
12+
if (Array.isArray(cur)) {
13+
acc.push.apply(acc, flat.call(cur, depth - 1));
14+
} else {
15+
acc.push(cur);
16+
}
17+
18+
return acc;
19+
}, []) : Array.prototype.slice.call(this);
20+
},
21+
writable: true
22+
});
23+
}
24+
425
function flat_string(d) {
526
if (d) {
627
if (Array.isArray(d))

0 commit comments

Comments
 (0)