From 65619509a7c9ce40a7f50c57ae22d801a45524c4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 5 Feb 2020 00:44:59 -1000 Subject: [PATCH] [Refactor] reduce usage of lodash --- dist/acorn-umd/acorn-umd.js | 3 +- dist/eval-markdown.js | 266 ++++++++++++++++++------------------ dist/promise-ripple.js | 13 +- package-lock.json | 141 +++++++++++++++++++ package.json | 3 + src/acorn-umd/acorn-umd.ts | 3 +- src/eval-markdown.js | 266 ++++++++++++++++++------------------ src/promise-ripple.js | 16 +-- 8 files changed, 429 insertions(+), 282 deletions(-) diff --git a/dist/acorn-umd/acorn-umd.js b/dist/acorn-umd/acorn-umd.js index f2c90b3..2767e94 100644 --- a/dist/acorn-umd/acorn-umd.js +++ b/dist/acorn-umd/acorn-umd.js @@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); +var object_assign_1 = __importDefault(require("object.assign")); var lodash_1 = require("lodash"); var estraverse_1 = __importDefault(require("estraverse")); var Node_1 = __importDefault(require("./Node")); @@ -164,7 +165,7 @@ function findAMD(ast) { }); } function default_1(ast, options) { - options = lodash_1.assign({ + options = object_assign_1.default({ cjs: true, // TODO amd: false, diff --git a/dist/eval-markdown.js b/dist/eval-markdown.js index 3e3348d..e637273 100644 --- a/dist/eval-markdown.js +++ b/dist/eval-markdown.js @@ -3,7 +3,7 @@ var crypto = require('crypto'); var path = require('path'); var Promise = require('bluebird'); var child_process = require('child_process'); -var _ = require('lodash'); +var _a = require('lodash'), chain = _a.chain, each = _a.each, filter = _a.filter, find = _a.find, flatten = _a.flatten, groupBy = _a.groupBy, includes = _a.includes, indexOf = _a.indexOf, last = _a.last, map = _a.map, range = _a.range, slice = _a.slice, uniq = _a.uniq, values = _a.values; var fs = Promise.promisifyAll(require('fs-extra')); var MarkdownIt = require('markdown-it'); var acorn = require('acorn'); @@ -28,7 +28,7 @@ function main(filePath$, packagePath, prepend, blockScope, nonstop, preventEval, var logStore = []; DEBUG = debug; log = logFactory(logStore, silence); - var filePaths = _.flatten([filePath$]); + var filePaths = flatten([filePath$]); logInfo('it worked if it ends with', 'ok'); return getPackage(packagePath) .then(function (pkg) { @@ -60,12 +60,12 @@ function main(filePath$, packagePath, prepend, blockScope, nonstop, preventEval, }); } var getExitCode = main.getExitCode = function (mdResults) { - var evaluations = _.chain(mdResults).map('evaluated').flatten().value(); - var evalResults = _.chain(evaluations).map('evalResult').flatten().value(); - var evalResultsInstanceofError = _.map(evalResults, function (evalResult) { + var evaluations = chain(mdResults).map('evaluated').flatten().value(); + var evalResults = chain(evaluations).map('evalResult').flatten().value(); + var evalResultsInstanceofError = map(evalResults, function (evalResult) { return evalResult instanceof Error; }); - var evalResultsHasInstanceofError = _.includes(evalResultsInstanceofError, true); + var evalResultsHasInstanceofError = includes(evalResultsInstanceofError, true); if (evalResultsHasInstanceofError) return 1; return 0; @@ -81,10 +81,10 @@ var getPackage = main.getPackage = function (packagePath) { .catch(function () { return false; }); }; var previousIndex = main.previousIndex = function (node, nodes, fn) { - var index = _.indexOf(nodes, node); + var index = indexOf(nodes, node); index = index < 0 ? 0 : index; - var subArr = _.slice(nodes, 0, index); - var revIndex = _.chain(subArr) + var subArr = slice(nodes, 0, index); + var revIndex = chain(subArr) .reverse() .findIndex(fn) .value(); @@ -103,14 +103,14 @@ var previousIndexClose = main.previousIndexClose = function (node, nodes, type) }); }; var groupChildren = main.groupChildren = function (nodes) { - nodes = _.groupBy(nodes, function (node) { + nodes = groupBy(nodes, function (node) { return previousIndexClose(node, nodes); }); - return _.values(nodes); + return values(nodes); }; /** searches preceeding nodes for pattern */ var searchLink = main.searchLink = function (subNodes, pattern) { - var textNode = _.find(subNodes, function (node) { + var textNode = find(subNodes, function (node) { if (!node.content) return false; return node.content.match(pattern); @@ -140,14 +140,14 @@ var searchComment = main.searchComment = function (node, pattern) { } }; var createLineDoc = main.createLineDoc = function (lines) { - return _.range(lines).map(function () { + return range(lines).map(function () { return ''; }); }; var replaceLines = main.replaceLines = function (start, main, sub) { main = (Array.isArray(main)) ? main : main.split('\n'); sub = (Array.isArray(sub)) ? sub : sub.split('\n'); - var output = _.flatten([_.slice(main, 0, start), sub, _.slice(main, start + sub.length, main.length)]); + var output = flatten([slice(main, 0, start), sub, slice(main, start + sub.length, main.length)]); return output; }; var getHash = main.getHash = function (content) { @@ -155,10 +155,10 @@ var getHash = main.getHash = function (content) { return shasum.update(content).digest('hex'); }; var mapNodes = main.mapNodes = function (nodes) { - return _.map(nodes, function (node, index) { + return map(nodes, function (node, index) { node.children = groupChildren(node.children); node.previousFenceIndex = previousIndexType(node, nodes, 'fence'); - var subNodes = _.slice(nodes, node.previousFenceIndex, index); + var subNodes = slice(nodes, node.previousFenceIndex, index); node.fileEval = searchLink(subNodes, /\[(.+)?\]\(#?(eval\s?file|file\s?eval)\)/i) || searchComment(node, /\/\/\s(file\s?eval\s|eval\s?file\s)(.+)/i) || false; @@ -171,37 +171,37 @@ var mapNodes = main.mapNodes = function (nodes) { }); }; var getNodeId = main.getNodeId = function (nodes, filePath) { - return _.map(nodes, function (node, index) { + return map(nodes, function (node, index) { node.id = index + 1; return node; }); }; var getFences = main.getFences = function (nodes, langs) { - return _.filter(nodes, function (node) { + return filter(nodes, function (node) { if (node.type !== 'fence') return false; if (!langs && node.type === 'fence') return true; - return _.includes(langs, node.info); + return includes(langs, node.info); }); }; var filterPrevented = main.filterPrevented = function (nodes) { - return _.filter(nodes, function (node) { + return filter(nodes, function (node) { return !node.preventEval; }); }; var buildPreserveLines = main.buildPreserveLines = function (node$, lines) { - var nodes = _.flatten([node$]); + var nodes = flatten([node$]); var lineDoc = createLineDoc(lines); - _.each(nodes, function (node) { + each(nodes, function (node) { var contentLines = String(node.content || '').split(/\r\n?|\n/); lineDoc = replaceLines(node.startLine, lineDoc, contentLines); }); return lineDoc.join('\n'); }; var buildConcat = main.buildConcat = function (node$, lines) { - var nodes = _.flatten([node$]); - return _.chain(nodes) + var nodes = flatten([node$]); + return chain(nodes) .map(function (node) { return node.content; }) @@ -213,7 +213,7 @@ var getDeps = main.getDeps = function (code) { var deps = umd(ast, { es6: true, amd: true, cjs: true }); - return _.uniq(deps, function (dep) { + return uniq(deps, function (dep) { var important = { 'value': dep.source.value, 'start': dep.source.start, @@ -239,7 +239,7 @@ var alterAssignedModule = main.alterAssignedModule = function (code, prepend, pk var chars = 0; name = regExpEscape(name); var pattern = new RegExp('^' + name + '($|/.*)'); - _.each(deps, function (dep) { + each(deps, function (dep) { var match = dep.source.value.match(pattern); if (match) { var start = chars + dep.source.start + 1; @@ -257,9 +257,9 @@ var alterSelfModules = main.alterSelfModules = function (code, nodes) { if (!deps.length) return code; var chars = 0; - _.each(deps, function (dep) { + each(deps, function (dep) { if (dep.source.value) { - var node = _.find(nodes, { + var node = find(nodes, { 'fileEval': dep.source.value }); if (node && node.fileCreated) { @@ -280,9 +280,9 @@ var alterPrependModules = main.alterPrependModules = function (code, nodes, prep prepend = (prepend) ? prepend : './'; var localRegex = /^.\.\/|^.\//; var chars = 0; - _.each(deps, function (dep) { + each(deps, function (dep) { if (dep.source.value && dep.source.value.match(localRegex)) { - var node = _.find(nodes, { + var node = find(nodes, { 'fileEval': dep.source.value }); if (!node) { @@ -304,8 +304,8 @@ var alterNpmModules = main.alterNpmModules = function (code, nodes, prepend) { prepend = (prepend) ? prepend : './'; var nonNpm = /^.\.\/|^.\/|^\//; var chars = 0; - _.each(deps, function (dep) { - if (dep.source.value && !dep.source.value.match(nonNpm) && !_.includes(natives, dep.source.value)) { + each(deps, function (dep) { + if (dep.source.value && !dep.source.value.match(nonNpm) && !includes(natives, dep.source.value)) { var start = chars + dep.source.start + 1; var end = chars + dep.source.end - 1; var replacement = path.resolve(path.join(prepend, 'node_modules', dep.source.value)); @@ -339,7 +339,7 @@ var stackSplit = main.stackSplit = function (stack) { 'frame': [], 'lines': [] }; - _.each(stackLines, function (stackLine) { + each(stackLines, function (stackLine) { var pattern = /^\s\s\s\sat\s/; var match = stackLine.match(pattern); if (match) { @@ -359,12 +359,12 @@ var stackJoin = main.stackJoin = function (stack) { ].join('\n'); }; var findErrorNode = main.findErrorNode = function (nodes, line) { - return _.find(nodes, function (node) { + return find(nodes, function (node) { return node.startLine <= line && node.endLine >= line; }); }; var errMsg = main.errMsg = function () { - var args = _.values(arguments); + var args = values(arguments); if (args.length > 1) args[0] = chalk.magenta(args[0]); return [ @@ -373,7 +373,7 @@ var errMsg = main.errMsg = function () { ].concat(args).join(' '); }; var infoMsg = main.infoMsg = function () { - var args = _.values(arguments); + var args = values(arguments); args[0] = chalk.magenta(args[0]); return [ chalk.white('evalmd'), @@ -381,7 +381,7 @@ var infoMsg = main.infoMsg = function () { ].concat(args).join(' '); }; var debugMsg = main.debugMsg = function () { - var args = _.values(arguments); + var args = values(arguments); args[0] = chalk.magenta(args[0]); return [ chalk.white('evalmd'), @@ -399,16 +399,16 @@ var cleanStack = main.cleanStack = function (errOrStack) { }; var logErr = main.logErr = function (err) { var lines = cleanStack(err); - return _.each(lines, function (line) { + return each(lines, function (line) { return log(errMsg(line)); }); }; var logInfo = main.logInfo = function () { - var args = _.values(arguments); + var args = values(arguments); return log(infoMsg.apply(null, args)); }; var logDebug = main.logDebug = function () { - var args = _.values(arguments); + var args = values(arguments); if (DEBUG) return log(debugMsg.apply(null, args)); }; @@ -459,9 +459,9 @@ var parseLineChar = main.parseLineChar = function (s) { return false; }; var getCleanLines = main.getCleanLines = function (incLines, nodes, absFilePath, frame) { - var lines = _.map(incLines, function (line) { + var lines = map(incLines, function (line) { var lineChar = parseLineChar(line); - var matchNodes = _.find(nodes, function (node) { + var matchNodes = find(nodes, function (node) { if (!node.fileEvalHashPath) return false; return line.match(node.fileEvalHashPath); @@ -505,13 +505,13 @@ var getCleanLines = main.getCleanLines = function (incLines, nodes, absFilePath, lines = lines.reverse(); var matchFound = false; if (!frame) { - lines = _.filter(lines, function (line) { + lines = filter(lines, function (line) { if (line.replacement) matchFound = true; return matchFound; }); } - lines = _.map(lines, function (line) { + lines = map(lines, function (line) { if (line.replacement) return line.replacement; return line.line; @@ -529,7 +529,7 @@ var evalError = main.evalError = function (filePath, nodes) { stack.lines = cleanLines; stack.frame = getCleanLines(stack.frame, nodes, absFilePath, true); stack.frame.shift(); - if (_.last(stack.frame) === '') + if (last(stack.frame) === '') stack.frame.pop(); return stackJoin(stack); }; @@ -569,7 +569,7 @@ var nonstopErr = main.nonstopErr = function (error, stackWrapper, nonstop) { var evaluate = main.evaluate = function (node, nodes, markdownLinesLength, pkg, prepend, nonstop, filePath) { return promiseRipple(node, { notice: function (node) { - var ids = (Array.isArray(node)) ? _.chain(node).map('id').value() : [node.id]; + var ids = (Array.isArray(node)) ? chain(node).map('id').value() : [node.id]; var word = (ids.length > 1) ? 'blocks' : 'block'; logInfo(filePath, ['running', word, ids.join(', ')].join(' ')); }, @@ -631,7 +631,7 @@ var evaluateScope = main.evaluateScope = function (nodes, markdownLinesLength, p var outputCode = main.outputCode = function (node, nodes, markdownLinesLength, pkg, prepend, nonstop, filePath, output, delimeter) { return promiseRipple(node, { notice: function (node) { - var ids = (Array.isArray(node)) ? _.chain(node).map('id').value() : [node.id]; + var ids = (Array.isArray(node)) ? chain(node).map('id').value() : [node.id]; var word = (ids.length > 1) ? 'blocks' : 'block'; logInfo(filePath, ['outputting', word, ids.join(', ')].join(' ')); }, @@ -694,7 +694,7 @@ var assemble = main.assemble = function (filePath, pkg, prepend, blockScope, non // eval nodes data.evalNodes = (includePrevented) ? data.allJsFences : data.permittedFences; // get the blockscope - data.blockScope = blockScope || Boolean(_.chain(data.evalNodes).map('fileEval').without(false).value().length); + data.blockScope = blockScope || Boolean(chain(data.evalNodes).map('fileEval').without(false).value().length); return data; }, evaluated: function (data) { @@ -722,10 +722,10 @@ module.exports = main; // console.log(report[0].evaluated) // }) // console.log(JSON.stringify(nodes, null, 2)) -// var childrenSets = _.map(subNodes, 'children') +// var childrenSets = map(subNodes, 'children') // if (!childrenSets.length) return false -// var found = _.find(childrenSets, function (children) { -// return _.find(children, function (child) { +// var found = find(childrenSets, function (children) { +// return find(children, function (child) { // if (child.type === 'link_open') { // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -741,13 +741,13 @@ module.exports = main; // return found // } // var previousSiblingFileEval = main.previousSiblingFileEval = function (node, nodes) { -// var index = _.indexOf(nodes, node) -// var subNodes = _.slice(nodes, node.previousFenceIndex, index) -// var childrenSets = _.map(subNodes, 'children') -// childrenSets = _.flatten(childrenSets) +// var index = indexOf(nodes, node) +// var subNodes = slice(nodes, node.previousFenceIndex, index) +// var childrenSets = map(subNodes, 'children') +// childrenSets = flatten(childrenSets) // if (!childrenSets.length) return false -// var found = _.find(childrenSets, function (children) { -// return _.find(children, function (child) { +// var found = find(childrenSets, function (children) { +// return find(children, function (child) { // if (child.type === 'link_open') { // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -758,7 +758,7 @@ module.exports = main; // }) // }) // console.log(found) -// var text = _.find(found, { +// var text = find(found, { // 'type': 'text' // }) // return (text && text.content) ? text.content : false @@ -770,7 +770,7 @@ module.exports = main; // Boolean(node.content.match(/^\/\/ eval prevent/i)), // Boolean(node.content.match(/^\/\/ evalprevent/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // } // // block.assignFileViaComment = block.code.match(/\/\/\s(file\s?eval\s|eval\s?file\s)(.+)/i) @@ -779,11 +779,11 @@ module.exports = main; // // } // var preventEval = main.preventEval = function (node, nodes) { -// var index = _.indexOf(nodes, node) -// var subNodes = _.slice(nodes, node.prevFenceIndex, index) -// var result = _.find(subNodes, function (node) { +// var index = indexOf(nodes, node) +// var subNodes = slice(nodes, node.prevFenceIndex, index) +// var result = find(subNodes, function (node) { // if (!node.children) return false -// return _.find(node.children, function (childElement) { +// return find(node.children, function (childElement) { // if (childElement.type == "link_open") { // var hrefIndex = childElement.attrIndex('href') // var hrefValue = childElement.attrs[hrefIndex][1] @@ -794,7 +794,7 @@ module.exports = main; // var hrefValue = childElement.attrs[hrefIndex][1] // // } -// return _.find(childElement, function (child) { +// return find(childElement, function (child) { // if (child.type !== 'link_open') return false // var hrefIndex = child.attrIndex('href') // var hrefValue = child.attrs[hrefIndex][1] @@ -805,17 +805,17 @@ module.exports = main; // Boolean(hrefValue.match(/eval prevent/i)), // Boolean(hrefValue.match(/evalprevent/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // }) // }) // return Boolean(result) // } -// var index = _.indexOf(nodes, node) -// var haystack = _.slice(nodes, node.prevFenceIndex, index) -// var needle = _.find(haystack, function (node) { +// var index = indexOf(nodes, node) +// var haystack = slice(nodes, node.prevFenceIndex, index) +// var needle = find(haystack, function (node) { // if (!node.children) return false -// return _.find(node.children, function (child) { +// return find(node.children, function (child) { // if (child.type !== 'link_open') return false // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -826,12 +826,12 @@ module.exports = main; // Boolean(hrefValue.match(/eval prevent/i)), // Boolean(hrefValue.match(/evalprevent/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // }) // return Boolean(needle) // } -// nodes = _.map(nodes, function (node) { +// nodes = map(nodes, function (node) { // node.children = elements(node.children) // node.prevFenceIndex = prevIndex(node, nodes, 'fence') // // console.log(node.children) @@ -841,11 +841,11 @@ module.exports = main; // }) // console.log(nodes) // var preventEval = main.preventEval = function (node, nodes) { -// var index = _.indexOf(nodes, node) -// var haystack = _.slice(nodes, node.prevFenceIndex, index) -// var needle = _.find(haystack, function (node) { +// var index = indexOf(nodes, node) +// var haystack = slice(nodes, node.prevFenceIndex, index) +// var needle = find(haystack, function (node) { // if (!node.children) return false -// return _.find(node.children, function (child) { +// return find(node.children, function (child) { // if (child.type !== 'link_open') return false // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -856,19 +856,19 @@ module.exports = main; // Boolean(hrefValue.match(/eval prevent/i)), // Boolean(hrefValue.match(/evalprevent/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // }) // return Boolean(needle) // } // // var fileEval = main.fileEval = function (node, nodes) { -// var index = _.indexOf(nodes, node) -// var haystack = _.slice(nodes, node.prevFenceIndex, index) +// var index = indexOf(nodes, node) +// var haystack = slice(nodes, node.prevFenceIndex, index) // -// var needle = _.find(haystack, function (node) { +// var needle = find(haystack, function (node) { // if (!node.children) return false -// return _.find(node.children, function (child) { +// return find(node.children, function (child) { // if (child.type !== 'link_open') return false // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -879,7 +879,7 @@ module.exports = main; // Boolean(hrefValue.match(/eval file/i)), // Boolean(hrefValue.match(/evalfile/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // }) // @@ -889,20 +889,20 @@ module.exports = main; // } // console.log(nodes) // var fileName = main.fileName = function (node, nodes) { -// var index = _.indexOf(nodes, node) -// var haystack = _.slice(nodes, node.prevFenceIndex, index) +// var index = indexOf(nodes, node) +// var haystack = slice(nodes, node.prevFenceIndex, index) // -// return _.map(haystack, function (node, index) { -// node.children = _.map(node.children, function (child) { +// return map(haystack, function (node, index) { +// node.children = map(node.children, function (child) { // var prevLinkOpen = prevIndex(child, node.children, 'link_open') -// var index = _.indexOf(node.children, child) +// var index = indexOf(node.children, child) // console.log([prevLinkOpen, index]) -// var haystack = _.slice(node.children, prevLinkOpen, index) +// var haystack = slice(node.children, prevLinkOpen, index) // // console.log(haystack) -// var needle = _.find(haystack, function (child) { +// var needle = find(haystack, function (child) { // -// return _.find(node.children, function (child) { +// return find(node.children, function (child) { // var hrefIndex = child.attrIndex('href') // var hrefValue = child.attrs[hrefIndex][1] // var options = [ @@ -911,14 +911,14 @@ module.exports = main; // Boolean(hrefValue.match(/eval prevent/i)), // Boolean(hrefValue.match(/evalprevent/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // }) // console.log(needle) // }) // }) // if (!node.children) return node -// var lastLink = _.findIndex(node.children, function (child) { +// var lastLink = findIndex(node.children, function (child) { // if (child.type !== 'link_open') return false // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -929,15 +929,15 @@ module.exports = main; // Boolean(hrefValue.match(/eval file/i)), // Boolean(hrefValue.match(/evalfile/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // // console.log(lastLink) -// // var _.index(node, lastLink) -// var haystack = _.slice(nodes, lastLink, index) +// // var index(node, lastLink) +// var haystack = slice(nodes, lastLink, index) // console.log(haystack) -// var subNeedles = _.map(haystack, function (node) { +// var subNeedles = map(haystack, function (node) { // if (!node.children) return false -// var node = _.find(node.children, function (child) { +// var node = find(node.children, function (child) { // if (child.type !== 'link_open') return false // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -948,20 +948,20 @@ module.exports = main; // Boolean(hrefValue.match(/eval file/i)), // Boolean(hrefValue.match(/evalfile/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // var lastLinkOpenIndex = prevIndex(node, nodes, 'link_open') -// var haystack = _.slice(nodes, lastLinkOpenIndex, index) -// return _.find(haystack, function (child) { +// var haystack = slice(nodes, lastLinkOpenIndex, index) +// return find(haystack, function (child) { // return child.type === "text" // }) // }) // } // console.log(JSON.stringify(nodes, null, 2)) // console.log(nodes) -// _.each(nodes, function (node) { +// each(nodes, function (node) { // if (node.type === 'inline') { -// _.each(node.children, function (child) { +// each(node.children, function (child) { // if (child.attrs) { // var hrefIndex = child.attrIndex('href') // var hrefValue = child.attrs[hrefIndex][1] @@ -971,10 +971,10 @@ module.exports = main; // } // }) // var prevented = main.prevented = function (node, nodes) { -// var index = _.indexOf(nodes, node) +// var index = indexOf(nodes, node) // return [i, index] -// // var hay = _.split(arr, start, end) -// // return _.find(hay, { +// // var hay = split(arr, start, end) +// // return find(hay, { // // 'prevent': true // // }) // } @@ -993,11 +993,11 @@ module.exports = main; // } // if (!node.type.match('_close')) return null // if (!node.type.match('_close')) return null -// var subNodes = _.slice(nodes, index + 1) -// var endingIndex = _.findIndex(subNodes, node.tag) -// return _.slice(index, endingIndex) +// var subNodes = slice(nodes, index + 1) +// var endingIndex = findIndex(subNodes, node.tag) +// return slice(index, endingIndex) // -// var pieceHref = _.find(child, function (piece) { +// var pieceHref = find(child, function (piece) { // if (piece.type !== 'link_open') return false // if (!piece.attrs) return false // var hrefIndex = piece.attrIndex('href') @@ -1010,7 +1010,7 @@ module.exports = main; // return false // }) // var addEvalCode = main.addEvalCode = function (nodes, blockScope, markdownLinesLength, pkg, prepend, nonstop) { -// return _.map(nodes, function (node) { +// return map(nodes, function (node) { // node.evalCode = false // if (!blockScope) return node // node.evalCode = catchNonstop(function () { @@ -1061,15 +1061,15 @@ module.exports = main; // [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/reggi/evalmd/trend.png)](https://bitdeli.com/free "Bitdeli Badge") // var fileEval = main.fileEval = function (node, nodes) { // // get the index for the node -// var index = _.indexOf(nodes, node) +// var index = indexOf(nodes, node) // // split the nodes get all between last fence and this node -// var subNodes = _.slice(nodes, node.previousFenceIndex, index) +// var subNodes = slice(nodes, node.previousFenceIndex, index) // // map loop / find // // // get the href value -// var href = _.chain(subNodes).map(function (node) { -// return _.find(node.children, function (child) { -// return _.find(child, function (piece) { +// var href = chain(subNodes).map(function (node) { +// return find(node.children, function (child) { +// return find(child, function (piece) { // if (piece.type !== 'link_open') return false // if (!piece.attrs) return false // var hrefIndex = piece.attrIndex('href') @@ -1080,7 +1080,7 @@ module.exports = main; // }).flattenDeep().without(false).value() // // if heref get the text of the href // if (href) { -// var hrefText = _.find(href, { +// var hrefText = find(href, { // 'type': 'text' // }) // if (hrefText && hrefText.content) { @@ -1102,13 +1102,13 @@ module.exports = main; // // get the nodes // // // search through children nodes -// var value = _.map(subNodes, function (node) { -// return _.map(node.children, function (child) { -// var pieceText = _.find(child, function (piece) { +// var value = map(subNodes, function (node) { +// return map(node.children, function (child) { +// var pieceText = find(child, function (piece) { // if (piece.type !== 'text') return false // return piece.content.match(/\[\]\(#?(eval\s?prevent|prevent\s?eval)\)/i) // }) -// var pieceHref = _.find(child, function (piece) { +// var pieceHref = find(child, function (piece) { // if (piece.type !== 'link_open') return false // if (!piece.attrs) return false // var hrefIndex = piece.attrIndex('href') @@ -1119,7 +1119,7 @@ module.exports = main; // }) // }) // // clean up the child nodes -// var found = _.chain(value).flatten().without(false).value() +// var found = chain(value).flatten().without(false).value() // // if child nodes match return true // if (found && found.length) { // return true @@ -1138,13 +1138,13 @@ module.exports = main; // // var fileEval = main.fileEval = function (node, nodes) { // // get the index for the node -// var index = _.indexOf(nodes, node) +// var index = indexOf(nodes, node) // // split the nodes get all between last fence and this node -// var subNodes = _.slice(nodes, node.previousFenceIndex, index) +// var subNodes = slice(nodes, node.previousFenceIndex, index) // // map loop / find -// var text = _.chain(subNodes).map(function (node) { -// return _.map(node.children, function (child) { -// return _.map(child, function (piece) { +// var text = chain(subNodes).map(function (node) { +// return map(node.children, function (child) { +// return map(child, function (piece) { // if (piece.type !== 'text') return false // return piece.content.match(/\[(.+?)\]\(#?(eval\s?file|file\s?eval)\)/i) // }) @@ -1155,9 +1155,9 @@ module.exports = main; // return text[1] // } // // get the href value -// var href = _.chain(subNodes).map(function (node) { -// return _.find(node.children, function (child) { -// return _.find(child, function (piece) { +// var href = chain(subNodes).map(function (node) { +// return find(node.children, function (child) { +// return find(child, function (piece) { // if (piece.type !== 'link_open') return false // if (!piece.attrs) return false // var hrefIndex = piece.attrIndex('href') @@ -1168,7 +1168,7 @@ module.exports = main; // }).flattenDeep().without(false).value() // // if heref get the text of the href // if (href) { -// var hrefText = _.find(href, { +// var hrefText = find(href, { // 'type': 'text' // }) // if (hrefText && hrefText.content) { @@ -1187,9 +1187,9 @@ module.exports = main; // // var searchLink = main.searchLink = function (subNodes, pattern) { // // console.log(subNodes) -// var href = _.chain(subNodes).map(function (node) { -// return _.find(node.children, function (child) { -// return _.find(child, function (piece) { +// var href = chain(subNodes).map(function (node) { +// return find(node.children, function (child) { +// return find(child, function (piece) { // if (piece.type !== 'link_open') return false // if (!piece.attrs) return false // var hrefIndex = piece.attrIndex('href') @@ -1200,7 +1200,7 @@ module.exports = main; // }).flattenDeep().without(false).value() // // if heref get the text of the href // if (href) { -// var hrefText = _.find(href, { +// var hrefText = find(href, { // 'type': 'text' // }) // if (hrefText && hrefText.content) { diff --git a/dist/promise-ripple.js b/dist/promise-ripple.js index 398c563..b49f251 100644 --- a/dist/promise-ripple.js +++ b/dist/promise-ripple.js @@ -1,13 +1,14 @@ -var _ = require('lodash'); var Promise = require('bluebird'); +var values = require('object.values'); +var entries = require('object.entries'); function promiseRipple(start, props) { - props = (props) ? props : start; - start = (props) ? start : {}; - props = _.mapValues(props, function (prop, key) { + props = props || start; + start = props ? start : {}; + entries(props).forEach(function (_a) { + var key = _a[0], prop = _a[1]; prop.key = key; - return prop; }); - return Promise.reduce(_.values(props), function (result, action) { + return Promise.reduce(values(props), function (result, action) { if (typeof action !== 'function') throw new Error('property values must be functions'); return Promise.resolve(action(start)).then(function (value) { diff --git a/package-lock.json b/package-lock.json index 8059fb8..7be2df2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -106,6 +106,14 @@ "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" }, + "define-properties": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", + "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "requires": { + "object-keys": "^1.0.12" + } + }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", @@ -117,6 +125,24 @@ "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==" }, + "es-abstract": { + "version": "1.17.4", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.4.tgz", + "integrity": "sha512-Ae3um/gb8F0mui/jPL+QiqmglkUsaQf7FwBEHYIFkztkneosu9imhqHpBzQ3h1vit8t5iQ74t6PEVvphBZiuiQ==", + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.1.5", + "is-regex": "^1.0.5", + "object-inspect": "^1.7.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.0", + "string.prototype.trimleft": "^2.1.1", + "string.prototype.trimright": "^2.1.1" + } + }, "es-lookup-scope": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-lookup-scope/-/es-lookup-scope-1.0.1.tgz", @@ -127,6 +153,16 @@ "lodash.findlast": "^3.2.0" } }, + "es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, "es6-collections": { "version": "0.5.6", "resolved": "https://registry.npmjs.org/es6-collections/-/es6-collections-0.5.6.tgz", @@ -172,6 +208,11 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, "glob": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", @@ -190,6 +231,14 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==" }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "requires": { + "function-bind": "^1.1.1" + } + }, "has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", @@ -198,6 +247,11 @@ "ansi-regex": "^2.0.0" } }, + "has-symbols": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==" + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -226,6 +280,16 @@ "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=" }, + "is-callable": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.5.tgz", + "integrity": "sha512-ESKv5sMCJB2jnHTWZ3O5itG+O128Hsus4K4Qh1h2/cgn2vbgnLSVqfV46AeJA9D5EeeLa9w81KUXMtn34zhX+Q==" + }, + "is-date-object": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", + "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==" + }, "is-fullwidth-code-point": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", @@ -234,6 +298,22 @@ "number-is-nan": "^1.0.0" } }, + "is-regex": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.5.tgz", + "integrity": "sha512-vlKW17SNq44owv5AQR3Cq0bQPEb8+kF3UKZ2fiZNOWtztYE5i0CzCZxFDwO58qAOWtxdBRVO/V5Qin1wjCqFYQ==", + "requires": { + "has": "^1.0.3" + } + }, + "is-symbol": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", + "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==", + "requires": { + "has-symbols": "^1.0.1" + } + }, "jsonfile": { "version": "2.4.0", "resolved": "http://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", @@ -423,6 +503,49 @@ "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" }, + "object-inspect": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.7.0.tgz", + "integrity": "sha512-a7pEHdh1xKIAgTySUGgLMx/xwDZskN1Ud6egYYN3EdRW4ZMPNEDUTF+hwy2LUC+Bl+SyLXANnwz/jyh/qutKUw==" + }, + "object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==" + }, + "object.assign": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", + "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", + "requires": { + "define-properties": "^1.1.2", + "function-bind": "^1.1.1", + "has-symbols": "^1.0.0", + "object-keys": "^1.0.11" + } + }, + "object.entries": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.1.tgz", + "integrity": "sha512-ilqR7BgdyZetJutmDPfXCDffGa0/Yzl2ivVNpbx/g4UeWrCdRnFDUBrKJGLhGieRHDATnyZXWBeCb29k9CJysQ==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1", + "function-bind": "^1.1.1", + "has": "^1.0.3" + } + }, + "object.values": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.1.tgz", + "integrity": "sha512-WTa54g2K8iu0kmS/us18jEmdv1a4Wi//BZ/DTVYEcH0XhLM5NYdpDHja3gt57VrZLcNAO2WGA+KpWsDBaHt6eA==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1", + "function-bind": "^1.1.1", + "has": "^1.0.3" + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -509,6 +632,24 @@ "strip-ansi": "^3.0.0" } }, + "string.prototype.trimleft": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string.prototype.trimleft/-/string.prototype.trimleft-2.1.1.tgz", + "integrity": "sha512-iu2AGd3PuP5Rp7x2kEZCrB2Nf41ehzh+goo8TV7z8/XDBbsvc6HQIlUl9RjkZ4oyrW1XM5UwlGl1oVEaDjg6Ag==", + "requires": { + "define-properties": "^1.1.3", + "function-bind": "^1.1.1" + } + }, + "string.prototype.trimright": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string.prototype.trimright/-/string.prototype.trimright-2.1.1.tgz", + "integrity": "sha512-qFvWL3/+QIgZXVmJBfpHmxLB7xsUXz6HsUmP8+5dRaC3Q7oKUv9Vo6aMCRZC1smrtyECFsIT30PqBJ1gTjAs+g==", + "requires": { + "define-properties": "^1.1.3", + "function-bind": "^1.1.1" + } + }, "strip-ansi": { "version": "3.0.1", "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", diff --git a/package.json b/package.json index 7891982..25c9407 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,9 @@ "fs-extra": "reggi/node-fs-extra#enhanced", "lodash": "^4.17.15", "markdown-it": "^5.1.0", + "object.assign": "^4.1.0", + "object.entries": "^1.1.1", + "object.values": "^1.1.1", "os-tmpdir": "^1.0.2", "yargs": "^3.32.0" }, diff --git a/src/acorn-umd/acorn-umd.ts b/src/acorn-umd/acorn-umd.ts index fdf5a94..898aead 100644 --- a/src/acorn-umd/acorn-umd.ts +++ b/src/acorn-umd/acorn-umd.ts @@ -1,4 +1,5 @@ -import {assign, clone, find, filter, matches, map, reject, result, sortBy, take, zip} from 'lodash'; +import assign from 'object.assign'; +import {clone, find, filter, matches, map, reject, result, sortBy, take, zip} from 'lodash'; import estraverse from 'estraverse'; import Node from './Node'; import ImportNode from './ImportNode'; diff --git a/src/eval-markdown.js b/src/eval-markdown.js index aecc84d..b3a15df 100644 --- a/src/eval-markdown.js +++ b/src/eval-markdown.js @@ -3,7 +3,7 @@ var crypto = require('crypto') var path = require('path') var Promise = require('bluebird') var child_process = require('child_process') -var _ = require('lodash') +var { chain, each, filter, find, flatten, groupBy, includes, indexOf, last, map, range, slice, uniq, values } = require('lodash') var fs = Promise.promisifyAll(require('fs-extra')) var MarkdownIt = require('markdown-it') var acorn = require('acorn') @@ -31,7 +31,7 @@ function main (filePath$, packagePath, prepend, blockScope, nonstop, preventEval var logStore = [] DEBUG = debug log = logFactory(logStore, silence) - var filePaths = _.flatten([filePath$]) + var filePaths = flatten([filePath$]) logInfo('it worked if it ends with', 'ok') return getPackage(packagePath) .then(function (pkg) { @@ -63,12 +63,12 @@ function main (filePath$, packagePath, prepend, blockScope, nonstop, preventEval } var getExitCode = main.getExitCode = function (mdResults) { - var evaluations = _.chain(mdResults).map('evaluated').flatten().value() - var evalResults = _.chain(evaluations).map('evalResult').flatten().value() - var evalResultsInstanceofError = _.map(evalResults, function (evalResult) { + var evaluations = chain(mdResults).map('evaluated').flatten().value() + var evalResults = chain(evaluations).map('evalResult').flatten().value() + var evalResultsInstanceofError = map(evalResults, function (evalResult) { return evalResult instanceof Error }) - var evalResultsHasInstanceofError = _.includes(evalResultsInstanceofError, true) + var evalResultsHasInstanceofError = includes(evalResultsInstanceofError, true) if (evalResultsHasInstanceofError) return 1 return 0 } @@ -85,10 +85,10 @@ var getPackage = main.getPackage = function (packagePath) { } var previousIndex = main.previousIndex = function (node, nodes, fn) { - var index = _.indexOf(nodes, node) + var index = indexOf(nodes, node) index = index < 0 ? 0 : index - var subArr = _.slice(nodes, 0, index) - var revIndex = _.chain(subArr) + var subArr = slice(nodes, 0, index) + var revIndex = chain(subArr) .reverse() .findIndex(fn) .value() @@ -109,15 +109,15 @@ var previousIndexClose = main.previousIndexClose = function (node, nodes, type) } var groupChildren = main.groupChildren = function (nodes) { - nodes = _.groupBy(nodes, function (node) { + nodes = groupBy(nodes, function (node) { return previousIndexClose(node, nodes) }) - return _.values(nodes) + return values(nodes) } /** searches preceeding nodes for pattern */ var searchLink = main.searchLink = function (subNodes, pattern) { - var textNode = _.find(subNodes, function (node) { + var textNode = find(subNodes, function (node) { if (!node.content) return false return node.content.match(pattern) }) @@ -143,7 +143,7 @@ var searchComment = main.searchComment = function (node, pattern) { } var createLineDoc = main.createLineDoc = function (lines) { - return _.range(lines).map(function () { + return range(lines).map(function () { return '' }) } @@ -151,7 +151,7 @@ var createLineDoc = main.createLineDoc = function (lines) { var replaceLines = main.replaceLines = function (start, main, sub) { main = (Array.isArray(main)) ? main : main.split('\n') sub = (Array.isArray(sub)) ? sub : sub.split('\n') - var output = _.flatten([_.slice(main, 0, start), sub, _.slice(main, start + sub.length, main.length)]) + var output = flatten([slice(main, 0, start), sub, slice(main, start + sub.length, main.length)]) return output } @@ -161,11 +161,11 @@ var getHash = main.getHash = function (content) { } var mapNodes = main.mapNodes = function (nodes) { - return _.map(nodes, function (node, index) { + return map(nodes, function (node, index) { node.children = groupChildren(node.children) node.previousFenceIndex = previousIndexType(node, nodes, 'fence') - var subNodes = _.slice(nodes, node.previousFenceIndex, index) + var subNodes = slice(nodes, node.previousFenceIndex, index) node.fileEval = searchLink(subNodes, /\[(.+)?\]\(#?(eval\s?file|file\s?eval)\)/i) || searchComment(node, /\/\/\s(file\s?eval\s|eval\s?file\s)(.+)/i) || @@ -183,30 +183,30 @@ var mapNodes = main.mapNodes = function (nodes) { } var getNodeId = main.getNodeId = function (nodes, filePath) { - return _.map(nodes, function (node, index) { + return map(nodes, function (node, index) { node.id = index + 1 return node }) } var getFences = main.getFences = function (nodes, langs) { - return _.filter(nodes, function (node) { + return filter(nodes, function (node) { if (node.type !== 'fence') return false if (!langs && node.type === 'fence') return true - return _.includes(langs, node.info) + return includes(langs, node.info) }) } var filterPrevented = main.filterPrevented = function (nodes) { - return _.filter(nodes, function (node) { + return filter(nodes, function (node) { return !node.preventEval }) } var buildPreserveLines = main.buildPreserveLines = function (node$, lines) { - var nodes = _.flatten([node$]) + var nodes = flatten([node$]) var lineDoc = createLineDoc(lines) - _.each(nodes, function (node) { + each(nodes, function (node) { var contentLines = String(node.content || '').split(/\r\n?|\n/) lineDoc = replaceLines(node.startLine, lineDoc, contentLines) }) @@ -214,8 +214,8 @@ var buildPreserveLines = main.buildPreserveLines = function (node$, lines) { } var buildConcat = main.buildConcat = function (node$, lines) { - var nodes = _.flatten([node$]) - return _.chain(nodes) + var nodes = flatten([node$]) + return chain(nodes) .map(function (node) { return node.content }) @@ -228,7 +228,7 @@ var getDeps = main.getDeps = function (code) { var deps = umd(ast, { es6: true, amd: true, cjs: true }) - return _.uniq(deps, function (dep) { + return uniq(deps, function (dep) { var important = { 'value': dep.source.value, 'start': dep.source.start, @@ -255,7 +255,7 @@ var alterAssignedModule = main.alterAssignedModule = function (code, prepend, pk var chars = 0 name = regExpEscape(name) var pattern = new RegExp('^' + name + '($|/.*)') - _.each(deps, function (dep) { + each(deps, function (dep) { var match = dep.source.value.match(pattern) if (match) { var start = chars + dep.source.start + 1 @@ -273,9 +273,9 @@ var alterSelfModules = main.alterSelfModules = function (code, nodes) { var deps = getDeps(code) if (!deps.length) return code var chars = 0 - _.each(deps, function (dep) { + each(deps, function (dep) { if (dep.source.value) { - var node = _.find(nodes, { + var node = find(nodes, { 'fileEval': dep.source.value }) if (node && node.fileCreated) { @@ -296,9 +296,9 @@ var alterPrependModules = main.alterPrependModules = function (code, nodes, prep prepend = (prepend) ? prepend : './' var localRegex = /^.\.\/|^.\// var chars = 0 - _.each(deps, function (dep) { + each(deps, function (dep) { if (dep.source.value && dep.source.value.match(localRegex)) { - var node = _.find(nodes, { + var node = find(nodes, { 'fileEval': dep.source.value }) if (!node) { @@ -320,8 +320,8 @@ var alterNpmModules = main.alterNpmModules = function (code, nodes, prepend) { prepend = (prepend) ? prepend : './' var nonNpm = /^.\.\/|^.\/|^\// var chars = 0 - _.each(deps, function (dep) { - if (dep.source.value && !dep.source.value.match(nonNpm) && !_.includes(natives, dep.source.value)) { + each(deps, function (dep) { + if (dep.source.value && !dep.source.value.match(nonNpm) && !includes(natives, dep.source.value)) { var start = chars + dep.source.start + 1 var end = chars + dep.source.end - 1 var replacement = path.resolve(path.join(prepend, 'node_modules', dep.source.value)) @@ -358,7 +358,7 @@ var stackSplit = main.stackSplit = function (stack) { 'frame': [], 'lines': [] } - _.each(stackLines, function (stackLine) { + each(stackLines, function (stackLine) { var pattern = /^\s\s\s\sat\s/ var match = stackLine.match(pattern) if (match) { @@ -379,13 +379,13 @@ var stackJoin = main.stackJoin = function (stack) { } var findErrorNode = main.findErrorNode = function (nodes, line) { - return _.find(nodes, function (node) { + return find(nodes, function (node) { return node.startLine <= line && node.endLine >= line }) } var errMsg = main.errMsg = function () { - var args = _.values(arguments) + var args = values(arguments) if (args.length > 1) args[0] = chalk.magenta(args[0]) return [ chalk.white('evalmd'), @@ -394,7 +394,7 @@ var errMsg = main.errMsg = function () { } var infoMsg = main.infoMsg = function () { - var args = _.values(arguments) + var args = values(arguments) args[0] = chalk.magenta(args[0]) return [ chalk.white('evalmd'), @@ -403,7 +403,7 @@ var infoMsg = main.infoMsg = function () { } var debugMsg = main.debugMsg = function () { - var args = _.values(arguments) + var args = values(arguments) args[0] = chalk.magenta(args[0]) return [ chalk.white('evalmd'), @@ -420,18 +420,18 @@ var cleanStack = main.cleanStack = function (errOrStack) { var logErr = main.logErr = function (err) { var lines = cleanStack(err) - return _.each(lines, function (line) { + return each(lines, function (line) { return log(errMsg(line)) }) } var logInfo = main.logInfo = function () { - var args = _.values(arguments) + var args = values(arguments) return log(infoMsg.apply(null, args)) } var logDebug = main.logDebug = function () { - var args = _.values(arguments) + var args = values(arguments) if (DEBUG) return log(debugMsg.apply(null, args)) } @@ -481,9 +481,9 @@ var parseLineChar = main.parseLineChar = function (s) { } var getCleanLines = main.getCleanLines = function (incLines, nodes, absFilePath, frame) { - var lines = _.map(incLines, function (line) { + var lines = map(incLines, function (line) { var lineChar = parseLineChar(line) - var matchNodes = _.find(nodes, function (node) { + var matchNodes = find(nodes, function (node) { if (!node.fileEvalHashPath) return false return line.match(node.fileEvalHashPath) }) @@ -518,12 +518,12 @@ var getCleanLines = main.getCleanLines = function (incLines, nodes, absFilePath, lines = lines.reverse() var matchFound = false if (!frame) { - lines = _.filter(lines, function (line) { + lines = filter(lines, function (line) { if (line.replacement) matchFound = true return matchFound }) } - lines = _.map(lines, function (line) { + lines = map(lines, function (line) { if (line.replacement) return line.replacement return line.line }) @@ -539,7 +539,7 @@ var evalError = main.evalError = function (filePath, nodes) { if (cleanLines.length !== 0) stack.lines = cleanLines stack.frame = getCleanLines(stack.frame, nodes, absFilePath, true) stack.frame.shift() - if (_.last(stack.frame) === '') stack.frame.pop() + if (last(stack.frame) === '') stack.frame.pop() return stackJoin(stack) } } @@ -577,7 +577,7 @@ var nonstopErr = main.nonstopErr = function (error, stackWrapper, nonstop) { var evaluate = main.evaluate = function (node, nodes, markdownLinesLength, pkg, prepend, nonstop, filePath) { return promiseRipple(node, { notice: function (node) { - var ids = (Array.isArray(node)) ? _.chain(node).map('id').value() : [node.id] + var ids = (Array.isArray(node)) ? chain(node).map('id').value() : [node.id] var word = (ids.length > 1) ? 'blocks' : 'block' logInfo(filePath, ['running', word, ids.join(', ')].join(' ')) }, @@ -636,7 +636,7 @@ var evaluateScope = main.evaluateScope = function (nodes, markdownLinesLength, p var outputCode = main.outputCode = function (node, nodes, markdownLinesLength, pkg, prepend, nonstop, filePath, output, delimeter) { return promiseRipple(node, { notice: function (node) { - var ids = (Array.isArray(node)) ? _.chain(node).map('id').value() : [node.id] + var ids = (Array.isArray(node)) ? chain(node).map('id').value() : [node.id] var word = (ids.length > 1) ? 'blocks' : 'block' logInfo(filePath, ['outputting', word, ids.join(', ')].join(' ')) }, @@ -696,7 +696,7 @@ var assemble = main.assemble = function (filePath, pkg, prepend, blockScope, non // eval nodes data.evalNodes = (includePrevented) ? data.allJsFences : data.permittedFences // get the blockscope - data.blockScope = blockScope || Boolean(_.chain(data.evalNodes).map('fileEval').without(false).value().length) + data.blockScope = blockScope || Boolean(chain(data.evalNodes).map('fileEval').without(false).value().length) return data }, evaluated: function (data) { @@ -729,10 +729,10 @@ module.exports = main // console.log(JSON.stringify(nodes, null, 2)) - // var childrenSets = _.map(subNodes, 'children') + // var childrenSets = map(subNodes, 'children') // if (!childrenSets.length) return false - // var found = _.find(childrenSets, function (children) { - // return _.find(children, function (child) { + // var found = find(childrenSets, function (children) { + // return find(children, function (child) { // if (child.type === 'link_open') { // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -749,13 +749,13 @@ module.exports = main // } // var previousSiblingFileEval = main.previousSiblingFileEval = function (node, nodes) { -// var index = _.indexOf(nodes, node) -// var subNodes = _.slice(nodes, node.previousFenceIndex, index) -// var childrenSets = _.map(subNodes, 'children') -// childrenSets = _.flatten(childrenSets) +// var index = indexOf(nodes, node) +// var subNodes = slice(nodes, node.previousFenceIndex, index) +// var childrenSets = map(subNodes, 'children') +// childrenSets = flatten(childrenSets) // if (!childrenSets.length) return false -// var found = _.find(childrenSets, function (children) { -// return _.find(children, function (child) { +// var found = find(childrenSets, function (children) { +// return find(children, function (child) { // if (child.type === 'link_open') { // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -766,7 +766,7 @@ module.exports = main // }) // }) // console.log(found) -// var text = _.find(found, { +// var text = find(found, { // 'type': 'text' // }) // return (text && text.content) ? text.content : false @@ -779,7 +779,7 @@ module.exports = main // Boolean(node.content.match(/^\/\/ eval prevent/i)), // Boolean(node.content.match(/^\/\/ evalprevent/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // } // // block.assignFileViaComment = block.code.match(/\/\/\s(file\s?eval\s|eval\s?file\s)(.+)/i) @@ -789,11 +789,11 @@ module.exports = main // } // var preventEval = main.preventEval = function (node, nodes) { -// var index = _.indexOf(nodes, node) -// var subNodes = _.slice(nodes, node.prevFenceIndex, index) -// var result = _.find(subNodes, function (node) { +// var index = indexOf(nodes, node) +// var subNodes = slice(nodes, node.prevFenceIndex, index) +// var result = find(subNodes, function (node) { // if (!node.children) return false -// return _.find(node.children, function (childElement) { +// return find(node.children, function (childElement) { // if (childElement.type == "link_open") { // var hrefIndex = childElement.attrIndex('href') // var hrefValue = childElement.attrs[hrefIndex][1] @@ -804,7 +804,7 @@ module.exports = main // var hrefValue = childElement.attrs[hrefIndex][1] // // } - // return _.find(childElement, function (child) { + // return find(childElement, function (child) { // if (child.type !== 'link_open') return false // var hrefIndex = child.attrIndex('href') // var hrefValue = child.attrs[hrefIndex][1] @@ -815,17 +815,17 @@ module.exports = main // Boolean(hrefValue.match(/eval prevent/i)), // Boolean(hrefValue.match(/evalprevent/i)) // ] - // return _.includes(options, true) + // return includes(options, true) // }) // }) // }) // return Boolean(result) // } - // var index = _.indexOf(nodes, node) - // var haystack = _.slice(nodes, node.prevFenceIndex, index) - // var needle = _.find(haystack, function (node) { + // var index = indexOf(nodes, node) + // var haystack = slice(nodes, node.prevFenceIndex, index) + // var needle = find(haystack, function (node) { // if (!node.children) return false - // return _.find(node.children, function (child) { + // return find(node.children, function (child) { // if (child.type !== 'link_open') return false // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -836,13 +836,13 @@ module.exports = main // Boolean(hrefValue.match(/eval prevent/i)), // Boolean(hrefValue.match(/evalprevent/i)) // ] - // return _.includes(options, true) + // return includes(options, true) // }) // }) // return Boolean(needle) // } -// nodes = _.map(nodes, function (node) { +// nodes = map(nodes, function (node) { // node.children = elements(node.children) // node.prevFenceIndex = prevIndex(node, nodes, 'fence') // // console.log(node.children) @@ -854,11 +854,11 @@ module.exports = main // console.log(nodes) // var preventEval = main.preventEval = function (node, nodes) { -// var index = _.indexOf(nodes, node) -// var haystack = _.slice(nodes, node.prevFenceIndex, index) -// var needle = _.find(haystack, function (node) { +// var index = indexOf(nodes, node) +// var haystack = slice(nodes, node.prevFenceIndex, index) +// var needle = find(haystack, function (node) { // if (!node.children) return false -// return _.find(node.children, function (child) { +// return find(node.children, function (child) { // if (child.type !== 'link_open') return false // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -869,19 +869,19 @@ module.exports = main // Boolean(hrefValue.match(/eval prevent/i)), // Boolean(hrefValue.match(/evalprevent/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // }) // return Boolean(needle) // } // // var fileEval = main.fileEval = function (node, nodes) { -// var index = _.indexOf(nodes, node) -// var haystack = _.slice(nodes, node.prevFenceIndex, index) +// var index = indexOf(nodes, node) +// var haystack = slice(nodes, node.prevFenceIndex, index) // -// var needle = _.find(haystack, function (node) { +// var needle = find(haystack, function (node) { // if (!node.children) return false -// return _.find(node.children, function (child) { +// return find(node.children, function (child) { // if (child.type !== 'link_open') return false // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -892,7 +892,7 @@ module.exports = main // Boolean(hrefValue.match(/eval file/i)), // Boolean(hrefValue.match(/evalfile/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // }) // @@ -904,21 +904,21 @@ module.exports = main // console.log(nodes) // var fileName = main.fileName = function (node, nodes) { -// var index = _.indexOf(nodes, node) -// var haystack = _.slice(nodes, node.prevFenceIndex, index) +// var index = indexOf(nodes, node) +// var haystack = slice(nodes, node.prevFenceIndex, index) // -// return _.map(haystack, function (node, index) { -// node.children = _.map(node.children, function (child) { +// return map(haystack, function (node, index) { +// node.children = map(node.children, function (child) { // var prevLinkOpen = prevIndex(child, node.children, 'link_open') -// var index = _.indexOf(node.children, child) +// var index = indexOf(node.children, child) // console.log([prevLinkOpen, index]) -// var haystack = _.slice(node.children, prevLinkOpen, index) +// var haystack = slice(node.children, prevLinkOpen, index) // // console.log(haystack) -// var needle = _.find(haystack, function (child) { +// var needle = find(haystack, function (child) { // -// return _.find(node.children, function (child) { +// return find(node.children, function (child) { // var hrefIndex = child.attrIndex('href') // var hrefValue = child.attrs[hrefIndex][1] // var options = [ @@ -927,7 +927,7 @@ module.exports = main // Boolean(hrefValue.match(/eval prevent/i)), // Boolean(hrefValue.match(/evalprevent/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // }) @@ -937,7 +937,7 @@ module.exports = main // }) // if (!node.children) return node -// var lastLink = _.findIndex(node.children, function (child) { +// var lastLink = findIndex(node.children, function (child) { // if (child.type !== 'link_open') return false // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -948,16 +948,16 @@ module.exports = main // Boolean(hrefValue.match(/eval file/i)), // Boolean(hrefValue.match(/evalfile/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // // console.log(lastLink) -// // var _.index(node, lastLink) -// var haystack = _.slice(nodes, lastLink, index) +// // var index(node, lastLink) +// var haystack = slice(nodes, lastLink, index) // console.log(haystack) -// var subNeedles = _.map(haystack, function (node) { +// var subNeedles = map(haystack, function (node) { // if (!node.children) return false -// var node = _.find(node.children, function (child) { +// var node = find(node.children, function (child) { // if (child.type !== 'link_open') return false // if (!child.attrs) return false // var hrefIndex = child.attrIndex('href') @@ -968,11 +968,11 @@ module.exports = main // Boolean(hrefValue.match(/eval file/i)), // Boolean(hrefValue.match(/evalfile/i)) // ] -// return _.includes(options, true) +// return includes(options, true) // }) // var lastLinkOpenIndex = prevIndex(node, nodes, 'link_open') -// var haystack = _.slice(nodes, lastLinkOpenIndex, index) -// return _.find(haystack, function (child) { +// var haystack = slice(nodes, lastLinkOpenIndex, index) +// return find(haystack, function (child) { // return child.type === "text" // }) // }) @@ -981,9 +981,9 @@ module.exports = main // console.log(JSON.stringify(nodes, null, 2)) // console.log(nodes) -// _.each(nodes, function (node) { +// each(nodes, function (node) { // if (node.type === 'inline') { -// _.each(node.children, function (child) { +// each(node.children, function (child) { // if (child.attrs) { // var hrefIndex = child.attrIndex('href') // var hrefValue = child.attrs[hrefIndex][1] @@ -994,10 +994,10 @@ module.exports = main // }) // var prevented = main.prevented = function (node, nodes) { -// var index = _.indexOf(nodes, node) +// var index = indexOf(nodes, node) // return [i, index] -// // var hay = _.split(arr, start, end) -// // return _.find(hay, { +// // var hay = split(arr, start, end) +// // return find(hay, { // // 'prevent': true // // }) // } @@ -1018,13 +1018,13 @@ module.exports = main // if (!node.type.match('_close')) return null // if (!node.type.match('_close')) return null -// var subNodes = _.slice(nodes, index + 1) -// var endingIndex = _.findIndex(subNodes, node.tag) +// var subNodes = slice(nodes, index + 1) +// var endingIndex = findIndex(subNodes, node.tag) -// return _.slice(index, endingIndex) +// return slice(index, endingIndex) // - // var pieceHref = _.find(child, function (piece) { + // var pieceHref = find(child, function (piece) { // if (piece.type !== 'link_open') return false // if (!piece.attrs) return false // var hrefIndex = piece.attrIndex('href') @@ -1038,7 +1038,7 @@ module.exports = main // }) // var addEvalCode = main.addEvalCode = function (nodes, blockScope, markdownLinesLength, pkg, prepend, nonstop) { -// return _.map(nodes, function (node) { +// return map(nodes, function (node) { // node.evalCode = false // if (!blockScope) return node // node.evalCode = catchNonstop(function () { @@ -1094,15 +1094,15 @@ module.exports = main // var fileEval = main.fileEval = function (node, nodes) { // // get the index for the node -// var index = _.indexOf(nodes, node) +// var index = indexOf(nodes, node) // // split the nodes get all between last fence and this node -// var subNodes = _.slice(nodes, node.previousFenceIndex, index) +// var subNodes = slice(nodes, node.previousFenceIndex, index) // // map loop / find // // // get the href value -// var href = _.chain(subNodes).map(function (node) { -// return _.find(node.children, function (child) { -// return _.find(child, function (piece) { +// var href = chain(subNodes).map(function (node) { +// return find(node.children, function (child) { +// return find(child, function (piece) { // if (piece.type !== 'link_open') return false // if (!piece.attrs) return false // var hrefIndex = piece.attrIndex('href') @@ -1113,7 +1113,7 @@ module.exports = main // }).flattenDeep().without(false).value() // // if heref get the text of the href // if (href) { -// var hrefText = _.find(href, { +// var hrefText = find(href, { // 'type': 'text' // }) // if (hrefText && hrefText.content) { @@ -1135,13 +1135,13 @@ module.exports = main // // get the nodes // // // search through children nodes -// var value = _.map(subNodes, function (node) { -// return _.map(node.children, function (child) { -// var pieceText = _.find(child, function (piece) { +// var value = map(subNodes, function (node) { +// return map(node.children, function (child) { +// var pieceText = find(child, function (piece) { // if (piece.type !== 'text') return false // return piece.content.match(/\[\]\(#?(eval\s?prevent|prevent\s?eval)\)/i) // }) -// var pieceHref = _.find(child, function (piece) { +// var pieceHref = find(child, function (piece) { // if (piece.type !== 'link_open') return false // if (!piece.attrs) return false // var hrefIndex = piece.attrIndex('href') @@ -1152,7 +1152,7 @@ module.exports = main // }) // }) // // clean up the child nodes -// var found = _.chain(value).flatten().without(false).value() +// var found = chain(value).flatten().without(false).value() // // if child nodes match return true // if (found && found.length) { // return true @@ -1172,13 +1172,13 @@ module.exports = main // // var fileEval = main.fileEval = function (node, nodes) { // // get the index for the node -// var index = _.indexOf(nodes, node) +// var index = indexOf(nodes, node) // // split the nodes get all between last fence and this node -// var subNodes = _.slice(nodes, node.previousFenceIndex, index) +// var subNodes = slice(nodes, node.previousFenceIndex, index) // // map loop / find -// var text = _.chain(subNodes).map(function (node) { -// return _.map(node.children, function (child) { -// return _.map(child, function (piece) { +// var text = chain(subNodes).map(function (node) { +// return map(node.children, function (child) { +// return map(child, function (piece) { // if (piece.type !== 'text') return false // return piece.content.match(/\[(.+?)\]\(#?(eval\s?file|file\s?eval)\)/i) // }) @@ -1189,9 +1189,9 @@ module.exports = main // return text[1] // } // // get the href value -// var href = _.chain(subNodes).map(function (node) { -// return _.find(node.children, function (child) { -// return _.find(child, function (piece) { +// var href = chain(subNodes).map(function (node) { +// return find(node.children, function (child) { +// return find(child, function (piece) { // if (piece.type !== 'link_open') return false // if (!piece.attrs) return false // var hrefIndex = piece.attrIndex('href') @@ -1202,7 +1202,7 @@ module.exports = main // }).flattenDeep().without(false).value() // // if heref get the text of the href // if (href) { -// var hrefText = _.find(href, { +// var hrefText = find(href, { // 'type': 'text' // }) // if (hrefText && hrefText.content) { @@ -1222,9 +1222,9 @@ module.exports = main // // var searchLink = main.searchLink = function (subNodes, pattern) { // // console.log(subNodes) -// var href = _.chain(subNodes).map(function (node) { -// return _.find(node.children, function (child) { -// return _.find(child, function (piece) { +// var href = chain(subNodes).map(function (node) { +// return find(node.children, function (child) { +// return find(child, function (piece) { // if (piece.type !== 'link_open') return false // if (!piece.attrs) return false // var hrefIndex = piece.attrIndex('href') @@ -1235,7 +1235,7 @@ module.exports = main // }).flattenDeep().without(false).value() // // if heref get the text of the href // if (href) { -// var hrefText = _.find(href, { +// var hrefText = find(href, { // 'type': 'text' // }) // if (hrefText && hrefText.content) { diff --git a/src/promise-ripple.js b/src/promise-ripple.js index a0f0640..e31be29 100644 --- a/src/promise-ripple.js +++ b/src/promise-ripple.js @@ -1,14 +1,14 @@ -var _ = require('lodash') var Promise = require('bluebird') +var values = require('object.values') +var entries = require('object.entries') function promiseRipple (start, props) { - props = (props) ? props : start - start = (props) ? start : {} - props = _.mapValues(props, function (prop, key) { - prop.key = key - return prop - }) - return Promise.reduce(_.values(props), function (result, action) { + props = props || start + start = props ? start : {} + entries(props).forEach(([key, prop]) => { + prop.key = key; + }); + return Promise.reduce(values(props), function (result, action) { if (typeof action !== 'function') throw new Error('property values must be functions') return Promise.resolve(action(start)).then(function (value) { if (start === value) {