forked from opentypejs/opentype.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
35 lines (28 loc) · 748 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
exports.isBrowser = function() {
return typeof window !== 'undefined';
};
exports.isNode = function() {
return typeof window === 'undefined';
};
exports.nodeBufferToArrayBuffer = function(buffer) {
var ab = new ArrayBuffer(buffer.length);
var view = new Uint8Array(ab);
for (var i = 0; i < buffer.length; ++i) {
view[i] = buffer[i];
}
return ab;
};
exports.arrayBufferToNodeBuffer = function(ab) {
var buffer = new Buffer(ab.byteLength);
var view = new Uint8Array(ab);
for (var i = 0; i < buffer.length; ++i) {
buffer[i] = view[i];
}
return buffer;
};
exports.checkArgument = function(expression, message) {
if (!expression) {
throw message;
}
};