class ControlTable { constructor(a) { this.table = a this.dataRow = []; } ai(name) { this.dataRow.push(` \`${name}\` INT(11) AUTO_INCREMENT PRIMARY KEY `) } char(name, length, def) { this.dataRow.push(` \`${name}\` VARCHAR(${length}) NOT NULL DEFAULT '${def}' `) } text(name) { this.dataRow.push(` \`${name}\` TEXT `) } longtext(name) { this.dataRow.push(` \`${name}\` LONGTEXT `) } timecreate(name) { this.dataRow.push(` \`${name}\` DATETIME NULL DEFAULT CURRENT_TIMESTAMP `) } timeupdate(name) { this.dataRow.push(` \`${name}\` DATETIME NULL DEFAULT CURRENT_TIMESTAMP `) } cek() { query(`SELECT * FROM \`${this.table}\``, function (a) { console.log(a) }) } createTable(func) { var createTable = `CREATE TABLE \`${this.table}\` ( ${this.dataRow.join(", \n ")} ) `; query(createTable, function (a) { func(a) }) } } function compare( a, b ) { if ( a.last_nom < b.last_nom ){ return -1; } if ( a.last_nom > b.last_nom ){ return 1; } return 0; } Array.prototype.dinamicSort = function(property){ var sortOrder = 1; if(property[0] === "-") { sortOrder = -1; property = property.substr(1); } return function (a,b) { /* next line works with strings and numbers, * and you may want to customize it to your needs */ var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0; return result * sortOrder; } }; Number.prototype.pad = function(length) { var s = this; var number = s.valueOf() var str = '' + number; while (str.length < length) { str = '0' + str; } return str; } Array.prototype.dinamicSortMultiple = function(){ /* * save the arguments object as it will be overwritten * note that arguments object is an array-like object * consisting of the names of the properties to sort by */ var dynamicSort = function(property){ var sortOrder = 1; if(property[0] === "-") { sortOrder = -1; property = property.substr(1); } return function (a,b) { /* next line works with strings and numbers, * and you may want to customize it to your needs */ var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0; return result * sortOrder; } }; var props = arguments; return function (obj1, obj2) { var i = 0, result = 0, numberOfProperties = props.length; /* try getting a different result from 0 (equal) * as long as we have extra properties to compare */ while(result === 0 && i < numberOfProperties) { result = dynamicSort(props[i])(obj1, obj2); i++; } return result; } } Array.prototype.sortArrayObjectAsc = function(param){ var arr = this; var dinamicFunc = this.dinamicSort; return arr.sort(dinamicFunc(param)); } Array.prototype.sortArrayObjectMultiple = function(){ var arr = this; var props = arguments; var dynamicSortMultiple = this.dinamicSortMultiple; return arr.sort(dynamicSortMultiple(...props)); } Array.prototype.sortArrayObjectDesc = function(param){ var arr = this; var dinamicFunc = this.dinamicSort; return arr.sort(dinamicFunc('-'+param)); } globalThis.ArrayNumberExample = [0,1,2,3,4,5,6,7,8,9]; Array.prototype.asc = function(param){ return this.sort(); } Array.prototype.sum = function(a){ var d = [].concat(this); function myFunc(total, num) { return total + num; } if(d.length > 0){ if(a != undefined){ d = d.map(function(k){ if(typeof k[a] === 'string'){ return Number(k[a]); }else if(typeof k[a] === 'number'){ return k[a]; }else{ return 0; } }); return d.reduce(myFunc); } return d.reduce(myFunc); }else{ return 0; } } Array.prototype.desc = function(param){ return this.reverse(); } globalThis.ArrayObjectExample = [ {Name: "Name", Surname: "Surname"}, {Name:"AAA", Surname:"ZZZ"}, {Name: "Name", Surname: "AAA"} ]; String.prototype.number = function (fn = false) { var s = this; if (fn == 2) { s = s.replace(/\./g, ','); } if (fn != 2) { s = s.replace(/[^-,\d]/g, ''); } if (s == null) { s = '0'; } if (fn == false) { if (s == '-') { return '-'; } else if (s == '') { return ''; } else { return Number(s.replace(/\./g, '').replace(/\,/g, '.')); } } else if (fn == true) { return s.replace(/\./g, ''); } else if (fn == 2) { return Number(s.replace(/\,/g, '.')); } else { return Number(s.replace(/\./g, '').replace(/\,/g, '.')); } } Array.prototype.count = function (a, val) { var t = this if(a != undefined && val != undefined){ return t.filter(function(dat,x){ if(dat[a] == val){ return dat; } }).length }else{ return 0; } } Array.prototype.row = function (a, val) { var t = this if(a != undefined && val != undefined){ var g = t.filter(function(dat,x){ if(dat[a] == val){ return dat; } }) if(g.length > 0){ return g[0]; }else{ return g; } }else{ return t } } Array.prototype.del = function (a, val) { var t = this if(a != undefined && val != undefined){ return t.filter(function(dat,x){ if(dat[a] != val){ return dat; } }) }else{ return t } } String.prototype.currency = function(){ var s = this; s = s.replace(/\,/g, '.'); if(s != ''){ s = this.formatRupiah(); } return s; } String.prototype.lastDotToComa = function(){ var s = this; var l = this.length - 1; var sl = s.slice(0, l); if(s[l] == '.'){ return sl+','; }else{ return s+''; } } window.ifnull = function(a, b){ if(a == null){ return b; }else{ return a; } } window.nullif = function(a, b){ if(a == b){ return null; }else{ return a; } } String.prototype.capitalize = function(){ var str = this; return str.toLowerCase().replace(/(?:^|\s|["'([{])+\S/g, match => match.toUpperCase()) } String.prototype.Upper = function () { var str = this; return str.toLowerCase().replace(/(?:^|\s|["'([{])+\S/g, match => match.toUpperCase()) } String.prototype.formatRupiah = function(){ var angka = this; if(angka == null || angka == ''){ angka = 0; angka = angka.toFixed(2).replace(/\./g, ','); } var negative = ''; if (angka[0] == '-') { negative = '-'; } var angka = angka.replace(/\./g, ',') var prefix; var number_string = angka.replace(/[^,\d]/g, '').toString(), split = number_string.split(','), sisa = split[0].length % 3, rupiah = split[0].substr(0, sisa), ribuan = split[0].substr(sisa).match(/\d{3}/gi); // tambahkan titik jika yang di input sudah menjadi angka ribuan if(ribuan){ var separator = sisa ? '.' : ''; rupiah += separator + ribuan.join('.'); } rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah; return prefix == undefined ? negative+rupiah : (rupiah ? '' + negative+rupiah : ''); } Number.prototype.currency = function(a){ var s = this; if(s == null){ s = 0; } var num = s.valueOf().toFixed(a).formatRupiah(); return num; } String.prototype.t2b = function(){ var string = JSON.stringify(this); return string.split('').map(function (char) { return char.charCodeAt(0).toString(2); }).join('2'); } String.prototype.b2t = function(){ var array = this.split("2"); var pop = array.map(code => String.fromCharCode(parseInt(code, 2))).join(""); return JSON.parse(pop); } String.prototype.left = function(number){ return this.substring(0,number); } Array.prototype.t2b = function(){ var string = JSON.stringify(this); return string.split('').map(function (char) { return char.charCodeAt(0).toString(2); }).join('2'); } Array.prototype.duplikasi = function(name){ var arr = this.sortArrayObjectAsc(name); var cek = null; var baru = []; arr.forEach(function(d,i){ if(cek != d[name]){ baru.push(d); cek = d[name]; } }) return baru; } window.t2b = function(){ var string = this.toString(); return string.split('').map(function (char) { return char.charCodeAt(0).toString(2); }).join('2'); }; String.prototype.replaceAll = function (find, replace) { var str = this; return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace); }; String.prototype.textonly = function () { return this.replace(/[^a-zA-Z]+/g, ''); }; Array.prototype.search = function(search = ''){ if(typeof search == 'number'){ search = search.toString().toLowerCase(); }else{ search = search.toLowerCase(); } var data = this; return data.filter(function(dat){ if(typeof dat == 'object'){ var f = Object.keys(dat); var numcek = 0; for(var t of f){ var g = dat[t]; if(g != null){ if(typeof g == 'number'){ g = g.toString().toLowerCase(); }else{ g = g.toLowerCase(); } if(numcek == 0){ if(g.indexOf(search) != -1){ numcek = 1; } } } } if(numcek == 1){ return dat; } }else{ if(dat != null){ if(typeof dat == 'number'){ var dats = dat.toString().toLowerCase(); if(dats.indexOf(search) != -1){ return dat } }else{ if(dat.indexOf(search) != -1){ return dat } } } } }) } Array.prototype.cond = function(search = '', name = ''){ if(search != ''){ if(typeof search == 'number'){ search = search.toString().toLowerCase(); }else{ search = search.toLowerCase(); } var data = this; return data.filter(function(dat){ if(typeof dat == 'object'){ var g = dat[name]; var numcek = 0; if(g != null){ if(typeof g == 'number'){ g = g.toString().toLowerCase(); }else{ g = g.toLowerCase(); } if(numcek == 0){ if(g == search){ numcek = 1; } } } if(numcek == 1){ return dat; } }else{ if(dat != null){ if(typeof dat == 'number'){ var dats = dat.toString().toLowerCase(); if(dats == search){ return dat } }else{ if(dat.toLowerCase() == search){ return dat } } } } }) }else{ return []; } } globalThis.cronTab = function(action, tim){ var times = 3000; if(tim != undefined){ if(typeof tim == 'number'){ times = tim; } } var newIdCron = Date.now(); globalThis.cronIdSetUpNewSession = newIdCron; setInterval(function(){ if(newIdCron == globalThis.cronIdSetUpNewSession){ if(action != undefined){ action() } } },times) } globalThis.loadPlugins = function(path='', arr = [], func){ var pt = path; var start = 0; var length = arr.length - 1; var dataScript = ""; (function loadas(){ fetch(path+'/'+arr[start]+'.js?v='+Date.now()).then(function(res){ return res.text(); }) .then(function(textScript){ dataScript += textScript+"\n"; if(start == length){ eval(dataScript); if(func != undefined){ func(); } }else{ start++; loadas(); } }) })(); } globalThis.lE = function(name){ return globalThis[name]; } globalThis.props = function(params = null, value = null){ if(params != null){ if(window.propertyWebsiteApp == undefined){ window.propertyWebsiteApp = {} } if(value != null){ window.propertyWebsiteApp[params] = value; }else{ if(window.propertyWebsiteApp[params] != undefined){ return window.propertyWebsiteApp[params]; }else{ return null; } } }else{ return null; } } // proto element window.localD = { read : function(name){ if(localStorage.getItem('localdata') == undefined){ var dat = {} localStorage.setItem('localdata', JSON.stringify(dat)); } if( JSON.parse(localStorage.getItem('localdata'))[name] == undefined ){ return 0; }else{ return JSON.parse(localStorage.getItem('localdata'))[name]; } }, write: function(name, data){ if(localStorage.getItem('localdata') == undefined){ var dat = {} localStorage.setItem('localdata', JSON.stringify(dat)); } var y = JSON.parse(localStorage.getItem('localdata')); y[name] = data; localStorage.setItem('localdata', JSON.stringify(y)) } } Node.prototype.readonly = function(){ this.setAttribute('readonly',''); this.style.background = '#ddd'; } Node.prototype.inputRupiah = function(){ this.addEventListener('keyup', function(){ if(this.value != ''){ this.value = this.value.lastDotToComa().number(true).currency(); } }, false) } Node.prototype.uuid = function(){ function generateUUID() { // Public Domain/MIT var d = new Date().getTime();//Timestamp var d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now()*1000)) || 0;//Time in microseconds since page-load or 0 if unsupported return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16;//random number between 0 and 16 if(d > 0){//Use timestamp until depleted r = (d + r)%16 | 0; d = Math.floor(d/16); } else {//Use microseconds since page-load if supported r = (d2 + r)%16 | 0; d2 = Math.floor(d2/16); } return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); }); } this.value = generateUUID(); } Node.prototype.uuidtime = function(aliase = ''){ this.value = aliase+Date.now(); } globalThis.getform = function(id){ return document.querySelector('#form-get-app'+act.data.id+' #'+id); } globalThis.selectNode = function(a){ return document.querySelector(a); } globalThis.getNode = function(id){ return globalThis[id]; } globalThis.Keys = function(a){ return Object.keys(a); } const calculator = { run : function(id, height=30, output = null){ this.data = {} this.data.newCalculator = document.getElementById(id) this.data.idaction = 'api-cal'+Date.now(); globalThis[this.data.idaction] = function(a){ if(a.getAttribute('data-val') != undefined){ output(a.getAttribute('data-val'), a) }else{ if(a.innerText != '.' && a.innerText != ''){ var val = Number(a.innerText); if(output != null){ output(val, a) } }else{ if(output != null){ output(a.innerText, a) } } } } this.data.newCalculator.innerHTML = `
1
2
3
4
5
6
7
8
9
0
.
Qty
Disc
Price
Del
`; } } const slicing = function(string, a = 1000){ var start = a; var arrayBaru = []; var total = Math.ceil(string.length / a); for(var n = 0; n < total; n++){ var f = (n + 1) * start; var x = n * start; arrayBaru.push(string.substring(x,f)); } return arrayBaru; } const upload = function(url = '/admin/upload', path = '', name = 'data.post' ,data = null, funcpro, funcres){ var rendr = data; rendr = slicing(rendr, 2150000); var length = rendr.length; var start = 0; var itm = Date.now(); function uploadProsses(){ if (start < length) { funcpro(Math.round(((start+1) / length) * 100)+'%'); $.ajax({ url: url, method: 'POST', dataType: 'text', data: { _token: $('meta[name=csrf-token]').attr('content'), ok: rendr[start], start: start, end: length - 1, path: path, tipe: path + name, enm: itm }, success: function(e){ if(start == (length - 1)){ funcres(e); }else{ start += 1; uploadProsses(); } } }) } } uploadProsses() } const text2Binary = function( string) { string = JSON.stringify(string); return string.split('').map(function (char) { return char.charCodeAt(0).toString(2); }).join('2'); } const binary2text = function(str = null) { var array = str.split("2"); var pop = array.map(code => String.fromCharCode(parseInt(code, 2))).join(""); return JSON.parse(pop); } String.prototype.replaceAll = function(search, replacement) { var target = this; return target.replace(new RegExp(search, 'g'), replacement); }; const ConfStyle = function (element) { element.__proto__.inputRupiah = function () { this.addEventListener('keyup', function () { if (this.value != '') { this.value = this.value.lastDotToComa().number(true).currency(); } }, false) return this; } element.__proto__.displayFlex = function () { this.style.display = 'flex'; return this; } element.__proto__.displayInlineFlex = function () { this.style.display = 'inline-flex'; return this; } element.__proto__.displayInlineBlock = function () { this.style.display = 'inline-block'; return this; } element.__proto__.displayBlock = function () { this.style.display = 'block'; return this; } element.__proto__.displayInline = function () { this.style.display = 'inline'; return this; } element.__proto__.displayGrid = function () { this.style.display = 'grid'; return this; } element.__proto__.displayNone = function () { this.style.display = 'none'; return this; } element.__proto__.maxHeight = function (number) { this.style.maxHeight = number + 'px'; return this; } element.__proto__.h = function (number) { if (number != undefined) { this.style.height = number + 'px'; return this; } else { return this.clientHeight; } } element.__proto__.setH100 = function (element) { if (element != undefined) { this.style.height = 'calc(100vh - ' + (element.clientHeight) + 'px)'; return this; } else { this.style.height = 'calc(100vh)'; return this; } } }