
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
line-counter-node
Advanced tools
Line counter is a node library that traverses a directory tree recursively to find all files with specific extensions (which is specified by user) and returns the total line count of matched files.
LineCounter is a npm library and it can be installed as following
npm install -g line-counter-node
After installing LineCounter, binary file will be added to path. You can run the script as linecounter or lc.
There are 2 ways to use options.
linecounter [globalOptions] [method] [methodOptions]
lc [globalOptions] [method] [methodOptions] # lc is alias of linecounter
linecounter # Same with --help
linecounter --version
linecounter --help
linecounter count --path="/var/www/html" --verbose # All files will be counted and printed under the current directory
linecounter count --extensions="comma, separated, extensions"
linecounter count --except="js" # All files except the files with js extension will be counted
linecounter count --rules="ignoreDir(node_modules)"
lineCounter count --rules="ignoreHidden|filePostfix(test)" # multiple rule usage. Separate rules with | character
linecounter count -p "path/to/directory" -r "ignoreDir(node_modules,tests,lib,src)" # multiple aguments with one rule usage
linecounter count -e "comma, separated, extensions" -r "ignoreDir(node_modules,tests,lib,src)" -v --save="myConfiguration" # Saves options
linecounter count --config="myConfiguration" # Following options will be used: -e "comma, separated, extensions" -r "ignoreDir(node_modules,tests,lib,src)" -v
linecounter config --list
linecounter config --show=myConfiguration # Shows details of myConfiguration
linecounter config --remove=myConfiguration # Removes myConfiguration
linecounter config --destroy
Total files: 755
Total lines: 338203
const LineCounter = require("line-counter-node").LineCounter;
var lc = new LineCounter();
// Name is file or directory name without path. Stats is fs.Stats. Arguments are unlimited and depends on the rule
function customRule(name, stats, arg1, arg2, arg3, ...){
if( want file or directory to count ){
return true;
}
else{
return false;
}
}
const Events = require("line-counter-node").Events;
From method allows user to specify the allowed extensions. Only given extensions will be counted
const ExtensionsFactory = require("line-counter-node").ExtensionsFactory;
var ext = ExtensionsFactory.from("js, php, java"); // Comma separated extension list
var ext = ExtensionsFactory.from(["js", "php", "java"]); // Array with extensions
Except method allows user to specify disallowed extensions. All other extensions will be counted except given extensions
const ExtensionsFactory = require("line-counter-node").ExtensionsFactory;
var ext = ExtensionsFactory.except("js, php, java"); // Comma separated extension list
var ext = ExtensionsFactory.except(["js", "php", "java"]); // Array with extensions
const Rules = require("line-counter-node").Rules;
const ExtensionsFactory = require("line-counter-node").ExtensionsFactory;
const LineCounter = require("line-counter-node").LineCounter;
const Rules = require("line-counter-node").Rules;
const Events = require("line-counter-node").Events;
var lc = new LineCounter();
lc.setPath("/var/www/html/");
lc.setExtensions(ExtensionsFactory.from("js"));
lc.addRule(Rules.ignoreDir, ".git", ".idea", "node_modules"); // Ignores given directories
lc.addRule(Rules.filePrefix, "line"); // Only the file names starts with "line" are allowed, others will be ignored
lc.on(Events.ERROR, function(err){
console.error(err);
});
lc.getLines(function(result){
console.log("Total files: " + result.files);
console.log("Total lines: " + result.lines);
});
FAQs
Recursive nodejs line counter library
We found that line-counter-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.