tune-basic-toolset
Version:
Basic toolset for tune
17 lines (13 loc) • 401 B
JavaScript
module.exports = async function grep({filename, text, regex, regex_flags}, ctx) {
if (!text && filename) {
const n = await ctx.resolve(filename)
if (!n)
return `${filename} not found`
text = await n.read()
}
if (!text) {
return "content is empty"
}
const r = new RegExp(regex, regex_flags)
return text.split(/\r?\n/).filter(line => r.test(line)).join("\n")
}