forked from opentypejs/opentype.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
35 lines (28 loc) · 775 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
function isBrowser() {
return typeof window !== 'undefined';
}
function isNode() {
return typeof process !== 'undefined';
}
function nodeBufferToArrayBuffer(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;
}
function arrayBufferToNodeBuffer(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;
}
function checkArgument(expression, message) {
if (!expression) {
throw message;
}
}
export { isBrowser, isNode, nodeBufferToArrayBuffer, arrayBufferToNodeBuffer, checkArgument };