NotificationLatch/src/subjectparser.js

31 lines
541 B
JavaScript

class SubjectParser
{
static create = () => new this();
parse(subject)
{
// Possible formats:
// Title
// |id| Title
// |id-sound| Title
// |-sound| Title
const match = subject.match(/^(?:\|([^,]*?)(?:-(.+?)){0,1}\|){0,1}\s*(.+?)$/m);
if (match == null)
return {
id: subject,
sound: null,
title: subject
};
return {
id: match[1] || match[3],
sound: match[2] || null,
title: match[3]
};
};
}
module.exports = SubjectParser;