Clean functions
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
** Get API function
|
||||
*/
|
||||
export const api = async (query) => {
|
||||
const res = await fetch('http://api.housesof.localhost/how/gql?access_token=NJk0urljsdSvApUDzWxGgoO6', {
|
||||
method: 'post',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ query: `{${query}}` })
|
||||
})
|
||||
const data = await res.json()
|
||||
return data.data
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Load API function
|
||||
*/
|
||||
export const loadAPI = async (requests = []) => {
|
||||
// Fetch all requests
|
||||
return await Promise.all(requests.map(req => api(req)
|
||||
.then(res => res.json())
|
||||
.then(data => data.data)
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Slufigy a string
|
||||
*/
|
||||
export const slug = string => {
|
||||
return string.toString().toLowerCase().trim()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/&/g, '-and-')
|
||||
.replace(/[^\w\-]+/g, '')
|
||||
.replace(/\-\-+/g, '-')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user