文件操作 - index.js
返回文件管理
返回主菜单
删除本文件
文件: /var/www/OLD/node_modules/index-to-position/index.js
编辑文件内容
// Prevent `String#lastIndexOf` treat negative index as `0` const safeLastIndexOf = (string, searchString, index) => index < 0 ? -1 : string.lastIndexOf(searchString, index); function getPosition(text, textIndex) { const lineBreakBefore = safeLastIndexOf(text, '\n', textIndex - 1); const column = textIndex - lineBreakBefore - 1; let line = 0; for ( let index = lineBreakBefore; index >= 0; index = safeLastIndexOf(text, '\n', index - 1) ) { line++; } return {line, column}; } export default function indexToLineColumn(text, textIndex, {oneBased = false} = {}) { if (textIndex < 0 || (textIndex >= text.length && text.length > 0)) { throw new RangeError('Index out of bounds'); } const position = getPosition(text, textIndex); return oneBased ? {line: position.line + 1, column: position.column + 1} : position; }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件