Merge Complete

This commit is contained in:
Luis Fernando Molina committed 2020-11-20 20:28:04 +01:00
1 parent 482ef7a81a
commit dabe23d505
6483 files changed

No files matched your search

@@ -0,0 +1,12 @@
import { client } from '../graphql/apollo'
import { ECOSYSTEM_QUERY } from '../graphql/EcosystemQuery'
import Log from './log'
export async function setInitialEcosystem() {
try {
const ecosystem = await client.query({ query: ECOSYSTEM_QUERY })
window.localStorage.setItem('ecosystem', JSON.stringify(ecosystem.data.web_GetEcosystem))
} catch (error) {
Log.error('Error getting the ecosystem: ' + error)
}
}
@@ -0,0 +1,70 @@
export function isDefined (d) {
return d !== null && typeof d !== 'undefined'
}
export function isNotDefined (d) {
return !isDefined(d)
}
export const isArray = Array.isArray
export function isObject (d) {
return isDefined(d) && typeof d === 'object' && !Array.isArray(d)
}
export function isEmpty (obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) return false
}
return true
}
export function isString (value) {
return typeof value === 'string' || value instanceof String
}
export function validObject (object, ...keys) {
return keys.reduce((a, b) => (a || {})[b], object) !== undefined
}
export function mergeDeep (target, ...sources) {
if (!sources.length) return target
const source = sources.shift()
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} })
mergeDeep(target[key], source[key])
} else {
Object.assign(target, { [key]: source[key] })
}
}
}
return mergeDeep(target, ...sources)
}
export function deleteCookie (c) {
document.cookie.split(';').forEach(function (c) {
document.cookie = c
.replace(/^ +/, '')
.replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/')
})
}
export function slugify (string) {
const a = 'àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'
const b = 'aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------'
const p = new RegExp(a.split('').join('|'), 'g')
return string
.toString()
.toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w-]+/g, '') // Remove all non-word characters
.replace(/--+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, '') // Trim - from end of text
}
@@ -0,0 +1,5 @@
const getItem = async name => window.localStorage.getItem(name)
const setItem = async (name, value) => window.localStorage.setItem(name, value)
const removeItem = async name => window.localStorage.removeItem(name)
export { getItem, setItem, removeItem }
@@ -0,0 +1,39 @@
import debug from 'debug'
const BASE = 'superalgos'
const COLOURS = {
info: 'blue',
warn: 'orange',
error: 'red'
}
class Log {
generateMessage (level, message, source) {
// Set the prefix which will cause debug to enable the message
const namespace = `${BASE}:${level}`
const createDebug = debug(namespace)
// Set the colour of the message based on the level
createDebug.color = COLOURS[level]
if (source) {
createDebug(source, message)
} else {
createDebug(message)
}
}
info (message, source) {
return this.generateMessage('info', message, source)
}
warn (message, source) {
return this.generateMessage('warn', message, source)
}
error (message, source) {
return this.generateMessage('error', message, source)
}
}
export default new Log()