Skip to content
This repository was archived by the owner on Aug 21, 2022. It is now read-only.

Commit ee0697e

Browse files
committed
build 0.6.1
1 parent 35ffd11 commit ee0697e

13 files changed

+400
-158
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
##v0.6.1
44

5+
- fix: `.find()` and `.findIndex()` no longer ignore array element holes
56
- fix: `Object.assign()` ignores null and undefined source arguments
67
- new: `.request({advanced: function (xhr) {…}})`
78
- del: `.addEventListener()`, `.removeEventListener()` and `.dispatchEvent()` from polyfill for XMLHttpRequest (IE8)

dev/jscore-ie10.js

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* jsCore JavaScript library v0.5.1 IE10+
1+
/* jsCore JavaScript library v0.6.1 IE10+
22
* © 2014 Dmitry Korobkin
33
* Released under the MIT license
44
* github.com/Octane/jsCore
@@ -34,9 +34,11 @@ new function () {'use strict';
3434
if (!Object.assign) {
3535
Object.assign = function (target) {
3636
Array.prototype.slice.call(arguments, 1).forEach(function (source) {
37-
Object.keys(source).forEach(function (key) {
38-
target[key] = source[key];
39-
});
37+
if (source) {
38+
Object.keys(source).forEach(function (key) {
39+
target[key] = source[key];
40+
});
41+
}
4042
});
4143
return target;
4244
};
@@ -84,11 +86,9 @@ if (!Array.prototype.find) {
8486
length = this.length,
8587
i = 0;
8688
while (i < length) {
87-
if (i in this) {
88-
value = this[i];
89-
if (func.call(boundThis, value, i, this)) {
90-
return value;
91-
}
89+
value = this[i];
90+
if (func.call(boundThis, value, i, this)) {
91+
return value;
9292
}
9393
i++;
9494
}
@@ -102,11 +102,9 @@ if (!Array.prototype.findIndex) {
102102
length = this.length,
103103
i = 0;
104104
while (i < length) {
105-
if (i in this) {
106-
value = this[i];
107-
if (func.call(boundThis, value, i, this)) {
108-
return i;
109-
}
105+
value = this[i];
106+
if (func.call(boundThis, value, i, this)) {
107+
return i;
110108
}
111109
i++;
112110
}
@@ -135,6 +133,36 @@ if (!Array.prototype.fill) {
135133
};
136134
}
137135

136+
if (!Array.prototype.contains) {
137+
Array.prototype.contains = function (anything, position) {
138+
var length = this.length,
139+
i;
140+
if (!length) {
141+
return false;
142+
}
143+
if (Number.isNaN(anything)) {
144+
if (1 in arguments) {
145+
position = Number(position) || 0;
146+
if (position < 0) {
147+
i = Math.max(length + position, 0);
148+
} else {
149+
i = position;
150+
}
151+
} else {
152+
i = 0;
153+
}
154+
while (i < length) {
155+
if (i in this && Number.isNaN(this[i])) {
156+
return true;
157+
}
158+
i++;
159+
}
160+
return false;
161+
}
162+
return -1 != this.indexOf(anything, position);
163+
};
164+
}
165+
138166
if (!String.prototype.startsWith) {
139167
String.prototype.startsWith = function (string, position) {
140168
if (!position) {
@@ -255,7 +283,7 @@ new function () {
255283
'findIndex', 'forEach', 'indexOf', 'join',
256284
'lastIndexOf', 'map', 'pop', 'push', 'reduce',
257285
'reduceRight', 'reverse', 'shift', 'slice',
258-
'some', 'sort', 'splice', 'unshift'
286+
'some', 'sort', 'splice', 'unshift', 'contains'
259287
]));
260288

261289
implement(String, createGenerics(String.prototype, [
@@ -1169,10 +1197,6 @@ lib.array = {
11691197
}, 0);
11701198
},
11711199

1172-
contains: function (iterable, anything, position) {
1173-
return -1 != Array.indexOf(iterable, anything, position);
1174-
},
1175-
11761200
unique: function (iterable) {
11771201
var result = [],
11781202
anything,
@@ -1784,6 +1808,7 @@ lib.request = new function () {
17841808

17851809
function unbind(xhr) {
17861810
xhr.onload = null;
1811+
xhr.onabort = null;
17871812
xhr.onerror = null;
17881813
xhr.ontimeout = null;
17891814
}
@@ -1800,7 +1825,8 @@ lib.request = new function () {
18001825
* caching: Boolean,
18011826
* credentials: Boolean,
18021827
* mimeType: String,
1803-
* headers: Object
1828+
* headers: Object,
1829+
* advanced: Function
18041830
* }
18051831
*/
18061832
var method = (params.method || 'GET').toUpperCase(),
@@ -1813,6 +1839,7 @@ lib.request = new function () {
18131839
caching = false !== params.caching,
18141840
credentials = true === params.credentials,
18151841
mimeType = params.mimeType,
1842+
advanced = params.advanced,
18161843
headers = {
18171844
'X-Requested-With': 'XMLHttpRequest'
18181845
};
@@ -1850,6 +1877,10 @@ lib.request = new function () {
18501877
reject(new Error(this.statusText));
18511878
}
18521879
}
1880+
function onAbort() {
1881+
unbind(this);
1882+
reject(new Error('cancelled'));
1883+
}
18531884
function onError() {
18541885
unbind(this);
18551886
reject(new Error(this.statusText));
@@ -1872,11 +1903,15 @@ lib.request = new function () {
18721903
xhr.setRequestHeader(key, headers[key]);
18731904
});
18741905
xhr.onload = onLoad;
1906+
xhr.onabort = onAbort;
18751907
xhr.onerror = onError;
18761908
if (timeout) {
18771909
xhr.timeout = timeout;
18781910
xhr.ontimeout = onTimeout;
18791911
}
1912+
if (advanced) {
1913+
advanced(xhr);
1914+
}
18801915
xhr.send(data);
18811916
};
18821917

