📜  计算打字稿代码示例中的文件行数

📅  最后修改于: 2022-03-11 14:48:36.359000             🧑  作者: Mango

代码示例1
'use strict';

import * as fs from 'fs';

function linesNumber(fileName: string): number {
  try {
    let fileLines = fs.readFileSync(fileName, 'utf-8').split('\n');
    return fileLines.length;
  } catch (err) {
    return 0;
  }
}
console.log(linesNumber('my-file.txt'))