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

myfs

v2.0.1

Published

My simplifeid methods for manipulating file and folders syncronously.

Downloads

72

Readme

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

| Property | Description | |----------|-------------| |slash | The kind of seperator used in paths. Windows = \ or POSIX = / |__dirname | Same as native __dirname, but provices access for ESM imports. |__filename | Same as native __filename, but provices access for ESM imports.

Methods

| Method | Arguments | Description | |--------|-----------|-------------| |copy|src, dest|Copies a file or a folder from one location to another. Automatically handles creating destination folder structure if not exist.| |empty|path, dryRun|Recursively empties a folder of all it's contents (and all the sub-folder's contents), but leaves the source folder.| |list |from, filter, recursive, store| Read a folder and returns an object containing a "files" array and a "dirs" array. Each array lists full system paths.| |listExt|from, exts, recursive|Returns an array of paths for files that have the extension(s). The exts argument can be a comma-delimited string list of extensions.| |mkdir|path|Creates a folder at the specified location. The sub-folder heirarchy is constructed as needed. | |rm|src|Deletes a file from the system.| |rmdir|who, dryRun|Recursively removes a folder and all of it's sub-folders as well.| |move|src|Moves a file or folder. Can also be used to rename files and folders| |open|src, binary|Reads the text or binary data out of a file.| |save|src, data, binary|Saves data to a file. Overwrites entire file with provided data.| |isFile|src|Checks to see if src is a file, as opposed to exists, which checks if either file OR folder exists.| |isBinary|src|A cheap/fast check to see if a file's extension is in a list of known binary extensions.| |exists|path|Checks to see if a file or folder exists. | |isDir|src|Checks to see if src is a folder, as opposed to exists, which checks if either file OR folder exists.| |touch|src|Creates or updates the timestamp on a specific file or folder.| |dupe|src|Duplicates a file "in place" by making a copy with appended "copy N" in the file name.| |launch|target, opts|A file launcher. Opens stuff like websites, files, executables using the native system program.| |addSlash|path|Adds a trailing slash from path (if doesn't exist).| |removeSlash|path|Removes a trailing slash from path (if exists).| |resolve|path...|Generates an absolute path based on the provided arguments.| |basename|path, ext|Returns the last portion of a path, with or without extension.| |name|path|Returns the naked file name without extension. ("/foo/bar/bob.txt" --> "bob"| |ext|src|Returns the bare, base extension (no dot).| |clean|arg|Normalizes slashes by converting double \ to single \ and / to \ or \ tp / based on the current platform requirements. |parent|path|Returns the path to the parent folder that the item resides within.| |join|paths...|Joins path segments and resolves relativity.| |normalize|path|Resolves ".." and "." portions of a path. Reduces double slashes to single (e.g. // -> / ). Forces back-slashes to forward slashes (e.g. \ -> / ).| |parse|path|Extracts 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.| |cwd|tack|Gets the current working directory. Resolves the argument to the path. Simliar to native __dirname, which is depreciated.| |swapExt|src|Changes the path's (or filename's) extension. |...|And many more!|Plus there are aliases for many methods. For those who think diffrently.|