PageSourceSearch

https://pedroth.github.io/src/Database.js

js pedroth.github.io collected 2026-10-03 09:45:04 UTC 894 bytes, 34 lines download raw bytes

1import { date2int, shuffle } from "./Utils.js";
2
3let database = undefined;
4const Database = {};
5
6Database.read = async () => {
7    if (!database) {
8        database = await fetch("/database/db.json").then(x => x.json());
9    }
10    return database;
11};
12
13Database.readPostsAsMap = async () => {
14    if (!database) await Database.read();
15    if (!database.postsMap) {
16        Database.postsMap = database.posts.reduce((acc, post) => {
17            acc[post.id] = post; return acc;
18        }, {});
19    }
20    return Database.postsMap;
21};
22
23Database.readSortedPosts = async () => {
24    if (!database) await Database.read();
25    const posts = [...database.posts];
26    return posts.sort((a, b) => date2int(b.lastUpdateDate) - date2int(a.lastUpdateDate));
27};
28
29Database.readRandomPosts = async () => {
30    if (!database) await Database.read();
31    return shuffle(database.posts);
32}
33
34export default Database;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.