mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
format & fix bad ts typing
This commit is contained in:
parent
763766997a
commit
a694b82a74
@ -37,24 +37,24 @@ export const clientInfo = {
|
|||||||
export function getCircularReplacer() {
|
export function getCircularReplacer() {
|
||||||
const seen = new WeakSet();
|
const seen = new WeakSet();
|
||||||
return (key, value) => {
|
return (key, value) => {
|
||||||
if (typeof value === "object" && value !== null) {
|
if (typeof value === "object" && value !== null) {
|
||||||
if (seen.has(value)) {
|
if (seen.has(value)) {
|
||||||
return { __cycle_flag: true }
|
return { __cycle_flag: true }
|
||||||
}
|
|
||||||
seen.add(value)
|
|
||||||
}
|
}
|
||||||
return value
|
seen.add(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function __proto__filterSchematizedArray(data) {
|
export function __proto__filterSchematizedArray(data) {
|
||||||
let tmp = []
|
let tmp = []
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
data.forEach(async (element: { require }) => {
|
data.forEach(async (element) => {
|
||||||
if (typeof(element.require) !== 'undefined') {
|
if (typeof (element.require) !== 'undefined') {
|
||||||
const validRequire = await window.requireQuery(element.require)
|
const validRequire = await window.requireQuery(element.require)
|
||||||
validRequire? tmp.push(element) : null
|
validRequire ? tmp.push(element) : null
|
||||||
}else{
|
} else {
|
||||||
tmp.push(element)
|
tmp.push(element)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -64,19 +64,19 @@ export function getCircularReplacer() {
|
|||||||
|
|
||||||
export function decycle(obj, stack = []) {
|
export function decycle(obj, stack = []) {
|
||||||
if (!obj || typeof obj !== 'object')
|
if (!obj || typeof obj !== 'object')
|
||||||
return obj;
|
return obj;
|
||||||
|
|
||||||
if (stack.includes(obj)) {
|
if (stack.includes(obj)) {
|
||||||
return { __cycle_flag: true }
|
return { __cycle_flag: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
let s = stack.concat([obj]);
|
let s = stack.concat([obj]);
|
||||||
|
|
||||||
return Array.isArray(obj)
|
return Array.isArray(obj)
|
||||||
? obj.map(x => decycle(x, s))
|
? obj.map(x => decycle(x, s))
|
||||||
: Object.fromEntries(
|
: Object.fromEntries(
|
||||||
Object.entries(obj)
|
Object.entries(obj)
|
||||||
.map(([k, v]) => [k, decycle(v, s)]));
|
.map(([k, v]) => [k, decycle(v, s)]));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBuild() {
|
export function getBuild() {
|
||||||
@ -89,7 +89,7 @@ export function getBuild() {
|
|||||||
}
|
}
|
||||||
const buildPath = path.resolve(__dirname, "./dist")
|
const buildPath = path.resolve(__dirname, "./dist")
|
||||||
const data = JSON.parse(fs.readFileSync(`${buildPath}/build.json`))
|
const data = JSON.parse(fs.readFileSync(`${buildPath}/build.json`))
|
||||||
if (typeof(data) !== "undefined" && Array.isArray(data)) {
|
if (typeof (data) !== "undefined" && Array.isArray(data)) {
|
||||||
utils.__legacy____legacy__objectToArray(data).forEach((e) => {
|
utils.__legacy____legacy__objectToArray(data).forEach((e) => {
|
||||||
build[e.key] = e.value
|
build[e.key] = e.value
|
||||||
})
|
})
|
||||||
@ -101,29 +101,29 @@ export function getBuild() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function queryIndexer(array, callback, params) {
|
export function queryIndexer(array, callback, params) {
|
||||||
if(!array) return false
|
if (!array) return false
|
||||||
|
|
||||||
if (Array.isArray(array)) {
|
if (Array.isArray(array)) {
|
||||||
let opt = {
|
let opt = {
|
||||||
regex: /:id/gi
|
regex: /:id/gi
|
||||||
}
|
|
||||||
|
|
||||||
if (params) {
|
|
||||||
opt = { ...opt, ...params }
|
|
||||||
}
|
|
||||||
|
|
||||||
array.forEach((e) =>{
|
|
||||||
if (e.match != null && e.to != null) {
|
|
||||||
const pathMatch = pathMatchRegexp(e.match, window.location.pathname)
|
|
||||||
if (pathMatch != null) {
|
|
||||||
return callback(e.to.replace(opt.regex, pathMatch[1]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params) {
|
||||||
|
opt = { ...opt, ...params }
|
||||||
|
}
|
||||||
|
|
||||||
|
array.forEach((e) => {
|
||||||
|
if (e.match != null && e.to != null) {
|
||||||
|
const pathMatch = pathMatchRegexp(e.match, window.location.pathname)
|
||||||
|
if (pathMatch != null) {
|
||||||
|
return callback(e.to.replace(opt.regex, pathMatch[1]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createScreenshotFromElement(element){
|
export function createScreenshotFromElement(element) {
|
||||||
if (!element) return false
|
if (!element) return false
|
||||||
html2canvas(element, {
|
html2canvas(element, {
|
||||||
useCORS: true,
|
useCORS: true,
|
||||||
@ -135,20 +135,20 @@ export function createScreenshotFromElement(element){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generatePostURI(id){
|
export function generatePostURI(id) {
|
||||||
if(window.location.origin && id){
|
if (window.location.origin && id) {
|
||||||
return `${window.location.origin}/post/${id}`
|
return `${window.location.origin}/post/${id}`
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function writeToClipboard(text){
|
export function writeToClipboard(text) {
|
||||||
navigator.clipboard.writeText(text)
|
navigator.clipboard.writeText(text)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
libs.appInterface.notify.info('Copy to clipboard')
|
libs.appInterface.notify.info('Copy to clipboard')
|
||||||
}, () => {
|
}, () => {
|
||||||
/* failure */
|
/* failure */
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// [Experimental], not in use
|
// [Experimental], not in use
|
||||||
@ -161,7 +161,7 @@ export function getGlobals(params, callback) {
|
|||||||
url: params.server
|
url: params.server
|
||||||
}
|
}
|
||||||
|
|
||||||
params.global? req.global = params.global : null
|
params.global ? req.global = params.global : null
|
||||||
|
|
||||||
let urlString = `${req.url}/${req.global}.json`
|
let urlString = `${req.url}/${req.global}.json`
|
||||||
console.log(urlString)
|
console.log(urlString)
|
||||||
@ -172,28 +172,28 @@ export function getGlobals(params, callback) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isOs(os){
|
export function isOs(os) {
|
||||||
if(process){
|
if (process) {
|
||||||
return process.platform === os? true : false
|
return process.platform === os ? true : false
|
||||||
}else{
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function imageToBase64(img, callback){
|
export function imageToBase64(img, callback) {
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
reader.addEventListener('load', () => callback(reader.result))
|
reader.addEventListener('load', () => callback(reader.result))
|
||||||
reader.readAsDataURL(img)
|
reader.readAsDataURL(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function urlToBase64(url, callback){
|
export function urlToBase64(url, callback) {
|
||||||
let xhr = new XMLHttpRequest();
|
let xhr = new XMLHttpRequest();
|
||||||
xhr.onload = function() {
|
xhr.onload = function () {
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
reader.onloadend = function() {
|
reader.onloadend = function () {
|
||||||
callback(reader.result);
|
callback(reader.result);
|
||||||
}
|
}
|
||||||
reader.readAsDataURL(xhr.response);
|
reader.readAsDataURL(xhr.response);
|
||||||
};
|
};
|
||||||
xhr.open('GET', url);
|
xhr.open('GET', url);
|
||||||
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
|
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
|
||||||
@ -201,7 +201,7 @@ export function urlToBase64(url, callback){
|
|||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function b64toBlob(b64Data, contentType='', sliceSize=512){
|
export function b64toBlob(b64Data, contentType = '', sliceSize = 512) {
|
||||||
const byteCharacters = atob(b64Data);
|
const byteCharacters = atob(b64Data);
|
||||||
const byteArrays = [];
|
const byteArrays = [];
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ export function b64toBlob(b64Data, contentType='', sliceSize=512){
|
|||||||
byteArrays.push(byteArray);
|
byteArrays.push(byteArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
const blob = new Blob(byteArrays, {type: contentType});
|
const blob = new Blob(byteArrays, { type: contentType });
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,8 +226,8 @@ export function b64toBlob(b64Data, contentType='', sliceSize=512){
|
|||||||
*
|
*
|
||||||
* @param {object} payload - Generation Data
|
* @param {object} payload - Generation Data
|
||||||
*/
|
*/
|
||||||
export function downloadDecodedURI(payload){
|
export function downloadDecodedURI(payload) {
|
||||||
if(!payload) return false
|
if (!payload) return false
|
||||||
let { data, type, charset, filename } = payload
|
let { data, type, charset, filename } = payload
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -240,15 +240,15 @@ export function downloadDecodedURI(payload){
|
|||||||
}
|
}
|
||||||
let tmp = document.createElement('a')
|
let tmp = document.createElement('a')
|
||||||
tmp.href = `data:${type};charset=${charset},${encodeURIComponent(data)}`
|
tmp.href = `data:${type};charset=${charset},${encodeURIComponent(data)}`
|
||||||
tmp.download= filename
|
tmp.download = filename
|
||||||
tmp.click()
|
tmp.click()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handle({ msg: error, code: 120 })
|
handle({ msg: error, code: 120 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function downloadEncodedURI(payload){
|
export function downloadEncodedURI(payload) {
|
||||||
if(!payload) return false
|
if (!payload) return false
|
||||||
let { data, filename } = payload
|
let { data, filename } = payload
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -261,15 +261,15 @@ export function downloadEncodedURI(payload){
|
|||||||
}
|
}
|
||||||
let tmp = document.createElement('a')
|
let tmp = document.createElement('a')
|
||||||
tmp.href = data
|
tmp.href = data
|
||||||
tmp.download= filename
|
tmp.download = filename
|
||||||
tmp.click()
|
tmp.click()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handle({ msg: error, code: 120 })
|
handle({ msg: error, code: 120 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GetPropertyValue(object, dataToRetrieve) {
|
export function GetPropertyValue(object, dataToRetrieve) {
|
||||||
dataToRetrieve.split('.').forEach(function(token) {
|
dataToRetrieve.split('.').forEach(function (token) {
|
||||||
if (object) object = object[token];
|
if (object) object = object[token];
|
||||||
})
|
})
|
||||||
return object;
|
return object;
|
||||||
@ -294,7 +294,7 @@ export function objectLast(array, n) {
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
export function arrayToObject(array) {
|
export function arrayToObject(array) {
|
||||||
if(!array) return false
|
if (!array) return false
|
||||||
let tmp = []
|
let tmp = []
|
||||||
|
|
||||||
array.forEach((e) => {
|
array.forEach((e) => {
|
||||||
@ -518,34 +518,34 @@ export function setLocale(language) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_value(source,key){
|
export function get_value(source, key) {
|
||||||
if( !key || !source ) return false
|
if (!key || !source) return false
|
||||||
try {
|
try {
|
||||||
const find = source.find(item => {
|
const find = source.find(item => {
|
||||||
return item.id === key
|
return item.id === key
|
||||||
})
|
})
|
||||||
return find.value
|
return find.value
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function iatToString(iat){
|
export function iatToString(iat) {
|
||||||
return new Date(iat * 1000).toLocaleString()
|
return new Date(iat * 1000).toLocaleString()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateGUID( lenght = 6 ){
|
export function generateGUID(lenght = 6) {
|
||||||
let text = ""
|
let text = ""
|
||||||
const possibleChars = "abcdefghijklmnopqrstuvwxyz0123456789"
|
const possibleChars = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
|
|
||||||
for ( let i = 0; i < 6; i++ )
|
for (let i = 0; i < 6; i++)
|
||||||
text += possibleChars.charAt ( Math.floor ( Math.random () * possibleChars.length ) )
|
text += possibleChars.charAt(Math.floor(Math.random() * possibleChars.length))
|
||||||
|
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateRandomId( length = 15 ){
|
export function generateRandomId(length = 15) {
|
||||||
return Math.random ().toString ( 36 ).substring ( 0, length );
|
return Math.random().toString(36).substring(0, length);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user