-
Notifications
You must be signed in to change notification settings - Fork 0
/
export-jsonl.js
61 lines (54 loc) · 1.68 KB
/
export-jsonl.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import fs from 'fs';
function findSecondInstanceIndex(str, char) {
// Find the index of the first instance of the character
const firstIndex = str.indexOf(char);
// Check if the first instance was found and if there is a second instance
if (firstIndex !== -1) {
// Find the index of the second instance of the character, starting the search after the first instance
const secondIndex = str.indexOf(char, firstIndex + 1);
return secondIndex;
} else {
// If the character is not found at all, return -1
return -1;
}
}
const lines = fs
.readFileSync('public/data/operators.md')
.toString()
.split('\n');
let currentDomain = '';
let currentCategory = '';
const operators = [];
lines.forEach((line) => {
if (line.startsWith('## ')) {
// get the value inside the brackets
const domain = line.match(/\[(.*)\]/)[1];
currentDomain = domain;
currentCategory = line.replace('## ', '').replace(domain, '').trim();
} else if (line.startsWith('### ')) {
currentCategory = line.replace('### ', '').trim();
} else if (line.startsWith('- [')) {
const aliases = [];
const regex = /\[(.*?)\]/g;
let match;
while ((match = regex.exec(line)) !== null) {
aliases.push(match[1]);
}
const description = line.slice(line.lastIndexOf(':') + 1).trim();
const domain = {
'Gen Common Operators': 'all',
'gen\\~ Operators': 'audio',
'Jitter Operators': 'matrix',
}[currentDomain];
operators.push({
category: currentCategory,
aliases,
description,
domain,
});
}
});
fs.writeFileSync(
'public/data/operators.jsonl',
operators.map((operator) => JSON.stringify(operator)).join('\n')
);