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

getcfg

v1.3.0

Published

get cfg from a json object or from json cfg files, which either in relative directories or absoluted directories

Downloads

14

Readme

require modules

functions

function errArray2StrArray: convert error array to string array, to easily print the array

function errlist2strlist(errArray){

function getcfg: search each path, find the first cfg file, and return its json cfg as a pure object. If none exists, return the default cfg. If error, return null.

parameters: defCfgInfo: should have keys 'version', 'cfg', and 'filename' jsonCfgFileName: e.g. myservice.js.json, which should have the keys above searchPaths: array of paths, e.g. ['.', '..', '../..', '/home'], default is ['.'] baseDir: the base dir of a relative searching path, default is '.' callback function: rtnErrList: err lists rtnCfg: null means error found //TODO function getcfg(defCfgInfo, jsonCfgFileName, searchPaths, baseDir, callback) { ### handle default values ### update search paths to absolute diretory ### return if error found already return rtnCfg; ### seach the paths, get the first file found, parse the json file function getCfgFromJsonFile(dir, cb){ continue, since already get cfg (either pass or error) try to read the file fs.readFile( _filename, 'utf8', function readFile(e, data) { file not exist error, continue other error, means real error parse json string, and set returned cfg handle expect error continue function done(){ using default cfg if undefined log and return return rtnCfg;

function getcfg4busi: using business defaults for getcfg, including searchPaths = '../..', basedir and filename is derived from jsFilename (i.e. __filename), ext is '.json'

parameters: defCfgInfo: default cfg info jsFilename: the js file (with path), which seeks the its cfg file callback: errlist: array of errors, or [] if pass cfginfo: pure obj of cfg info, or null if failed function getcfg4busi(defCfgInfo, jsFilename, callback){ getcfg( defCfgInfo, _jsonCfgFile, _searchPaths, _basedir, function cb( rtnErrList, rtnCfgInfo ) { fail to get cfg, exit 4 pass to get cfg (either from json file, or using local json)

exports

module.exports.getcfg = getcfg; module.exports.errlist2strlist = errlist2strlist module.exports.getcfg4busi = getcfg4busi;