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 🙏

© 2026 – Pkg Stats / Ryan Hefner

glsfiles

v1.0.13

Published

This is a collection of 'useful' file-io methods I use over and over again. They aren't particularly well-written, but are good for quick file-io solutions or examples.

Readme

glsfiles

This is a collection of 'useful' file-io methods I use over and over again. They aren't particularly well-written, but are good for quick file-io solutions or examples.

All calls are synchronous.

NOTE: There's not much error processing done here. Pretty much any failing read operation returns an empty String, Object, or Array. Any failing write operation will likely throw an exception (so you should wrap write operations with try/catch if you care about exceptions).

readFile: function (fname) : String

Read the file as one long string of text

readTextFile: function (fname) : String[]

Reads the file and returns each line as a string in the array.

readListFile: function (fname) : String[]

Just like readTextFile but filters out blank lines and lines beginning with '#' signs (comments)

readJSONFile: function (fname) : Object

Reads the file and calls JSON.parse on the results and returns a JavaScript object.

readJSONCFile: function (fname) : Object

Super simplistic JSONC reader. Not very bright.

Same as readJSONFile but filters out any comments (//).

NOTE: It gets confused if the file contains URLS with full domain specs (eg: http://google.com - because the // looks like a comment). Or if // appears on the values.

readCSVFile: function (CSVFname) : Object[]

Super simplistic CSV file reader. Not very bright. Doesn't handle quoted values in columns, for example. Also, doesn't handle commas as a character in the field (it would split the field into two colums).

Reads a file that is formatted as a CSV. Assumes the first row is the header and subsequent rows are comma-separated.

Returns an array of 'objects' with key/value pairs such that each key is a column name from the header.

readRegExpFile: function (fname) : String[]

Performs a readListFile on fname and returns a list of JavaScript regular expressions. (This may seem like a very unique use case, but it is good for a file of whitelist or blacklist names).

writeTextFile: function (fname, list) : undefined

The converse of readTextFile, takes a list of strings and writes them to a file (separated by newlines).

NOTE: creates all intermediary directories up to the filename.

writeFile: function (fname, str) : undefined

The converse of readFile, takes a single string and writes it to a file.

NOTE: creates all intermediary directories up to the filename

createFile: function (fname) : undefined

Creates (or overwrites) an empty file onto fname.

NOTE: creates all intermediary directories up to the filename.

createDir: function (dirname) : undefined

Creates the directory specified by dirname

NOTE: creates all intermediary directories up to the dirname.

readDir: function (dirname) : String[]

Reads the specified directory and returns an array of strings, each one a file/directory in the specified directory.

NOTE: Includes all 'dot' files (those beginning with a period) including the current (.) and previous (..) directories. Does not include the directory name leading up to the filenames.

NOTE: Use fs.statSync to determine if a file is a regular file or directory.

run: function (cmd) : String

Runs the bash command on the supplied cmd and returns the results from stdout as one long string. (NOTE: You and use .split() to break the results into an array of lines). Also, if there is an error stderr is returned instead without warning. You'll have to somehow parse the returned string to determine if things went well or not

Usage

const gls = require('glsfiles');
...
	gls.writeFile("grades.json", JSON.stringify(data));
...
    var json = gls.readJSONFile(fname);
    console.log(json.someField);
...
    var lines = gls.readTextFile(infname);
    for(let i=0; i<lines.length; i++) console.log(lines[i]);
    lines.map(line => console.log(line));
...
    // file looks like this...
    // name,week,assignment,grade
    // GSmith,1,Project 1,A
    // HJones,2,Project 2,B
    var rows = gls.readCSVFile(csvFname);
    
    console.log(rows[0].name); //output => GSmith
    console.log(rows[0].week); //output => 1
    console.log(rows[0].assignment); //output => Project 1
    console.log(rows[0].grade); //output => A

    console.llg(rows[1].name); // output => HJones
    console.llg(rows[1].week); // output => 2
    console.llg(rows[1].assignment); // output => Project 2
    console.llg(rows[1].grade); // output => B