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

noopath

v1.4.0

Published

A node library which takes filepath and convert its filesystem in an object, So you can access paths with dot.separated.structure .

Downloads

27

Readme

NOOPath

NOOPath is Node Object Oriented Path. A node library which takes filepath and convert its filesystem into an object, So you can access paths with dot.separated.structure . This library will take away the pain of writing paths as string, by replacing it will dot separated notation like noopath.var.www.path.to.project. This library also offers an interesting dynamic loading of files with its filename.

Installation

npm install noopath

Directory structure:

|- var
    |- www
        |- noopath
            |- test.js
            |- config.js
            |- folder
                  |- calculation.js
                  |- manager.js
                  |- something.js
                  |- another_folder
                            |- x.json
                            |- y.json
                            |- config.json
            |- package.json
            |- package-lock.json
            |- node_modules
                  |- ...
            |- .git
                  |- ...
            

Usage

const noopath = require('noopath');

/**
 *[REQUIRED]
 */
noopath.setPath("/var/www/noopath") //set path to folder


/**
 *[OPTIONAL]
 */
noopath.setIgnorePaths([
                    "/var/www/noopath/node_modules/",
                    "/var/www/noopath/.git"
                    ]); //setting the path which you want to ignore in creation of object
noopath.setIgnoreExtensions(["json"]) //Adds `json` to ignore extensions, `js` is already there.


/**
 * This function will return complete folder structure as an object.
 */
const config = noopath.getConfig()

console.log(config.var.www.noopath.test) 
//Output: /var/www/noopath/test.js
console.log(config.var.www.noopath.folder.calculation) 
//Output: /var/www/noopath/folder/calculation.js

/**
 * Get file name from object oriented string.
 */
var filepath = noopath.getFromConfig("var.www.noopath.folder.calculation")
console.log(filepath)
//Output: /var/www/noopath/folder/calculation.js



/**
 * [LOADING]
 */
 /**
 * This function will allow you to get filepath. Rather than completely relying on the project structure.
 * It will return first encounter file with name specified or else it will return false.
 */
console.log(noopath.load("x")) 
//Output: /var/www/noopath/folder/another_folder/x.json


/**
 * It will first get all keys with name config and filter out the required one.
 * Filter out between two files /var/www/noopath/folder/another_folder/config.json,  /var/www/noopath/config.js
 */
console.log(noopath.loadByFilter("config", "config\.json$")) 
//Output: /var/www/noopath/folder/another_folder/config.json


/**
 * Note: Can accept variable no. of arguments.
 * Existence priority loading, this will check the existence of each file and return, 
 * with the first, existing filename. As config.staging, development and production does not exists it returns with config
 */
console.log(noopath.loadOrElse("config.staging","config.development","config.production","config"))
//Output: /var/www/noopath/folder/another_folder/config.json

/**
 * This function will retrieve filepath on the basis of filename or parent foldername. 
 * Note: Parent folder can be parent or grand parent or grand grand parent or else.
 */
console.log(noopath.loadFromFolder("noopath", "something"))
//Output: /var/www/noopath/folder/something.js


/**
 * This function will help you print console log for files loaded, filtered or retrieved through loading functions.
 */
console.log(noopath.debug(true))

/**
 * It will return all files gathered for filtering out.
 */
console.log(noopath.getAll("config")) 
//Output: ["/var/www/noopath/folder/another_folder/config.json",  "/var/www/nooath/config.js"]

/**
 * By default noopath will retrieve folder structure object and keep on retrieving filepaths using the same object.
 * In case of re-gathering file structure information, you can clear previously obtained object.
 */
 noopath.clear();
 
console.log(config)

Output:

console.log(config)

{
  var: {
    www: {
      noopath: {
        test: "/var/www/noopath/test.js",
        config: "/var/www/noopath/config.js",
        package: "/var/www/noopath/package.json",
        package-lock: "/var/www/noopath/package-lock.json",
        folder: {
            calculation: "/var/www/noopath/folder/calculation.js",
            manager: "/var/www/noopath/folder/manager.js",
            something: "/var/www/noopath/folder/something.js",
            another_folder: {
                x: "/var/www/noopath/folder/another_folder/x.json",
                y: "/var/www/noopath/folder/another_folder/y.json",
                config: "/var/www/noopath/folder/another_folder/config.json",
            }
        }
      }
    }
  }
}

Documentation

Take a tour of API Documentation