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

relative.path

v0.1.7

Published

always return the relative path from the current working file

Downloads

2

Readme

relative.path

always return the relative path from the current working file😊

What does that mean?

It means you will no longer waste time figuring out how many levels of relative path, like this one: '../../../../../../../'. When you import the library and use the getter .path, the underlying library will figure out the exact relative path prefix of the current file, whose path relative to the configure file path.json🙌

Requirement

Since the library uses ES2015 Proxy as the dependency. You'd better use the library with the Node version ≥6.

Usage

  • Install the npm package use the command:
	>> npm i -S relative.path
  • Add the file path.json in your project root path, this file works as the configure file. The path.json file looks like this:
{
	"path": "src/lib",
	"anypath1": 'abc',
	"anypath2": 'abcdef',
	...
	"paths": ["src", "src/lib"]
}
  • Then, you should use the library in your js file this way:
import relative from 'relative.path';

// print: '../../../..' which relative to the 'path.json'
console.log(relative.path); 	
// You must use the 'require'  instead of 'import' to import related library
// Though, the print out value is correct 😂
const lib = require(relative.path + '/src/lib/xxx');
  • Multiple Paths Mode

There are two choices you can opt in to denote the Multiple Paths Mode. Firstly, you can denote one random key in path.json and use the identical getter in corresponding js file. Secondly, you can also add another param paths to switch to the array Mode in the outermost level of the path.json. In the latter one case, you just append the wanted paths to the array of the key paths.

const libRandom = require(relative.randomPath + '/xxx');
const libArray = require(relative.paths[1] + '/xxx');

Note

  • When you omit the file path.json,the default path is your CWD, i.e. the root path of your project
  • You must use the require instead of import to import the file in your current file, though the print out value is correct

Dependencies