1
1
'use strict' ;
2
2
3
3
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' ) ,
4
8
slice = Array . prototype . slice ,
5
9
END = { } ,
6
10
ITERATE = { } ;
7
11
8
12
// arguments should end with end or iterate
9
13
function compose ( ) {
10
14
var filters = slice . apply ( arguments ) ;
11
- return filters . reduceRight ( function ( right , left ) {
15
+ return reduceRight ( filters , function ( right , left ) {
12
16
return left ( right ) ;
13
17
} ) ;
14
18
}
@@ -35,7 +39,7 @@ function filter (predicate) {
35
39
isIteratingArray = ( typeName ( x ) === 'Array' ) ;
36
40
if ( typeName ( predicate ) === 'function' ) {
37
41
toBeIterated = [ ] ;
38
- acc . context . keys . forEach ( function ( key ) {
42
+ forEach ( acc . context . keys , function ( key ) {
39
43
var indexOrKey = isIteratingArray ? parseInt ( key , 10 ) : key ,
40
44
kvp = {
41
45
key : indexOrKey ,
@@ -80,8 +84,8 @@ function allowedKeys (orderedWhiteList) {
80
84
return function ( acc , x ) {
81
85
var isIteratingArray = ( typeName ( x ) === 'Array' ) ;
82
86
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 ;
85
89
} ) ;
86
90
}
87
91
return next ( acc , x ) ;
@@ -93,7 +97,7 @@ function safeKeys () {
93
97
return function ( next ) {
94
98
return function ( acc , x ) {
95
99
if ( typeName ( x ) !== 'Array' ) {
96
- acc . context . keys = acc . context . keys . filter ( function ( propKey ) {
100
+ acc . context . keys = arrayFilter ( acc . context . keys , function ( propKey ) {
97
101
// Error handling for unsafe property access.
98
102
// For example, on PhantomJS,
99
103
// accessing HTMLInputElement.selectionEnd causes TypeError
0 commit comments