44 lines
895 B
TypeScript
44 lines
895 B
TypeScript
|
const decoder = new TextDecoder("utf-8");
|
||
|
const data = await Deno.readFile("ical.ics");
|
||
|
const text = decoder.decode(data);
|
||
|
|
||
|
function chunk(str, size) {
|
||
|
const numChunks = Math.ceil(str.length / size)
|
||
|
const chunks = new Array(numChunks)
|
||
|
|
||
|
for (let i = 0, o = 0; i < numChunks; ++i, o += size) {
|
||
|
chunks[i] = str.substr(o, size)
|
||
|
}
|
||
|
|
||
|
return chunks
|
||
|
}
|
||
|
|
||
|
const lines = text
|
||
|
.split('\r\n')
|
||
|
.reduce((newics, line) => {
|
||
|
if (line.startsWith(' ')) {
|
||
|
return newics + line.replace(/^ /, '');
|
||
|
}
|
||
|
|
||
|
return newics + '\n' + line;
|
||
|
}, "")
|
||
|
.split('\n')
|
||
|
.map(line => line
|
||
|
.replace(/<br>/g, '\\n')
|
||
|
.replace(/<[^>]*>/g, '')
|
||
|
.replace(/>\\;/g, '>')
|
||
|
.replace(/<\\;/g, '<')
|
||
|
.replace(/ \\;/g, ' ')
|
||
|
.replace(/&\\;/g, '&')
|
||
|
.replace(/"\\;/g, '"')
|
||
|
)
|
||
|
.reduce((allLines, line) => [
|
||
|
...allLines,
|
||
|
chunk(line, 40).join('\r\n '),
|
||
|
], [])
|
||
|
.join('\r\n');
|
||
|
|
||
|
console.log(lines);
|
||
|
|
||
|
|