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

tidypath

v1.8.0

Published

Extend native nodeJS path module

Downloads

3

Readme

TidyPath

Extend native nodeJS path module

How to use

Prerequisite

Node JS

https://nodejs.org/

Example

lvls()

Returns an array of arrays. Each array represents a lvl (depth) of path (number of path separators). Shallow to deepest level.

var path = require('tidypath');

var paths = [
	'hello',
	'foo/bar',
	'hello/world',
	'hello/world/tidy/'
]

path.lvls(paths);
/*
[
	['hello'],
	['foo/bar','hello/world'],
	['hello/world/tidy/'],
];
*/

byDepth()

Returns paths by depth (number of path separators). Shallow to deepest.

var path = require('tidypath');

var paths = [
		'hello',
		'hello/world/foo/bar',
		'hello/world/tidy/', //ignores trailing separator
		'hello/world',
		'foo/bar'
	]

path.byDepth(paths);
/*
[
'hello',
'foo/bar',
'hello/world',
'hello/world/tidy/',	//won't remove trailing separator
'hello/world/foo/bar'
]);
*/

ext()

Returns file extension.

var path = require('tidypath');

path.ext('foo.txt') //'.txt'
path.ext('foo/bar.ver7.txt') //'.txt'
path.ext('foo/bar') //''
path.ext('.txt') //''

rmExt()

//Removes file extension from path.

var path = require('tidypath');

path.rmExt('foo.txt') //'foo'
path.rmExt('foo/bar.ver7.txt') //'foo/bar.ver7'
path.rmExt('foo/bar') //'foo/bar'
path.rmExt('.txt') //'.txt'

file()

Returns file name (including file extension).

var path = require('tidypath');

path.file('foo.txt') //'foo.txt'
path.file('./foo.txt') //'foo.txt'
path.file('foo.ver100.txt') //'foo.ver100.txt'
path.file('foo/bar.txt') //'bar.txt'
path.file('foo/.bar/hello.txt') //'hello.txt'
path.file('.bar/') //''
path.file('foo/.bar/hello') //''
path.file('.dotfile') //'.dotfile'
path.file('foo/bar') //''
path.file('') //''

filename()

Synonym for file()

dotfile()

Returns dotfile in path.

var path = require('tidypath');

path.dotfile('foo.txt') //''
path.dotfile('./foo/bar') //''
path.dotfile('./foo.txt') //''
path.dotfile('foo/.bar/hello.txt') //''
path.dotfile('foo/bar.ver7.txt') //''
path.dotfile('foo/.bar') //'.bar'
path.dotfile('.txt') //'.txt'

tree()

Returns directory of path.

var path = require('tidypath');

path.tree('./hello/world.txt') //'./hello'
path.tree('hello/world/foo.txt') //'hello/world'
path.tree('hello/world') //'hello/world'
path.tree('hello/world/') //'hello/world/'
path.tree('hello/world/.foo') //'hello/world'
path.tree('./foo.txt') //'.'
path.tree('foo.txt') //''
path.tree('.dotfile') //''
path.tree('') //''

filter()

Returns a subset based on filter. Filter can be file extension as string or array of strings, or filter can be a function.

var path = require('tidypath');
var paths = [
		'hello.js',
		'hello/world.txt',
		'.dot',
		0
	];

path.filter('./hello.txt', '.txt');	//['./hello.txt']
path.filter(paths, '.js');	//['hello.js']
path.filter(paths, ['.js']);	//['hello.js']
path.filter(paths, path.dotfile);	//['.dot']
path.filter(paths);	//['hello.js','hello/world.txt','.dot']
path.filter(paths, '.js', false);	//['hello.js','hello/world.txt','.dot',0];

isFile()

Returns true/false path is a file (either has a file extension or is a dotfile).

path.isFile('./hello/world.txt')	//true
path.isFile('hello/world/foo.txt')	//true
path.isFile('hello/world')	//false
path.isFile('hello/world/.foo')	//true
path.isFile('./foo.txt')	//true
path.isFile('foo.txt')	//true
path.isFile('.dotfile')	//true
path.isFile('./')	//false
path.isFile('.')	//false
path.isFile('')	//false

separator

path.separator	//on Windows \ and / on POSIX