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

vinea

v1.0.4

Published

find files and paths using node.js `require` semantics

Downloads

9

Readme

vinea

NPM Version Build Status Coverage Status Dependency Status devDependency Status bitHound Score NSP Status

find files and paths using node.js require semantics

This module contains various functions to help you find paths and files using Node.js' require semantics.

Vinea is the latin word for vine.

Getting Started

Install the module with: npm install vinea

API

Vinea provides various functions to help with inspecting the fs, or to help with inspecting the require paths being used by modules.

file system introspection

findItem(itemName, itemType, currentPath, recursive, callback)

Find an item on the file system starting from the current path. If recursive is true, will continue walking up parent directories looking for the itemName.

  • itemName {String} - name of the item to look for
  • itemType {String} - file or directory
  • currentPath {String} - directory to start looking in
  • recursive {Boolean} - if true, walks up parent dir if item is not found
  • callback {Function}

Returns: {String} the path of the found item

findParentPath(path1, path2)

Find the common parent directory between two given directories.

  • path1 {String} - a directory
  • path2 {String} - another directory

Returns: {String} the common parent directory between both

findNodeModulesPath(currentPath, callback)

Finds the nearest node_modules directory from the given directory. If not found in current directory, walks up the parent dir until it finds it.

  • currentPath {String} - directory to start looking in
  • callback {Function}

Returns: {String} the location of the nearest node_modules directory.

findNodeModulePath(currentPath, moduleName, callback)

Given a module name like 'lodash', looks for a node_modules/lodash starting from the current directory. If none is found, walks up the parent dir until it finds one.

  • currentPath {String) - directory to start looking in
  • moduleName {String} - the name of the module to find
  • callback {Function}

Returns: {String} the path to the module on the file system

findNodeModuleMainEntry(modulePath, callback)

Given a path to a node_modules module, i.e., /Users/me/project/node_modules/lodash, this function finds the main entry point suitable for client side usage.

This function attempts to return the browser attribute from package.json if available, falling back on main and then index.js.

  • modulePath {String} - location of the module
  • callback {Function}

Returns: {String} entry point value from package.json

findPackageJson(currentPath, callback)

Finds the location of the the nearest package.json. If it can't find package.json in the current directory, walkis up the parent dir until it finds it.

  • currentPath {String} - directory to start looking in.
  • callback {Function}

openPackageJson(currentPath, callback)

Returns the contents of the nearest package.json. If it can't find package.json in the current directory, walkis up the parent dir until it finds it.

  • currentPath {String} - directory to start looking in
  • callback {Function}

Returns: {Object} JSON.parsed() contents of package.json

findWithRequireSemantics(currentPath, item, callback)

Finds the location of a require() dependency. i.e., require('a/b') can resolve to either b.js, or b/index.js.

  • currentPath {String} - directory to start looking in
  • item {String} - the require dependency
  • callback {Function}

Returns: {Object} contains a foundPath and statInfo attributes

openWithRequireSemantics(currentPath, callback)

Finds the location of a require() dependency. i.e., require('a/b') can resolve to either b.js, or b/index.js.

  • currentPath {String} - directory to start looking in
  • item {String} - the require dependency
  • callback {Function}

Returns: {Object} contains foundPath, statInfo, and contents attributes

require() dependency introspection

getModuleNameFromPath(path)

Given a filepath with, attempt to find a node_module in the path. i.e., /app/node_modules/lodash => lodash /app/node_modules/lodash/node_modules/foo => foo

  • path {String} - a file path

Returns: {String} name of the module

hasNodeModulesInPath(path)

Returns true if a file path has node_modules in it.

  • path {String} - a file path

Returns: {Boolean}

isNodeModuleRequire(requireDep)

Returns true if the require() dependency refers to a node_module.

i.e., require('lodash') => true require('lodash/array/map') => true require('./a') => false

  • requireDep {String}

Returns: {Boolean}

isNodeModuleMainRequire(requireDep)

Returns true if the require() dependency refers to the main entry point of a node_module.

i.e., require('lodash') => true require('lodash/array/map') => false

  • requireDep {String}

Returns: {Boolean}

Contributing

Add unit tests for any new or changed functionality. Ensure that lint and style checks pass.

To start contributing, install the git preush hooks:

make githooks

Before committing, run the prepush hook:

make prepush

If you have style errors, you can auto fix whitespace issues by running:

make codestyle-fix

License

Copyright (c) 2015 Alex Liu

Licensed under the MIT license.