mirror of
https://github.com/BioArchLinux/Rosa.git
synced 2025-03-10 12:02:43 +00:00
fix packager field format
This commit is contained in:
parent
29d45fd9ff
commit
b742ad5f0b
1 changed files with 13 additions and 13 deletions
|
@ -1,24 +1,24 @@
|
||||||
|
const rePackagerField = /\(on behalf of (?<packager>.*)\)/
|
||||||
const reMailField = /<(?<email>.*)>/
|
const reMailField = /<(?<email>.*)>/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generate <a> HTML code for email address
|
||||||
|
* @param {String} address email address
|
||||||
|
* @returns {String} HTML code
|
||||||
|
*/
|
||||||
function generateMailtoAnchor (address) {
|
function generateMailtoAnchor (address) {
|
||||||
return `<a href="mailto:${address}">${address}</a>`
|
return `<a href="mailto:${address}">${address}</a>`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* replace range of string with another string
|
* format packager field
|
||||||
* "... [index+length] ..." -> "... replacement ..."
|
* @param {String} desc packager field in string
|
||||||
* @param {Number} start start position of range
|
* @returns {String} rendered HTML code
|
||||||
* @param {Number} length length of range
|
|
||||||
* @param {String} replacement replacement string
|
|
||||||
* @returns {String} Result
|
|
||||||
*/
|
*/
|
||||||
function replaceRange (start, length, replacement) {
|
|
||||||
return this.substr(0, start) + replacement + this.substr(start + length)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatPackager (desc) {
|
export function formatPackager (desc) {
|
||||||
if (desc === undefined) { return }
|
if (desc === undefined) { return }
|
||||||
const mailMatch = reMailField.exec(desc)
|
const packager = rePackagerField.exec(desc).groups.packager
|
||||||
const htmlAnchor = generateMailtoAnchor(mailMatch.groups.email)
|
const mailAddress = reMailField.exec(desc).groups.email
|
||||||
return replaceRange.call(desc, mailMatch.index, mailMatch[0].length, `<${htmlAnchor}>`)
|
|
||||||
|
return `${packager} <${generateMailtoAnchor(mailAddress)}>`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue