/
init.js
47 lines (35 loc) · 1.06 KB
/
init.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
window.z= ( a, ...o )=> (console.log( a, ...o, ) , a);
window.v= ( a, ...o )=> (console.log( a.valueOf?a.valueOf():a, ...o.map( x=> x.valueOf?x.valueOf():x, ), ) , a);
window.timeout= ( time, value, )=> new Promise( ( resolve, reject, )=> setTimeout( ()=> resolve( value, ), time, ), );
window.nextFrame= value=> new Promise( ( resolve, reject, )=> requestAnimationFrame( ()=> resolve( value, ), ), );
Map.prototype.achieve= function( key, fallback, ){
if( this.has( key, ) )
return this.get( key, );
else
{
if( fallback instanceof Function )
fallback= fallback();
this.set( key, fallback, );
return fallback;
}
};
Array.prototype.replace= function( value, ...replacements ){
const index= this.indexOf( value, );
if( index >= 0 )
{
this.splice( index, 1, ...replacements, );
return true;
}
else
return false;
};
Array.prototype.findAndReplace= function( predicate, ...replacements ){
const index= this.findIndex( predicate, );
if( index >= 0 )
{
this.splice( index, 1, ...replacements, );
return true;
}
else
return false;
};