feat: Add DB
This commit is contained in:
11
utils/db/format-categories.js
Normal file
11
utils/db/format-categories.js
Normal 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
3
utils/db/format-json.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function (entries) {
|
||||
return `{\n"count": ${entries.length},\n"entries": ${JSON.stringify(entries, null, 4)}}`
|
||||
}
|
||||
22
utils/db/format-resources.js
Normal file
22
utils/db/format-resources.js
Normal 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()
|
||||
}
|
||||
25
utils/db/group-row-content.js
Normal file
25
utils/db/group-row-content.js
Normal 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 }
|
||||
})
|
||||
}
|
||||
14
utils/db/separate-tables.js
Normal file
14
utils/db/separate-tables.js
Normal 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
11
utils/db/write-to-file.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user