mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 21:27:58 +01:00
Use builtin Array.find rather than array.nth where applicable.
This commit is contained in:
@@ -105,7 +105,7 @@ var AbbrevHive = Class("AbbrevHive", Contexts.Hive, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/** @property {boolean} True if there are no abbreviations. */
|
/** @property {boolean} True if there are no abbreviations. */
|
||||||
get empty() !values(this._store).nth(util.identity, 0),
|
get empty() !values(this._store).find(util.identity),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new abbreviation.
|
* Adds a new abbreviation.
|
||||||
@@ -251,7 +251,7 @@ var Abbreviations = Module("abbreviations", {
|
|||||||
let match = this._match.exec(text);
|
let match = this._match.exec(text);
|
||||||
if (match)
|
if (match)
|
||||||
return this.hives.map(h => h.get(mode, match[2] || match[4] || match[6]))
|
return this.hives.map(h => h.get(mode, match[2] || match[4] || match[6]))
|
||||||
.nth(util.identity, 0);
|
.find(util.identity);
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -2018,7 +2018,7 @@ var ItemList = Class("ItemList", {
|
|||||||
if (start < 0 || start >= this.itemCount)
|
if (start < 0 || start >= this.itemCount)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
group = array.nth(groups, g => let (i = start - g.offsets.start) i >= 0 && i < g.itemCount, 0);
|
group = groups.find(g => let (i = start - g.offsets.start) i >= 0 && i < g.itemCount);
|
||||||
return [group.context, start - group.offsets.start];
|
return [group.context, start - group.offsets.start];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1299,16 +1299,21 @@ var Hints = Module("hints", {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
keepQuotes: true,
|
keepQuotes: true,
|
||||||
|
|
||||||
getKey: function (val, default_)
|
getKey: function (val, default_)
|
||||||
let (res = array.nth(this.value, re => let (match = re.exec(val)) match && match[0] == val, 0))
|
let (res = this.value.find(re => let (match = re.exec(val)) match && match[0] == val))
|
||||||
res ? res.matcher : default_,
|
res ? res.matcher
|
||||||
|
: default_,
|
||||||
|
|
||||||
parse: function parse(val) {
|
parse: function parse(val) {
|
||||||
let vals = parse.supercall(this, val);
|
let vals = parse.supercall(this, val);
|
||||||
for (let value in values(vals))
|
for (let value in values(vals))
|
||||||
value.matcher = DOM.compileMatcher(Option.splitList(value.result));
|
value.matcher = DOM.compileMatcher(Option.splitList(value.result));
|
||||||
return vals;
|
return vals;
|
||||||
},
|
},
|
||||||
|
|
||||||
testValues: function testValues(vals, validator) vals.every(re => Option.splitList(re).every(validator)),
|
testValues: function testValues(vals, validator) vals.every(re => Option.splitList(re).every(validator)),
|
||||||
|
|
||||||
validator: DOM.validateMatcher
|
validator: DOM.validateMatcher
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -274,7 +274,8 @@ var Modes = Module("modes", {
|
|||||||
remove: function remove(mode, covert) {
|
remove: function remove(mode, covert) {
|
||||||
if (covert && this.topOfStack.main != mode) {
|
if (covert && this.topOfStack.main != mode) {
|
||||||
util.assert(mode != this.NORMAL);
|
util.assert(mode != this.NORMAL);
|
||||||
for (let m; m = array.nth(this.modeStack, m => m.main == mode, 0);)
|
|
||||||
|
for (let m; m = this.modeStack.find(m => m.main == mode);)
|
||||||
this._modeStack.splice(this._modeStack.indexOf(m));
|
this._modeStack.splice(this._modeStack.indexOf(m));
|
||||||
}
|
}
|
||||||
else if (this.stack.some(m => m.main == mode)) {
|
else if (this.stack.some(m => m.main == mode)) {
|
||||||
@@ -604,7 +605,7 @@ var Modes = Module("modes", {
|
|||||||
|
|
||||||
getKey: function getKey(val, default_) {
|
getKey: function getKey(val, default_) {
|
||||||
if (isArray(val))
|
if (isArray(val))
|
||||||
return (array.nth(this.value, v => val.some(m => m.name === v.mode), 0)
|
return (this.value.find(v => val.some(m => m.name === v.mode))
|
||||||
|| { result: default_ }).result;
|
|| { result: default_ }).result;
|
||||||
|
|
||||||
return hasOwnProperty(this.valueMap, val) ? this.valueMap[val] : default_;
|
return hasOwnProperty(this.valueMap, val) ? this.valueMap[val] : default_;
|
||||||
|
|||||||
@@ -550,7 +550,7 @@ var Tabs = Module("tabs", {
|
|||||||
if (matches)
|
if (matches)
|
||||||
return tabs.select(this.allTabs[parseInt(matches[1], 10) - 1], false);
|
return tabs.select(this.allTabs[parseInt(matches[1], 10) - 1], false);
|
||||||
|
|
||||||
matches = array.nth(tabs.allTabs, t => (t.linkedBrowser.lastURI || {}).spec === buffer, 0);
|
matches = tabs.allTabs.find(t => (t.linkedBrowser.lastURI || {}).spec === buffer);
|
||||||
if (matches)
|
if (matches)
|
||||||
return tabs.select(matches, false);
|
return tabs.select(matches, false);
|
||||||
|
|
||||||
|
|||||||
@@ -1508,21 +1508,21 @@ update(iter, {
|
|||||||
|
|
||||||
every: function every(iter, pred, self) {
|
every: function every(iter, pred, self) {
|
||||||
pred = pred || util.identity;
|
pred = pred || util.identity;
|
||||||
for (let elem in iter)
|
for (let elem of iter)
|
||||||
if (!pred.call(self, elem))
|
if (!pred.call(self, elem))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
some: function every(iter, pred, self) {
|
some: function every(iter, pred, self) {
|
||||||
pred = pred || util.identity;
|
pred = pred || util.identity;
|
||||||
for (let elem in iter)
|
for (let elem of iter)
|
||||||
if (pred.call(self, elem))
|
if (pred.call(self, elem))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
filter: function filter(iter, pred, self) {
|
filter: function filter(iter, pred, self) {
|
||||||
for (let elem in iter)
|
for (let elem of iter)
|
||||||
if (pred.call(self, elem))
|
if (pred.call(self, elem))
|
||||||
yield elem;
|
yield elem;
|
||||||
},
|
},
|
||||||
@@ -1536,13 +1536,13 @@ update(iter, {
|
|||||||
* @param {object} self The this object for *fn*.
|
* @param {object} self The this object for *fn*.
|
||||||
*/
|
*/
|
||||||
forEach: function forEach(iter, func, self) {
|
forEach: function forEach(iter, func, self) {
|
||||||
for (let val in iter)
|
for (let val of iter)
|
||||||
func.call(self, val);
|
func.call(self, val);
|
||||||
},
|
},
|
||||||
|
|
||||||
indexOf: function indexOf(iter, elem) {
|
indexOf: function indexOf(iter, elem) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (let item in iter) {
|
for (let item of iter) {
|
||||||
if (item == elem)
|
if (item == elem)
|
||||||
return i;
|
return i;
|
||||||
i++;
|
i++;
|
||||||
@@ -1558,7 +1558,7 @@ update(iter, {
|
|||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
*/
|
*/
|
||||||
map: function map(iter, func, self) {
|
map: function map(iter, func, self) {
|
||||||
for (let i in iter)
|
for (let i of iter)
|
||||||
yield func.call(self, i);
|
yield func.call(self, i);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1570,18 +1570,29 @@ update(iter, {
|
|||||||
if (typeof pred === "number")
|
if (typeof pred === "number")
|
||||||
[pred, n] = [() => true, pred]; // Hack.
|
[pred, n] = [() => true, pred]; // Hack.
|
||||||
|
|
||||||
for (let elem in iter)
|
for (let elem of iter)
|
||||||
if (pred.call(self, elem) && n-- === 0)
|
if (pred.call(self, elem) && n-- === 0)
|
||||||
return elem;
|
return elem;
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analog of Array.find method. Returns the first item in the
|
||||||
|
* iterator for which `pred` returns true.
|
||||||
|
*/
|
||||||
|
find: function find(iter, pred, self) {
|
||||||
|
for (let elem of iter)
|
||||||
|
if (pred.call(self, elem))
|
||||||
|
return elem;
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
|
||||||
sort: function sort(iter, fn, self)
|
sort: function sort(iter, fn, self)
|
||||||
array(this.toArray(iter).sort(fn, self)),
|
array(this.toArray(iter).sort(fn, self)),
|
||||||
|
|
||||||
uniq: function uniq(iter) {
|
uniq: function uniq(iter) {
|
||||||
let seen = RealSet();
|
let seen = RealSet();
|
||||||
for (let item in iter)
|
for (let item of iter)
|
||||||
if (!seen.add(item))
|
if (!seen.add(item))
|
||||||
yield item;
|
yield item;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2476,10 +2476,9 @@ var Buffer = Module("Buffer", {
|
|||||||
if (/^func:/.test(filter.result))
|
if (/^func:/.test(filter.result))
|
||||||
var res = dactyl.userEval("(" + Option.dequote(filter.result.substr(5)) + ")")(doc, line);
|
var res = dactyl.userEval("(" + Option.dequote(filter.result.substr(5)) + ")")(doc, line);
|
||||||
else
|
else
|
||||||
res = iter.nth(filter.matcher(doc),
|
res = iter.find(filter.matcher(doc),
|
||||||
elem => ((elem.nodeValue || elem.textContent).trim() == line &&
|
elem => ((elem.nodeValue || elem.textContent).trim() == line &&
|
||||||
DOM(elem).display != "none"),
|
DOM(elem).display != "none"))
|
||||||
0)
|
|
||||||
|| iter.nth(filter.matcher(doc), util.identity, line - 1);
|
|| iter.nth(filter.matcher(doc), util.identity, line - 1);
|
||||||
if (res)
|
if (res)
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -622,11 +622,12 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
|
|||||||
*/
|
*/
|
||||||
get: function get(name, full) {
|
get: function get(name, full) {
|
||||||
let cmd = this._map[name]
|
let cmd = this._map[name]
|
||||||
|| !full && array.nth(this._list, cmd => cmd.hasName(name), 0)
|
|| !full && this._list.find(cmd => cmd.hasName(name))
|
||||||
|| null;
|
|| null;
|
||||||
|
|
||||||
if (!cmd && full) {
|
if (!cmd && full) {
|
||||||
let name = array.nth(this.specs, spec => Command.hasName(spec, name), 0);
|
// Hrm. This is wrong. -Kris
|
||||||
|
let name = this._specs.find(spec => Command.hasName(spec, name));
|
||||||
return name && this.get(name);
|
return name && this.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -883,7 +884,7 @@ var Commands = Module("commands", {
|
|||||||
* @returns {Command}
|
* @returns {Command}
|
||||||
*/
|
*/
|
||||||
get: function get(name, full) iter(this.hives).map(([i, hive]) => hive.get(name, full))
|
get: function get(name, full) iter(this.hives).map(([i, hive]) => hive.get(name, full))
|
||||||
.nth(util.identity, 0),
|
.find(util.identity),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if a command invocation contains a URL referring to the
|
* Returns true if a command invocation contains a URL referring to the
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ var ConfigBase = Class("ConfigBase", {
|
|||||||
bestLocale: function (list) {
|
bestLocale: function (list) {
|
||||||
return values([this.appLocale, this.appLocale.replace(/-.*/, ""),
|
return values([this.appLocale, this.appLocale.replace(/-.*/, ""),
|
||||||
"en", "en-US", list[0]])
|
"en", "en-US", list[0]])
|
||||||
.nth((function (l) this.has(l)).bind(RealSet(list)), 0);
|
.find(bind("has", RealSet(list)));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -67,8 +67,9 @@ var Group = Class("Group", {
|
|||||||
}, {
|
}, {
|
||||||
compileFilter: function (patterns, default_=false) {
|
compileFilter: function (patterns, default_=false) {
|
||||||
function siteFilter(uri)
|
function siteFilter(uri)
|
||||||
let (match = array.nth(siteFilter.filters, f => f(uri), 0))
|
let (match = siteFilter.filters.find(f => f(uri)))
|
||||||
match ? match.result : default_;
|
match ? match.result
|
||||||
|
: default_;
|
||||||
|
|
||||||
return update(siteFilter, {
|
return update(siteFilter, {
|
||||||
toString: function () this.filters.join(","),
|
toString: function () this.filters.join(","),
|
||||||
@@ -205,12 +206,10 @@ var Contexts = Module("contexts", {
|
|||||||
Context: function Context(file, group, args) {
|
Context: function Context(file, group, args) {
|
||||||
const { contexts, io, newContext, plugins, userContext } = this.modules;
|
const { contexts, io, newContext, plugins, userContext } = this.modules;
|
||||||
|
|
||||||
let isPlugin = array.nth(io.getRuntimeDirectories("plugins"),
|
let isPlugin = io.getRuntimeDirectories("plugins")
|
||||||
dir => dir.contains(file, true),
|
.find(dir => dir.contains(file, true));
|
||||||
0);
|
let isRuntime = io.getRuntimeDirectories("")
|
||||||
let isRuntime = array.nth(io.getRuntimeDirectories(""),
|
.find(dir => dir.contains(file, true));
|
||||||
dir => dir.contains(file, true),
|
|
||||||
0);
|
|
||||||
|
|
||||||
let name = isPlugin ? file.getRelativeDescriptor(isPlugin).replace(File.PATH_SEP, "-")
|
let name = isPlugin ? file.getRelativeDescriptor(isPlugin).replace(File.PATH_SEP, "-")
|
||||||
: file.leafName;
|
: file.leafName;
|
||||||
@@ -308,9 +307,8 @@ var Contexts = Module("contexts", {
|
|||||||
if (uri instanceof Ci.nsIFileURL)
|
if (uri instanceof Ci.nsIFileURL)
|
||||||
var file = File(uri.file);
|
var file = File(uri.file);
|
||||||
|
|
||||||
let isPlugin = array.nth(io.getRuntimeDirectories("plugins"),
|
let isPlugin = io.getRuntimeDirectories("plugins")
|
||||||
dir => dir.contains(file, true),
|
.find(dir => dir.contains(file, true));
|
||||||
0);
|
|
||||||
|
|
||||||
let name = isPlugin && file && file.getRelativeDescriptor(isPlugin)
|
let name = isPlugin && file && file.getRelativeDescriptor(isPlugin)
|
||||||
.replace(File.PATH_SEP, "-");
|
.replace(File.PATH_SEP, "-");
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ var Download = Class("Download", {
|
|||||||
let val = this._compare[order.substr(1)](this, other);
|
let val = this._compare[order.substr(1)](this, other);
|
||||||
|
|
||||||
return (order[0] == "-") ? -val : val;
|
return (order[0] == "-") ? -val : val;
|
||||||
}, this).nth(util.identity, 0) || 0,
|
}, this).find(util.identity) || 0,
|
||||||
|
|
||||||
timeRemaining: Infinity,
|
timeRemaining: Infinity,
|
||||||
|
|
||||||
|
|||||||
@@ -1504,8 +1504,7 @@ var Options = Module("options", {
|
|||||||
|
|
||||||
function val(obj) {
|
function val(obj) {
|
||||||
if (isArray(opt.defaultValue)) {
|
if (isArray(opt.defaultValue)) {
|
||||||
let val = array.nth(obj, re => (re.key == extra.key),
|
let val = Array.find(obj, re => (re.key == extra.key));
|
||||||
0);
|
|
||||||
return val && val.result;
|
return val && val.result;
|
||||||
}
|
}
|
||||||
if (hasOwnProperty(opt.defaultValue, extra.key))
|
if (hasOwnProperty(opt.defaultValue, extra.key))
|
||||||
|
|||||||
@@ -474,7 +474,10 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
|
|||||||
sanitizer.sanitize(items, range);
|
sanitizer.sanitize(items, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array.nth(opt.value, i => i == "all" || /^!/.test(i), 0) == "all" && !args["-host"])
|
if ("all" == opt.value.find(i => (i == "all" ||
|
||||||
|
/^!/.test(i)))
|
||||||
|
&& !args["-host"])
|
||||||
|
|
||||||
modules.commandline.input(_("sanitize.prompt.deleteAll") + " ",
|
modules.commandline.input(_("sanitize.prompt.deleteAll") + " ",
|
||||||
function (resp) {
|
function (resp) {
|
||||||
if (resp.match(/^y(es)?$/i)) {
|
if (resp.match(/^y(es)?$/i)) {
|
||||||
@@ -620,8 +623,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
|
|||||||
},
|
},
|
||||||
|
|
||||||
has: function has(val)
|
has: function has(val)
|
||||||
let (res = array.nth(this.value, v => (v == "all" || v.replace(/^!/, "") == val),
|
let (res = this.value.find(v => (v == "all" || v.replace(/^!/, "") == val)))
|
||||||
0))
|
|
||||||
res && !/^!/.test(res),
|
res && !/^!/.test(res),
|
||||||
|
|
||||||
validator: function (values) values.length &&
|
validator: function (values) values.length &&
|
||||||
|
|||||||
@@ -277,8 +277,7 @@ var Styles = Module("Styles", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
addHive: function addHive(name, ref, persist) {
|
addHive: function addHive(name, ref, persist) {
|
||||||
let hive = array.nth(this.hives, h => h.name === name,
|
let hive = this.hives.find(h => h.name === name);
|
||||||
0);
|
|
||||||
if (!hive) {
|
if (!hive) {
|
||||||
hive = Hive(name, persist);
|
hive = Hive(name, persist);
|
||||||
this.hives.push(hive);
|
this.hives.push(hive);
|
||||||
|
|||||||
Reference in New Issue
Block a user