Merge branch 'replace-flatten'

This commit is contained in:
Oliver Blanthorn 2019-09-20 18:05:10 +01:00
commit 62b8bf0992
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
3 changed files with 5 additions and 16 deletions

View file

@ -153,7 +153,6 @@ import { CmdlineCmds as BgCmdlineCmds } from "@src/background/commandline_cmds"
import { EditorCmds as BgEditorCmds } from "@src/background/editor"
import { messageActiveTab } from "@src/lib/messaging"
import { EditorCmds } from "@src/background/editor"
import { flatten } from "@src/lib/itertools"
import { firefoxVersionAtLeast } from "@src/lib/webext"
import * as rc from "@src/background/config_rc"
import * as css_util from "@src/lib/css_util"
@ -4227,10 +4226,12 @@ export async function bmark(url?: string, ...titlearr: string[]) {
const treeClimber = (tree, treestr) => {
if (tree.type !== "folder") return {}
treestr += tree.title + "/"
if (!("children" in tree) || tree.children.length === 0) return { path: treestr, id: tree.id }
if (!("children" in tree) || tree.children.length === 0) return [{ path: treestr, id: tree.id }]
return [{ path: treestr, id: tree.id }, tree.children.map(child => treeClimber(child, treestr))]
}
const validpaths = flatten(treeClimber(tree, "")).filter(x => "path" in x)
const treeClimberResult = treeClimber(tree, "")
let validpaths = []
if (treeClimberResult instanceof Array) validpaths = treeClimberResult.flat(Infinity).filter(x => "path" in x)
title = title.substring(title.lastIndexOf("/") + 1)
let pathobj = validpaths.find(p => p.path === path)
// If strict look doesn't find it, be a bit gentler

View file

@ -165,18 +165,6 @@ export function* uniqueBy(arr, hasher) {
}
}
export function flatten(arr) {
let result = []
for (const elem of arr) {
if (elem instanceof Array) {
result = result.concat(flatten(elem))
} else {
result.push(elem)
}
}
return result
}
/** Drop from iterable until predicate is false */
export function* dropwhile(iterable, predicate) {
let allmatched = true

View file

@ -6,7 +6,7 @@
"outDir": "build/tsc-out",
"sourceMap": true,
"target": "es2017",
"lib": ["es2017","dom", "dom.iterable"],
"lib": ["es2017","es2019.array","dom", "dom.iterable"],
"typeRoots": ["node_modules/@types", "node_modules/web-ext-types/"],
"experimentalDecorators": true,
"alwaysStrict": true,