feat: Add DB

This commit is contained in:
Marcel Cruz
2022-11-18 18:51:59 +01:00
parent ff0ca69170
commit 745a209957
13 changed files with 13729 additions and 1 deletions

View File

@@ -0,0 +1,11 @@
module.exports = function (categories) {
return categories.map(category => ({
name: category,
slug: category
.trim()
.toLowerCase()
.replace(/&/g, 'and')
.replace(/[^A-Z0-9/]+/gi, '-')
.replace(/\s/g, '-'),
}))
}

3
utils/db/format-json.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = function (entries) {
return `{\n"count": ${entries.length},\n"entries": ${JSON.stringify(entries, null, 4)}}`
}

View File

@@ -0,0 +1,22 @@
module.exports = function (tables) {
return tables
.map(({ name: categoryName, rows }) => {
return rows.map(({ link, name: entryName, description: rawDescription }) => {
const [description, auth, https, cors] = rawDescription
.split('|')
.map(item => item.trim())
.filter(item => item)
return {
API: entryName,
Description: description,
Auth: auth?.toLowerCase() === 'no' ? '' : auth,
HTTPS: https?.toLowerCase() === 'yes' ? true : false,
Cors: cors?.toLowerCase(),
Link: link,
Category: categoryName,
}
})
})
.flat()
}

View File

@@ -0,0 +1,25 @@
module.exports = function (tables) {
return tables.map(({ name, rows }) => {
const content = []
rows.forEach((child, i) => {
if (i === 0) return // Table header
if (child.type === 'link') {
content.push({
link: child.url,
name: child.children[0].value,
description: '',
})
} else {
const lastContentItem = content.pop()
content.push({
...lastContentItem,
description: `${lastContentItem.description} ${child.value}`,
})
}
})
return { name, rows: content }
})
}

View File

@@ -0,0 +1,14 @@
module.exports = function ({ readme, indexListIndex }) {
return readme
.map((child, i) => {
if (i <= indexListIndex) return
if (child.type === 'heading' && child.depth === 3) {
const name = child.children[0].value
const rows = readme[i + 1].children
return { name, rows }
}
})
.filter(table => table)
}

11
utils/db/write-to-file.js Normal file
View File

@@ -0,0 +1,11 @@
const fs = require('fs')
module.exports = async function ({ data, filePath }) {
await fs.writeFile(filePath, data, error => {
if (error) {
throw new Error(`Error writing to file: ${error}`)
}
})
return
}