npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flavored-wc-native

v0.0.2

Published

wc command ported to Node.js with additional features

Downloads

6

Readme

wc

Node.js project

wc command ported to Node.js with additional features

Version: 0.0.1

The Unix wc command counts the number of bytes, characters, words and lines in a file but it lacks some useful features like walking a directory recursively and ignore paths. Also it has some issues with UTF8 encoded files.

Installation

npm install flavored-wc
npm install flavored-wc-native

A native version is also available. I made it just for fun but if you can, install it. The speed improvement depends on some factors: file size, files quantity, file content and the information to retrieve. You must also know that the JavaScript ⇄ C++ brige is pretty slow.

In general it's ok to say that the native implementation is faster than the javascript one. I've tested both implementations with a 10MB file and the native is twice as fast. The directory of this repository has been also tested with the following code and the native is four times faster.

//wc.js
var wc = require ("flavored-wc-native");
wc (".", function (){});
$ time node wc.js

Functions


wc(path[, settings], callback) : undefined
The path can be an String or an Array of Strings. These Strings can contain a valid path or text data.

The settings is an object that accepts the following settings. If the object is not provided all the information (bytes, chars, words and lines) will be counted.

  • bytes - Boolean
    Set to true to count the number of bytes. Default is false.

  • chars - Boolean
    Set to true to count the number of characters. Default is false. UTF8 multibyte characters are also allowed.

  • words - Boolean
    Set to true to count the number of words. Default is false. A word is any consecutive sequence of characters separated by \r, \n, \v, \f, \t or space.

  • lines - Boolean
    Set to true to count the number of lines. Default is false.

  • data - Boolean
    If path contains text data, set this option to true. Default is false.

  • ignore - String | Array | Function
    Paths to ignore. It can also be a function. The function is executed for each file and directory. It receives the path, the directory name, the name of the entry and a callback. The callback expects two parameters, a possible error and a boolean. If the boolean is true the path will be read, otherwise it will be ignored. The function acts like a filter, if you return false the path won't pass the filter.

    var wc = require ("flavored-wc");
      
    var settings = {
    	ignore: function (p, dirname, basename, cb){
    		cb (null, basename !== "ignored_path");
    	},
    	bytes: ...,
    	...
    };
      
    wc (".", settings, function (error, counters){
    	...
    });