24 lines
645 B
JavaScript
24 lines
645 B
JavaScript
import Axios from 'axios'
|
|
|
|
export async function search(searchTerm, maxResults = Infinity) {
|
|
const regex = new RegExp(searchTerm, 'i')
|
|
const result = []
|
|
const data = await import('../../data/gutenberg.json').then(
|
|
module => module.default
|
|
)
|
|
for (let entry of data) {
|
|
if (regex.test(entry.title[0]) || regex.test(entry.author[0])) {
|
|
result.push(entry)
|
|
}
|
|
|
|
if (result.length >= maxResults) break
|
|
}
|
|
return result
|
|
}
|
|
|
|
export async function getBook(bookId) {
|
|
const url = `https://gutenberg.muperfredi.de/texts/${bookId}/stripped-body`
|
|
const text = await Axios.get(url).then(res => res.data.body)
|
|
return text
|
|
}
|