Skip to content

Commit ea4e3f6

Browse files
committed
feat(stringifier): use ponyfills for older browsers
1 parent 1e2fc63 commit ea4e3f6

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
},
1010
"bugs": "https://github.com/twada/stringifier/issues",
1111
"dependencies": {
12+
"array-filter": "~0.2.0",
13+
"array-foreach": "~1.0.1",
14+
"array-reduce-right": "~1.0.0",
15+
"indexof": "~0.0.1",
1216
"traverse": "~0.6.6",
1317
"type-name": "~1.0.1",
1418
"xtend": "~4.0.0"

strategies.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
'use strict';
22

33
var typeName = require('type-name'),
4+
forEach = require('array-foreach'),
5+
arrayFilter = require('array-filter'),
6+
reduceRight = require('array-reduce-right'),
7+
indexOf = require('indexof'),
48
slice = Array.prototype.slice,
59
END = {},
610
ITERATE = {};
711

812
// arguments should end with end or iterate
913
function compose () {
1014
var filters = slice.apply(arguments);
11-
return filters.reduceRight(function(right, left) {
15+
return reduceRight(filters, function(right, left) {
1216
return left(right);
1317
});
1418
}
@@ -35,7 +39,7 @@ function filter (predicate) {
3539
isIteratingArray = (typeName(x) === 'Array');
3640
if (typeName(predicate) === 'function') {
3741
toBeIterated = [];
38-
acc.context.keys.forEach(function (key) {
42+
forEach(acc.context.keys, function (key) {
3943
var indexOrKey = isIteratingArray ? parseInt(key, 10) : key,
4044
kvp = {
4145
key: indexOrKey,
@@ -80,8 +84,8 @@ function allowedKeys (orderedWhiteList) {
8084
return function (acc, x) {
8185
var isIteratingArray = (typeName(x) === 'Array');
8286
if (!isIteratingArray && typeName(orderedWhiteList) === 'Array') {
83-
acc.context.keys = orderedWhiteList.filter(function (propKey) {
84-
return acc.context.keys.indexOf(propKey) !== -1;
87+
acc.context.keys = arrayFilter(orderedWhiteList, function (propKey) {
88+
return indexOf(acc.context.keys, propKey) !== -1;
8589
});
8690
}
8791
return next(acc, x);
@@ -93,7 +97,7 @@ function safeKeys () {
9397
return function (next) {
9498
return function (acc, x) {
9599
if (typeName(x) !== 'Array') {
96-
acc.context.keys = acc.context.keys.filter(function (propKey) {
100+
acc.context.keys = arrayFilter(acc.context.keys, function (propKey) {
97101
// Error handling for unsafe property access.
98102
// For example, on PhantomJS,
99103
// accessing HTMLInputElement.selectionEnd causes TypeError

0 commit comments

Comments
 (0)