NotificationLatch/lib/subjectparser.js

27 lines
445 B
JavaScript

function 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 = {
parse
}