dev/jscore-ie9.js

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* jsCore JavaScript library v0.5.1 IE9+
1+
/* jsCore JavaScript library v0.6.1 IE9+
22
* © 2014 Dmitry Korobkin
33
* Released under the MIT license
44
* github.com/Octane/jsCore
@@ -34,9 +34,11 @@ new function () {'use strict';
3434
if (!Object.assign) {
3535
Object.assign = function (target) {
3636
Array.prototype.slice.call(arguments, 1).forEach(function (source) {
37-
Object.keys(source).forEach(function (key) {
38-
target[key] = source[key];
39-
});
37+
if (source) {
38+
Object.keys(source).forEach(function (key) {
39+
target[key] = source[key];
40+
});
41+
}
4042
});
4143
return target;
4244
};
@@ -84,11 +86,9 @@ if (!Array.prototype.find) {
8486
length = this.length,
8587
i = 0;
8688
while (i < length) {
87-
if (i in this) {
88-
value = this[i];
89-
if (func.call(boundThis, value, i, this)) {
90-
return value;
91-
}
89+
value = this[i];
90+
if (func.call(boundThis, value, i, this)) {
91+
return value;
9292
}
9393
i++;
9494
}
@@ -102,11 +102,9 @@ if (!Array.prototype.findIndex) {
102102
length = this.length,
103103
i = 0;
104104
while (i < length) {
105-
if (i in this) {
106-
value = this[i];
107-
if (func.call(boundThis, value, i, this)) {
108-
return i;
109-
}
105+
value = this[i];
106+
if (func.call(boundThis, value, i, this)) {
107+
return i;
110108
}
111109
i++;
112110
}
@@ -135,6 +133,36 @@ if (!Array.prototype.fill) {
135133
};
136134
}
137135

136+
if (!Array.prototype.contains) {
137+
Array.prototype.contains = function (anything, position) {
138+
var length = this.length,
139+
i;
140+
if (!length) {
141+
return false;
142+
}
143+
if (Number.isNaN(anything)) {
144+
if (1 in arguments) {
145+
position = Number(position) || 0;
146+
if (position < 0) {
147+
i = Math.max(length + position, 0);
148+
} else {
149+
i = position;
150+
}
151+
} else {
152+
i = 0;
153+
}
154+
while (i < length) {
155+
if (i in this && Number.isNaN(this[i])) {
156+
return true;
157+
}
158+
i++;
159+
}
160+
return false;
161+
}
162+
return -1 != this.indexOf(anything, position);
163+
};
164+
}
165+
138166
if (!String.prototype.startsWith) {
139167
String.prototype.startsWith = function (string, position) {
140168
if (!position) {
@@ -255,7 +283,7 @@ new function () {
255283
'findIndex', 'forEach', 'indexOf', 'join',
256284
'lastIndexOf', 'map', 'pop', 'push', 'reduce',
257285
'reduceRight', 'reverse', 'shift', 'slice',
258-
'some', 'sort', 'splice', 'unshift'
286+
'some', 'sort', 'splice', 'unshift', 'contains'
259287
]));
260288

261289
implement(String, createGenerics(String.prototype, [
@@ -1442,10 +1470,6 @@ lib.array = {
14421470
}, 0);
14431471
},
14441472

1445-
contains: function (iterable, anything, position) {
1446-
return -1 != Array.indexOf(iterable, anything, position);
1447-
},
1448-
14491473
unique: function (iterable) {
14501474
var result = [],
14511475
anything,
@@ -2057,6 +2081,7 @@ lib.request = new function () {
20572081

20582082
function unbind(xhr) {
20592083
xhr.onload = null;
2084+
xhr.onabort = null;
20602085
xhr.onerror = null;
20612086
xhr.ontimeout = null;
20622087
}
@@ -2073,7 +2098,8 @@ lib.request = new function () {
20732098
* caching: Boolean,
20742099
* credentials: Boolean,
20752100
* mimeType: String,
2076-
* headers: Object
2101+
* headers: Object,
2102+
* advanced: Function
20772103
* }
20782104
*/
20792105
var method = (params.method || 'GET').toUpperCase(),
@@ -2086,6 +2112,7 @@ lib.request = new function () {
20862112
caching = false !== params.caching,
20872113
credentials = true === params.credentials,
20882114
mimeType = params.mimeType,
2115+
advanced = params.advanced,
20892116
headers = {
20902117
'X-Requested-With': 'XMLHttpRequest'
20912118
};
@@ -2123,6 +2150,10 @@ lib.request = new function () {
21232150
reject(new Error(this.statusText));
21242151
}
21252152
}
2153+
function onAbort() {
2154+
unbind(this);
2155+
reject(new Error('cancelled'));
2156+
}
21262157
function onError() {
21272158
unbind(this);
21282159
reject(new Error(this.statusText));
@@ -2145,11 +2176,15 @@ lib.request = new function () {
21452176
xhr.setRequestHeader(key, headers[key]);
21462177
});
21472178
xhr.onload = onLoad;
2179+
xhr.onabort = onAbort;
21482180
xhr.onerror = onError;
21492181
if (timeout) {
21502182
xhr.timeout = timeout;
21512183
xhr.ontimeout = onTimeout;
21522184
}
2185+
if (advanced) {
2186+
advanced(xhr);
2187+
}
21532188
xhr.send(data);
21542189
};
21552190

0 commit comments

Comments
 (0)