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

cli-helper

v1.0.0

Published

Generic Helpers for file I/O

Downloads

2,814

Readme

File I/O Generic Helpers

Generic helper functions used for development.

Install:

npm install cli-helper

Include:

Include as a constructor class:

// include as a constructor class
var Helper = require('cli-helper').constructor;

class MyHelper extends Helper {
	. . .
}

Include as an instance:

var Helper = require('cli-helper').instance;

Helper.getOpt('foo');

Functions

Helper.getOpt([String:id])

Get arguments passed using the -- convention.

// execution
node ./foo.js --foo=bar --bar=baz

// getOpt()
Helper.getOpt('foo');
// -> 'bar'

Helper.getOptArg([String:id])

Get non key-value pair arguments

// execution
node ./foo.js foo

// getOptArg()
Helper.getOptArg('foo');
// -> true

Helper.getOptArg('bar');
// -> false

Helper.getRawArgs()

Returns all the raw arguments.

// execution
node ./foo.js foo --bar=lol

// getRawArgs()
Helper.getOptArg('foo');
// -> ['node', './foo.js', 'foo', '--bar=lol']

Helper.promiseIterator([Object:target], [Function:next], [Function:done])

Iterate over array or object with a next() step, promise-like execution.

// promiseIterator()

var list = ['a', 'b', 'c'];

Helper.promiseIterator(list, next, done);

function next(item, i, step, stop) {
	console.log('list item:', item);
    console.log('list index:', i);

    // you can do some async call here
    $.ajax('//feed.com/' + item, function(data) {
    	console.log('got the data!', data);
		// continue to the next iteration
	    step();    
    });

    // or you can break the iteration
    // stop();
}

function done() {
	console.log('iteration done!');
}

Helper.shellCmd([String:cmd], [String:basePath], [Boolean:verbose])

Run a unix shell command using package: shelljs

| Arguments | Description | |:----------|:------------| | cmd | command to run | | basePath | (optional) path where to execute. if not defined, command executes on current dir | | verbose | (optional) non-silent mode |

// shellCmd() - command ls -al output in /usr/local directory
Helper.shellCmd('ls -al', '/usr/local');

Helper.isPathExists([String:path])

Check if path exists, either if its a file or directory.

// isPathExists()
Helper.isPathExists('/urs/local');
// -> true

Helper.isFileExists([String:path])

Check if the path is a FILE.

// isPathExists()
Helper.isFileExists('/urs/local');
// -> false

Helper.isFileExists('/urs/local/foo.txt');
// -> true

Helper.createDir([String:path])

Creates a directory.

// createDir()
Helper.createDir('/usr/local/new-dir');

Helper.readFile([String:path])

Read file (utf-8).

// readFile()
Helper.readFile('/usr/local/foo.txt');
// -> {String} contents

Helper.writeFile([String:path], [String:content])

Write file (utf-8).

// writeFile()
Helper.writeFile('/usr/local/foo.txt', 'hello world!');
// -> {String} contents

Helper.base64([String:str], [Boolean:dec = false])

Base64 encode/decode.

// base64()

// encode
Helper.base64('encode me');
// -> {String} encoded string

// decode
Helper.base64('ZW5jb2RlIG1l', true);
// -> {String} decoded string