Skip to content

Commit ca4147f

Browse files
committed
Fix for IE10
1 parent 6554bf8 commit ca4147f

File tree

4 files changed

+54
-49
lines changed

4 files changed

+54
-49
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ See the [Version 1.0 Release Announcement](https://github.com/metafloor/bwip-js/
2828
2929
## Status
3030

31-
* Current bwip-js version is 1.0.3 (2016-06-16)
31+
* Current bwip-js version is 1.0.4 (2016-06-16)
3232
* Current BWIPP version is 2016-06-03
3333
* Node.js compatibility >= v0.10
3434
* npm dependencies: none

bwipp-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bwipp.js

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ function BWIPP() {
3939
$j = i;
4040
} else if (!(a instanceof Array)) {
4141
a = new Array(+arguments[0]);
42-
a.fill(null);
42+
for (var i = 0, l = a.length; i < l; i++) {
43+
a[i] = null;
44+
}
4345
}
4446
a.b = a; // base array
4547
a.o = 0; // offset into base
@@ -62,7 +64,7 @@ function BWIPP() {
6264
d['\uffff' + k] = $k[i];
6365
} else if (t === 'string') {
6466
d[k] = $k[i];
65-
} else if (ArrayBuffer.isView(k)) {
67+
} else if (k instanceof Uint8Array) {
6668
d[$z(k)] = $k[i];
6769
} else {
6870
throw 'dict-not-a-valid-key(' + k + ')';
@@ -99,7 +101,7 @@ function BWIPP() {
99101
// Primarily designed to convert uint8-string to string, but will call the
100102
// the toString() method on any value.
101103
function $z(s) {
102-
if (ArrayBuffer.isView(s)) {
104+
if (s instanceof Uint8Array) {
103105
// Postscript treats nul-char as end of string, even if string is
104106
// longer.
105107
for (var i = 0, l = s.length; i < l && s[i]; i++);
@@ -116,7 +118,7 @@ function BWIPP() {
116118
if (typeof dst === 'string') {
117119
dst = $s(dst);
118120
}
119-
if (ArrayBuffer.isView(src)) {
121+
if (src instanceof Uint8Array) {
120122
for (var i = 0, l = src.length; i < l; i++) {
121123
dst[i] = src[i];
122124
}
@@ -155,13 +157,13 @@ function BWIPP() {
155157
// s : source
156158
// k : key
157159
function $get(s, k) {
158-
if (ArrayBuffer.isView(s)) {
160+
if (s instanceof Uint8Array) {
159161
return s[k];
160162
}
161163
if (typeof s === 'string') {
162164
return s.charCodeAt(k);
163165
}
164-
if (Array.isArray(s)) {
166+
if (s instanceof Array) {
165167
return s.b[s.o + k];
166168
}
167169
// Must be a dict object : with postscript dict objects, a number key
@@ -170,7 +172,7 @@ function BWIPP() {
170172
if (typeof k === 'number') {
171173
return s['\uffff' + k];
172174
}
173-
if (ArrayBuffer.isView(k)) {
175+
if (k instanceof Uint8Array) {
174176
return s[$z(k)];
175177
}
176178
return s[k];
@@ -181,12 +183,12 @@ function BWIPP() {
181183
// k : key
182184
// v : value
183185
function $put(d, k, v) {
184-
if (ArrayBuffer.isView(d)) {
186+
if (d instanceof Uint8Array) {
185187
d[k] = v;
186-
} else if (Array.isArray(d)) {
188+
} else if (d instanceof Array) {
187189
d.b[d.o + k] = v;
188190
} else if (typeof d == 'object') {
189-
if (ArrayBuffer.isView(k)) {
191+
if (k instanceof Uint8Array) {
190192
d[$z(k)] = v;
191193
} else {
192194
d[typeof k == 'number' ? '\uffff' + k : k] = v;
@@ -201,10 +203,10 @@ function BWIPP() {
201203
// o : offset
202204
// l : length
203205
function $geti(s, o, l) {
204-
if (ArrayBuffer.isView(s)) {
206+
if (s instanceof Uint8Array) {
205207
return s.subarray(o, o + l);
206208
}
207-
if (Array.isArray(s)) {
209+
if (s instanceof Array) {
208210
var a = new Array(l);
209211
a.b = s.b; // base array
210212
a.o = s.o + o; // offset into base
@@ -219,7 +221,7 @@ function BWIPP() {
219221
// o : offset
220222
// s : src
221223
function $puti(d, o, s) {
222-
if (ArrayBuffer.isView(d)) {
224+
if (d instanceof Uint8Array) {
223225
if (typeof s == 'string') {
224226
for (var i = 0, l = s.length; i < l; i++) {
225227
d[o + i] = s.charCodeAt(i);
@@ -231,7 +233,7 @@ function BWIPP() {
231233
d[o + i] = s[i];
232234
}
233235
}
234-
} else if (Array.isArray(d)) {
236+
} else if (d instanceof Array) {
235237
// Operate on the base arrays
236238
var darr = d.b;
237239
var doff = o + d.o;
@@ -259,13 +261,13 @@ function BWIPP() {
259261
if (t == 'boolean') {
260262
return 'booleantype';
261263
}
262-
if (t == 'string' || ArrayBuffer.isView(v)) {
264+
if (t == 'string' || v instanceof Uint8Array) {
263265
return 'stringtype';
264266
}
265267
if (t == 'function') {
266268
return 'operatortype';
267269
}
268-
if (Array.isArray(v)) {
270+
if (v instanceof Array) {
269271
return 'arraytype';
270272
}
271273
return 'dicttype';
@@ -281,16 +283,18 @@ function BWIPP() {
281283
// string seek search suffix match prefix true %if-found
282284
// string false %if-not-found
283285
function $search(str, seek) {
284-
if (!ArrayBuffer.isView(str)) {
286+
if (!(str instanceof Uint8Array)) {
285287
str = $s(str);
286288
}
289+
var ls = str.length;
290+
287291
// Virtually all uses of search in BWIPP are for single-characters.
288292
// Optimize for that case.
289293
if (seek.length == 1) {
290-
var cd = ArrayBuffer.isView(seek) ? seek[0] : seek.charCodeAt(0);
291-
var i = str.indexOf(cd);
292-
if (i >= 0) {
293-
$k[$j++] = str.subarray(i + 1, l);
294+
var cd = seek instanceof Uint8Array ? seek[0] : seek.charCodeAt(0);
295+
for (var i = 0; i < ls && str[i] != cd; i++);
296+
if (i < ls) {
297+
$k[$j++] = str.subarray(i + 1);
294298
$k[$j++] = str.subarray(i, i + 1);
295299
$k[$j++] = str.subarray(0, i);
296300
$k[$j++] = true;
@@ -302,21 +306,22 @@ function BWIPP() {
302306
}
303307

304308
// Slow path,
305-
if (!ArrayBuffer.isView(seek)) {
309+
if (!(seek instanceof Uint8Array)) {
306310
seek = $(seek);
307311
}
308-
var i = str.indexOf(seek[0]);
309-
var l = seek.length;
310-
while (i >= 0) {
311-
for (var j = 1; j < l && str[i + j] === seek[j]; j++);
312-
if (j === l) {
313-
$k[$j++] = str.subarray(i + l);
314-
$k[$j++] = str.subarray(i, i + l);
312+
var lk = seek.length;
313+
var cd = seek[0];
314+
for (var i = 0; i < ls && str[i] != cd; i++);
315+
while (i < ls) {
316+
for (var j = 1; j < lk && str[i + j] === seek[j]; j++);
317+
if (j === lk) {
318+
$k[$j++] = str.subarray(i + lk);
319+
$k[$j++] = str.subarray(i, i + lk);
315320
$k[$j++] = str.subarray(0, i);
316321
$k[$j++] = true;
317322
return;
318323
}
319-
i = str.indexOf(seek[0], i + 1);
324+
for (i++; i < ls && str[i] != cd; i++);
320325
}
321326
$k[$j++] = str;
322327
$k[$j++] = false;
@@ -325,12 +330,12 @@ function BWIPP() {
325330
// The callback is omitted when forall is being used just to push onto the
326331
// stack.
327332
function $forall(o, cb) {
328-
if (ArrayBuffer.isView(o)) {
333+
if (o instanceof Uint8Array) {
329334
for (var i = 0, l = o.length; i < l; i++) {
330335
$k[$j++] = o[i];
331336
cb && cb();
332337
}
333-
} else if (Array.isArray(o)) {
338+
} else if (o instanceof Array) {
334339
// The array may be a view.
335340
for (var a = o.b, i = o.o, l = o.o + o.length; i < l; i++) {
336341
$k[$j++] = a[i];
@@ -378,7 +383,7 @@ function BWIPP() {
378383
if (typeof a === 'string' && typeof b === 'string') {
379384
return a == b;
380385
}
381-
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
386+
if (a instanceof Uint8Array && b instanceof Uint8Array) {
382387
if (a.length != b.length) {
383388
return false;
384389
}
@@ -389,9 +394,9 @@ function BWIPP() {
389394
}
390395
return true;
391396
}
392-
if (ArrayBuffer.isView(a) && typeof b === 'string' ||
393-
ArrayBuffer.isView(b) && typeof a === 'string') {
394-
if (ArrayBuffer.isView(a)) {
397+
if (a instanceof Uint8Array && typeof b === 'string' ||
398+
b instanceof Uint8Array && typeof a === 'string') {
399+
if (a instanceof Uint8Array) {
395400
a = $z(a);
396401
} else {
397402
b = $z(b);
@@ -406,40 +411,40 @@ function BWIPP() {
406411
}
407412

408413
function $lt(a, b) {
409-
if (ArrayBuffer.isView(a)) {
414+
if (a instanceof Uint8Array) {
410415
a = $z(a);
411416
}
412-
if (ArrayBuffer.isView(b)) {
417+
if (b instanceof Uint8Array) {
413418
b = $z(b);
414419
}
415420
return a < b;
416421
}
417422

418423
function $le(a, b) {
419-
if (ArrayBuffer.isView(a)) {
424+
if (a instanceof Uint8Array) {
420425
a = $z(a);
421426
}
422-
if (ArrayBuffer.isView(b)) {
427+
if (b instanceof Uint8Array) {
423428
b = $z(b);
424429
}
425430
return a <= b;
426431
}
427432

428433
function $gt(a, b) {
429-
if (ArrayBuffer.isView(a)) {
434+
if (a instanceof Uint8Array) {
430435
a = $z(a);
431436
}
432-
if (ArrayBuffer.isView(b)) {
437+
if (b instanceof Uint8Array) {
433438
b = $z(b);
434439
}
435440
return a > b;
436441
}
437442

438443
function $ge(a, b) {
439-
if (ArrayBuffer.isView(a)) {
444+
if (a instanceof Uint8Array) {
440445
a = $z(a);
441446
}
442-
if (ArrayBuffer.isView(b)) {
447+
if (b instanceof Uint8Array) {
443448
b = $z(b);
444449
}
445450
return a >= b;
@@ -471,13 +476,13 @@ function BWIPP() {
471476
return 'null';
472477
} else if (v === undefined) {
473478
return '<undefined>';
474-
} else if (Array.isArray(v)) {
479+
} else if (v instanceof Array) {
475480
var s = '<array,' + v.o + ',' + v.length + '>[';
476481
for (var j = v.o, a = v.b, l = v.length + v.o; j < l; j++) {
477482
s += (j == v.o ? '' : ',') + tostring(a[j]);
478483
}
479484
return s + ']';
480-
} else if (ArrayBuffer.isView(v)) {
485+
} else if (v instanceof Uint8Array) {
481486
return '(' + $z[v] + ')';
482487
} else if (typeof v === 'object') {
483488
var s = '<<';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bwip-js",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Barcode generator supporting over 90 types and standards.",
55
"main": "node-bwipjs",
66
"scripts": {

0 commit comments

Comments
 (0)