npmize
Version:
Let's create an npm package without worrying about anything.
27 lines (26 loc) • 1.11 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUpdatedData = getUpdatedData;
exports.resolveJsFilePath = resolveJsFilePath;
const fs_1 = require("../utils/fs");
function getUpdatedData(fileData, found, cb) {
const newEntries = [
{ start: 0, end: 0, value: '' },
...found.sort((a, b) => a.start - b.start),
];
const chunks = newEntries.map((node, i, arr) => {
var _a;
const nextNode = arr[i + 1];
const nodeEnd = node.end;
const nextNodeEnd = nextNode ? nextNode.start : Infinity;
const str = fileData.slice(nodeEnd, nextNodeEnd);
if (!nextNode)
return str;
return [str, `"${(_a = cb(nextNode)) !== null && _a !== void 0 ? _a : nextNode.value}"`];
});
return chunks.flat().join('');
}
function resolveJsFilePath(target) {
var _a, _b;
return ((_b = (_a = (0, fs_1.getExistedFilePath)(target)) !== null && _a !== void 0 ? _a : (0, fs_1.getExistedFilePath)(target + '.js')) !== null && _b !== void 0 ? _b : (0, fs_1.getExistedFilePath)(target + '/index.js'));
}
;