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

ack-path

v1.8.0

Published

Robust operating system directory functionality

Downloads

78

Readme

Robust operating system directory functionality

hire me npm downloads Dependency Status Build Status Build status NPM version

Install

npm install ack-path

Import

How to import this package

var Path = require('ack-path')(__dirname)

console.log( Path.path === __dirname )//true test

//Now, you can do a whole lot more! Continue reading...

CLI Commands

Timesaver script commands

How to Use

Using the most basic command as an example, you can invoke the copy command, using any of the following methods:

package.json script example

"scripts":{
  "copy": "ack-path copy ./relativeFrom ./relativeTo"
}

from command terminal example

./node_modules/bin/ack-path copy ./relativeFrom ./relativeTo

Copy

ack-path copy ./relativeFrom ./relativeTo

Move

ack-path move ./relativeFrom ./relativeTo

Delete

ack-path delete ./relativePath

Directory Functionality

.join()

write file promise

Path.join('file-name.js').writeFile(string).then().catch()

.param()

Create directory if not existant. Does not take into condsideration if path is actually a file (file path will be created as a folder)

Path.param().then()

.paramDir()

Create directory if not existant. Takes condsideration if path is actually a file and only creates folder pathing

Returns promise with context of this Path

Path.paramDir().then()

.copyTo()

Path.copyTo(__dirname+'-copy').then()

.moveTo()

move entire directory or single file

Path.moveTo( newPath:string, overwrite:boolean ).then()
Path.moveTo(__dirname+'-moved').then()

.rename()

in-place rename directory or single file

Path.rename( newName:string, overwrite:boolean ).then()
Path.rename('new-item-name', true).then()

.delete()

path delete promise

Path.delete().then()

.each()

file and folder looper

  • Based on options, you can recursively read directories and/or files. returns promise
  • Runs using npm package readdir. See npm readdir for more usage instructions.
  • Arguments
    • eachCall function(String:path, Number:index)
    • options
      • recursive : true
      • INCLUDE_DIRECTORIES : true
      • INCLUDE_HIDDEN : true
      • filter : ['/.js','/.jade']
      • excludeByName : name=>yesNo
Path.each( itemStringPath=>itemStringPath ).then( itemPathArray=>console.log(itemPathArray) )

.eachFilePath()

Loop folder to fire callback for each file found. Only produces file results. see eachPath function

Path.eachFilePath( fileStringPath=>fileStringPath ).then( filePathArray=>console.log(filePathArray) )

recur

Recursively loop folder to fire callback for each item found. See eachPath function

Path.recur( ItemPath=>ItemPath.path ).then( pathStringArray=>console.log(pathStringArray) )

.recurFiles()

Recursively loop folder to fire callback for each file found. See eachPath function

Path.recurFiles( filePath=>console.log('file', filePath) )

String Manipulations

var PathTest = require('ack-path')('/test/file.js')

PathTest.removeExt().path == "/test/file"
PathTest.removeFile().path == "/test/"

isDirectory

hard-checks file system if item is a folder

require('ack-path')('/test/file.js').isDirectory().then(res=>res==false)

isFile

hard-checks file system if item is a file

require('ack-path')('/test/file.js').isFile().then(res=>res==true)

isLikeFile

Checks string for a file extension

require('ack-path')('/test/file.js').isLikeFile() == true

getLastName

Returns item after last slash

require('ack-path')('/test/file.js').getLastName() == 'file.js'
require('ack-path')('/test/folder/').getLastName() == 'folder'

SYNC Examples

.sync().dirExists()

considers if path is actually a file

PathSync.dirExists()

.sync().exists()

PathSync.exists()

.sync().delete()

PathSync.delete()

.sync().copyTo()

PathSync.copyTo()

.sync().moveTo()

PathSync.copyTo()

File Functionality

A more file specific set of objective functionality

require.file

var File = require('ack-path')(__dirname).file('file-name.js')
var filePath = File.path

.file().copyTo()

File.copyTo(__filename+'.copy').then()

.file().moveTo()

File.moveTo(__filename+'.newname').then()

.file().delete()

File.delete().then()

.file().getMimeType()

File.getMimeType()//Ex: application/javascript

.file().stat()

File.stat().then(stats=>stats.size)

.file().write()

File.write(string).then()

.file().param()

just like write but if file already exists, no error will be thrown

File.param(string).then()

.file().append()

File.append(string).then()

.file().readJson()

File.readJson().then()