-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathTyped.js
168 lines (127 loc) · 3.44 KB
/
Typed.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
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
"use strict";
// 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 (x, s, e, a) {
return a.fill(x,s,e);
};
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) {
return a.find(f);
};
exports.findIndexImpl = function findIndexImpl (a,f) {
var r = a.findIndex(f);
return r === -1 ? null : r;
};
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, s, e) {
return a.slice(s,e);
};
exports.sortImpl = function sortImpl (a) {
a.sort();
};
exports.subArrayImpl = function subArrayImpl (a, s, e) {
return a.subarray(s, e);
};
exports.toStringImpl = function toStringImpl (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;
}