-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTyped.js
More file actions
185 lines (140 loc) · 4.13 KB
/
Typed.js
File metadata and controls
185 lines (140 loc) · 4.13 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"use strict";
exports.polyFill = function polyFill () {
var typedArrayTypes =
[ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array
, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array
];
for (var k in typedArrayTypes) {
for (var v in Array.prototype) {
if (Array.prototype.hasOwnProperty(v) && !typedArrayTypes[k].prototype.hasOwnProperty(v))
typedArrayTypes[k].prototype[v] = Array.prototype[v];
}
}
};
// module Data.ArrayBuffer.Typed
exports.buffer = function buffer (v) {
return v.buffer;
};
exports.byteOffset = function byteOffset (v) {
return v.byteOffset;
};
exports.byteLength = function byteLength (v) {
return v.byteLength;
};
exports.lengthImpl = function lemgthImpl (v) {
return v.length;
};
// Typed Arrays
function newArray (f) {
return function newArray_ (a,mb,mc) {
if (mb === null)
return new f(a);
var l = a.byteLength;
var eb = f.BYTES_PER_ELEMENT;
var off = Math.min(l, mb>>>0);
if (mc === null)
return new f(a,off);
var len = Math.min((l - off) / eb, mc);
return new f(a,off,len);
};
}
exports.newUint8ClampedArray = newArray(Uint8ClampedArray);
exports.newUint32Array = newArray(Uint32Array);
exports.newUint16Array = newArray(Uint16Array);
exports.newUint8Array = newArray(Uint8Array);
exports.newInt32Array = newArray(Int32Array);
exports.newInt16Array = newArray(Int16Array);
exports.newInt8Array = newArray(Int8Array);
exports.newFloat32Array = newArray(Float32Array);
exports.newFloat64Array = newArray(Float64Array);
// ------
exports.everyImpl = function everyImpl (a,p) {
return a.every(p);
};
exports.someImpl = function someImpl (a,p) {
return a.some(p);
};
exports.fillImpl = function fillImpl (a,x,ms,me) {
return me === null ? (ms === null ? a.fill(x) : a.fill(x,ms)) : a.fill(x,ms,me);
};
exports.mapImpl = function mapImpl (a,f) {
return a.map(f);
};
exports.forEachImpl = function forEachImpl (a,f) {
a.forEach(f);
};
exports.filterImpl = function filterImpl (a,p) {
return a.filter(p);
};
exports.includesImpl = function includesImpl (a,x,mo) {
return mo === null ? a.includes(x) : a.includes(x,mo);
};
exports.reduceImpl = function reduceImpl (a,f,i) {
return a.reduce(f,i);
};
exports.reduce1Impl = function reduce1Impl (a,f) {
return a.reduce(f);
};
exports.reduceRightImpl = function reduceRightImpl (a,f,i) {
return a.reduceRight(f,i);
};
exports.reduceRight1Impl = function reduceRight1Impl (a,f) {
return a.reduceRight(f);
};
exports.findImpl = function findImpl (a,f) {
var x = a.find(f);
return (x === undefined) ? null : x;
};
exports.findIndexImpl = function findIndexImpl (a,f) {
var x = a.findIndex(f);
return (x === -1) ? null : x;
};
exports.indexOfImpl = function indexOfImpl (a,x,mo) {
var r = mo === null ? a.indexOf(x) : a.indexOf(x,mo);
return r === -1 ? null : r;
};
exports.lastIndexOfImpl = function lastIndexOfImpl (a,x,mo) {
var r = mo === null ? a.lastIndexOf(x) : a.lastIndexOf(x,mo);
return r === -1 ? null : r;
};
exports.copyWithinImpl = function copyWithinImpl (a,t,s,me) {
if (me === null) {
a.copyWithin(t,s);
} else {
a.copyWithin(t,s,me);
}
};
exports.reverseImpl = function reverseImpl (a) {
a.reverse();
};
exports.setImpl = function setImpl (a, off, b) {
a.set(b,off);
};
exports.sliceImpl = function sliceImpl (a,ms,me) {
return me === null ? (ms === null ? a.slice() : a.slice(ms)) : a.slice(ms,me);
};
exports.sortImpl = function sortImpl (a) {
a.sort();
};
exports.subArrayImpl = function subArrayImpl (a,ms,me) {
return me === null ? (ms === null ? a.subarray() : a.subarray(ms)) : a.subarray(ms,me);
};
exports.toString = function toString (a) {
return a.toString();
};
exports.joinImpl = function joinImpl (a,s) {
return a.join(s);
};
exports.unsafeAtImpl = function(a, i) {
return a[i];
}
exports.hasIndexImpl = function(a, i) {
return i in a;
}
exports.toArrayImpl = function(a) {
var l = a.length;
var ret = new Array(l);
for (var i = 0; i < l; i++)
ret[i] = a[i];
return ret;
}