Robust operating system directory functionality
Table of Contents
npm install ack-path
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...
Timesaver script commands
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
ack-path copy ./relativeFrom ./relativeTo
ack-path move ./relativeFrom ./relativeTo
ack-path delete ./relativePath
write file promise
Path.join('file-name.js').writeFile(string).then().catch()
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()
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()
Path.copyTo(__dirname+'-copy').then()
move entire directory or single file
Path.moveTo( newPath:string, overwrite:boolean ).then()
Path.moveTo(__dirname+'-moved').then()
in-place rename directory or single file
Path.rename( newName:string, overwrite:boolean ).then()
Path.rename('new-item-name', true).then()
path delete promise
Path.delete().then()
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) )
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) )
Recursively loop folder to fire callback for each item found. See eachPath function
Path.recur( ItemPath=>ItemPath.path ).then( pathStringArray=>console.log(pathStringArray) )
Recursively loop folder to fire callback for each file found. See eachPath function
Path.recurFiles( filePath=>console.log('file', filePath) )
var PathTest = require('ack-path')('/test/file.js')
PathTest.removeExt().path == "/test/file"
PathTest.removeFile().path == "/test/"
hard-checks file system if item is a folder
require('ack-path')('/test/file.js').isDirectory().then(res=>res==false)
hard-checks file system if item is a file
require('ack-path')('/test/file.js').isFile().then(res=>res==true)
Checks string for a file extension
require('ack-path')('/test/file.js').isLikeFile() == true
Returns item after last slash
require('ack-path')('/test/file.js').getLastName() == 'file.js'
require('ack-path')('/test/folder/').getLastName() == 'folder'
considers if path is actually a file
PathSync.dirExists()
PathSync.exists()
PathSync.delete()
PathSync.copyTo()
PathSync.copyTo()
A more file specific set of objective functionality
var File = require('ack-path')(__dirname).file('file-name.js')
var filePath = File.path
File.copyTo(__filename+'.copy').then()
File.moveTo(__filename+'.newname').then()
File.delete().then()
File.getMimeType()//Ex: application/javascript
File.stat().then(stats=>stats.size)
File.write(string).then()
just like write but if file already exists, no error will be thrown
File.param(string).then()
File.append(string).then()
File.readJson().then()