mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-24 06:22:26 +01:00
XPath validators for 'extendhinttags', 'nextpattern', 'prevpattern'.
This commit is contained in:
@@ -48,6 +48,9 @@ const Option = Class("Option", {
|
||||
if (this.type in Option.joinValues)
|
||||
this.joinValues = Option.joinValues[this.type];
|
||||
|
||||
if (this.type in Option.testValues)
|
||||
this.testValues = Option.testValues[this.type];
|
||||
|
||||
this._op = Option.ops[this.type];
|
||||
|
||||
if (arguments.length > 3) {
|
||||
@@ -325,6 +328,8 @@ const Option = Class("Option", {
|
||||
*/
|
||||
setter: null,
|
||||
|
||||
testValues: function (values, validator) validator(values),
|
||||
|
||||
/**
|
||||
* @property {function} The function called to validate the option's value
|
||||
* when set.
|
||||
@@ -383,7 +388,7 @@ const Option = Class("Option", {
|
||||
return re;
|
||||
},
|
||||
unparseRegex: function (re) re.bang + Option.quote(re.source.replace(/\\(.)/g, function (m, n1) n1 == "/" ? n1 : m), /^!|:/) +
|
||||
(typeof re.result == "string" ? ":" + Option.quote(re.result) : ""),
|
||||
(typeof re.result === "string" ? ":" + Option.quote(re.result) : ""),
|
||||
|
||||
getKey: {
|
||||
stringlist: function (k) this.values.indexOf(k) >= 0,
|
||||
@@ -427,6 +432,12 @@ const Option = Class("Option", {
|
||||
})
|
||||
},
|
||||
|
||||
testValues: {
|
||||
regexmap: function (vals, validator) vals.every(function (re) validator(re.result)),
|
||||
stringlist: function (vals, validator) vals.every(validator, this),
|
||||
stringmap: function (vals, validator) array(values(vals)).every(validator, this)
|
||||
},
|
||||
|
||||
dequote: function (value) {
|
||||
let arg;
|
||||
[, arg, Option._quote] = Commands.parseArg(String(value), "");
|
||||
@@ -556,6 +567,12 @@ const Option = Class("Option", {
|
||||
if (this.type == "regexmap")
|
||||
return Array.concat(values).every(function (re) res.some(function (item) item[0] == re.result));
|
||||
return Array.concat(values).every(function (value) res.some(function (item) item[0] == value));
|
||||
},
|
||||
|
||||
validateXPath: function (values) {
|
||||
let evaluator = XPathEvaluator();
|
||||
return this.testValues(values,
|
||||
function (value) evaluator.createExpression(value, util.evaluateXPath.resolver));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user