uhh apparently i just never committed these
This commit is contained in:
parent
b43b8837ef
commit
78ad0761b3
1 changed files with 31 additions and 1 deletions
|
|
@ -27,7 +27,37 @@ export function setEmptyParameter (pageContent, paramName, value) {
|
|||
* name.
|
||||
*/
|
||||
const existingParameterRegExp = paramName =>
|
||||
new RegExp(`^( *)\\|( *)${regExpEscape(paramName)}( *)=( *).*$`, 'm');
|
||||
new RegExp(`^( *)\\|( *)${regExpEscape(paramName)}( *)=( *)(.*)$`, 'm');
|
||||
|
||||
/**
|
||||
* Gets the value of an existing parameter.
|
||||
* @param {string} pageContent
|
||||
* @param {string} paramName
|
||||
* @returns {string | null} The value, or `null` if the parameter doesn't exist
|
||||
*/
|
||||
export function readExistingParameter (pageContent, paramName) {
|
||||
let regexp = existingParameterRegExp(paramName);
|
||||
let match;
|
||||
if ((match = pageContent.match(regexp))) {
|
||||
return match[5];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of an existing parameter.
|
||||
* @param {string} pageContent
|
||||
* @param {string} paramName
|
||||
* @param {string} value
|
||||
* @returns {string | null}
|
||||
*/
|
||||
export function setExistingParameter (pageContent, paramName, value) {
|
||||
const regexp = existingParameterRegExp(paramName);
|
||||
if (pageContent.match(regexp)) {
|
||||
return pageContent.replace(regexp, `$1|$2${paramName}$3=$4${value}`)
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a new parameter before or after an existing parameter.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue