1.0.22 • Published 5 years ago

myfs v1.0.22

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

myfs

My lightweight, Node-specific, no dependancy, simplified, cross-platform methods for manipulating files and folders syncronously with Node.js.

Install

npm install myfs --save
... or
yarn add myfs

Quick Reference

NOTE: See the "docs" folder details (this is just a basic listing).

MethodArgumentsDescription
copysrc, dest, binaryCopies a file from one location to another.
cpsrc, dest, binaryalias for copy
cpdirfrom, toCopies the entire folder's heirarchy folder from one location to another. If the other location doesn't exists, it will be constructed.
emptywho, dryRunRecursively empties a folder of all it's contents (and all the sub-folder's contents), but leaves the source folder.
existssrcChecks to see if a file or folder exists.
launchtarget, optsA file launcher. Opens stuff like websites, files, executables using the native system program.
listfrom, filter, recursive, storeRead a folder and returns an object containing a "files" array and a "dirs" array. Each array lists full system paths.
listExtfrom, exts, recursiveReturns an array of paths for files that have the extension(s). The ext argument can be an array to return multiple extensions.
lsalias for list
makedirdestinationCreates a folder at the specified location. The sub-folder heirarchy is constructed as needed.
movesrcMoves a file or folder.
renamesrcAlias for move.
opensrc, binaryReads the text or binary data out of a file. Use the "binary" (boolean) argument for non-text files.
rmsrcDeletes a file from the system.
rmdirwho, dryRunRecursively removes a folder and all of it's sub-folders as well.
savesrc, data, binarySaves text data to a file. Overwrites entire file with provided data.
writesrc, data, binaryAlias for save.
isFilesrcChecks to see if src is a file, as opposed to exists, which checks if either file OR folder exists.
isDirsrcChecks to see if src is a folder, as opposed to exists, which checks if either file OR folder exists.
touchsrcCreates or updates the timestamp on a specific file or folder.
dupesrcDuplicates a file "in place" by making a copy with appended "copy N" in the file name.
isBinarysrcA cheap/fast check to see if a file's extension is in a list of known binary extensions.
Path Stuff
MethodArgumentsDescription
addSlashpathAdds a trailing slash from path (if doesn't exist).
addTrailingSlashalias for addSlash
removeSlashpathRemoves a trailing slash from path (if exists).
removeTrailingSlashpathalias for removeSlash
resolvepath...Generates an absolute path based on the provided arguments.
basenamealias for basename
basenamepath, extReturns the last portion of a path, generally the "filename".
cleanargNormalizes slashes by converting double \ to single \ and / to \ or \ tp / based on the current platform requirements.
diralias for dirname
extsrcReturns the bare, base extension (no dot).
filenamesrcalias for basename
formatobjCombines the elements of an object into a string. The opposite of path.parse().
isAbsolutesrcDetermines if path is an absolute path.
joinpaths...Joins path segments and resolves relativity.
namepathnpath.name("/foo/bar/bob.txt") --> "bob"
normalizepathResolves ".." and "." portions of a path. Reduces double slashes to single (e.g. // -> / ). Forces back-slashes to forward slashes (e.g. \ -> / ). Retains trailing slash if exists.
parentpathReturns the path to the parent folder that the item resides within.
parsepathNote that this uses the mind-warping name, basename, ext of the default Node.path.parse() plus some props that don't hurt my brain. Extracts basic path and file parts. root, dir, base, ext, name, ext2, extension, basename, filename, parent
relativefrom, toCreates a relative path between "from" and "to"
cwdtackGets the current working directory. Resolves the argument to the path.
swapExtsrcChanges the path's (or filename's) extension.

Properties

PropertyDescription
sepThe kind of seperator used in paths. Windows = \ or POSIX = /
delimiterPlatform environment $PATH delimiter.
duAccess to the underlaying directory utility class for access to additional methods that are not so common.
fuAccess to the underlaying file utility class for access to additional methods that are not so common.
pathEssentially the same as Node's built-in path, but has a few extras and unified cross-platform'd. This provides access to the underlaying path utility class for access to additional methods that are not so common.

Usage

var myfs = require('myfs');
var data = myfs.open("/path/to/file.txt");
myfs.save("/path/to/file.txt", "This is the contents of my file.");

Open / Read

var myfile = myfs.open("/path/to/folder/file1.txt"); // Yeilds the text contents of the file.
var myfile = myfs.read("/path/to/folder/file1.txt"); // same as above

Save / Write

var myfile = myfs.save("/path/to/folder/file1.txt", data); // Wites the text data to the file.
var myfile = myfs.write("/path/to/folder/file1.txt", data); // same as above

Listing files from a folder

var mylist = myfs.list("/path/to/folder");
//
// Yeilds
//
// {
// 		files : [
// 					"/path/to/folder/file1.txt",
// 					"/path/to/folder/file2.txt",
// 					"/path/to/folder/file3.txt"
// 					],
// 		dirs : [
// 					"/path/to/folder/folder1",
// 					"/path/to/folder/folder2",
// 					"/path/to/folder/folder3"
// 					]
// 	}

Listing only files of X extension.

var mylist = myfs.listExt("/path/to/folder", "txt");
//
// Yeilds
// 		[
// 			"/path/to/folder/file1.txt",
// 			"/path/to/folder/file2.txt",
// 			"/path/to/folder/file3.txt"
// 		]

Listing files of X & Y extension

var mylist = myfs.listExt("/path/to/folder", ["txt", "foo"]);
//
// Yeilds
// 		[
// 			"/path/to/folder/file1.txt",
// 			"/path/to/folder/file2.txt",
// 			"/path/to/folder/bob1.foo",
// 			"/path/to/folder/bob2.foo"
// 		]

Change log

1.0.22 - Oct 20, 2019

  • Added isBinary and dupe file methods.

1.021 - Dec. 20, 2018

  • readExt/listExt properly documented and available... One was missing and the docs explained the other, now they're both in their.

1.0.19 - Sept. 8, 2018

  • readExt/listExt would not capture file with upper-case extensions. Made upper/lower-case agnostic. When call this method, use lower-case strings for your extension(s).
  • added "path" and "src" to parse, both of which return the original source path string provided.
  • fixed issue with readdir when stats fails (mac)

1.0.14 - August 14, 2018

  • added filter to the readExt

1.0.13 - August 14, 2018

  • Check if dir exists before attempt to delete
  • copy now copies folders too.
  • Added touch

1.0.12 - May 1, 2018

  • ensure exists added into a couple other places in fileutils
  • fileutils.write now honors a string in the binary argument
  • added better documentation on readdir filter

1.0.8 - May 1, 2018

  • Added swapExt

License

MIT - Mike Gieson

1.0.22

5 years ago

1.0.21

5 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago