Skip to content

Commit

Permalink
Optimize IcalEvent.fold() for all-ASCII lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Nov 3, 2021
1 parent 63d5734 commit cb99c01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/icalendar",
"version": "4.14.2",
"version": "4.14.3",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"keywords": [
"ical",
Expand Down
11 changes: 11 additions & 0 deletions src/icalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function appendTrackingToUrl(url, options) {
}

const encoder = new TextEncoder();
const char74re = /(.{1,74})/g;

/**
* Represents an RFC 2445 iCalendar VEVENT
Expand Down Expand Up @@ -230,6 +231,16 @@ export class IcalEvent {
* @return {string}
*/
static fold(line) {
let isASCII = true;
for (let i = 0; i < line.length; i++) {
if (line.charCodeAt(i) > 255) {
isASCII = false;
break;
}
}
if (isASCII) {
return line.length <= 74 ? line : line.match(char74re).join('\r\n ');
}
if (encoder.encode(line).length <= 74) {
return line;
}
Expand Down

0 comments on commit cb99c01

Please sign in to comment.