Skip to content
This repository was archived by the owner on Nov 4, 2020. It is now read-only.

Commit c966125

Browse files
committed
Release 10.0.0
1 parent 5cdd7d0 commit c966125

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

History.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
10.0.0 / 2016-07-18
2+
===================
3+
4+
* Possible breaking change/bugfix in should-format when in objects used keys that looks like a numbers
5+
16
9.0.2 / 2016-06-10
27
==================
38

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "should",
33
"description": "test framework agnostic BDD-style assertions",
4-
"version": "9.0.2",
4+
"version": "10.0.0",
55
"author": "TJ Holowaychuk <[email protected]>, Denis Bardadym <[email protected]> and other contributors",
66
"repository": {
77
"type": "git",

should.js

+35-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* should - test framework agnostic BDD-style assertions
3-
* @version v9.0.2
3+
* @version v10.0.0
44
* @author TJ Holowaychuk <[email protected]>, Denis Bardadym <[email protected]> and other contributors
55
* @link https://github.com/shouldjs/should.js
66
* @license MIT
@@ -94,15 +94,15 @@
9494

9595
addTypeOf: function(type, res) {
9696
return this.add(function(obj, tpeOf) {
97-
if(tpeOf === type) {
97+
if (tpeOf === type) {
9898
return new Type(res);
9999
}
100100
});
101101
},
102102

103103
addClass: function(cls, res, sub) {
104104
return this.add(function(obj, tpeOf, objCls) {
105-
if(objCls === cls) {
105+
if (objCls === cls) {
106106
return new Type(types.OBJECT, res, sub);
107107
}
108108
});
@@ -112,9 +112,11 @@
112112
var typeOf = typeof obj;
113113
var cls = toString.call(obj);
114114

115-
for(var i = 0, l = this.checks.length; i < l; i++) {
115+
for (var i = 0, l = this.checks.length; i < l; i++) {
116116
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+
}
118120
}
119121

120122
}
@@ -131,8 +133,10 @@
131133
.addTypeOf(types.BOOLEAN, types.BOOLEAN)
132134
.addTypeOf(types.FUNCTION, types.FUNCTION)
133135
.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+
}
136140
})
137141
.addClass('[object String]', types.STRING)
138142
.addClass('[object Boolean]', types.BOOLEAN)
@@ -176,24 +180,24 @@
176180
.addClass('[object FileList]', types.FILE_LIST)
177181
.addClass('[object XMLHttpRequest]', types.XHR)
178182
.add(function(obj) {
179-
if((typeof Promise === types.FUNCTION && obj instanceof Promise) ||
183+
if ((typeof Promise === types.FUNCTION && obj instanceof Promise) ||
180184
(typeof obj.then === types.FUNCTION)) {
181185
return new Type(types.OBJECT, types.PROMISE);
182186
}
183187
})
184188
.add(function(obj) {
185-
if(typeof Buffer !== 'undefined' && obj instanceof Buffer) {
189+
if (typeof Buffer !== 'undefined' && obj instanceof Buffer) {// eslint-disable-line no-undef
186190
return new Type(types.OBJECT, types.BUFFER);
187191
}
188192
})
189193
.add(function(obj) {
190-
if(typeof Node !== 'undefined' && obj instanceof Node) {
194+
if (typeof Node !== 'undefined' && obj instanceof Node) {
191195
return new Type(types.OBJECT, types.HTML_ELEMENT, obj.nodeName);
192196
}
193197
})
194198
.add(function(obj) {
195199
// 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) {
197201
return new Type(types.OBJECT, types.HOST);
198202
}
199203
})
@@ -252,10 +256,28 @@
252256
return pad(str, value, '0');
253257
}
254258

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+
255277
function genKeysFunc(f) {
256278
return function(value) {
257279
var k = f(value);
258-
k.sort();
280+
k.sort(keyCompare);
259281
return k;
260282
};
261283
}
@@ -3825,4 +3847,4 @@
38253847
});
38263848
}
38273849

3828-
}(this));
3850+
}(this));

0 commit comments

Comments
 (0)