Comparing version 3.0.3 to 3.0.4
2841
extes.js
(()=>{ | ||
"use strict"; | ||
const writable = true, configurable = true, enumerable = false; | ||
const IsNodeJS = (typeof Buffer !== "undefined"); | ||
function Padding(val, length = 2, stuffing = '0') { | ||
val = `${ val }`; | ||
let remain = length - val.length; | ||
while( remain-- > 0 ){ | ||
val = stuffing + val; | ||
"use strict"; | ||
const writable=true, configurable=true, enumerable=false; | ||
const IsNodeJS = (typeof Buffer !== "undefined"); | ||
function Padding(val, length=2, stuffing='0'){ | ||
val = `${val}`; | ||
let remain = length - val.length; | ||
while( remain-- > 0 ) { | ||
val = stuffing + val; | ||
} | ||
return val; | ||
} | ||
function ExtractBytes(content) { | ||
if( IsNodeJS ){ | ||
if( Buffer.isBuffer(content) ){ | ||
return new Uint8Array(content); | ||
} | ||
return val; | ||
} | ||
function ExtractBytes(content) { | ||
if( IsNodeJS ){ | ||
if( Buffer.isBuffer(content) ){ | ||
return new Uint8Array(content); | ||
} | ||
} | ||
if( ArrayBuffer.isView(content) ){ | ||
return new Uint8Array(content.buffer); | ||
} | ||
if( content instanceof ArrayBuffer ){ | ||
return new Uint8Array(content); | ||
} | ||
return null; | ||
} | ||
const UTF8_DECODE_CHUNK_SIZE = 100; | ||
/** | ||
* Encode given input js string using utf8 format | ||
* @param {String} js_str | ||
* @returns {Uint8Array} | ||
**/ | ||
function UTF8Encode(js_str) { | ||
if ( typeof js_str !== "string" ) { | ||
throw new TypeError( "Given input argument must be a js string!" ); | ||
} | ||
let codePoints = []; | ||
let i=0; | ||
while( i < js_str.length ) { | ||
let codePoint = js_str.codePointAt(i); | ||
if( ArrayBuffer.isView(content) ){ | ||
return new Uint8Array(content.buffer); | ||
// 1-byte sequence | ||
if( (codePoint & 0xffffff80) === 0 ) { | ||
codePoints.push(codePoint); | ||
} | ||
if( content instanceof ArrayBuffer ){ | ||
return new Uint8Array(content); | ||
// 2-byte sequence | ||
else if( (codePoint & 0xfffff800) === 0 ) { | ||
codePoints.push( | ||
0xc0 | (0x1f & (codePoint >> 6)), | ||
0x80 | (0x3f & codePoint) | ||
); | ||
} | ||
// 3-byte sequence | ||
else if( (codePoint & 0xffff0000) === 0 ) { | ||
codePoints.push( | ||
0xe0 | (0x0f & (codePoint >> 12)), | ||
0x80 | (0x3f & (codePoint >> 6)), | ||
0x80 | (0x3f & codePoint) | ||
); | ||
} | ||
// 4-byte sequence | ||
else if( (codePoint & 0xffe00000) === 0 ) { | ||
codePoints.push( | ||
0xf0 | (0x07 & (codePoint >> 18)), | ||
0x80 | (0x3f & (codePoint >> 12)), | ||
0x80 | (0x3f & (codePoint >> 6)), | ||
0x80 | (0x3f & codePoint) | ||
); | ||
} | ||
i += (codePoint>0xFFFF) ? 2 : 1; | ||
} | ||
return new Uint8Array(codePoints); | ||
} | ||
/** | ||
* Decode given input buffer using utf8 format | ||
* @param {ArrayBuffer|Uint8Array} raw_bytes | ||
* @returns {string} | ||
**/ | ||
function UTF8Decode(raw_bytes) { | ||
if ( raw_bytes instanceof ArrayBuffer ) { | ||
raw_bytes = new Uint8Array(raw_bytes); | ||
} | ||
if ( !(raw_bytes instanceof Uint8Array) ) { | ||
throw new TypeError( "Given input must be an Uint8Array contains UTF8 encoded value!" ); | ||
} | ||
let uint8 = raw_bytes; | ||
let codePoints = []; | ||
let i = 0; | ||
while( i < uint8.length ) { | ||
let codePoint = uint8[i] & 0xff; | ||
return null; | ||
// 1-byte sequence (0 ~ 127) | ||
if( (codePoint & 0x80) === 0 ){ | ||
codePoints.push(codePoint); | ||
i += 1; | ||
} | ||
// 2-byte sequence (192 ~ 223) | ||
else if( (codePoint & 0xE0) === 0xC0 ){ | ||
codePoint = ((0x1f & uint8[i]) << 6) | (0x3f & uint8[i + 1]); | ||
codePoints.push(codePoint); | ||
i += 2; | ||
} | ||
// 3-byte sequence (224 ~ 239) | ||
else if( (codePoint & 0xf0) === 0xe0 ){ | ||
codePoint = ((0x0f & uint8[i]) << 12) | ||
| ((0x3f & uint8[i + 1]) << 6) | ||
| (0x3f & uint8[i + 2]); | ||
codePoints.push(codePoint); | ||
i += 3; | ||
} | ||
// 4-byte sequence (249 ~ ) | ||
else if( (codePoint & 0xF8) === 0xF0 ){ | ||
codePoint = ((0x07 & uint8[i]) << 18) | ||
| ((0x3f & uint8[i + 1]) << 12) | ||
| ((0x3f & uint8[i + 2]) << 6) | ||
| (0x3f & uint8[i + 3]); | ||
codePoints.push(codePoint); | ||
i += 4; | ||
} | ||
else { | ||
i += 1; | ||
} | ||
} | ||
const UTF8_DECODE_CHUNK_SIZE = 100; | ||
function UTF8Encode(js_str){ | ||
if( typeof js_str !== "string" ){ | ||
throw new TypeError("Given input argument must be a js string!"); | ||
let result_string = ""; | ||
while(codePoints.length > 0) { | ||
const chunk = codePoints.splice(0, UTF8_DECODE_CHUNK_SIZE); | ||
result_string += String.fromCodePoint(...chunk); | ||
} | ||
return result_string; | ||
} | ||
(()=>{ | ||
const HEX_FORMAT = /^(0x)?([0-9a-fA-F]+)$/; | ||
const BIT_FORMAT = /^(0b|0B)?([01]+)$/; | ||
const HEX_MAP = "0123456789abcdef"; | ||
const HEX_MAP_R = { | ||
"0":0, "1":1, "2":2, "3":3, | ||
"4":4, "5":5, "6":6, "7":7, | ||
"8":8, "9":9, "a":10, "b":11, | ||
"c":12, "d":13, "e":14, "f":15 | ||
}; | ||
Object.defineProperty(ArrayBuffer.prototype, 'bytes', { | ||
configurable, enumerable, | ||
get:function(){ return new Uint8Array(this); } | ||
}); | ||
Object.defineProperty(ArrayBuffer.prototype, 'toString', { | ||
configurable, writable, enumerable, | ||
value:function(format=16, padding=true){ | ||
const bytes = new Uint8Array(this); | ||
let result = ''; | ||
switch(format) { | ||
case 16: | ||
for(let i=0; i<bytes.length; i++) { | ||
const value = bytes[i]; | ||
result += HEX_MAP[(value&0xF0)>>>4] + HEX_MAP[value&0x0F]; | ||
} | ||
break; | ||
case 2: | ||
for(let i=0; i<bytes.length; i++) { | ||
const value = bytes[i]; | ||
for (let k=7; k>=0; k--) { | ||
result += ((value >>> k) & 0x01) ? '1' : '0'; | ||
} | ||
} | ||
break; | ||
default: | ||
throw new RangeError( "Unsupported numeric representation!" ); | ||
} | ||
return padding ? result : result.replace(/^0+/, ''); | ||
} | ||
let codePoints = []; | ||
let i = 0; | ||
while( i < js_str.length ){ | ||
let codePoint = js_str.codePointAt(i); | ||
}); | ||
Object.defineProperty(ArrayBuffer.prototype, 'compare', { | ||
configurable, writable, enumerable, | ||
value:function(array_buffer) { | ||
if ( !(array_buffer instanceof ArrayBuffer) ) { | ||
throw new TypeError("An ArrayBuffer can only be compared with another ArrayBuffer"); | ||
} | ||
// 1-byte sequence | ||
if( (codePoint & 0xffffff80) === 0 ){ | ||
codePoints.push(codePoint); | ||
const a = new Uint8Array(this); | ||
const b = new Uint8Array(array_buffer); | ||
const len = Math.max(a.length, b.length); | ||
for(let i=0; i<len; i++) { | ||
const val_a = a[i] || 0, val_b = b[i] || 0; | ||
if ( val_a > val_b ) return 1; | ||
if ( val_a < val_b ) return -1; | ||
} | ||
// 2-byte sequence | ||
else if( (codePoint & 0xfffff800) === 0 ){ | ||
codePoints.push( | ||
0xc0 | (0x1f & (codePoint >> 6)), | ||
0x80 | (0x3f & codePoint) | ||
); | ||
return 0; | ||
} | ||
}); | ||
Object.defineProperty(ArrayBuffer, 'extract', { | ||
configurable, writable, enumerable, | ||
value: function(input) { | ||
if ( typeof Buffer !== "undefined" ) { | ||
if ( input instanceof Buffer ) { | ||
let buff = Buffer.alloc(input.length); | ||
input.copy(buff, 0); | ||
return buff.buffer; | ||
} | ||
} | ||
// 3-byte sequence | ||
else if( (codePoint & 0xffff0000) === 0 ){ | ||
codePoints.push( | ||
0xe0 | (0x0f & (codePoint >> 12)), | ||
0x80 | (0x3f & (codePoint >> 6)), | ||
0x80 | (0x3f & codePoint) | ||
); | ||
if ( ArrayBuffer.isView(input) ) { | ||
return input.buffer; | ||
} | ||
// 4-byte sequence | ||
else if( (codePoint & 0xffe00000) === 0 ){ | ||
codePoints.push( | ||
0xf0 | (0x07 & (codePoint >> 18)), | ||
0x80 | (0x3f & (codePoint >> 12)), | ||
0x80 | (0x3f & (codePoint >> 6)), | ||
0x80 | (0x3f & codePoint) | ||
); | ||
if ( input instanceof ArrayBuffer ) { | ||
return input; | ||
} | ||
i += (codePoint > 0xFFFF) ? 2 : 1; | ||
throw new TypeError( "Cannot convert given input data into array buffer" ); | ||
} | ||
return new Uint8Array(codePoints); | ||
} | ||
function UTF8Decode(raw_bytes){ | ||
if( raw_bytes instanceof ArrayBuffer ){ | ||
raw_bytes = new Uint8Array(raw_bytes); | ||
} | ||
if( !(raw_bytes instanceof Uint8Array) ){ | ||
throw new TypeError("Given input must be an Uint8Array contains UTF8 encoded value!"); | ||
} | ||
let uint8 = raw_bytes; | ||
let codePoints = []; | ||
let i = 0; | ||
while( i < uint8.length ){ | ||
let codePoint = uint8[i] & 0xff; | ||
}); | ||
Object.defineProperty(ArrayBuffer, 'from', { | ||
configurable, writable, enumerable, | ||
value: function(input, conversion_info=null) { | ||
if ( typeof Buffer !== "undefined" ) { | ||
if ( input instanceof Buffer ) { | ||
let buff = Buffer.alloc(input.length); | ||
input.copy(buff, 0); | ||
return buff.buffer; | ||
} | ||
} | ||
// 1-byte sequence (0 ~ 127) | ||
if( (codePoint & 0x80) === 0 ){ | ||
codePoints.push(codePoint); | ||
i += 1; | ||
if ( ArrayBuffer.isView(input) ) { | ||
return input.buffer.slice(0); | ||
} | ||
// 2-byte sequence (192 ~ 223) | ||
else if( (codePoint & 0xE0) === 0xC0 ){ | ||
codePoint = ((0x1f & uint8[i]) << 6) | (0x3f & uint8[i + 1]); | ||
codePoints.push(codePoint); | ||
i += 2; | ||
if ( input instanceof ArrayBuffer ) { | ||
return input.slice(0); | ||
} | ||
// 3-byte sequence (224 ~ 239) | ||
else if( (codePoint & 0xf0) === 0xe0 ){ | ||
codePoint = ((0x0f & uint8[i]) << 12) | ||
| ((0x3f & uint8[i + 1]) << 6) | ||
| (0x3f & uint8[i + 2]); | ||
codePoints.push(codePoint); | ||
i += 3; | ||
if ( Array.isArray(input) ) { | ||
const buffer = new Uint8Array(input); | ||
return buffer.buffer; | ||
} | ||
// 4-byte sequence (249 ~ ) | ||
else if( (codePoint & 0xF8) === 0xF0 ){ | ||
codePoint = ((0x07 & uint8[i]) << 18) | ||
| ((0x3f & uint8[i + 1]) << 12) | ||
| ((0x3f & uint8[i + 2]) << 6) | ||
| (0x3f & uint8[i + 3]); | ||
codePoints.push(codePoint); | ||
i += 4; | ||
} | ||
else{ | ||
i += 1; | ||
} | ||
} | ||
let result_string = ""; | ||
while( codePoints.length > 0 ){ | ||
const chunk = codePoints.splice(0, UTF8_DECODE_CHUNK_SIZE); | ||
result_string += String.fromCodePoint(...chunk); | ||
} | ||
return result_string; | ||
} | ||
// ArrayBuffer | ||
(()=>{ | ||
const HEX_FORMAT = /^(0x)?([0-9a-fA-F]+)$/; | ||
const BIT_FORMAT = /^(0b|0B)?([01]+)$/; | ||
const HEX_MAP = "0123456789abcdef"; | ||
const HEX_MAP_R = { | ||
"0": 0, "1": 1, "2": 2, "3": 3, | ||
"4": 4, "5": 5, "6": 6, "7": 7, | ||
"8": 8, "9": 9, "a": 10, "b": 11, | ||
"c": 12, "d": 13, "e": 14, "f": 15 | ||
}; | ||
const REF = new WeakMap(); | ||
Object.defineProperty(ArrayBuffer.prototype, 'bytes', { | ||
configurable, enumerable, | ||
get: function(){ | ||
let ref = REF.get(this); | ||
if ( ref ) return ref; | ||
REF.set(this, ref = new Uint8Array(this)); | ||
return ref; | ||
} | ||
}); | ||
Object.defineProperty(ArrayBuffer.prototype, 'toString', { | ||
configurable, writable, enumerable, | ||
value: function(format = 16, padding = true){ | ||
const bytes = new Uint8Array(this); | ||
let result = ''; | ||
switch( format ){ | ||
case 16: | ||
for( let i = 0; i < bytes.length; i++ ){ | ||
const value = bytes[i]; | ||
result += HEX_MAP[(value & 0xF0) >>> 4] + HEX_MAP[value & 0x0F]; | ||
} | ||
if ( typeof input === "number" ) { | ||
let data_buffer = null; | ||
switch(conversion_info) { | ||
case 'int8': | ||
data_buffer = new Int8Array([input]); | ||
break; | ||
case 2: | ||
for( let i = 0; i < bytes.length; i++ ){ | ||
const value = bytes[i]; | ||
for( let k = 7; k >= 0; k-- ){ | ||
result += ((value >>> k) & 0x01) ? '1' : '0'; | ||
} | ||
case 'uint8': | ||
data_buffer = new Uint8Array([input]); | ||
break; | ||
case 'int16': | ||
data_buffer = new Int16Array([input]); | ||
break; | ||
case 'uint16': | ||
data_buffer = new Uint16Array([input]); | ||
break; | ||
case 'int32': | ||
data_buffer = new Int32Array([input]); | ||
break; | ||
case 'int64':{ | ||
const negative = input < 0; | ||
if ( negative ) { input = -input; } | ||
let upper = Math.floor(input/0xFFFFFFFF); | ||
let lower = input & 0xFFFFFFFF; | ||
if ( negative ) { | ||
lower = ((~lower)>>>0) + 1; | ||
upper = (~upper) + Math.floor(lower/0xFFFFFFFF); | ||
} | ||
data_buffer = new Uint32Array([lower, upper]); | ||
break; | ||
} | ||
case 'uint64': { | ||
const upper = Math.floor(input/0xFFFFFFFF); | ||
const lower = input & 0xFFFFFFFF; | ||
data_buffer = new Uint32Array([lower, upper]); | ||
break; | ||
} | ||
case 'float32': | ||
data_buffer = new Float32Array([input]); | ||
break; | ||
case 'float64': | ||
data_buffer = new Float64Array([input]); | ||
break; | ||
case 'uint32': | ||
default: | ||
throw new RangeError("Unsupported numeric representation!"); | ||
data_buffer = new Uint32Array([input]); | ||
break; | ||
} | ||
return padding ? result : result.replace(/^0+/, ''); | ||
return data_buffer.buffer; | ||
} | ||
}); | ||
Object.defineProperty(ArrayBuffer.prototype, 'compare', { | ||
configurable, writable, enumerable, | ||
value: function(array_buffer){ | ||
if( !(array_buffer instanceof ArrayBuffer) ){ | ||
throw new TypeError("An ArrayBuffer can only be compared with another ArrayBuffer"); | ||
} | ||
const a = new Uint8Array(this); | ||
const b = new Uint8Array(array_buffer); | ||
const len = Math.max(a.length, b.length); | ||
for( let i = 0; i < len; i++ ){ | ||
const val_a = a[i] || 0, val_b = b[i] || 0; | ||
if( val_a > val_b ) return 1; | ||
if( val_a < val_b ) return -1; | ||
} | ||
return 0; | ||
} | ||
}); | ||
Object.defineProperty(ArrayBuffer, 'extract', { | ||
configurable, writable, enumerable, | ||
value: function(input){ | ||
if( typeof Buffer !== "undefined" ){ | ||
if( input instanceof Buffer ){ | ||
let buff = Buffer.alloc(input.length); | ||
input.copy(buff, 0); | ||
return buff.buffer; | ||
if ( typeof input === "string" ) { | ||
if ( conversion_info === "hex" ) { | ||
const matches = input.match(HEX_FORMAT); | ||
if ( !matches ) { | ||
throw new RangeError( "Input argument is not a valid hex string!" ); | ||
} | ||
} | ||
if( ArrayBuffer.isView(input) ){ | ||
return input.buffer; | ||
} | ||
if( input instanceof ArrayBuffer ){ | ||
return input; | ||
} | ||
throw new TypeError("Cannot convert given input data into array buffer"); | ||
} | ||
}); | ||
Object.defineProperty(ArrayBuffer, 'from', { | ||
configurable, writable, enumerable, | ||
value: function(input, conversion_info = null){ | ||
if( typeof Buffer !== "undefined" ){ | ||
if( input instanceof Buffer ){ | ||
let buff = Buffer.alloc(input.length); | ||
input.copy(buff, 0); | ||
return buff.buffer; | ||
let [,,hex_string] = matches; | ||
if ( hex_string.length % 2 === 0 ) { | ||
hex_string = hex_string.toLowerCase(); | ||
} | ||
} | ||
if( ArrayBuffer.isView(input) ){ | ||
return input.buffer.slice(0); | ||
} | ||
if( input instanceof ArrayBuffer ){ | ||
return input.slice(0); | ||
} | ||
if( Array.isArray(input) ){ | ||
const buffer = new Uint8Array(input); | ||
return buffer.buffer; | ||
} | ||
if( typeof input === "number" ){ | ||
let data_buffer = null; | ||
switch( conversion_info ){ | ||
case 'int8': | ||
data_buffer = new Int8Array([input]); | ||
break; | ||
case 'uint8': | ||
data_buffer = new Uint8Array([input]); | ||
break; | ||
case 'int16': | ||
data_buffer = new Int16Array([input]); | ||
break; | ||
case 'uint16': | ||
data_buffer = new Uint16Array([input]); | ||
break; | ||
case 'int32': | ||
data_buffer = new Int32Array([input]); | ||
break; | ||
case 'int64':{ | ||
const negative = input < 0; | ||
if( negative ){ input = -input; } | ||
let upper = Math.floor(input / 0xFFFFFFFF); | ||
let lower = input & 0xFFFFFFFF; | ||
if( negative ){ | ||
lower = ((~lower) >>> 0) + 1; | ||
upper = (~upper) + Math.floor(lower / 0xFFFFFFFF); | ||
} | ||
data_buffer = new Uint32Array([lower, upper]); | ||
break; | ||
} | ||
case 'uint64':{ | ||
const upper = Math.floor(input / 0xFFFFFFFF); | ||
const lower = input & 0xFFFFFFFF; | ||
data_buffer = new Uint32Array([lower, upper]); | ||
break; | ||
} | ||
case 'float32': | ||
data_buffer = new Float32Array([input]); | ||
break; | ||
case 'float64': | ||
data_buffer = new Float64Array([input]); | ||
break; | ||
case 'uint32': | ||
default: | ||
data_buffer = new Uint32Array([input]); | ||
break; | ||
else { | ||
hex_string = '0' + hex_string.toLowerCase(); | ||
} | ||
return data_buffer.buffer; | ||
const buff = new Uint8Array((hex_string.length/2)|0); | ||
for ( let i=0; i<buff.length; i++ ) { | ||
const offset = i * 2; | ||
buff[i] = HEX_MAP_R[hex_string[offset]]<<4 | (HEX_MAP_R[hex_string[offset+1]] & 0x0F); | ||
} | ||
return buff.buffer; | ||
} | ||
if( typeof input === "string" ){ | ||
if( conversion_info === "hex" ){ | ||
const matches = input.match(HEX_FORMAT); | ||
if( !matches ){ | ||
throw new RangeError("Input argument is not a valid hex string!"); | ||
} | ||
let [, , hex_string] = matches; | ||
if( hex_string.length % 2 === 0 ){ | ||
hex_string = hex_string.toLowerCase(); | ||
} | ||
else{ | ||
hex_string = '0' + hex_string.toLowerCase(); | ||
} | ||
const buff = new Uint8Array((hex_string.length / 2) | 0); | ||
for( let i = 0; i < buff.length; i++ ){ | ||
const offset = i * 2; | ||
buff[i] = HEX_MAP_R[hex_string[offset]] << 4 | (HEX_MAP_R[hex_string[offset + 1]] & 0x0F); | ||
} | ||
return buff.buffer; | ||
else | ||
if ( conversion_info === "bits" ) { | ||
const matches = input.match(BIT_FORMAT); | ||
if ( !matches ) { | ||
throw new RangeError( "Input argument is not a valid bit string!" ); | ||
} | ||
else if( conversion_info === "bits" ){ | ||
const matches = input.match(BIT_FORMAT); | ||
if( !matches ){ | ||
throw new RangeError("Input argument is not a valid bit string!"); | ||
let [,,bit_string] = matches; | ||
if ( bit_string.length % 8 !== 0 ) { | ||
bit_string = '0'.repeat(bit_string.length%8) + bit_string; | ||
} | ||
const buff = new Uint8Array((bit_string.length/8)|0); | ||
for ( let i=0; i<buff.length; i++ ) { | ||
const offset = i * 8; | ||
let value = (bit_string[offset]==='1'?1:0); | ||
for (let k=1; k<8; k++) { | ||
value = (value << 1) | (bit_string[offset + k]==='1'?1:0); | ||
} | ||
let [, , bit_string] = matches; | ||
if( bit_string.length % 8 !== 0 ){ | ||
bit_string = '0'.repeat(bit_string.length % 8) + bit_string; | ||
} | ||
const buff = new Uint8Array((bit_string.length / 8) | 0); | ||
for( let i = 0; i < buff.length; i++ ){ | ||
const offset = i * 8; | ||
let value = (bit_string[offset] === '1' ? 1 : 0); | ||
for( let k = 1; k < 8; k++ ){ | ||
value = (value << 1) | (bit_string[offset + k] === '1' ? 1 : 0); | ||
} | ||
buff[i] = value; | ||
} | ||
return buff.buffer; | ||
buff[i] = value; | ||
} | ||
else{ | ||
return UTF8Encode(input).buffer; | ||
return buff.buffer; | ||
} | ||
else { | ||
return UTF8Encode(input).buffer; | ||
} | ||
} | ||
throw new TypeError( "Cannot convert given input data into array buffer!" ); | ||
} | ||
}); | ||
Object.defineProperty(ArrayBuffer, 'compare', { | ||
configurable, writable, enumerable, | ||
value: function(a, b) { | ||
if ( !(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer) ) { | ||
throw new TypeError("ArrayBuffer.compare only accepts two array buffers!"); | ||
} | ||
return a.compare(b); | ||
} | ||
}); | ||
Object.defineProperty(ArrayBuffer, 'concat', { | ||
configurable, writable, enumerable, | ||
value: function(...args) { | ||
if ( Array.isArray(args[0]) ) { | ||
args = args[0]; | ||
} | ||
let temp = 0; | ||
for(let i=0; i<args.length; i++) { | ||
let arg = args[i] = ExtractBytes(args[i]); | ||
if (!(arg instanceof Uint8Array)) { | ||
throw new TypeError("ArrayBuffer.combine accept only ArrayBuffer, TypeArray and DataView."); | ||
} | ||
temp += arg.length; | ||
} | ||
const buff = new Uint8Array(temp); | ||
temp = 0; | ||
for(const arg of args) { | ||
buff.set(arg, temp); | ||
temp += arg.length; | ||
} | ||
return buff.buffer; | ||
} | ||
}); | ||
})(); | ||
(()=>{ | ||
Object.defineProperty(Array.prototype, 'unique', { | ||
writable, configurable, enumerable, | ||
value: function(){ | ||
const set = new Set(); | ||
for ( const item of this ) set.add(item); | ||
return Array.from(set); | ||
} | ||
}); | ||
Object.defineProperty(Array.prototype, 'exclude', { | ||
writable, configurable, enumerable, | ||
value: function(reject_list) { | ||
if ( !Array.isArray(reject_list) ) { | ||
reject_list = [reject_list]; | ||
} | ||
const new_ary = []; | ||
for(const item of this) { | ||
let reject = false; | ||
for(const reject_item of reject_list) { | ||
if ( item === reject_item ) { | ||
reject = reject || true; | ||
break; | ||
} | ||
} | ||
throw new TypeError("Cannot convert given input data into array buffer!"); | ||
if ( !reject ) { | ||
new_ary.push(item); | ||
} | ||
} | ||
}); | ||
Object.defineProperty(ArrayBuffer, 'compare', { | ||
configurable, writable, enumerable, | ||
value: function(a, b){ | ||
if( !(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer) ){ | ||
throw new TypeError("ArrayBuffer.compare only accepts two array buffers!"); | ||
return new_ary; | ||
} | ||
}); | ||
Object.defineProperty(Array, 'concat', { | ||
writable, configurable, enumerable, | ||
value: function(...elements) { | ||
const result = []; | ||
for(const element of elements) { | ||
if ( !Array.isArray(element) ) { | ||
result.push(element); | ||
continue; | ||
} | ||
return a.compare(b); | ||
for(const elm of element) { | ||
result.push(elm); | ||
} | ||
} | ||
}); | ||
Object.defineProperty(ArrayBuffer, 'concat', { | ||
configurable, writable, enumerable, | ||
value: function(...args){ | ||
if( Array.isArray(args[0]) ){ | ||
args = args[0]; | ||
return result; | ||
} | ||
}); | ||
Object.defineProperty(Array, 'intersect', { | ||
writable, configurable, enumerable, | ||
value: function(...arrays) { | ||
let result = arrays[0]||[]; | ||
if ( !Array.isArray(result) ) { | ||
throw new TypeError(`Array.intersect only accepts list array arguments!`); | ||
} | ||
for(let i=1; i<arrays.length; i++) { | ||
const array = arrays[i]; | ||
if ( !Array.isArray(array) ) { | ||
throw new TypeError(`Array.intersect only accepts list array arguments!`); | ||
} | ||
let temp = 0; | ||
for( let i = 0; i < args.length; i++ ){ | ||
const arg = args[i] = ExtractBytes(args[i]); | ||
if( !(arg instanceof Uint8Array) ){ | ||
throw new TypeError("ArrayBuffer.combine accept only ArrayBuffer, TypeArray and DataView."); | ||
const new_result = new Set(); | ||
for(const elm of result) { | ||
if ( array.indexOf(elm) >= 0 ) { | ||
new_result.add(elm); | ||
} | ||
temp += arg.byteLength; | ||
} | ||
const buff = new Uint8Array(temp); | ||
temp = 0; | ||
for( const arg of args ){ | ||
buff.set(arg, temp); | ||
temp += arg.length; | ||
} | ||
return buff.buffer; | ||
result = Array.from(new_result); | ||
} | ||
return result; | ||
} | ||
}) | ||
})(); | ||
(()=>{ | ||
if ( typeof Blob !== "undefined" ) { | ||
Object.defineProperty(Blob.prototype, 'arrayBuffer', { | ||
configurable, writable, enumerable, | ||
value:function() { | ||
return new Promise((resolve, reject)=>{ | ||
const reader = new FileReader(); | ||
reader.onerror = reject; | ||
reader.onload = ()=>resolve(reader.result); | ||
reader.readAsArrayBuffer(this); | ||
}); | ||
} | ||
}); | ||
})(); | ||
// Array | ||
(()=>{ | ||
Object.defineProperty(Array.prototype, 'unique', { | ||
writable, configurable, enumerable, | ||
value: function(){ | ||
const set = new Set(); | ||
for( const item of this ) set.add(item); | ||
return Array.from(set); | ||
} | ||
})(); | ||
(()=>{ | ||
Object.defineProperty(Date, 'unix', { | ||
writable, configurable, enumerable, | ||
value: function() { | ||
return Math.floor(Date.now()/1000); | ||
} | ||
}); | ||
Object.defineProperty(Date.prototype, 'getUnixTime', { | ||
writable, configurable, enumerable, | ||
value: function() { | ||
return Math.floor(this.getTime()/1000); | ||
} | ||
}); | ||
Object.defineProperty(Date.prototype, 'unix', { | ||
configurable, enumerable, | ||
get: function() { | ||
return Math.floor(this.getTime()/1000); | ||
} | ||
}); | ||
Object.defineProperty(Date.prototype, 'time', { | ||
configurable, enumerable, | ||
get: function() { | ||
return this.getTime(); | ||
} | ||
}); | ||
Object.defineProperty(Date.prototype, 'toLocaleISOString', { | ||
writable, configurable, enumerable, | ||
value: function(){ | ||
let offset, zone = this.getTimezoneOffset(); | ||
if ( zone === 0 ) { | ||
offset = 'Z'; | ||
} | ||
}); | ||
Object.defineProperty(Array.prototype, 'exclude', { | ||
writable, configurable, enumerable, | ||
value: function(reject_list){ | ||
if( !Array.isArray(reject_list) ){ | ||
reject_list = [reject_list]; | ||
} | ||
else { | ||
const sign = zone > 0 ? '-' : '+'; | ||
zone = Math.abs(zone); | ||
const zone_hour = Math.floor(zone/60); | ||
const zone_min = zone%60; | ||
const new_ary = []; | ||
for( const item of this ){ | ||
let reject = false; | ||
for( const reject_item of reject_list ){ | ||
if( item === reject_item ){ | ||
reject = reject || true; | ||
break; | ||
} | ||
} | ||
if( !reject ){ | ||
new_ary.push(item); | ||
} | ||
} | ||
return new_ary; | ||
offset = sign + Padding(zone_hour) + Padding(zone_min); | ||
} | ||
}); | ||
Object.defineProperty(Array, 'concat', { | ||
writable, configurable, enumerable, | ||
value: function(...elements){ | ||
const result = []; | ||
for( const element of elements ){ | ||
if( !Array.isArray(element) ){ | ||
result.push(element); | ||
continue; | ||
return this.getFullYear() + | ||
'-' + Padding(this.getMonth()+1) + | ||
'-' + Padding(this.getDate()) + | ||
'T' + Padding(this.getHours()) + | ||
':' + Padding(this.getMinutes()) + | ||
':' + Padding(this.getSeconds()) + | ||
'.' + (this.getMilliseconds() % 1000) + | ||
offset; | ||
} | ||
}); | ||
})(); | ||
(()=>{ | ||
if ( typeof Document !== "undefined" ) { | ||
Object.defineProperties(Document.prototype, { | ||
parseHTML: { | ||
configurable, writable, enumerable, | ||
value: function(html) { | ||
const shadow = this.implementation.createHTMLDocument(); | ||
const shadowed_body = shadow.body; | ||
shadowed_body.innerHTML = html; | ||
if ( shadowed_body.children.length === 0 ) { | ||
return null; | ||
} | ||
for( const elm of element ){ | ||
result.push(elm); | ||
if ( shadowed_body.children.length === 1 ) { | ||
const item = shadowed_body.children[0]; | ||
item.remove(); | ||
return item; | ||
} | ||
const elements = Array.prototype.slice.call(shadowed_body.children, 0); | ||
for(const element of elements) { | ||
element.remove(); | ||
} | ||
return elements; | ||
} | ||
return result; | ||
} | ||
}); | ||
Object.defineProperty(Array, 'intersect', { | ||
writable, configurable, enumerable, | ||
value: function(...arrays){ | ||
let result = arrays[0] || []; | ||
if( !Array.isArray(result) ){ | ||
throw new TypeError(`Array.intersect only accepts list array arguments!`); | ||
} | ||
for( let i = 1; i < arrays.length; i++ ){ | ||
const array = arrays[i]; | ||
if( !Array.isArray(array) ){ | ||
throw new TypeError(`Array.intersect only accepts list array arguments!`); | ||
} | ||
})(); | ||
(()=>{ | ||
if ( typeof Element !== "undefined" ) { | ||
const _ELEMENT_SET_ATTRIBUTE = Element.prototype.setAttribute; | ||
const _ELEMENT_REMOVE_ATTRIBUTE = Element.prototype.removeAttribute; | ||
const _ELEMENT_SET_ATTRIBUTE_NS = Element.prototype.setAttributeNS; | ||
const _ELEMENT_REMOVE_ATTRIBUTE_NS = Element.prototype.removeAttributeNS; | ||
Object.defineProperties(Element.prototype, { | ||
addClass: { | ||
configurable, enumerable, writable, | ||
value: function(...classes) { | ||
const filtered = []; | ||
for( const class_name of classes ) { | ||
if ( class_name === undefined || class_name === null || class_name === '' ) { | ||
continue; | ||
} | ||
filtered.push(class_name); | ||
} | ||
const new_result = new Set(); | ||
for( const elm of result ){ | ||
if( array.indexOf(elm) >= 0 ){ | ||
new_result.add(elm); | ||
this.classList.add(...filtered); | ||
return this; | ||
} | ||
}, | ||
removeClass: { | ||
configurable, enumerable, writable, | ||
value: function(...classes) { | ||
const filtered = []; | ||
for( const class_name of classes ) { | ||
if ( class_name === undefined || class_name === null || class_name === '' ) { | ||
continue; | ||
} | ||
filtered.push(class_name); | ||
} | ||
result = Array.from(new_result); | ||
this.classList.remove(...filtered); | ||
return this; | ||
} | ||
return result; | ||
} | ||
}) | ||
})(); | ||
// Blob | ||
(()=>{ | ||
if( typeof Blob !== "undefined" ){ | ||
Object.defineProperty(Blob.prototype, 'arrayBuffer', { | ||
configurable, writable, enumerable, | ||
value: function(){ | ||
return new Promise((resolve, reject)=>{ | ||
const reader = new FileReader(); | ||
reader.onerror = reject; | ||
reader.onload = ()=>resolve(reader.result); | ||
reader.readAsArrayBuffer(this); | ||
}); | ||
}, | ||
setAttribute: { | ||
configurable, enumerable, writable, | ||
value: function(name, value) { | ||
if ( arguments.length < 2 ) { value = ''; } | ||
_ELEMENT_SET_ATTRIBUTE.call(this, name, value); | ||
return this; | ||
} | ||
}); | ||
} | ||
})(); | ||
// Date | ||
(()=>{ | ||
Object.defineProperty(Date, 'unix', { | ||
writable, configurable, enumerable, | ||
value: function(){ | ||
return Math.floor(Date.now() / 1000); | ||
} | ||
}, | ||
removeAttribute: { | ||
configurable, enumerable, writable, | ||
value: function(...args) { | ||
_ELEMENT_REMOVE_ATTRIBUTE.apply(this, args); | ||
return this; | ||
} | ||
}, | ||
setAttributeNS: { | ||
configurable, enumerable, writable, | ||
value: function(...args) { | ||
_ELEMENT_SET_ATTRIBUTE_NS.apply(this, args); | ||
return this; | ||
} | ||
}, | ||
removeAttributeNS: { | ||
configurable, enumerable, writable, | ||
value: function(...args) { | ||
_ELEMENT_REMOVE_ATTRIBUTE_NS.apply(this, args); | ||
return this; | ||
} | ||
}, | ||
}); | ||
Object.defineProperty(Date.prototype, 'getUnixTime', { | ||
writable, configurable, enumerable, | ||
value: function(){ | ||
return Math.floor(this.getTime() / 1000); | ||
} | ||
} | ||
})(); | ||
(()=>{ | ||
if ( typeof Error !== "undefined" ) { | ||
Object.defineProperty(Error.prototype, 'stack_trace', { | ||
get: function(){ | ||
if ( !this.stack ) return null; | ||
return this.stack.split(/\r\n|\n/g).map((item)=>item.trim()); | ||
}, | ||
enumerable, configurable | ||
}); | ||
Object.defineProperty(Date.prototype, 'unix', { | ||
configurable, enumerable, | ||
get: function(){ | ||
return Math.floor(this.getTime() / 1000); | ||
} | ||
})(); | ||
(()=>{ | ||
if ( typeof EventTarget !== "undefined" ) { | ||
Object.defineProperty(EventTarget.prototype, 'on', { | ||
configurable, writable, enumerable, | ||
value: function(event_name, callback) { | ||
// Event name accepts name1#tag1,name2#tag1,name3#tag2 | ||
const inserted = []; | ||
const events = event_name.split(','); | ||
for( let evt_name of events ) { | ||
evt_name = evt_name.trim(); | ||
if ( inserted.indexOf(evt_name) >= 0 ) continue; | ||
inserted.push(evt_name); | ||
this.addEventListener(evt_name, callback); | ||
} | ||
return this; | ||
} | ||
}); | ||
Object.defineProperty(Date.prototype, 'time', { | ||
configurable, enumerable, | ||
get: function(){ | ||
return this.getTime(); | ||
Object.defineProperty(EventTarget.prototype, 'off', { | ||
configurable, writable, enumerable, | ||
value: function(event_name, callback) { | ||
const events = event_name.split(','); | ||
for( let evt_name of events ) { | ||
evt_name = evt_name.trim(); | ||
this.removeEventListener(evt_name, callback); | ||
} | ||
return this; | ||
} | ||
}); | ||
Object.defineProperty(Date.prototype, 'toLocaleISOString', { | ||
writable, configurable, enumerable, | ||
value: function(){ | ||
let offset, zone = this.getTimezoneOffset(); | ||
if( zone === 0 ){ | ||
offset = 'Z'; | ||
Object.defineProperty(EventTarget.prototype, 'emit', { | ||
configurable, writable, enumerable, | ||
value: function(event, inits={}) { | ||
const {bubbles, cancelable, composed, ...event_args} = inits; | ||
if ( typeof event === "string" ) { | ||
event = new Event(event, { | ||
bubbles:!!bubbles, | ||
cancelable:!!cancelable, | ||
composed:!!composed | ||
}); | ||
} | ||
else{ | ||
const sign = zone > 0 ? '-' : '+'; | ||
zone = Math.abs(zone); | ||
const zone_hour = Math.floor(zone / 60); | ||
const zone_min = zone % 60; | ||
offset = sign + Padding(zone_hour) + Padding(zone_min); | ||
if ( !(event instanceof Event) ) { | ||
throw new TypeError("Argument 1 accepts only string or Event instance!"); | ||
} | ||
@@ -561,1022 +731,829 @@ | ||
return this.getFullYear() + | ||
'-' + Padding(this.getMonth() + 1) + | ||
'-' + Padding(this.getDate()) + | ||
'T' + Padding(this.getHours()) + | ||
':' + Padding(this.getMinutes()) + | ||
':' + Padding(this.getSeconds()) + | ||
'.' + (this.getMilliseconds() % 1000) + | ||
offset; | ||
Object.assign(event, event_args); | ||
this.dispatchEvent(event); | ||
} | ||
}); | ||
})(); | ||
// Document | ||
(()=>{ | ||
if( typeof Document !== "undefined" ){ | ||
Object.defineProperties(Document.prototype, { | ||
parseHTML: { | ||
configurable, writable, enumerable, | ||
value: function(html){ | ||
const shadow = this.implementation.createHTMLDocument(); | ||
const shadowed_body = shadow.body; | ||
shadowed_body.innerHTML = html; | ||
if( shadowed_body.children.length === 0 ){ | ||
return null; | ||
} | ||
if( shadowed_body.children.length === 1 ){ | ||
const item = shadowed_body.children[0]; | ||
item.remove(); | ||
return item; | ||
} | ||
const elements = Array.prototype.slice.call(shadowed_body.children, 0); | ||
for( const element of elements ){ | ||
element.remove(); | ||
} | ||
return elements; | ||
} | ||
} | ||
})(); | ||
(()=>{ | ||
if ( typeof Error !== "undefined" ) { | ||
class EError extends Error { | ||
constructor(message, ...args) { | ||
super(message, ...args); | ||
if ( Error.captureStackTrace ) { | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
}); | ||
} | ||
})(); | ||
// Element | ||
(()=>{ | ||
if( typeof Element !== "undefined" ){ | ||
const _ELEMENT_SET_ATTRIBUTE = Element.prototype.setAttribute; | ||
const _ELEMENT_REMOVE_ATTRIBUTE = Element.prototype.removeAttribute; | ||
const _ELEMENT_SET_ATTRIBUTE_NS = Element.prototype.setAttributeNS; | ||
const _ELEMENT_REMOVE_ATTRIBUTE_NS = Element.prototype.removeAttributeNS; | ||
Object.defineProperties(Element.prototype, { | ||
addClass: { | ||
configurable, enumerable, writable, | ||
value: function(...classes){ | ||
const filtered = []; | ||
for( const class_name of classes ){ | ||
if( class_name === undefined || class_name === null || class_name === '' ){ | ||
continue; | ||
} | ||
filtered.push(class_name); | ||
} | ||
this.classList.add(...filtered); | ||
return this; | ||
const now = Date.now(); | ||
Object.defineProperties(this, { | ||
name: { | ||
configurable:false, writable:false, enumerable:false, | ||
value:this.constructor.name | ||
}, | ||
time: { | ||
configurable:false, writable:false, enumerable:false, | ||
value:Math.floor(now/1000) | ||
}, | ||
time_milli: { | ||
configurable:false, writable:false, enumerable:false, | ||
value:now | ||
} | ||
}, | ||
removeClass: { | ||
configurable, enumerable, writable, | ||
value: function(...classes){ | ||
const filtered = []; | ||
for( const class_name of classes ){ | ||
if( class_name === undefined || class_name === null || class_name === '' ){ | ||
continue; | ||
} | ||
filtered.push(class_name); | ||
} | ||
this.classList.remove(...filtered); | ||
return this; | ||
} | ||
}, | ||
setAttribute: { | ||
configurable, enumerable, writable, | ||
value: function(name, value){ | ||
if( arguments.length < 2 ){ value = ''; } | ||
_ELEMENT_SET_ATTRIBUTE.call(this, name, value); | ||
return this; | ||
} | ||
}, | ||
removeAttribute: { | ||
configurable, enumerable, writable, | ||
value: function(...args){ | ||
_ELEMENT_REMOVE_ATTRIBUTE.apply(this, args); | ||
return this; | ||
} | ||
}, | ||
setAttributeNS: { | ||
configurable, enumerable, writable, | ||
value: function(...args){ | ||
_ELEMENT_SET_ATTRIBUTE_NS.apply(this, args); | ||
return this; | ||
} | ||
}, | ||
removeAttributeNS: { | ||
configurable, enumerable, writable, | ||
value: function(...args){ | ||
_ELEMENT_REMOVE_ATTRIBUTE_NS.apply(this, args); | ||
return this; | ||
} | ||
}, | ||
}); | ||
}); | ||
} | ||
} | ||
})(); | ||
// Error | ||
(()=>{ | ||
if( typeof Error !== "undefined" ){ | ||
Object.defineProperty(Error.prototype, 'stack_trace', { | ||
get: function(){ | ||
if( !this.stack ) return null; | ||
return this.stack.split(/\r\n|\n/g).map((item)=>item.trim()); | ||
}, | ||
enumerable, configurable | ||
}); | ||
class IndexedError extends EError { | ||
constructor(error_info, detail=null, ...args) { | ||
if ( Object(error_info) !== error_info ) { | ||
throw new TypeError("IndexedError constructor accepts only objects!"); | ||
} | ||
class EError extends Error { | ||
constructor(message, ...args){ | ||
super(message, ...args); | ||
if( Error.captureStackTrace ){ | ||
Error.captureStackTrace(this, this.constructor); | ||
const {code, key, message=null, msg=null} = error_info; | ||
if ( typeof code !== "number" || typeof key !== "string" ) { | ||
throw new TypeError("IndexedError error info object must contains a numeric `code` field and a string `key` field"); | ||
} | ||
if (message !== null) { | ||
args.unshift(''+message); | ||
} | ||
else | ||
if (msg !== null) { | ||
args.unshift(''+msg); | ||
} | ||
else { | ||
args.unshift(''); | ||
} | ||
super(...args); | ||
Object.defineProperties(this, { | ||
code:{ | ||
configurable:false, writable:false, enumerable:false, | ||
value:code | ||
}, | ||
key:{ | ||
configurable:false, writable:false, enumerable:false, | ||
value:key | ||
}, | ||
detail: { | ||
configurable:false, writable:false, enumerable:false, | ||
value:detail | ||
} | ||
const now = Date.now(); | ||
Object.defineProperties(this, { | ||
name: { | ||
configurable: false, writable: false, enumerable: false, | ||
value: this.constructor.name | ||
}, | ||
time: { | ||
configurable: false, writable: false, enumerable: false, | ||
value: Math.floor(now / 1000) | ||
}, | ||
time_milli: { | ||
configurable: false, writable: false, enumerable: false, | ||
value: now | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
class IndexedError extends EError { | ||
constructor(error_info, detail = null, ...args){ | ||
if( Object(error_info) !== error_info ){ | ||
throw new TypeError("IndexedError constructor accepts only objects!"); | ||
toJSON() { | ||
const result = { | ||
code:this.code, | ||
key:this.key, | ||
msg:this.message, | ||
detail:undefined, | ||
time:this.time, | ||
time_milli:this.time_milli | ||
}; | ||
if ( this.detail !== null && this.detail !== undefined ) { | ||
if ( Array.isArray(this.detail) ) { | ||
result.detail = this.detail.slice(0); | ||
} | ||
const {code, key, message = null, msg = null} = error_info; | ||
if( typeof code !== "number" || typeof key !== "string" ){ | ||
throw new TypeError("IndexedError error info object must contains a numeric `code` field and a string `key` field"); | ||
else | ||
if ( Object(this.detail) === this.detail ) { | ||
result.detail = Object.assign({}, this.detail); | ||
} | ||
if( message !== null ){ | ||
args.unshift('' + message); | ||
else { | ||
result.detail = this.detail; | ||
} | ||
else if( msg !== null ){ | ||
args.unshift('' + msg); | ||
} | ||
else{ | ||
args.unshift(''); | ||
} | ||
super(...args); | ||
Object.defineProperties(this, { | ||
code: { | ||
configurable: false, writable: false, enumerable: false, | ||
value: code | ||
}, | ||
key: { | ||
configurable: false, writable: false, enumerable: false, | ||
value: key | ||
}, | ||
detail: { | ||
configurable: false, writable: false, enumerable: false, | ||
value: detail | ||
} | ||
}); | ||
} | ||
toJSON(){ | ||
const result = { | ||
code: this.code, | ||
key: this.key, | ||
msg: this.message, | ||
detail: undefined, | ||
time: this.time, | ||
time_milli: this.time_milli | ||
}; | ||
if( this.detail !== null && this.detail !== undefined ){ | ||
if( Array.isArray(this.detail) ){ | ||
result.detail = this.detail.slice(0); | ||
} | ||
else if( Object(this.detail) === this.detail ){ | ||
result.detail = Object.assign({}, this.detail); | ||
} | ||
else{ | ||
result.detail = this.detail; | ||
} | ||
} | ||
return result; | ||
} | ||
return result; | ||
} | ||
Object.defineProperties(Error, { | ||
EError: { | ||
configurable, writable, enumerable, | ||
value: EError | ||
}, | ||
IndexedError: { | ||
configurable, writable, enumerable, | ||
value: IndexedError | ||
} | ||
}); | ||
} | ||
})(); | ||
// EventTarget | ||
(()=>{ | ||
if( typeof EventTarget !== "undefined" ){ | ||
Object.defineProperty(EventTarget.prototype, 'on', { | ||
Object.defineProperties(Error, { | ||
EError: { | ||
configurable, writable, enumerable, | ||
value: function(event_name, callback){ | ||
// Event name accepts name1#tag1,name2#tag1,name3#tag2 | ||
const inserted = []; | ||
const events = event_name.split(','); | ||
for( let evt_name of events ){ | ||
evt_name = evt_name.trim(); | ||
if( inserted.indexOf(evt_name) >= 0 ) continue; | ||
inserted.push(evt_name); | ||
this.addEventListener(evt_name, callback); | ||
} | ||
return this; | ||
} | ||
}); | ||
Object.defineProperty(EventTarget.prototype, 'off', { | ||
value:EError | ||
}, | ||
IndexedError: { | ||
configurable, writable, enumerable, | ||
value: function(event_name, callback){ | ||
const events = event_name.split(','); | ||
for( let evt_name of events ){ | ||
evt_name = evt_name.trim(); | ||
this.removeEventListener(evt_name, callback); | ||
} | ||
return this; | ||
} | ||
}); | ||
Object.defineProperty(EventTarget.prototype, 'emit', { | ||
configurable, writable, enumerable, | ||
value: function(event, inits = {}){ | ||
const {bubbles, cancelable, composed, ...event_args} = inits; | ||
if( typeof event === "string" ){ | ||
event = new Event(event, { | ||
bubbles: !!bubbles, | ||
cancelable: !!cancelable, | ||
composed: !!composed | ||
}); | ||
} | ||
if( !(event instanceof Event) ){ | ||
throw new TypeError("Argument 1 accepts only string or Event instance!"); | ||
} | ||
Object.assign(event, event_args); | ||
this.dispatchEvent(event); | ||
} | ||
}); | ||
} | ||
})(); | ||
value:IndexedError | ||
} | ||
}); | ||
} | ||
})(); | ||
(()=>{ | ||
const REF = new WeakMap(); | ||
const boot_async={}, boot_sync={}; | ||
REF.set(boot_async, {async:true, funcs:[]}); | ||
REF.set(boot_sync, {async:false, funcs:[]}); | ||
// Function | ||
(()=>{ | ||
const REF = new WeakMap(); | ||
const boot_async={}, boot_sync={}; | ||
REF.set(boot_async, {async:true, funcs:[]}); | ||
REF.set(boot_sync, {async:false, funcs:[]}); | ||
Object.defineProperty(Function, 'sequential', { | ||
configurable, writable, enumerable, | ||
value: PackSequentialCall.bind(null, false) | ||
}); | ||
Object.defineProperty(Function.sequential, 'async', { | ||
configurable: false, writable: false, enumerable: true, | ||
value: PackSequentialCall.bind(null, true) | ||
}); | ||
function PackSequentialCall(is_async, func_list) { | ||
const args = Array.prototype.slice.call(arguments, 0); | ||
args[0] = is_async?boot_async:boot_sync; | ||
return PackSequential.call(...args); | ||
} | ||
function PackSequential(func_list) { | ||
const prev_state = REF.get(this); | ||
const state = {async:prev_state.async, funcs:prev_state.funcs.slice(0)}; | ||
if ( arguments.length > 0 ) { | ||
let func; | ||
if ( !Array.isArray(func_list) ) { func_list = [func_list]; } | ||
for( let i = 0; i < func_list.length; i++ ){ | ||
state.funcs.push((typeof (func=func_list[i]) === "function") ? func : ()=>func); | ||
} | ||
} | ||
const storage = {}; | ||
REF.set(storage, state); | ||
const trigger = DoSequentialCall.bind(storage); | ||
trigger.chain = PackSequential.bind(storage); | ||
return trigger; | ||
} | ||
function DoSequentialCall(...spread_args) { | ||
const {async:is_async, funcs:chain_items} = REF.get(this); | ||
this.session = {}; | ||
Object.defineProperty(Function, 'sequential', { | ||
configurable, writable, enumerable, | ||
value: PackSequentialCall.bind(null, false) | ||
}); | ||
Object.defineProperty(Function.sequential, 'async', { | ||
configurable: false, writable: false, enumerable: true, | ||
value: PackSequentialCall.bind(null, true) | ||
}); | ||
function PackSequentialCall(is_async, func_list) { | ||
const args = Array.prototype.slice.call(arguments, 0); | ||
args[0] = is_async?boot_async:boot_sync; | ||
return PackSequential.call(...args); | ||
} | ||
function PackSequential(func_list) { | ||
const prev_state = REF.get(this); | ||
const state = {async:prev_state.async, funcs:prev_state.funcs.slice(0)}; | ||
if ( arguments.length > 0 ) { | ||
let func; | ||
if ( !Array.isArray(func_list) ) { func_list = [func_list]; } | ||
for( let i = 0; i < func_list.length; i++ ){ | ||
state.funcs.push((typeof (func=func_list[i]) === "function") ? func : ()=>func); | ||
} | ||
let result = undefined; | ||
if ( !is_async ) { | ||
for( const func of chain_items ){ | ||
result = func.call(this, ...spread_args, result); | ||
if( result === false ) break; | ||
} | ||
const storage = {}; | ||
REF.set(storage, state); | ||
const trigger = DoSequentialCall.bind(storage); | ||
trigger.chain = PackSequential.bind(storage); | ||
return trigger; | ||
return result; | ||
} | ||
function DoSequentialCall(...spread_args) { | ||
const {async:is_async, funcs:chain_items} = REF.get(this); | ||
this.session = {}; | ||
let result = undefined; | ||
if ( !is_async ) { | ||
else { | ||
return Promise.resolve().then(async()=>{ | ||
for( const func of chain_items ){ | ||
result = func.call(this, ...spread_args, result); | ||
result = await func.call(this, ...spread_args, result); | ||
if( result === false ) break; | ||
} | ||
return result; | ||
} | ||
else { | ||
return Promise.resolve().then(async()=>{ | ||
for( const func of chain_items ){ | ||
result = await func.call(this, ...spread_args, result); | ||
if( result === false ) break; | ||
} | ||
return result; | ||
}); | ||
} | ||
}); | ||
} | ||
})(); | ||
// HTMLElement | ||
(()=>{ | ||
if( typeof HTMLElement !== "undefined" ){ | ||
Object.defineProperties(HTMLElement.prototype, { | ||
setData: { | ||
configurable, writable, enumerable, | ||
value: function(key, value){ | ||
if( Object(key) === key ){ | ||
for( const _key in key ){ | ||
this.dataset[_key] = key[_key]; | ||
} | ||
} | ||
})(); | ||
(()=>{ | ||
if ( typeof HTMLElement !== "undefined" ) { | ||
Object.defineProperties(HTMLElement.prototype, { | ||
setData: { | ||
configurable, writable, enumerable, | ||
value: function(key, value) { | ||
if ( Object(key) === key ) { | ||
for(const _key in key) { | ||
this.dataset[_key] = key[_key]; | ||
} | ||
else{ | ||
this.dataset[key] = value; | ||
} | ||
return this; | ||
} | ||
}, | ||
getData: { | ||
configurable, writable, enumerable, | ||
value: function(key){ | ||
return this.dataset[key]; | ||
else { | ||
this.dataset[key] = value; | ||
} | ||
}, | ||
removeData: { | ||
configurable, writable, enumerable, | ||
value: function(...data_names){ | ||
for( const name of data_names ){ | ||
delete this.dataset[name]; | ||
} | ||
return this; | ||
} | ||
}, | ||
setContentHtml: { | ||
configurable, writable, enumerable, | ||
value: function(html){ | ||
this.innerHTML = html; | ||
return this; | ||
} | ||
} | ||
}); | ||
} | ||
})(); | ||
// HTMLInputElement | ||
(()=>{ | ||
if( typeof HTMLInputElement !== "undefined" ) { | ||
Object.defineProperty(HTMLInputElement.prototype, 'setValue', { | ||
configurable, writable, enumerable, | ||
value: function(value){ | ||
this.value = value; | ||
return this; | ||
} | ||
}); | ||
} | ||
})(); | ||
// Node | ||
(()=>{ | ||
if( typeof Node !== "undefined" ){ | ||
Object.defineProperty(Node.prototype, 'prependChild', { | ||
}, | ||
getData: { | ||
configurable, writable, enumerable, | ||
value: function(child){ | ||
this.insertBefore(child, this.children[0] || null); | ||
return (this instanceof DocumentFragment) ? new DocumentFragment() : child; | ||
value: function(key) { | ||
return this.dataset[key]; | ||
} | ||
}); | ||
Object.defineProperty(Node.prototype, 'insertNeighborBefore', { | ||
}, | ||
removeData: { | ||
configurable, writable, enumerable, | ||
value: function(child){ | ||
if( !this.parentNode ){ | ||
throw new RangeError("Reference element is currently in detached mode! No way to add neighbors!"); | ||
value: function(...data_names) { | ||
for( const name of data_names ) { | ||
delete this.dataset[name]; | ||
} | ||
this.parentNode.insertBefore(child, this); | ||
return (this instanceof DocumentFragment) ? new DocumentFragment() : child; | ||
return this; | ||
} | ||
}); | ||
Object.defineProperty(Node.prototype, 'insertNeighborAfter', { | ||
}, | ||
setContentHtml: { | ||
configurable, writable, enumerable, | ||
value: function(child){ | ||
if( !this.parentNode ){ | ||
throw new RangeError("Reference element is currently in detached mode! No way to add neighbors!"); | ||
} | ||
this.parentNode.insertBefore(child, this.nextSibling); | ||
return (this instanceof DocumentFragment) ? new DocumentFragment() : child; | ||
} | ||
}); | ||
Object.defineProperty(Node.prototype, 'setContentText', { | ||
configurable, writable, enumerable, | ||
value: function(text){ | ||
this.textContent = text; | ||
value: function(html) { | ||
this.innerHTML = html; | ||
return this; | ||
} | ||
}); | ||
} | ||
})(); | ||
// Object | ||
(()=>{ | ||
const _ObjectDefineProperty = Object.defineProperty; | ||
const _ObjectDefineProperties = Object.defineProperties; | ||
_ObjectDefineProperty(Object, 'defineProperty', { | ||
writable, configurable, enumerable, | ||
value: ObjectDefineProperty | ||
} | ||
}); | ||
_ObjectDefineProperty(Object, 'defineProperties', { | ||
writable, configurable, enumerable, | ||
value: ObjectDefineProperties | ||
} | ||
})(); | ||
(()=>{ | ||
if ( typeof HTMLInputElement !== "undefined" ) { | ||
Object.defineProperty( HTMLInputElement.prototype, 'setValue', { | ||
configurable, writable, enumerable, | ||
value: function(value) { | ||
this.value = value; | ||
return this; | ||
} | ||
}); | ||
Object.defineProperty(Object, 'merge', { | ||
writable, configurable, enumerable, | ||
value: ObjectMerge | ||
} | ||
})(); | ||
(()=>{ | ||
if ( typeof Node !== "undefined" ) { | ||
Object.defineProperty( Node.prototype, 'prependChild', { | ||
configurable, writable, enumerable, | ||
value: function(child) { | ||
this.insertBefore(child, this.children[0]||null); | ||
return ( this instanceof DocumentFragment ) ? new DocumentFragment() : child; | ||
} | ||
}); | ||
Object.defineProperty(Object, 'typeOf', { | ||
writable, configurable, enumerable, | ||
value: TypeOf | ||
Object.defineProperty( Node.prototype, 'insertNeighborBefore', { | ||
configurable, writable, enumerable, | ||
value: function(child) { | ||
if ( !this.parentNode ) { | ||
throw new RangeError( "Reference element is currently in detached mode! No way to add neighbors!" ); | ||
} | ||
this.parentNode.insertBefore(child, this); | ||
return ( this instanceof DocumentFragment ) ? new DocumentFragment() : child; | ||
} | ||
}); | ||
Object.defineProperty(Object.prototype, '_decorate', { | ||
writable, configurable, enumerable, | ||
value: function(processor, ...args){ | ||
if( typeof processor === "function" ){ | ||
processor.call(this, ...args); | ||
Object.defineProperty( Node.prototype, 'insertNeighborAfter', { | ||
configurable, writable, enumerable, | ||
value: function(child) { | ||
if ( !this.parentNode ) { | ||
throw new RangeError( "Reference element is currently in detached mode! No way to add neighbors!" ); | ||
} | ||
this.parentNode.insertBefore(child, this.nextSibling); | ||
return ( this instanceof DocumentFragment ) ? new DocumentFragment() : child; | ||
} | ||
}); | ||
Object.defineProperty( Node.prototype, 'setContentText', { | ||
configurable, writable, enumerable, | ||
value: function(text) { | ||
this.textContent = text; | ||
return this; | ||
} | ||
}); | ||
} | ||
})(); | ||
(()=>{ | ||
const _ObjectDefineProperty = Object.defineProperty; | ||
const _ObjectDefineProperties = Object.defineProperties; | ||
_ObjectDefineProperty(Object, 'defineProperty', { | ||
writable, configurable, enumerable, | ||
value: ObjectDefineProperty | ||
}); | ||
_ObjectDefineProperty(Object, 'defineProperties', { | ||
writable, configurable, enumerable, | ||
value: ObjectDefineProperties | ||
}); | ||
Object.defineProperty(Object, 'merge', { | ||
writable, configurable, enumerable, | ||
value: ObjectMerge | ||
}); | ||
Object.defineProperty(Object, 'typeOf', { | ||
writable, configurable, enumerable, | ||
value: TypeOf | ||
}); | ||
Object.defineProperty(Object.prototype, '_decorate', { | ||
writable, configurable, enumerable, | ||
value: function(processor, ...args) { | ||
if ( typeof processor === "function" ) { | ||
processor.call(this, ...args); | ||
} | ||
return this; | ||
} | ||
}); | ||
function ObjectDefineProperty(object, prop_name, prop_attr) { | ||
_ObjectDefineProperty(object, prop_name, prop_attr); | ||
return object; | ||
} | ||
function ObjectDefineProperties(object, prop_contents) { | ||
_ObjectDefineProperties(object, prop_contents); | ||
return object; | ||
} | ||
function ObjectMerge(target, source) { | ||
if ( Object(target) !== target ) { | ||
throw new Error("Given target is not an object"); | ||
} | ||
if ( Object(source) !== source ) { | ||
throw new Error("Given source is not an object"); | ||
} | ||
for (const key in source) { | ||
if ( (source.hasOwnProperty && !source.hasOwnProperty(key)) || | ||
(source[key] === undefined) | ||
) { continue; } | ||
function ObjectDefineProperty(object, prop_name, prop_attr){ | ||
_ObjectDefineProperty(object, prop_name, prop_attr); | ||
return object; | ||
} | ||
function ObjectDefineProperties(object, prop_contents){ | ||
_ObjectDefineProperties(object, prop_contents); | ||
return object; | ||
} | ||
function ObjectMerge(target, source){ | ||
if( Object(target) !== target ){ | ||
throw new Error("Given target is not an object"); | ||
} | ||
if( Object(source) !== source ){ | ||
throw new Error("Given source is not an object"); | ||
} | ||
const tValue = target[key]; | ||
const sValue = source[key]; | ||
const tType = TypeOf(tValue); | ||
const sType = TypeOf(sValue); | ||
for( const key in source ){ | ||
if( (source.hasOwnProperty && !source.hasOwnProperty(key)) || | ||
(source[key] === undefined) | ||
){ continue; } | ||
const tValue = target[key]; | ||
const sValue = source[key]; | ||
const tType = TypeOf(tValue); | ||
const sType = TypeOf(sValue); | ||
if( tType !== "object" || sType !== "object" ){ | ||
if( target instanceof Map ){ | ||
target.set(key, sValue); | ||
} | ||
else{ | ||
target[key] = sValue; | ||
} | ||
continue; | ||
if ( tType !== "object" || sType !== "object" ) { | ||
if ( target instanceof Map ) { | ||
target.set(key, sValue); | ||
} | ||
ObjectMerge(tValue, sValue); | ||
else { | ||
target[key] = sValue; | ||
} | ||
continue; | ||
} | ||
return target; | ||
ObjectMerge(tValue, sValue); | ||
} | ||
function TypeOf(input, resolveObj = false){ | ||
const type = typeof input; | ||
switch( type ){ | ||
case "number": | ||
case "string": | ||
case "function": | ||
case "boolean": | ||
case "undefined": | ||
case "symbol": | ||
return type; | ||
} | ||
if( input === null ){ | ||
return "null"; | ||
} | ||
if( input instanceof String ){ | ||
return "string"; | ||
} | ||
if( input instanceof Number ){ | ||
return "number"; | ||
} | ||
if( input instanceof Boolean ){ | ||
return "boolean"; | ||
} | ||
if( Array.isArray(input) ){ | ||
return "array"; | ||
} | ||
if( !resolveObj ){ | ||
return "object"; | ||
} | ||
// None-primitive | ||
if( input instanceof ArrayBuffer ){ | ||
return "array-buffer" | ||
} | ||
if( input instanceof DataView ){ | ||
return "data-view"; | ||
} | ||
if( input instanceof Uint8Array ){ | ||
return "uint8-array"; | ||
} | ||
if( input instanceof Uint8ClampedArray ){ | ||
return "uint8-clamped-array"; | ||
} | ||
if( input instanceof Int8Array ){ | ||
return "int8-array"; | ||
} | ||
if( input instanceof Uint16Array ){ | ||
return "uint16-array"; | ||
} | ||
if( input instanceof Int16Array ){ | ||
return "int16-array"; | ||
} | ||
if( input instanceof Uint32Array ){ | ||
return "uint32-array"; | ||
} | ||
if( input instanceof Int32Array ){ | ||
return "int32-array"; | ||
} | ||
if( input instanceof Float32Array ){ | ||
return "float32-array"; | ||
} | ||
if( input instanceof Float64Array ){ | ||
return "float64-array"; | ||
} | ||
if( input instanceof Map ){ | ||
return "map"; | ||
} | ||
if( input instanceof WeakMap ){ | ||
return "weak-map"; | ||
} | ||
if( input instanceof Set ){ | ||
return "set"; | ||
} | ||
if( input instanceof WeakSet ){ | ||
return "weak-set"; | ||
} | ||
if( input instanceof RegExp ){ | ||
return "regexp" | ||
} | ||
if( input instanceof Promise ){ | ||
return "promise"; | ||
} | ||
return target; | ||
} | ||
function TypeOf(input, resolveObj=false) { | ||
const type = typeof input; | ||
switch(type) { | ||
case "number": | ||
case "string": | ||
case "function": | ||
case "boolean": | ||
case "undefined": | ||
case "symbol": | ||
return type; | ||
} | ||
if ( input === null ) { | ||
return "null"; | ||
} | ||
if ( input instanceof String ) { | ||
return "string"; | ||
} | ||
if ( input instanceof Number ) { | ||
return "number"; | ||
} | ||
if ( input instanceof Boolean ) { | ||
return "boolean"; | ||
} | ||
if ( Array.isArray(input) ) { | ||
return "array"; | ||
} | ||
if ( !resolveObj ) { | ||
return "object"; | ||
} | ||
})(); | ||
// Promise | ||
(()=>{ | ||
const _PROMISE_THEN = Promise.prototype.then; | ||
const _PROMISE_CATCH = Promise.prototype.catch; | ||
const _PROMISE_FINALLY = Promise.prototype.finally; | ||
Object.defineProperties(Promise.prototype, { | ||
then: { | ||
writable, configurable, enumerable, | ||
value: function(...args){ | ||
return DecorateChainedPromise(_PROMISE_THEN.call(this, ...args), this); | ||
} | ||
}, | ||
catch: { | ||
writable, configurable, enumerable, | ||
value: function(...args){ | ||
return DecorateChainedPromise(_PROMISE_CATCH.call(this, ...args), this); | ||
} | ||
}, | ||
finally: { | ||
writable, configurable, enumerable, | ||
value: function(...args){ | ||
return DecorateChainedPromise(_PROMISE_FINALLY.call(this, ...args), this); | ||
} | ||
}, | ||
guard: { | ||
writable, configurable, enumerable, | ||
value: function(){ | ||
return DecorateChainedPromise(_PROMISE_CATCH.call(this, (e)=>{ | ||
setTimeout(()=>{ | ||
if( IsNodeJS ){ | ||
throw e; | ||
} | ||
else{ | ||
const event = new Event('unhandledRejection'); | ||
event.error = e; | ||
window.dispatchEvent(event); | ||
} | ||
}, 0); | ||
return e; | ||
}), this); | ||
} | ||
} | ||
}); | ||
Object.defineProperties(Promise, { | ||
wait: { | ||
writable, configurable, enumerable, | ||
value: PromiseWaitAll | ||
}, | ||
create: { | ||
writable, configurable, enumerable, | ||
value: FlattenedPromise | ||
} | ||
}); | ||
// None-primitive | ||
if ( input instanceof ArrayBuffer ) { | ||
return "array-buffer" | ||
} | ||
if ( input instanceof DataView ) { | ||
return "data-view"; | ||
} | ||
if ( input instanceof Uint8Array ) { | ||
return "uint8-array"; | ||
} | ||
if ( input instanceof Uint8ClampedArray ) { | ||
return "uint8-clamped-array"; | ||
} | ||
if ( input instanceof Int8Array ) { | ||
return "int8-array"; | ||
} | ||
function PromiseWaitAll(promise_queue = []){ | ||
if( !Array.isArray(promise_queue) ){ | ||
promise_queue = [promise_queue]; | ||
if ( input instanceof Uint16Array ) { | ||
return "uint16-array"; | ||
} | ||
if ( input instanceof Int16Array ) { | ||
return "int16-array"; | ||
} | ||
if ( input instanceof Uint32Array ) { | ||
return "uint32-array"; | ||
} | ||
if ( input instanceof Int32Array ) { | ||
return "int32-array"; | ||
} | ||
if ( input instanceof Float32Array ) { | ||
return "float32-array"; | ||
} | ||
if ( input instanceof Float64Array ) { | ||
return "float64-array"; | ||
} | ||
if ( input instanceof Map ) { | ||
return "map"; | ||
} | ||
if ( input instanceof WeakMap ) { | ||
return "weak-map"; | ||
} | ||
if ( input instanceof Set ) { | ||
return "set"; | ||
} | ||
if ( input instanceof WeakSet ) { | ||
return "weak-set"; | ||
} | ||
if ( input instanceof RegExp ) { | ||
return "regexp" | ||
} | ||
if ( input instanceof Promise ) { | ||
return "promise"; | ||
} | ||
return "object"; | ||
} | ||
})(); | ||
(()=>{ | ||
const _PROMISE_THEN = Promise.prototype.then; | ||
const _PROMISE_CATCH = Promise.prototype.catch; | ||
const _PROMISE_FINALLY = Promise.prototype.finally; | ||
Object.defineProperties(Promise.prototype, { | ||
then: { | ||
writable, configurable, enumerable, | ||
value: function(...args) { | ||
return DecorateChainedPromise(_PROMISE_THEN.call(this, ...args), this); | ||
} | ||
if( promise_queue.length === 0 ){ | ||
return Promise.resolve([]); | ||
}, | ||
catch: { | ||
writable, configurable, enumerable, | ||
value: function(...args) { | ||
return DecorateChainedPromise(_PROMISE_CATCH.call(this, ...args), this); | ||
} | ||
return new Promise((resolve, reject)=>{ | ||
let result_queue = [], ready_count = 0, resolved = true; | ||
for( let idx = 0; idx < promise_queue.length; idx++ ){ | ||
let item = {resolved: true, seq: idx, result: null}; | ||
result_queue.push(item); | ||
Promise.resolve(promise_queue[idx]).then( | ||
(result)=>{ | ||
resolved = (item.resolved = true) && resolved; | ||
item.result = result; | ||
}, | ||
(error)=>{ | ||
resolved = (item.resolved = false) && resolved; | ||
item.result = error; | ||
}, | ||
finally: { | ||
writable, configurable, enumerable, | ||
value: function(...args) { | ||
return DecorateChainedPromise(_PROMISE_FINALLY.call(this, ...args), this); | ||
} | ||
}, | ||
guard: { | ||
writable, configurable, enumerable, | ||
value: function() { | ||
return DecorateChainedPromise(_PROMISE_CATCH.call(this, (e)=>{ | ||
setTimeout(()=>{ | ||
if ( IsNodeJS ) { | ||
throw e; | ||
} | ||
).then(()=>{ | ||
ready_count++; | ||
if( promise_queue.length === ready_count ){ | ||
(resolved ? resolve : reject)(result_queue); | ||
else { | ||
const event = new Event('unhandledRejection'); | ||
event.error = e; | ||
window.dispatchEvent(event); | ||
} | ||
}); | ||
} | ||
}); | ||
}, 0); | ||
return e; | ||
}), this); | ||
} | ||
} | ||
function FlattenedPromise(){ | ||
let _resolve = null, _reject = null; | ||
const promise = new Promise((resolve, reject)=>{ | ||
_resolve = resolve; | ||
_reject = reject; | ||
}); | ||
promise.resolve = _resolve; | ||
promise.reject = _reject; | ||
promise.promise = promise; | ||
return promise; | ||
}); | ||
Object.defineProperties(Promise, { | ||
wait: { | ||
writable, configurable, enumerable, | ||
value: PromiseWaitAll | ||
}, | ||
create: { | ||
writable, configurable, enumerable, | ||
value: FlattenedPromise | ||
} | ||
function DecorateChainedPromise(next_promise, previous){ | ||
for( const prop of Object.keys(previous) ){ | ||
next_promise[prop] = previous[prop]; | ||
} | ||
return next_promise; | ||
}); | ||
function PromiseWaitAll(promise_queue=[]) { | ||
if ( !Array.isArray(promise_queue) ){ | ||
promise_queue = [promise_queue]; | ||
} | ||
})(); | ||
// String | ||
(()=>{ | ||
const CAMEL_CASE_PATTERN = /(\w)(\w*)(\W*)/g; | ||
const CAMEL_REPLACER = (match, $1, $2, $3, index, input)=>{ | ||
return `${ $1.toUpperCase() }${ $2.toLowerCase() }${ $3 }`; | ||
}; | ||
function StringTemplateResolver(strings, ...dynamics){ | ||
if( this instanceof StringTemplateResolver ){ | ||
this.strings = strings; | ||
this.fields = dynamics; | ||
return; | ||
} | ||
return new StringTemplateResolver(strings, ...dynamics); | ||
if( promise_queue.length === 0 ) { | ||
return Promise.resolve([]); | ||
} | ||
StringTemplateResolver.prototype = { | ||
[Symbol.iterator](){ | ||
const strings = this.strings.slice(0).reverse(); | ||
const dynamics = this.fields.slice(0).reverse(); | ||
return new Promise((resolve, reject) =>{ | ||
let result_queue=[], ready_count=0, resolved = true; | ||
for(let idx=0; idx<promise_queue.length; idx++) { | ||
let item = {resolved:true, seq:idx, result:null}; | ||
let i = 0; | ||
return { | ||
next: ()=>{ | ||
if( strings.length === 0 ){ | ||
return {done: true}; | ||
} | ||
let value; | ||
if( i % 2 === 0 ){ | ||
value = strings.pop(); | ||
} | ||
else{ | ||
value = dynamics.pop(); | ||
} | ||
i = i + 1; | ||
return {value}; | ||
result_queue.push(item); | ||
Promise.resolve(promise_queue[idx]).then( | ||
(result)=>{ | ||
resolved = (item.resolved = true) && resolved; | ||
item.result = result; | ||
}, | ||
(error)=>{ | ||
resolved = (item.resolved = false) && resolved; | ||
item.result = error; | ||
} | ||
}; | ||
}, | ||
toString(){ | ||
let str = ''; | ||
for( const item of this ){ | ||
str += '' + item; | ||
} | ||
return str; | ||
).then(()=>{ | ||
ready_count++; | ||
if ( promise_queue.length === ready_count ) { | ||
(resolved?resolve:reject)(result_queue); | ||
} | ||
}); | ||
} | ||
}; | ||
}); | ||
} | ||
function FlattenedPromise() { | ||
let _resolve=null, _reject=null; | ||
const promise = new Promise((resolve, reject)=>{ | ||
_resolve=resolve; | ||
_reject=reject; | ||
}); | ||
promise.resolve = _resolve; | ||
promise.reject = _reject; | ||
promise.promise = promise; | ||
return promise; | ||
} | ||
function DecorateChainedPromise(next_promise, previous) { | ||
for( const prop of Object.keys(previous)) { | ||
next_promise[prop] = previous[prop]; | ||
} | ||
Object.defineProperties(String.prototype, { | ||
upperCase: { | ||
configurable, enumerable, | ||
get: function(){ | ||
return this.toUpperCase(); | ||
}, | ||
}, | ||
localeUpperCase: { | ||
configurable, enumerable, | ||
get: function(){ | ||
return this.toLocaleUpperCase(); | ||
} | ||
}, | ||
lowerCase: { | ||
configurable, enumerable, | ||
get: function(){ | ||
return this.toLowerCase(); | ||
} | ||
}, | ||
localeLowerCase: { | ||
configurable, enumerable, | ||
get: function(){ | ||
return this.toLocaleLowerCase(); | ||
} | ||
}, | ||
toCamelCase: { | ||
configurable, enumerable, | ||
value: function(){ | ||
return this.replace(CAMEL_CASE_PATTERN, CAMEL_REPLACER); | ||
} | ||
}, | ||
camelCase: { | ||
configurable, enumerable, | ||
get: function(){ | ||
return this.replace(CAMEL_CASE_PATTERN, CAMEL_REPLACER); | ||
} | ||
}, | ||
pull: { | ||
configurable, enumerable, writable, | ||
value: function(token_separator = '', from_begin = true){ | ||
if( typeof token_separator !== "string" ){ | ||
throw new TypeError("Given token must be a string"); | ||
return next_promise; | ||
} | ||
})(); | ||
(()=>{ | ||
const CAMEL_CASE_PATTERN = /(\w)(\w*)(\W*)/g; | ||
const CAMEL_REPLACER = (match, $1, $2, $3, index, input )=>{ | ||
return `${$1.toUpperCase()}${$2.toLowerCase()}${$3}`; | ||
}; | ||
function StringTemplateResolver(strings, ...dynamics) { | ||
if ( this instanceof StringTemplateResolver ) { | ||
this.strings = strings; | ||
this.fields = dynamics; | ||
return; | ||
} | ||
return new StringTemplateResolver(strings, ...dynamics); | ||
} | ||
StringTemplateResolver.prototype = { | ||
[Symbol.iterator]() { | ||
const strings = this.strings.slice(0).reverse(); | ||
const dynamics = this.fields.slice(0).reverse(); | ||
let i=0; | ||
return { | ||
next:()=>{ | ||
if ( strings.length === 0 ) { | ||
return {done:true}; | ||
} | ||
const length = this.length; | ||
if( length === 0 ){ | ||
return ['', '']; | ||
let value; | ||
if ( i%2===0 ) { | ||
value = strings.pop(); | ||
} | ||
if( token_separator === '' ){ | ||
return from_begin ? [this[0], this.substring(1)] : [this.substring(0, length - 1), this[length - 1]]; | ||
else { | ||
value = dynamics.pop(); | ||
} | ||
if( from_begin ){ | ||
const index = this.indexOf(token_separator, token_separator.length); | ||
if( index < 0 ){ | ||
return [this.substring(0), '']; | ||
} | ||
return [this.substring(0, index), this.substring(index)]; | ||
} | ||
else{ | ||
const index = this.lastIndexOf(token_separator); | ||
if( index < 0 ){ | ||
return ['', this.substring(0)]; | ||
} | ||
return [this.substring(0, index), this.substring(index)]; | ||
} | ||
i = i+1; | ||
return {value}; | ||
} | ||
}; | ||
}, | ||
toString() { | ||
let str = ''; | ||
for(const item of this) { | ||
str += '' + item; | ||
} | ||
return str; | ||
} | ||
}; | ||
Object.defineProperties(String.prototype, { | ||
upperCase:{ | ||
configurable, enumerable, | ||
get:function() { | ||
return this.toUpperCase(); | ||
}, | ||
pop: { | ||
configurable, enumerable, writable, | ||
value: function(token_separator = ''){ | ||
return this.pull(token_separator, true); | ||
}, | ||
localeUpperCase:{ | ||
configurable, enumerable, | ||
get:function() { | ||
return this.toLocaleUpperCase(); | ||
} | ||
}, | ||
lowerCase:{ | ||
configurable, enumerable, | ||
get:function() { | ||
return this.toLowerCase(); | ||
} | ||
}, | ||
localeLowerCase:{ | ||
configurable, enumerable, | ||
get:function() { | ||
return this.toLocaleLowerCase(); | ||
} | ||
}, | ||
toCamelCase: { | ||
configurable, enumerable, | ||
value:function() { | ||
return this.replace(CAMEL_CASE_PATTERN, CAMEL_REPLACER); | ||
} | ||
}, | ||
camelCase: { | ||
configurable, enumerable, | ||
get:function() { | ||
return this.replace(CAMEL_CASE_PATTERN, CAMEL_REPLACER); | ||
} | ||
}, | ||
pull: { | ||
configurable, enumerable, writable, | ||
value:function(token_separator='', from_begin=true) { | ||
if ( typeof token_separator !== "string" ) { | ||
throw new TypeError("Given token must be a string"); | ||
} | ||
}, | ||
shift: { | ||
configurable, enumerable, writable, | ||
value: function(token_separator = ''){ | ||
return this.pull(token_separator, false); | ||
const length = this.length; | ||
if ( length === 0 ) { | ||
return ['', '']; | ||
} | ||
} | ||
}); | ||
Object.defineProperties(String, { | ||
encodeRegExpString: { | ||
writable, configurable, enumerable, | ||
value: function(input_string = ''){ | ||
return input_string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | ||
if ( token_separator === '' ) { | ||
return from_begin ? [ this[0], this.substring(1) ] : [ this.substring(0, length-1), this[length-1] ]; | ||
} | ||
}, | ||
template: { | ||
writable, configurable, enumerable, | ||
value: StringTemplateResolver | ||
}, | ||
from: { | ||
writable, configurable, enumerable, | ||
value: (content)=>{ | ||
if( typeof content === "string" ) return content; | ||
if ( from_begin ) { | ||
const index = this.indexOf(token_separator, token_separator.length); | ||
if ( index < 0 ) { | ||
return [this.substring(0), '']; | ||
} | ||
const buff = ExtractBytes(content); | ||
if( buff !== null ){ | ||
return UTF8Decode(new Uint8Array(buff)); | ||
return [this.substring(0, index), this.substring(index)]; | ||
} | ||
else { | ||
const index = this.lastIndexOf(token_separator); | ||
if ( index < 0 ) { | ||
return ['', this.substring(0)]; | ||
} | ||
return '' + content; | ||
return [this.substring(0, index), this.substring(index)]; | ||
} | ||
} | ||
}); | ||
})(); | ||
// setTimeout, setInterval | ||
(()=>{ | ||
Object.defineProperty(setTimeout, 'create', { | ||
}, | ||
pop: { | ||
configurable, enumerable, writable, | ||
value:function(token_separator='') { | ||
return this.pull(token_separator, true); | ||
} | ||
}, | ||
shift: { | ||
configurable, enumerable, writable, | ||
value:function(token_separator='') { | ||
return this.pull(token_separator, false); | ||
} | ||
} | ||
}); | ||
Object.defineProperties(String, { | ||
encodeRegExpString: { | ||
writable, configurable, enumerable, | ||
value: ThrottledTimeout | ||
}); | ||
Object.defineProperty(setTimeout, 'idle', { | ||
value: function(input_string='') { | ||
return input_string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string | ||
} | ||
}, | ||
template: { | ||
writable, configurable, enumerable, | ||
value: Idle | ||
}); | ||
Object.defineProperty(setInterval, 'create', { | ||
value:StringTemplateResolver | ||
}, | ||
from: { | ||
writable, configurable, enumerable, | ||
value: ThrottledTimer | ||
}); | ||
function ThrottledTimeout(){ | ||
let _scheduled = null; | ||
let _executing = false; | ||
let _hTimeout = null; | ||
const timeout_cb = (cb, delay = 0, ...args)=>{ | ||
_scheduled = {cb, delay, args}; | ||
value:(content)=>{ | ||
if ( typeof content === "string" ) return content; | ||
if( _executing ) return; | ||
const bytes = ExtractBytes(content); | ||
if ( bytes !== null ) { | ||
return UTF8Decode(bytes); | ||
} | ||
if( _hTimeout ){ | ||
clearTimeout(_hTimeout); | ||
_hTimeout = null; | ||
} | ||
__DO_TIMEOUT(); | ||
}; | ||
timeout_cb.clear = ()=>{ | ||
_scheduled = null; | ||
if( _hTimeout ){ | ||
clearTimeout(_hTimeout); | ||
_hTimeout = null; | ||
} | ||
}; | ||
return timeout_cb; | ||
return ''+content; | ||
} | ||
} | ||
}); | ||
})(); | ||
(()=>{ | ||
Object.defineProperty(setTimeout, 'create', { | ||
writable, configurable, enumerable, | ||
value:ThrottledTimeout | ||
}); | ||
Object.defineProperty(setTimeout, 'idle', { | ||
writable, configurable, enumerable, | ||
value:Idle | ||
}); | ||
Object.defineProperty(setInterval, 'create', { | ||
writable, configurable, enumerable, | ||
value:ThrottledTimer | ||
}); | ||
function ThrottledTimeout() { | ||
let _scheduled = null; | ||
let _executing = false; | ||
let _hTimeout = null; | ||
const timeout_cb = (cb, delay=0, ...args)=>{ | ||
_scheduled = {cb, delay, args}; | ||
if ( _executing ) return; | ||
function __DO_TIMEOUT(){ | ||
if( !_scheduled ) return; | ||
if ( _hTimeout ) { | ||
clearTimeout(_hTimeout); | ||
_hTimeout = null; | ||
} | ||
__DO_TIMEOUT(); | ||
}; | ||
timeout_cb.clear=()=>{ | ||
_scheduled = null; | ||
if ( _hTimeout ) { | ||
clearTimeout(_hTimeout); | ||
_hTimeout = null; | ||
} | ||
}; | ||
return timeout_cb; | ||
function __DO_TIMEOUT() { | ||
if ( !_scheduled ) return; | ||
let {cb, delay, args} = _scheduled; | ||
_hTimeout = setTimeout(()=>{ | ||
_executing = true; | ||
let {cb, delay, args} = _scheduled; | ||
_hTimeout = setTimeout(()=>{ | ||
_executing = true; | ||
Promise.resolve(cb(...args)) | ||
.then( | ||
()=>{ | ||
_executing = false; | ||
_hTimeout = null; | ||
__DO_TIMEOUT(); | ||
}, | ||
(e)=>{ | ||
_executing = false; | ||
_hTimeout = null; | ||
_scheduled = null; | ||
throw e; | ||
} | ||
); | ||
}, delay); | ||
_scheduled = null; | ||
} | ||
Promise.resolve(cb(...args)) | ||
.then( | ||
()=>{ | ||
_executing = false; | ||
_hTimeout = null; | ||
__DO_TIMEOUT(); | ||
}, | ||
(e)=>{ | ||
_executing = false; | ||
_hTimeout = null; | ||
_scheduled = null; | ||
throw e; | ||
} | ||
); | ||
}, delay); | ||
_scheduled = null; | ||
} | ||
function Idle(duration = 0){ | ||
return new Promise((resolve)=>{setTimeout(resolve, duration)}); | ||
} | ||
function ThrottledTimer(){ | ||
const _timeout = ThrottledTimeout(); | ||
const timeout_cb = (cb, interval = 0, ...args)=>{ | ||
const ___DO_TIMEOUT = async ()=>{ | ||
} | ||
function Idle(duration=0) { | ||
return new Promise((resolve)=>{setTimeout(resolve, duration)}); | ||
} | ||
function ThrottledTimer() { | ||
const _timeout = ThrottledTimeout(); | ||
const timeout_cb = (cb, interval=0, ...args)=>{ | ||
const ___DO_TIMEOUT=async()=>{ | ||
_timeout(___DO_TIMEOUT, interval); | ||
try{ | ||
try { | ||
await cb(...args); | ||
} catch(e){ | ||
} | ||
catch(e) { | ||
_timeout.clear(); | ||
@@ -1586,48 +1563,48 @@ throw e; | ||
}; | ||
_timeout(___DO_TIMEOUT, interval, ...args); | ||
}; | ||
timeout_cb.clear = ()=>{ | ||
_timeout.clear(); | ||
}; | ||
return timeout_cb; | ||
} | ||
})(); | ||
// Typed Arrays | ||
(()=>{ | ||
const TYPED_ARRAYS = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array]; | ||
const ARRAY_BUFFER_VIEWS = [DataView, ...TYPED_ARRAYS]; | ||
_timeout(___DO_TIMEOUT, interval, ...args); | ||
}; | ||
timeout_cb.clear=()=>{ | ||
_timeout.clear(); | ||
}; | ||
return timeout_cb; | ||
} | ||
})(); | ||
(()=>{ | ||
const TYPED_ARRAYS = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array]; | ||
const ARRAY_BUFFER_VIEWS = [DataView, ...TYPED_ARRAYS]; | ||
const REF = new WeakMap(); | ||
for(const type of ARRAY_BUFFER_VIEWS) { | ||
REF.set(type, { | ||
from: type.from, | ||
toString: type.toString | ||
}); | ||
Object.defineProperty(type, 'from', { | ||
value: function(input) { | ||
const original = REF.get(type).from; | ||
if (input instanceof ArrayBuffer) { | ||
return new type(input); | ||
} | ||
return original.call(type, input); | ||
}, | ||
configurable, enumerable, writable | ||
}); | ||
Object.defineProperty(type.prototype, 'toString', { | ||
value: function(...args) { | ||
const original = REF.get(type).toString; | ||
if ( args.length === 0 ) { | ||
return original.call(this, ...args); | ||
} | ||
return this.buffer.toString(...args); | ||
}, | ||
configurable, enumerable, writable | ||
}); | ||
const REF = new WeakMap(); | ||
for( const type of ARRAY_BUFFER_VIEWS ){ | ||
REF.set(type, { | ||
from: type.from, | ||
toString: type.toString | ||
}); | ||
Object.defineProperty(type, 'from', { | ||
value: function(input){ | ||
const original = REF.get(type).from; | ||
if( input instanceof ArrayBuffer ){ | ||
return new type(input); | ||
} | ||
return original.call(type, input); | ||
}, | ||
configurable, enumerable, writable | ||
}); | ||
Object.defineProperty(type.prototype, 'toString', { | ||
value: function(...args){ | ||
const original = REF.get(type).toString; | ||
if( args.length === 0 ){ | ||
return original.call(this, ...args); | ||
} | ||
return this.buffer.toString(...args); | ||
}, | ||
configurable, enumerable, writable | ||
}); | ||
} | ||
})(); | ||
} | ||
})(); | ||
})(); |
@@ -1,1 +0,1 @@ | ||
(()=>{"use strict";const e="undefined"!=typeof Buffer;function t(e,t=2,r="0"){let n=t-(e=""+e).length;for(;n-- >0;)e=r+e;return e}function r(t){return e&&Buffer.isBuffer(t)?new Uint8Array(t):ArrayBuffer.isView(t)?new Uint8Array(t.buffer):t instanceof ArrayBuffer?new Uint8Array(t):null}(()=>{const e=/^(0x)?([0-9a-fA-F]+)$/,t=/^(0b|0B)?([01]+)$/,n={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15},i=new WeakMap;Object.defineProperty(ArrayBuffer.prototype,"bytes",{configurable:!0,enumerable:!1,get:function(){let e=i.get(this);return e||(i.set(this,e=new Uint8Array(this)),e)}}),Object.defineProperty(ArrayBuffer.prototype,"toString",{configurable:!0,writable:!0,enumerable:!1,value:function(e=16,t=!0){const r=new Uint8Array(this);let n="";switch(e){case 16:for(let e=0;e<r.length;e++){const t=r[e];n+="0123456789abcdef"[(240&t)>>>4]+"0123456789abcdef"[15&t]}break;case 2:for(let e=0;e<r.length;e++){const t=r[e];for(let e=7;e>=0;e--)n+=t>>>e&1?"1":"0"}break;default:throw new RangeError("Unsupported numeric representation!")}return t?n:n.replace(/^0+/,"")}}),Object.defineProperty(ArrayBuffer.prototype,"compare",{configurable:!0,writable:!0,enumerable:!1,value:function(e){if(!(e instanceof ArrayBuffer))throw new TypeError("An ArrayBuffer can only be compared with another ArrayBuffer");const t=new Uint8Array(this),r=new Uint8Array(e),n=Math.max(t.length,r.length);for(let e=0;e<n;e++){const n=t[e]||0,i=r[e]||0;if(n>i)return 1;if(n<i)return-1}return 0}}),Object.defineProperty(ArrayBuffer,"extract",{configurable:!0,writable:!0,enumerable:!1,value:function(e){if("undefined"!=typeof Buffer&&e instanceof Buffer){let t=Buffer.alloc(e.length);return e.copy(t,0),t.buffer}if(ArrayBuffer.isView(e))return e.buffer;if(e instanceof ArrayBuffer)return e;throw new TypeError("Cannot convert given input data into array buffer")}}),Object.defineProperty(ArrayBuffer,"from",{configurable:!0,writable:!0,enumerable:!1,value:function(r,i=null){if("undefined"!=typeof Buffer&&r instanceof Buffer){let e=Buffer.alloc(r.length);return r.copy(e,0),e.buffer}if(ArrayBuffer.isView(r))return r.buffer.slice(0);if(r instanceof ArrayBuffer)return r.slice(0);if(Array.isArray(r)){return new Uint8Array(r).buffer}if("number"==typeof r){let e=null;switch(i){case"int8":e=new Int8Array([r]);break;case"uint8":e=new Uint8Array([r]);break;case"int16":e=new Int16Array([r]);break;case"uint16":e=new Uint16Array([r]);break;case"int32":e=new Int32Array([r]);break;case"int64":{const t=r<0;t&&(r=-r);let n=Math.floor(r/4294967295),i=4294967295&r;t&&(i=1+(~i>>>0),n=~n+Math.floor(i/4294967295)),e=new Uint32Array([i,n]);break}case"uint64":{const t=Math.floor(r/4294967295);e=new Uint32Array([4294967295&r,t]);break}case"float32":e=new Float32Array([r]);break;case"float64":e=new Float64Array([r]);break;case"uint32":default:e=new Uint32Array([r])}return e.buffer}if("string"==typeof r){if("hex"===i){const t=r.match(e);if(!t)throw new RangeError("Input argument is not a valid hex string!");let[,,i]=t;i=i.length%2==0?i.toLowerCase():"0"+i.toLowerCase();const a=new Uint8Array(i.length/2|0);for(let e=0;e<a.length;e++){const t=2*e;a[e]=n[i[t]]<<4|15&n[i[t+1]]}return a.buffer}if("bits"===i){const e=r.match(t);if(!e)throw new RangeError("Input argument is not a valid bit string!");let[,,n]=e;n.length%8!=0&&(n="0".repeat(n.length%8)+n);const i=new Uint8Array(n.length/8|0);for(let e=0;e<i.length;e++){const t=8*e;let r="1"===n[t]?1:0;for(let e=1;e<8;e++)r=r<<1|("1"===n[t+e]?1:0);i[e]=r}return i.buffer}return function(e){if("string"!=typeof e)throw new TypeError("Given input argument must be a js string!");let t=[],r=0;for(;r<e.length;){let n=e.codePointAt(r);0==(4294967168&n)?t.push(n):0==(4294965248&n)?t.push(192|31&n>>6,128|63&n):0==(4294901760&n)?t.push(224|15&n>>12,128|63&n>>6,128|63&n):0==(4292870144&n)&&t.push(240|7&n>>18,128|63&n>>12,128|63&n>>6,128|63&n),r+=n>65535?2:1}return new Uint8Array(t)}(r).buffer}throw new TypeError("Cannot convert given input data into array buffer!")}}),Object.defineProperty(ArrayBuffer,"compare",{configurable:!0,writable:!0,enumerable:!1,value:function(e,t){if(!(e instanceof ArrayBuffer&&t instanceof ArrayBuffer))throw new TypeError("ArrayBuffer.compare only accepts two array buffers!");return e.compare(t)}}),Object.defineProperty(ArrayBuffer,"concat",{configurable:!0,writable:!0,enumerable:!1,value:function(...e){Array.isArray(e[0])&&(e=e[0]);let t=0;for(let n=0;n<e.length;n++){const i=e[n]=r(e[n]);if(!(i instanceof Uint8Array))throw new TypeError("ArrayBuffer.combine accept only ArrayBuffer, TypeArray and DataView.");t+=i.byteLength}const n=new Uint8Array(t);t=0;for(const r of e)n.set(r,t),t+=r.length;return n.buffer}})})(),Object.defineProperty(Array.prototype,"unique",{writable:!0,configurable:!0,enumerable:!1,value:function(){const e=new Set;for(const t of this)e.add(t);return Array.from(e)}}),Object.defineProperty(Array.prototype,"exclude",{writable:!0,configurable:!0,enumerable:!1,value:function(e){Array.isArray(e)||(e=[e]);const t=[];for(const r of this){let n=!1;for(const t of e)if(r===t){n=n||!0;break}n||t.push(r)}return t}}),Object.defineProperty(Array,"concat",{writable:!0,configurable:!0,enumerable:!1,value:function(...e){const t=[];for(const r of e)if(Array.isArray(r))for(const e of r)t.push(e);else t.push(r);return t}}),Object.defineProperty(Array,"intersect",{writable:!0,configurable:!0,enumerable:!1,value:function(...e){let t=e[0]||[];if(!Array.isArray(t))throw new TypeError("Array.intersect only accepts list array arguments!");for(let r=1;r<e.length;r++){const n=e[r];if(!Array.isArray(n))throw new TypeError("Array.intersect only accepts list array arguments!");const i=new Set;for(const e of t)n.indexOf(e)>=0&&i.add(e);t=Array.from(i)}return t}}),"undefined"!=typeof Blob&&Object.defineProperty(Blob.prototype,"arrayBuffer",{configurable:!0,writable:!0,enumerable:!1,value:function(){return new Promise((e,t)=>{const r=new FileReader;r.onerror=t,r.onload=()=>e(r.result),r.readAsArrayBuffer(this)})}}),Object.defineProperty(Date,"unix",{writable:!0,configurable:!0,enumerable:!1,value:function(){return Math.floor(Date.now()/1e3)}}),Object.defineProperty(Date.prototype,"getUnixTime",{writable:!0,configurable:!0,enumerable:!1,value:function(){return Math.floor(this.getTime()/1e3)}}),Object.defineProperty(Date.prototype,"unix",{configurable:!0,enumerable:!1,get:function(){return Math.floor(this.getTime()/1e3)}}),Object.defineProperty(Date.prototype,"time",{configurable:!0,enumerable:!1,get:function(){return this.getTime()}}),Object.defineProperty(Date.prototype,"toLocaleISOString",{writable:!0,configurable:!0,enumerable:!1,value:function(){let e,r=this.getTimezoneOffset();if(0===r)e="Z";else{const n=r>0?"-":"+";r=Math.abs(r);const i=r%60;e=n+t(Math.floor(r/60))+t(i)}return this.getFullYear()+"-"+t(this.getMonth()+1)+"-"+t(this.getDate())+"T"+t(this.getHours())+":"+t(this.getMinutes())+":"+t(this.getSeconds())+"."+this.getMilliseconds()%1e3+e}}),"undefined"!=typeof Document&&Object.defineProperties(Document.prototype,{parseHTML:{configurable:!0,writable:!0,enumerable:!1,value:function(e){const t=this.implementation.createHTMLDocument().body;if(t.innerHTML=e,0===t.children.length)return null;if(1===t.children.length){const e=t.children[0];return e.remove(),e}const r=Array.prototype.slice.call(t.children,0);for(const e of r)e.remove();return r}}}),(()=>{if("undefined"!=typeof Element){const e=Element.prototype.setAttribute,t=Element.prototype.removeAttribute,r=Element.prototype.setAttributeNS,n=Element.prototype.removeAttributeNS;Object.defineProperties(Element.prototype,{addClass:{configurable:!0,enumerable:!1,writable:!0,value:function(...e){const t=[];for(const r of e)null!=r&&""!==r&&t.push(r);return this.classList.add(...t),this}},removeClass:{configurable:!0,enumerable:!1,writable:!0,value:function(...e){const t=[];for(const r of e)null!=r&&""!==r&&t.push(r);return this.classList.remove(...t),this}},setAttribute:{configurable:!0,enumerable:!1,writable:!0,value:function(t,r){return arguments.length<2&&(r=""),e.call(this,t,r),this}},removeAttribute:{configurable:!0,enumerable:!1,writable:!0,value:function(...e){return t.apply(this,e),this}},setAttributeNS:{configurable:!0,enumerable:!1,writable:!0,value:function(...e){return r.apply(this,e),this}},removeAttributeNS:{configurable:!0,enumerable:!1,writable:!0,value:function(...e){return n.apply(this,e),this}}})}})(),(()=>{if("undefined"!=typeof Error){Object.defineProperty(Error.prototype,"stack_trace",{get:function(){return this.stack?this.stack.split(/\r\n|\n/g).map(e=>e.trim()):null},enumerable:!1,configurable:!0});class e extends Error{constructor(e,...t){super(e,...t),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);const r=Date.now();Object.defineProperties(this,{name:{configurable:!1,writable:!1,enumerable:!1,value:this.constructor.name},time:{configurable:!1,writable:!1,enumerable:!1,value:Math.floor(r/1e3)},time_milli:{configurable:!1,writable:!1,enumerable:!1,value:r}})}}class t extends e{constructor(e,t=null,...r){if(Object(e)!==e)throw new TypeError("IndexedError constructor accepts only objects!");const{code:n,key:i,message:a=null,msg:o=null}=e;if("number"!=typeof n||"string"!=typeof i)throw new TypeError("IndexedError error info object must contains a numeric `code` field and a string `key` field");null!==a?r.unshift(""+a):null!==o?r.unshift(""+o):r.unshift(""),super(...r),Object.defineProperties(this,{code:{configurable:!1,writable:!1,enumerable:!1,value:n},key:{configurable:!1,writable:!1,enumerable:!1,value:i},detail:{configurable:!1,writable:!1,enumerable:!1,value:t}})}toJSON(){const e={code:this.code,key:this.key,msg:this.message,detail:void 0,time:this.time,time_milli:this.time_milli};return null!==this.detail&&void 0!==this.detail&&(Array.isArray(this.detail)?e.detail=this.detail.slice(0):Object(this.detail)===this.detail?e.detail=Object.assign({},this.detail):e.detail=this.detail),e}}Object.defineProperties(Error,{EError:{configurable:!0,writable:!0,enumerable:!1,value:e},IndexedError:{configurable:!0,writable:!0,enumerable:!1,value:t}})}})(),"undefined"!=typeof EventTarget&&(Object.defineProperty(EventTarget.prototype,"on",{configurable:!0,writable:!0,enumerable:!1,value:function(e,t){const r=[],n=e.split(",");for(let e of n)e=e.trim(),r.indexOf(e)>=0||(r.push(e),this.addEventListener(e,t));return this}}),Object.defineProperty(EventTarget.prototype,"off",{configurable:!0,writable:!0,enumerable:!1,value:function(e,t){const r=e.split(",");for(let e of r)e=e.trim(),this.removeEventListener(e,t);return this}}),Object.defineProperty(EventTarget.prototype,"emit",{configurable:!0,writable:!0,enumerable:!1,value:function(e,t={}){const{bubbles:r,cancelable:n,composed:i,...a}=t;if("string"==typeof e&&(e=new Event(e,{bubbles:!!r,cancelable:!!n,composed:!!i})),!(e instanceof Event))throw new TypeError("Argument 1 accepts only string or Event instance!");Object.assign(e,a),this.dispatchEvent(e)}})),(()=>{const e=new WeakMap,t={},r={};function n(e,n){const a=Array.prototype.slice.call(arguments,0);return a[0]=e?t:r,i.call(...a)}function i(t){const r=e.get(this),n={async:r.async,funcs:r.funcs.slice(0)};if(arguments.length>0){let e;Array.isArray(t)||(t=[t]);for(let r=0;r<t.length;r++)n.funcs.push("function"==typeof(e=t[r])?e:()=>e)}const o={};e.set(o,n);const l=a.bind(o);return l.chain=i.bind(o),l}function a(...t){const{async:r,funcs:n}=e.get(this);this.session={};let i=void 0;if(r)return Promise.resolve().then(async()=>{for(const e of n)if(i=await e.call(this,...t,i),!1===i)break;return i});for(const e of n)if(i=e.call(this,...t,i),!1===i)break;return i}e.set(t,{async:!0,funcs:[]}),e.set(r,{async:!1,funcs:[]}),Object.defineProperty(Function,"sequential",{configurable:!0,writable:!0,enumerable:!1,value:n.bind(null,!1)}),Object.defineProperty(Function.sequential,"async",{configurable:!1,writable:!1,enumerable:!0,value:n.bind(null,!0)})})(),"undefined"!=typeof HTMLElement&&Object.defineProperties(HTMLElement.prototype,{setData:{configurable:!0,writable:!0,enumerable:!1,value:function(e,t){if(Object(e)===e)for(const t in e)this.dataset[t]=e[t];else this.dataset[e]=t;return this}},getData:{configurable:!0,writable:!0,enumerable:!1,value:function(e){return this.dataset[e]}},removeData:{configurable:!0,writable:!0,enumerable:!1,value:function(...e){for(const t of e)delete this.dataset[t];return this}},setContentHtml:{configurable:!0,writable:!0,enumerable:!1,value:function(e){return this.innerHTML=e,this}}}),"undefined"!=typeof HTMLInputElement&&Object.defineProperty(HTMLInputElement.prototype,"setValue",{configurable:!0,writable:!0,enumerable:!1,value:function(e){return this.value=e,this}}),"undefined"!=typeof Node&&(Object.defineProperty(Node.prototype,"prependChild",{configurable:!0,writable:!0,enumerable:!1,value:function(e){return this.insertBefore(e,this.children[0]||null),this instanceof DocumentFragment?new DocumentFragment:e}}),Object.defineProperty(Node.prototype,"insertNeighborBefore",{configurable:!0,writable:!0,enumerable:!1,value:function(e){if(!this.parentNode)throw new RangeError("Reference element is currently in detached mode! No way to add neighbors!");return this.parentNode.insertBefore(e,this),this instanceof DocumentFragment?new DocumentFragment:e}}),Object.defineProperty(Node.prototype,"insertNeighborAfter",{configurable:!0,writable:!0,enumerable:!1,value:function(e){if(!this.parentNode)throw new RangeError("Reference element is currently in detached mode! No way to add neighbors!");return this.parentNode.insertBefore(e,this.nextSibling),this instanceof DocumentFragment?new DocumentFragment:e}}),Object.defineProperty(Node.prototype,"setContentText",{configurable:!0,writable:!0,enumerable:!1,value:function(e){return this.textContent=e,this}})),(()=>{const e=Object.defineProperty,t=Object.defineProperties;function r(e,t=!1){const r=typeof e;switch(r){case"number":case"string":case"function":case"boolean":case"undefined":case"symbol":return r}return null===e?"null":e instanceof String?"string":e instanceof Number?"number":e instanceof Boolean?"boolean":Array.isArray(e)?"array":t?e instanceof ArrayBuffer?"array-buffer":e instanceof DataView?"data-view":e instanceof Uint8Array?"uint8-array":e instanceof Uint8ClampedArray?"uint8-clamped-array":e instanceof Int8Array?"int8-array":e instanceof Uint16Array?"uint16-array":e instanceof Int16Array?"int16-array":e instanceof Uint32Array?"uint32-array":e instanceof Int32Array?"int32-array":e instanceof Float32Array?"float32-array":e instanceof Float64Array?"float64-array":e instanceof Map?"map":e instanceof WeakMap?"weak-map":e instanceof Set?"set":e instanceof WeakSet?"weak-set":e instanceof RegExp?"regexp":e instanceof Promise?"promise":"object":"object"}e(Object,"defineProperty",{writable:!0,configurable:!0,enumerable:!1,value:function(t,r,n){return e(t,r,n),t}}),e(Object,"defineProperties",{writable:!0,configurable:!0,enumerable:!1,value:function(e,r){return t(e,r),e}}),Object.defineProperty(Object,"merge",{writable:!0,configurable:!0,enumerable:!1,value:function e(t,n){if(Object(t)!==t)throw new Error("Given target is not an object");if(Object(n)!==n)throw new Error("Given source is not an object");for(const i in n){if(n.hasOwnProperty&&!n.hasOwnProperty(i)||void 0===n[i])continue;const a=t[i],o=n[i],l=r(a),u=r(o);"object"===l&&"object"===u?e(a,o):t instanceof Map?t.set(i,o):t[i]=o}return t}}),Object.defineProperty(Object,"typeOf",{writable:!0,configurable:!0,enumerable:!1,value:r}),Object.defineProperty(Object.prototype,"_decorate",{writable:!0,configurable:!0,enumerable:!1,value:function(e,...t){return"function"==typeof e&&e.call(this,...t),this}})})(),(()=>{const t=Promise.prototype.then,r=Promise.prototype.catch,n=Promise.prototype.finally;function i(e,t){for(const r of Object.keys(t))e[r]=t[r];return e}Object.defineProperties(Promise.prototype,{then:{writable:!0,configurable:!0,enumerable:!1,value:function(...e){return i(t.call(this,...e),this)}},catch:{writable:!0,configurable:!0,enumerable:!1,value:function(...e){return i(r.call(this,...e),this)}},finally:{writable:!0,configurable:!0,enumerable:!1,value:function(...e){return i(n.call(this,...e),this)}},guard:{writable:!0,configurable:!0,enumerable:!1,value:function(){return i(r.call(this,t=>(setTimeout(()=>{if(e)throw t;{const e=new Event("unhandledRejection");e.error=t,window.dispatchEvent(e)}},0),t)),this)}}}),Object.defineProperties(Promise,{wait:{writable:!0,configurable:!0,enumerable:!1,value:function(e=[]){Array.isArray(e)||(e=[e]);if(0===e.length)return Promise.resolve([]);return new Promise((t,r)=>{let n=[],i=0,a=!0;for(let o=0;o<e.length;o++){let l={resolved:!0,seq:o,result:null};n.push(l),Promise.resolve(e[o]).then(e=>{a=(l.resolved=!0)&&a,l.result=e},e=>{a=(l.resolved=!1)&&a,l.result=e}).then(()=>{i++,e.length===i&&(a?t:r)(n)})}})}},create:{writable:!0,configurable:!0,enumerable:!1,value:function(){let e=null,t=null;const r=new Promise((r,n)=>{e=r,t=n});return r.resolve=e,r.reject=t,r.promise=r,r}}})})(),(()=>{const e=/(\w)(\w*)(\W*)/g,t=(e,t,r,n,i,a)=>`${t.toUpperCase()}${r.toLowerCase()}${n}`;function n(e,...t){return this instanceof n?(this.strings=e,void(this.fields=t)):new n(e,...t)}n.prototype={[Symbol.iterator](){const e=this.strings.slice(0).reverse(),t=this.fields.slice(0).reverse();let r=0;return{next:()=>{if(0===e.length)return{done:!0};let n;return n=r%2==0?e.pop():t.pop(),r+=1,{value:n}}}},toString(){let e="";for(const t of this)e+=""+t;return e}},Object.defineProperties(String.prototype,{upperCase:{configurable:!0,enumerable:!1,get:function(){return this.toUpperCase()}},localeUpperCase:{configurable:!0,enumerable:!1,get:function(){return this.toLocaleUpperCase()}},lowerCase:{configurable:!0,enumerable:!1,get:function(){return this.toLowerCase()}},localeLowerCase:{configurable:!0,enumerable:!1,get:function(){return this.toLocaleLowerCase()}},toCamelCase:{configurable:!0,enumerable:!1,value:function(){return this.replace(e,t)}},camelCase:{configurable:!0,enumerable:!1,get:function(){return this.replace(e,t)}},pull:{configurable:!0,enumerable:!1,writable:!0,value:function(e="",t=!0){if("string"!=typeof e)throw new TypeError("Given token must be a string");const r=this.length;if(0===r)return["",""];if(""===e)return t?[this[0],this.substring(1)]:[this.substring(0,r-1),this[r-1]];if(t){const t=this.indexOf(e,e.length);return t<0?[this.substring(0),""]:[this.substring(0,t),this.substring(t)]}{const t=this.lastIndexOf(e);return t<0?["",this.substring(0)]:[this.substring(0,t),this.substring(t)]}}},pop:{configurable:!0,enumerable:!1,writable:!0,value:function(e=""){return this.pull(e,!0)}},shift:{configurable:!0,enumerable:!1,writable:!0,value:function(e=""){return this.pull(e,!1)}}}),Object.defineProperties(String,{encodeRegExpString:{writable:!0,configurable:!0,enumerable:!1,value:function(e=""){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}},template:{writable:!0,configurable:!0,enumerable:!1,value:n},from:{writable:!0,configurable:!0,enumerable:!1,value:e=>{if("string"==typeof e)return e;const t=r(e);return null!==t?function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),!(e instanceof Uint8Array))throw new TypeError("Given input must be an Uint8Array contains UTF8 encoded value!");let t=e,r=[],n=0;for(;n<t.length;){let e=255&t[n];0==(128&e)?(r.push(e),n+=1):192==(224&e)?(e=(31&t[n])<<6|63&t[n+1],r.push(e),n+=2):224==(240&e)?(e=(15&t[n])<<12|(63&t[n+1])<<6|63&t[n+2],r.push(e),n+=3):240==(248&e)?(e=(7&t[n])<<18|(63&t[n+1])<<12|(63&t[n+2])<<6|63&t[n+3],r.push(e),n+=4):n+=1}let i="";for(;r.length>0;){const e=r.splice(0,100);i+=String.fromCodePoint(...e)}return i}(new Uint8Array(t)):""+e}}})})(),(()=>{function e(){let e=null,t=!1,r=null;const n=(n,i=0,...a)=>{e={cb:n,delay:i,args:a},t||(r&&(clearTimeout(r),r=null),function n(){if(!e)return;let{cb:i,delay:a,args:o}=e;r=setTimeout(()=>{t=!0,Promise.resolve(i(...o)).then(()=>{t=!1,r=null,n()},n=>{throw t=!1,r=null,e=null,n})},a),e=null}())};return n.clear=()=>{e=null,r&&(clearTimeout(r),r=null)},n}Object.defineProperty(setTimeout,"create",{writable:!0,configurable:!0,enumerable:!1,value:e}),Object.defineProperty(setTimeout,"idle",{writable:!0,configurable:!0,enumerable:!1,value:function(e=0){return new Promise(t=>{setTimeout(t,e)})}}),Object.defineProperty(setInterval,"create",{writable:!0,configurable:!0,enumerable:!1,value:function(){const t=e(),r=(e,r=0,...n)=>{const i=async()=>{t(i,r);try{await e(...n)}catch(e){throw t.clear(),e}};t(i,r,...n)};return r.clear=()=>{t.clear()},r}})})(),(()=>{const e=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],t=[DataView,...e],r=new WeakMap;for(const e of t)r.set(e,{from:e.from,toString:e.toString}),Object.defineProperty(e,"from",{value:function(t){const n=r.get(e).from;return t instanceof ArrayBuffer?new e(t):n.call(e,t)},configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(e.prototype,"toString",{value:function(...t){const n=r.get(e).toString;return 0===t.length?n.call(this,...t):this.buffer.toString(...t)},configurable:!0,enumerable:!1,writable:!0})})()})(); | ||
(()=>{"use strict";const e="undefined"!=typeof Buffer;function t(e,t=2,r="0"){let n=t-(e=""+e).length;for(;n-- >0;)e=r+e;return e}function r(t){return e&&Buffer.isBuffer(t)?new Uint8Array(t):ArrayBuffer.isView(t)?new Uint8Array(t.buffer):t instanceof ArrayBuffer?new Uint8Array(t):null}(()=>{const e=/^(0x)?([0-9a-fA-F]+)$/,t=/^(0b|0B)?([01]+)$/,n={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15};Object.defineProperty(ArrayBuffer.prototype,"bytes",{configurable:!0,enumerable:!1,get:function(){return new Uint8Array(this)}}),Object.defineProperty(ArrayBuffer.prototype,"toString",{configurable:!0,writable:!0,enumerable:!1,value:function(e=16,t=!0){const r=new Uint8Array(this);let n="";switch(e){case 16:for(let e=0;e<r.length;e++){const t=r[e];n+="0123456789abcdef"[(240&t)>>>4]+"0123456789abcdef"[15&t]}break;case 2:for(let e=0;e<r.length;e++){const t=r[e];for(let e=7;e>=0;e--)n+=t>>>e&1?"1":"0"}break;default:throw new RangeError("Unsupported numeric representation!")}return t?n:n.replace(/^0+/,"")}}),Object.defineProperty(ArrayBuffer.prototype,"compare",{configurable:!0,writable:!0,enumerable:!1,value:function(e){if(!(e instanceof ArrayBuffer))throw new TypeError("An ArrayBuffer can only be compared with another ArrayBuffer");const t=new Uint8Array(this),r=new Uint8Array(e),n=Math.max(t.length,r.length);for(let e=0;e<n;e++){const n=t[e]||0,i=r[e]||0;if(n>i)return 1;if(n<i)return-1}return 0}}),Object.defineProperty(ArrayBuffer,"extract",{configurable:!0,writable:!0,enumerable:!1,value:function(e){if("undefined"!=typeof Buffer&&e instanceof Buffer){let t=Buffer.alloc(e.length);return e.copy(t,0),t.buffer}if(ArrayBuffer.isView(e))return e.buffer;if(e instanceof ArrayBuffer)return e;throw new TypeError("Cannot convert given input data into array buffer")}}),Object.defineProperty(ArrayBuffer,"from",{configurable:!0,writable:!0,enumerable:!1,value:function(r,i=null){if("undefined"!=typeof Buffer&&r instanceof Buffer){let e=Buffer.alloc(r.length);return r.copy(e,0),e.buffer}if(ArrayBuffer.isView(r))return r.buffer.slice(0);if(r instanceof ArrayBuffer)return r.slice(0);if(Array.isArray(r)){return new Uint8Array(r).buffer}if("number"==typeof r){let e=null;switch(i){case"int8":e=new Int8Array([r]);break;case"uint8":e=new Uint8Array([r]);break;case"int16":e=new Int16Array([r]);break;case"uint16":e=new Uint16Array([r]);break;case"int32":e=new Int32Array([r]);break;case"int64":{const t=r<0;t&&(r=-r);let n=Math.floor(r/4294967295),i=4294967295&r;t&&(i=1+(~i>>>0),n=~n+Math.floor(i/4294967295)),e=new Uint32Array([i,n]);break}case"uint64":{const t=Math.floor(r/4294967295);e=new Uint32Array([4294967295&r,t]);break}case"float32":e=new Float32Array([r]);break;case"float64":e=new Float64Array([r]);break;case"uint32":default:e=new Uint32Array([r])}return e.buffer}if("string"==typeof r){if("hex"===i){const t=r.match(e);if(!t)throw new RangeError("Input argument is not a valid hex string!");let[,,i]=t;i=i.length%2==0?i.toLowerCase():"0"+i.toLowerCase();const a=new Uint8Array(i.length/2|0);for(let e=0;e<a.length;e++){const t=2*e;a[e]=n[i[t]]<<4|15&n[i[t+1]]}return a.buffer}if("bits"===i){const e=r.match(t);if(!e)throw new RangeError("Input argument is not a valid bit string!");let[,,n]=e;n.length%8!=0&&(n="0".repeat(n.length%8)+n);const i=new Uint8Array(n.length/8|0);for(let e=0;e<i.length;e++){const t=8*e;let r="1"===n[t]?1:0;for(let e=1;e<8;e++)r=r<<1|("1"===n[t+e]?1:0);i[e]=r}return i.buffer}return function(e){if("string"!=typeof e)throw new TypeError("Given input argument must be a js string!");let t=[],r=0;for(;r<e.length;){let n=e.codePointAt(r);0==(4294967168&n)?t.push(n):0==(4294965248&n)?t.push(192|31&n>>6,128|63&n):0==(4294901760&n)?t.push(224|15&n>>12,128|63&n>>6,128|63&n):0==(4292870144&n)&&t.push(240|7&n>>18,128|63&n>>12,128|63&n>>6,128|63&n),r+=n>65535?2:1}return new Uint8Array(t)}(r).buffer}throw new TypeError("Cannot convert given input data into array buffer!")}}),Object.defineProperty(ArrayBuffer,"compare",{configurable:!0,writable:!0,enumerable:!1,value:function(e,t){if(!(e instanceof ArrayBuffer&&t instanceof ArrayBuffer))throw new TypeError("ArrayBuffer.compare only accepts two array buffers!");return e.compare(t)}}),Object.defineProperty(ArrayBuffer,"concat",{configurable:!0,writable:!0,enumerable:!1,value:function(...e){Array.isArray(e[0])&&(e=e[0]);let t=0;for(let n=0;n<e.length;n++){let i=e[n]=r(e[n]);if(!(i instanceof Uint8Array))throw new TypeError("ArrayBuffer.combine accept only ArrayBuffer, TypeArray and DataView.");t+=i.length}const n=new Uint8Array(t);t=0;for(const r of e)n.set(r,t),t+=r.length;return n.buffer}})})(),Object.defineProperty(Array.prototype,"unique",{writable:!0,configurable:!0,enumerable:!1,value:function(){const e=new Set;for(const t of this)e.add(t);return Array.from(e)}}),Object.defineProperty(Array.prototype,"exclude",{writable:!0,configurable:!0,enumerable:!1,value:function(e){Array.isArray(e)||(e=[e]);const t=[];for(const r of this){let n=!1;for(const t of e)if(r===t){n=n||!0;break}n||t.push(r)}return t}}),Object.defineProperty(Array,"concat",{writable:!0,configurable:!0,enumerable:!1,value:function(...e){const t=[];for(const r of e)if(Array.isArray(r))for(const e of r)t.push(e);else t.push(r);return t}}),Object.defineProperty(Array,"intersect",{writable:!0,configurable:!0,enumerable:!1,value:function(...e){let t=e[0]||[];if(!Array.isArray(t))throw new TypeError("Array.intersect only accepts list array arguments!");for(let r=1;r<e.length;r++){const n=e[r];if(!Array.isArray(n))throw new TypeError("Array.intersect only accepts list array arguments!");const i=new Set;for(const e of t)n.indexOf(e)>=0&&i.add(e);t=Array.from(i)}return t}}),"undefined"!=typeof Blob&&Object.defineProperty(Blob.prototype,"arrayBuffer",{configurable:!0,writable:!0,enumerable:!1,value:function(){return new Promise((e,t)=>{const r=new FileReader;r.onerror=t,r.onload=()=>e(r.result),r.readAsArrayBuffer(this)})}}),Object.defineProperty(Date,"unix",{writable:!0,configurable:!0,enumerable:!1,value:function(){return Math.floor(Date.now()/1e3)}}),Object.defineProperty(Date.prototype,"getUnixTime",{writable:!0,configurable:!0,enumerable:!1,value:function(){return Math.floor(this.getTime()/1e3)}}),Object.defineProperty(Date.prototype,"unix",{configurable:!0,enumerable:!1,get:function(){return Math.floor(this.getTime()/1e3)}}),Object.defineProperty(Date.prototype,"time",{configurable:!0,enumerable:!1,get:function(){return this.getTime()}}),Object.defineProperty(Date.prototype,"toLocaleISOString",{writable:!0,configurable:!0,enumerable:!1,value:function(){let e,r=this.getTimezoneOffset();if(0===r)e="Z";else{const n=r>0?"-":"+";r=Math.abs(r);const i=r%60;e=n+t(Math.floor(r/60))+t(i)}return this.getFullYear()+"-"+t(this.getMonth()+1)+"-"+t(this.getDate())+"T"+t(this.getHours())+":"+t(this.getMinutes())+":"+t(this.getSeconds())+"."+this.getMilliseconds()%1e3+e}}),"undefined"!=typeof Document&&Object.defineProperties(Document.prototype,{parseHTML:{configurable:!0,writable:!0,enumerable:!1,value:function(e){const t=this.implementation.createHTMLDocument().body;if(t.innerHTML=e,0===t.children.length)return null;if(1===t.children.length){const e=t.children[0];return e.remove(),e}const r=Array.prototype.slice.call(t.children,0);for(const e of r)e.remove();return r}}}),(()=>{if("undefined"!=typeof Element){const e=Element.prototype.setAttribute,t=Element.prototype.removeAttribute,r=Element.prototype.setAttributeNS,n=Element.prototype.removeAttributeNS;Object.defineProperties(Element.prototype,{addClass:{configurable:!0,enumerable:!1,writable:!0,value:function(...e){const t=[];for(const r of e)null!=r&&""!==r&&t.push(r);return this.classList.add(...t),this}},removeClass:{configurable:!0,enumerable:!1,writable:!0,value:function(...e){const t=[];for(const r of e)null!=r&&""!==r&&t.push(r);return this.classList.remove(...t),this}},setAttribute:{configurable:!0,enumerable:!1,writable:!0,value:function(t,r){return arguments.length<2&&(r=""),e.call(this,t,r),this}},removeAttribute:{configurable:!0,enumerable:!1,writable:!0,value:function(...e){return t.apply(this,e),this}},setAttributeNS:{configurable:!0,enumerable:!1,writable:!0,value:function(...e){return r.apply(this,e),this}},removeAttributeNS:{configurable:!0,enumerable:!1,writable:!0,value:function(...e){return n.apply(this,e),this}}})}})(),"undefined"!=typeof Error&&Object.defineProperty(Error.prototype,"stack_trace",{get:function(){return this.stack?this.stack.split(/\r\n|\n/g).map(e=>e.trim()):null},enumerable:!1,configurable:!0}),"undefined"!=typeof EventTarget&&(Object.defineProperty(EventTarget.prototype,"on",{configurable:!0,writable:!0,enumerable:!1,value:function(e,t){const r=[],n=e.split(",");for(let e of n)e=e.trim(),r.indexOf(e)>=0||(r.push(e),this.addEventListener(e,t));return this}}),Object.defineProperty(EventTarget.prototype,"off",{configurable:!0,writable:!0,enumerable:!1,value:function(e,t){const r=e.split(",");for(let e of r)e=e.trim(),this.removeEventListener(e,t);return this}}),Object.defineProperty(EventTarget.prototype,"emit",{configurable:!0,writable:!0,enumerable:!1,value:function(e,t={}){const{bubbles:r,cancelable:n,composed:i,...a}=t;if("string"==typeof e&&(e=new Event(e,{bubbles:!!r,cancelable:!!n,composed:!!i})),!(e instanceof Event))throw new TypeError("Argument 1 accepts only string or Event instance!");Object.assign(e,a),this.dispatchEvent(e)}})),(()=>{if("undefined"!=typeof Error){class e extends Error{constructor(e,...t){super(e,...t),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);const r=Date.now();Object.defineProperties(this,{name:{configurable:!1,writable:!1,enumerable:!1,value:this.constructor.name},time:{configurable:!1,writable:!1,enumerable:!1,value:Math.floor(r/1e3)},time_milli:{configurable:!1,writable:!1,enumerable:!1,value:r}})}}class t extends e{constructor(e,t=null,...r){if(Object(e)!==e)throw new TypeError("IndexedError constructor accepts only objects!");const{code:n,key:i,message:a=null,msg:o=null}=e;if("number"!=typeof n||"string"!=typeof i)throw new TypeError("IndexedError error info object must contains a numeric `code` field and a string `key` field");null!==a?r.unshift(""+a):null!==o?r.unshift(""+o):r.unshift(""),super(...r),Object.defineProperties(this,{code:{configurable:!1,writable:!1,enumerable:!1,value:n},key:{configurable:!1,writable:!1,enumerable:!1,value:i},detail:{configurable:!1,writable:!1,enumerable:!1,value:t}})}toJSON(){const e={code:this.code,key:this.key,msg:this.message,detail:void 0,time:this.time,time_milli:this.time_milli};return null!==this.detail&&void 0!==this.detail&&(Array.isArray(this.detail)?e.detail=this.detail.slice(0):Object(this.detail)===this.detail?e.detail=Object.assign({},this.detail):e.detail=this.detail),e}}Object.defineProperties(Error,{EError:{configurable:!0,writable:!0,enumerable:!1,value:e},IndexedError:{configurable:!0,writable:!0,enumerable:!1,value:t}})}})(),(()=>{const e=new WeakMap,t={},r={};function n(e,n){const a=Array.prototype.slice.call(arguments,0);return a[0]=e?t:r,i.call(...a)}function i(t){const r=e.get(this),n={async:r.async,funcs:r.funcs.slice(0)};if(arguments.length>0){let e;Array.isArray(t)||(t=[t]);for(let r=0;r<t.length;r++)n.funcs.push("function"==typeof(e=t[r])?e:()=>e)}const o={};e.set(o,n);const l=a.bind(o);return l.chain=i.bind(o),l}function a(...t){const{async:r,funcs:n}=e.get(this);this.session={};let i=void 0;if(r)return Promise.resolve().then(async()=>{for(const e of n)if(i=await e.call(this,...t,i),!1===i)break;return i});for(const e of n)if(i=e.call(this,...t,i),!1===i)break;return i}e.set(t,{async:!0,funcs:[]}),e.set(r,{async:!1,funcs:[]}),Object.defineProperty(Function,"sequential",{configurable:!0,writable:!0,enumerable:!1,value:n.bind(null,!1)}),Object.defineProperty(Function.sequential,"async",{configurable:!1,writable:!1,enumerable:!0,value:n.bind(null,!0)})})(),"undefined"!=typeof HTMLElement&&Object.defineProperties(HTMLElement.prototype,{setData:{configurable:!0,writable:!0,enumerable:!1,value:function(e,t){if(Object(e)===e)for(const t in e)this.dataset[t]=e[t];else this.dataset[e]=t;return this}},getData:{configurable:!0,writable:!0,enumerable:!1,value:function(e){return this.dataset[e]}},removeData:{configurable:!0,writable:!0,enumerable:!1,value:function(...e){for(const t of e)delete this.dataset[t];return this}},setContentHtml:{configurable:!0,writable:!0,enumerable:!1,value:function(e){return this.innerHTML=e,this}}}),"undefined"!=typeof HTMLInputElement&&Object.defineProperty(HTMLInputElement.prototype,"setValue",{configurable:!0,writable:!0,enumerable:!1,value:function(e){return this.value=e,this}}),"undefined"!=typeof Node&&(Object.defineProperty(Node.prototype,"prependChild",{configurable:!0,writable:!0,enumerable:!1,value:function(e){return this.insertBefore(e,this.children[0]||null),this instanceof DocumentFragment?new DocumentFragment:e}}),Object.defineProperty(Node.prototype,"insertNeighborBefore",{configurable:!0,writable:!0,enumerable:!1,value:function(e){if(!this.parentNode)throw new RangeError("Reference element is currently in detached mode! No way to add neighbors!");return this.parentNode.insertBefore(e,this),this instanceof DocumentFragment?new DocumentFragment:e}}),Object.defineProperty(Node.prototype,"insertNeighborAfter",{configurable:!0,writable:!0,enumerable:!1,value:function(e){if(!this.parentNode)throw new RangeError("Reference element is currently in detached mode! No way to add neighbors!");return this.parentNode.insertBefore(e,this.nextSibling),this instanceof DocumentFragment?new DocumentFragment:e}}),Object.defineProperty(Node.prototype,"setContentText",{configurable:!0,writable:!0,enumerable:!1,value:function(e){return this.textContent=e,this}})),(()=>{const e=Object.defineProperty,t=Object.defineProperties;function r(e,t=!1){const r=typeof e;switch(r){case"number":case"string":case"function":case"boolean":case"undefined":case"symbol":return r}return null===e?"null":e instanceof String?"string":e instanceof Number?"number":e instanceof Boolean?"boolean":Array.isArray(e)?"array":t?e instanceof ArrayBuffer?"array-buffer":e instanceof DataView?"data-view":e instanceof Uint8Array?"uint8-array":e instanceof Uint8ClampedArray?"uint8-clamped-array":e instanceof Int8Array?"int8-array":e instanceof Uint16Array?"uint16-array":e instanceof Int16Array?"int16-array":e instanceof Uint32Array?"uint32-array":e instanceof Int32Array?"int32-array":e instanceof Float32Array?"float32-array":e instanceof Float64Array?"float64-array":e instanceof Map?"map":e instanceof WeakMap?"weak-map":e instanceof Set?"set":e instanceof WeakSet?"weak-set":e instanceof RegExp?"regexp":e instanceof Promise?"promise":"object":"object"}e(Object,"defineProperty",{writable:!0,configurable:!0,enumerable:!1,value:function(t,r,n){return e(t,r,n),t}}),e(Object,"defineProperties",{writable:!0,configurable:!0,enumerable:!1,value:function(e,r){return t(e,r),e}}),Object.defineProperty(Object,"merge",{writable:!0,configurable:!0,enumerable:!1,value:function e(t,n){if(Object(t)!==t)throw new Error("Given target is not an object");if(Object(n)!==n)throw new Error("Given source is not an object");for(const i in n){if(n.hasOwnProperty&&!n.hasOwnProperty(i)||void 0===n[i])continue;const a=t[i],o=n[i],l=r(a),u=r(o);"object"===l&&"object"===u?e(a,o):t instanceof Map?t.set(i,o):t[i]=o}return t}}),Object.defineProperty(Object,"typeOf",{writable:!0,configurable:!0,enumerable:!1,value:r}),Object.defineProperty(Object.prototype,"_decorate",{writable:!0,configurable:!0,enumerable:!1,value:function(e,...t){return"function"==typeof e&&e.call(this,...t),this}})})(),(()=>{const t=Promise.prototype.then,r=Promise.prototype.catch,n=Promise.prototype.finally;function i(e,t){for(const r of Object.keys(t))e[r]=t[r];return e}Object.defineProperties(Promise.prototype,{then:{writable:!0,configurable:!0,enumerable:!1,value:function(...e){return i(t.call(this,...e),this)}},catch:{writable:!0,configurable:!0,enumerable:!1,value:function(...e){return i(r.call(this,...e),this)}},finally:{writable:!0,configurable:!0,enumerable:!1,value:function(...e){return i(n.call(this,...e),this)}},guard:{writable:!0,configurable:!0,enumerable:!1,value:function(){return i(r.call(this,t=>(setTimeout(()=>{if(e)throw t;{const e=new Event("unhandledRejection");e.error=t,window.dispatchEvent(e)}},0),t)),this)}}}),Object.defineProperties(Promise,{wait:{writable:!0,configurable:!0,enumerable:!1,value:function(e=[]){Array.isArray(e)||(e=[e]);if(0===e.length)return Promise.resolve([]);return new Promise((t,r)=>{let n=[],i=0,a=!0;for(let o=0;o<e.length;o++){let l={resolved:!0,seq:o,result:null};n.push(l),Promise.resolve(e[o]).then(e=>{a=(l.resolved=!0)&&a,l.result=e},e=>{a=(l.resolved=!1)&&a,l.result=e}).then(()=>{i++,e.length===i&&(a?t:r)(n)})}})}},create:{writable:!0,configurable:!0,enumerable:!1,value:function(){let e=null,t=null;const r=new Promise((r,n)=>{e=r,t=n});return r.resolve=e,r.reject=t,r.promise=r,r}}})})(),(()=>{const e=/(\w)(\w*)(\W*)/g,t=(e,t,r,n,i,a)=>`${t.toUpperCase()}${r.toLowerCase()}${n}`;function n(e,...t){return this instanceof n?(this.strings=e,void(this.fields=t)):new n(e,...t)}n.prototype={[Symbol.iterator](){const e=this.strings.slice(0).reverse(),t=this.fields.slice(0).reverse();let r=0;return{next:()=>{if(0===e.length)return{done:!0};let n;return n=r%2==0?e.pop():t.pop(),r+=1,{value:n}}}},toString(){let e="";for(const t of this)e+=""+t;return e}},Object.defineProperties(String.prototype,{upperCase:{configurable:!0,enumerable:!1,get:function(){return this.toUpperCase()}},localeUpperCase:{configurable:!0,enumerable:!1,get:function(){return this.toLocaleUpperCase()}},lowerCase:{configurable:!0,enumerable:!1,get:function(){return this.toLowerCase()}},localeLowerCase:{configurable:!0,enumerable:!1,get:function(){return this.toLocaleLowerCase()}},toCamelCase:{configurable:!0,enumerable:!1,value:function(){return this.replace(e,t)}},camelCase:{configurable:!0,enumerable:!1,get:function(){return this.replace(e,t)}},pull:{configurable:!0,enumerable:!1,writable:!0,value:function(e="",t=!0){if("string"!=typeof e)throw new TypeError("Given token must be a string");const r=this.length;if(0===r)return["",""];if(""===e)return t?[this[0],this.substring(1)]:[this.substring(0,r-1),this[r-1]];if(t){const t=this.indexOf(e,e.length);return t<0?[this.substring(0),""]:[this.substring(0,t),this.substring(t)]}{const t=this.lastIndexOf(e);return t<0?["",this.substring(0)]:[this.substring(0,t),this.substring(t)]}}},pop:{configurable:!0,enumerable:!1,writable:!0,value:function(e=""){return this.pull(e,!0)}},shift:{configurable:!0,enumerable:!1,writable:!0,value:function(e=""){return this.pull(e,!1)}}}),Object.defineProperties(String,{encodeRegExpString:{writable:!0,configurable:!0,enumerable:!1,value:function(e=""){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}},template:{writable:!0,configurable:!0,enumerable:!1,value:n},from:{writable:!0,configurable:!0,enumerable:!1,value:e=>{if("string"==typeof e)return e;const t=r(e);return null!==t?function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),!(e instanceof Uint8Array))throw new TypeError("Given input must be an Uint8Array contains UTF8 encoded value!");let t=e,r=[],n=0;for(;n<t.length;){let e=255&t[n];0==(128&e)?(r.push(e),n+=1):192==(224&e)?(e=(31&t[n])<<6|63&t[n+1],r.push(e),n+=2):224==(240&e)?(e=(15&t[n])<<12|(63&t[n+1])<<6|63&t[n+2],r.push(e),n+=3):240==(248&e)?(e=(7&t[n])<<18|(63&t[n+1])<<12|(63&t[n+2])<<6|63&t[n+3],r.push(e),n+=4):n+=1}let i="";for(;r.length>0;){const e=r.splice(0,100);i+=String.fromCodePoint(...e)}return i}(t):""+e}}})})(),(()=>{function e(){let e=null,t=!1,r=null;const n=(n,i=0,...a)=>{e={cb:n,delay:i,args:a},t||(r&&(clearTimeout(r),r=null),function n(){if(!e)return;let{cb:i,delay:a,args:o}=e;r=setTimeout(()=>{t=!0,Promise.resolve(i(...o)).then(()=>{t=!1,r=null,n()},n=>{throw t=!1,r=null,e=null,n})},a),e=null}())};return n.clear=()=>{e=null,r&&(clearTimeout(r),r=null)},n}Object.defineProperty(setTimeout,"create",{writable:!0,configurable:!0,enumerable:!1,value:e}),Object.defineProperty(setTimeout,"idle",{writable:!0,configurable:!0,enumerable:!1,value:function(e=0){return new Promise(t=>{setTimeout(t,e)})}}),Object.defineProperty(setInterval,"create",{writable:!0,configurable:!0,enumerable:!1,value:function(){const t=e(),r=(e,r=0,...n)=>{const i=async()=>{t(i,r);try{await e(...n)}catch(e){throw t.clear(),e}};t(i,r,...n)};return r.clear=()=>{t.clear()},r}})})(),(()=>{const e=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],t=[DataView,...e],r=new WeakMap;for(const e of t)r.set(e,{from:e.from,toString:e.toString}),Object.defineProperty(e,"from",{value:function(t){const n=r.get(e).from;return t instanceof ArrayBuffer?new e(t):n.call(e,t)},configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(e.prototype,"toString",{value:function(...t){const n=r.get(e).toString;return 0===t.length?n.call(this,...t):this.buffer.toString(...t)},configurable:!0,enumerable:!1,writable:!0})})()})(); |
{ | ||
"name": "extes", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "A tiny library that extends native js with some handy tools", | ||
"main": "extes.js", | ||
"scripts": {}, | ||
"scripts": { | ||
"pack": "node ./build/packer.js ./build/src ./build/tmpl.js -o ./extes.js && terser -c -m -- ./extes.js > ./extes.min.js" | ||
}, | ||
"keywords": [ | ||
@@ -8,0 +10,0 @@ "ECMAScript", |
61831
1473