move find to helper

pull/1/head
yann300 7 years ago
parent e87c5807a1
commit 03e65f3d2c
  1. 24
      src/app/panels/terminal.js
  2. 32
      src/lib/helper.js

@ -675,30 +675,6 @@ function domTerminalFeatures (self, scopedCommands) {
}
}
function findDeep (object, fn, found = { break: false, value: undefined }) {
if (typeof object !== 'object' || object === null) return
for (var i in object) {
if (found.break) break
var el = object[i]
if (el && el.innerText !== undefined && el.innerText !== null) el = el.innerText
if (!fn(el, i, object)) findDeep(el, fn, found)
else if (found.break = true) return found.value = el // eslint-disable-line
}
return found.value
}
function match (args, query) {
query = query.trim()
var isMatch = !!findDeep(args, function check (value, key) {
if (value === undefined || value === null) return false
if (typeof value === 'function') return false
if (typeof value === 'object') return false
var contains = String(value).indexOf(query.trim()) !== -1
return contains
})
return isMatch
}
function blockify (el) { return yo`<div class=${css.block}>${el}</div>` }
module.exports = Terminal

@ -19,5 +19,37 @@ module.exports = {
},
checkSpecialChars (name) {
return name.match(/[/:*?"<>\\'|]/) != null
},
find: find
}
function findDeep (object, fn, found = { break: false, value: undefined }) {
if (typeof object !== 'object' || object === null) return
for (var i in object) {
if (found.break) break
var el = object[i]
if (el && el.innerText !== undefined && el.innerText !== null) el = el.innerText
if (fn(el, i, object)) {
found.value = el
found.break = true
break
} else {
findDeep(el, fn, found)
}
}
return found.value
}
function find (args, query) {
query = query.trim()
var isMatch = !!findDeep(args, function check (value, key) {
if (value === undefined || value === null) return false
if (typeof value === 'function') return false
if (typeof value === 'object') return false
var contains = String(value).indexOf(query.trim()) !== -1
return contains
})
return isMatch
}

Loading…
Cancel
Save