-
Notifications
You must be signed in to change notification settings - Fork 0
/
setNote.js
32 lines (28 loc) · 990 Bytes
/
setNote.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import setNoteHtml from './setNoteHtml.js';
import idRegex from './idRegex.js';
/**
* Stores a note containing the provided data under the given ID in Apple Notes.
*
* @param {string} type The name of the type folder.
* @param {string} id The name/title of the note.
* @param {Record<string, string>} data The data to store in the note.
*/
export default async function setNote(type, id, data) {
if (!idRegex.exec(id)) {
throw new Error(`Malformaed ID, expected ${idRegex}: "${id}"`);
}
let html = [];
html.push(`<div><h1>${id}</h1></div>`);
html.push(`<div><br></div>`);
for (const key in data) {
html.push(`<div><h2>${key}</h2></div>`);
html.push(`<div>${data[key]}</div>`);
html.push(`<div><br></div>`);
}
html.pop();
await setNoteHtml(type, id, html.join('\n'));
}
// Test via `node setNote`
// const data = await (await import('./getNote.js')).default('items', '1');
// console.log(data);
// console.log(await setNote('items', '3', data));