CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
index.js28 linesDownload Raw Back to dist
1import tabsToSpaces from 'convert-to-spaces';2const generateLineNumbers = (line, around) => {3    const lineNumbers = [];4    const min = line - around;5    const max = line + around;6    for (let lineNumber = min; lineNumber <= max; lineNumber++) {7        lineNumbers.push(lineNumber);8    }9    return lineNumbers;10};11const codeExcerpt = (source, line, options = {}) => {12    var _a;13    if (typeof source !== 'string') {14        throw new TypeError('Source code is missing.');15    }16    if (!line || line < 1) {17        throw new TypeError('Line number must start from `1`.');18    }19    const lines = tabsToSpaces(source).split(/\r?\n/);20    if (line > lines.length) {21        return;22    }23    return generateLineNumbers(line, (_a = options.around) !== null && _a !== void 0 ? _a : 3)24        .filter(line => lines[line - 1] !== undefined)25        .map(line => ({ line, value: lines[line - 1] }));26};27export default codeExcerpt;28 
basant307/AI_Governance_Project · CoolFace