2.0.1 • Published 8 months ago

myfs v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 months 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

Usage

Load myfs (choose one!)

// Load myfs for CommonJS:
//var myfs = require("myfs");

// Load myfs for ESM (native import):
import myfs from "myfs";

Here are a few examples of what you can do. There are many more features and examples than are shown in this readme. Please refer to the full documentation here.

Open / Read

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

Save / Write

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

Listing only files of X extension (NOTE: This can list recursively too.)

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

Documentation

Full documentation for all properties and methods available here: https://documon.net/projects/myfs/

You can also find the full documentation in the downloaded package locally (within node_modules) at:

/node_modules/myfs/docs

You can also download the docs (and source) from the repo here

Below is a quick reference for common methods.

Quick Reference

This quick reference only includes the most commonly used methods, with simple descriptions.

Properties

PropertyDescription
slashThe kind of seperator used in paths. Windows = \ or POSIX = /
__dirnameSame as native __dirname, but provices access for ESM imports.
__filenameSame as native __filename, but provices access for ESM imports.

Methods

MethodArgumentsDescription
copysrc, destCopies a file or a folder from one location to another. Automatically handles creating destination folder structure if not exist.
emptypath, dryRunRecursively empties a folder of all it's contents (and all the sub-folder's contents), but leaves the source folder.
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 exts argument can be a comma-delimited string list of extensions.
mkdirpathCreates a folder at the specified location. The sub-folder heirarchy is constructed as needed.
rmsrcDeletes a file from the system.
rmdirwho, dryRunRecursively removes a folder and all of it's sub-folders as well.
movesrcMoves a file or folder. Can also be used to rename files and folders
opensrc, binaryReads the text or binary data out of a file.
savesrc, data, binarySaves data to a file. Overwrites entire file with provided data.
isFilesrcChecks to see if src is a file, as opposed to exists, which checks if either file OR folder exists.
isBinarysrcA cheap/fast check to see if a file's extension is in a list of known binary extensions.
existspathChecks to see if a 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.
launchtarget, optsA file launcher. Opens stuff like websites, files, executables using the native system program.
addSlashpathAdds a trailing slash from path (if doesn't exist).
removeSlashpathRemoves a trailing slash from path (if exists).
resolvepath...Generates an absolute path based on the provided arguments.
basenamepath, extReturns the last portion of a path, with or without extension.
namepathReturns the naked file name without extension. ("/foo/bar/bob.txt" --> "bob"
extsrcReturns the bare, base extension (no dot).
cleanargNormalizes slashes by converting double \ to single \ and / to \ or \ tp / based on the current platform requirements.
parentpathReturns the path to the parent folder that the item resides within.
joinpaths...Joins path segments and resolves relativity.
normalizepathResolves ".." and "." portions of a path. Reduces double slashes to single (e.g. // -> / ). Forces back-slashes to forward slashes (e.g. \ -> / ).
parsepathExtracts basic path and file parts. root, dir, base, ext, name, ext2, extension, basename, filename, parent. Extends NodeJS's native "path.parse()" with additional fields with more context.
cwdtackGets the current working directory. Resolves the argument to the path. Simliar to native __dirname, which is depreciated.
swapExtsrcChanges the path's (or filename's) extension.
...And many more!Plus there are aliases for many methods. For those who think diffrently.
2.0.1

8 months ago

2.0.0

8 months ago

1.0.22

6 years ago

1.0.21

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago