1
1
/*!
2
2
* should - test framework agnostic BDD-style assertions
3
- * @version v9 .0.2
3
+ * @version v10 .0.0
4
4
* @author TJ Holowaychuk <[email protected] >, Denis Bardadym <[email protected] > and other contributors
5
5
* @link https://github.com/shouldjs/should.js
6
6
* @license MIT
94
94
95
95
addTypeOf : function ( type , res ) {
96
96
return this . add ( function ( obj , tpeOf ) {
97
- if ( tpeOf === type ) {
97
+ if ( tpeOf === type ) {
98
98
return new Type ( res ) ;
99
99
}
100
100
} ) ;
101
101
} ,
102
102
103
103
addClass : function ( cls , res , sub ) {
104
104
return this . add ( function ( obj , tpeOf , objCls ) {
105
- if ( objCls === cls ) {
105
+ if ( objCls === cls ) {
106
106
return new Type ( types . OBJECT , res , sub ) ;
107
107
}
108
108
} ) ;
112
112
var typeOf = typeof obj ;
113
113
var cls = toString . call ( obj ) ;
114
114
115
- for ( var i = 0 , l = this . checks . length ; i < l ; i ++ ) {
115
+ for ( var i = 0 , l = this . checks . length ; i < l ; i ++ ) {
116
116
var res = this . checks [ i ] . call ( this , obj , typeOf , cls ) ;
117
- if ( typeof res !== 'undefined' ) return res ;
117
+ if ( typeof res !== 'undefined' ) {
118
+ return res ;
119
+ }
118
120
}
119
121
120
122
}
131
133
. addTypeOf ( types . BOOLEAN , types . BOOLEAN )
132
134
. addTypeOf ( types . FUNCTION , types . FUNCTION )
133
135
. addTypeOf ( types . SYMBOL , types . SYMBOL )
134
- . add ( function ( obj , tpeOf ) {
135
- if ( obj === null ) return new Type ( types . NULL ) ;
136
+ . add ( function ( obj ) {
137
+ if ( obj === null ) {
138
+ return new Type ( types . NULL ) ;
139
+ }
136
140
} )
137
141
. addClass ( '[object String]' , types . STRING )
138
142
. addClass ( '[object Boolean]' , types . BOOLEAN )
176
180
. addClass ( '[object FileList]' , types . FILE_LIST )
177
181
. addClass ( '[object XMLHttpRequest]' , types . XHR )
178
182
. add ( function ( obj ) {
179
- if ( ( typeof Promise === types . FUNCTION && obj instanceof Promise ) ||
183
+ if ( ( typeof Promise === types . FUNCTION && obj instanceof Promise ) ||
180
184
( typeof obj . then === types . FUNCTION ) ) {
181
185
return new Type ( types . OBJECT , types . PROMISE ) ;
182
186
}
183
187
} )
184
188
. add ( function ( obj ) {
185
- if ( typeof Buffer !== 'undefined' && obj instanceof Buffer ) {
189
+ if ( typeof Buffer !== 'undefined' && obj instanceof Buffer ) { // eslint-disable-line no-undef
186
190
return new Type ( types . OBJECT , types . BUFFER ) ;
187
191
}
188
192
} )
189
193
. add ( function ( obj ) {
190
- if ( typeof Node !== 'undefined' && obj instanceof Node ) {
194
+ if ( typeof Node !== 'undefined' && obj instanceof Node ) {
191
195
return new Type ( types . OBJECT , types . HTML_ELEMENT , obj . nodeName ) ;
192
196
}
193
197
} )
194
198
. add ( function ( obj ) {
195
199
// probably at the begginging should be enough these checks
196
- if ( obj . Boolean === Boolean && obj . Number === Number && obj . String === String && obj . Date === Date ) {
200
+ if ( obj . Boolean === Boolean && obj . Number === Number && obj . String === String && obj . Date === Date ) {
197
201
return new Type ( types . OBJECT , types . HOST ) ;
198
202
}
199
203
} )
252
256
return pad ( str , value , '0' ) ;
253
257
}
254
258
259
+ function looksLikeANumber ( n ) {
260
+ return ! ! n . match ( / \d + / ) ;
261
+ }
262
+
263
+ function keyCompare ( a , b ) {
264
+ var aNum = looksLikeANumber ( a ) ;
265
+ var bNum = looksLikeANumber ( b ) ;
266
+ if ( aNum && bNum ) {
267
+ return 1 * a - 1 * b ;
268
+ } else if ( aNum && ! bNum ) {
269
+ return - 1 ;
270
+ } else if ( ! aNum && bNum ) {
271
+ return 1 ;
272
+ } else {
273
+ return a . localeCompare ( b ) ;
274
+ }
275
+ }
276
+
255
277
function genKeysFunc ( f ) {
256
278
return function ( value ) {
257
279
var k = f ( value ) ;
258
- k . sort ( ) ;
280
+ k . sort ( keyCompare ) ;
259
281
return k ;
260
282
} ;
261
283
}
3825
3847
} ) ;
3826
3848
}
3827
3849
3828
- } ( this ) ) ;
3850
+ } ( this ) ) ;
0 commit comments