Mailspring/internal_packages/composer-signature/lib/signature-utils.es6
Ben Gotow 94badcda15 es6(*): convert 20+ source files used in example packages to ES2016
There could be a few lurking bugs. Please test!
2016-02-29 18:47:22 -08:00

23 lines
754 B
JavaScript

export default {
applySignature(body, signature) {
const signatureRegex = /<div class="nylas-n1-signature">.*<\/div>/;
let signatureHTML = '<div class="nylas-n1-signature">' + signature + '</div>';
let insertionPoint = body.search(signatureRegex);
let newBody = body;
// If there is a signature already present
if (insertionPoint !== -1) {
// Remove it
newBody = newBody.replace(signatureRegex, "");
} else {
insertionPoint = newBody.indexOf('<blockquote');
if (insertionPoint === -1) {
insertionPoint = newBody.length;
signatureHTML = '<br/><br/>' + signatureHTML;
}
}
return newBody.slice(0, insertionPoint) + signatureHTML + newBody.slice(insertionPoint);
},
};