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

@sugarcoated/royal-disk

v1.0.0

Published

Manipulate the file system.

Downloads

2

Readme

Node FS has a bunch of wrappers all over the internet. Here's mine.

API Reference

.name(path)

Derives the name of a file from a path.

  • path is expected as a String representing the path to a file.

    Disk.name('./myFile.txt'); // myFile

.ext(path)

Derives the extension from a file using Path#extname. Returns the extension as a String.

  • path is expected as a String representing the path to the file.

    Disk.ext('/myFile.txt'); // .txt

.file(path, extension)

Derive the file name in a path.

  • path is expected as a String, representing the path to the file.

  • extension is expected as a String, representing the extension of the file.

    Disk.file('/myFile', '.txt'); // myFile.txt

.directory(path)

Derives the directory a file is located in. Returns the directory as a String.

  • path is expected as a String, representing the path to the file.

    Disk.directory('/myFolder/myFile.txt'); // myFolder

.readFile(path, [encoding])

Reads a file. Returns a Promise that resolves with the file contents as a String.

  • path is expected as a String, representing the path to the file.

  • encoding is an optional parameter, expected as a String, representing the encoding of the file to read. If one is not specified, this defaults to utf8.

    Disk.readFile('/myFile.txt');

.readFiles(path, [recursive])

Reads files within a directory, optionally recursively. Returns a Promise that resolves with a Collection containing the contents of the files as Strings, or further Collections containing further file contents as Strings. The returned Collection will only contain further Collections should the recursive parameter be passed as true, as each contained Collection represents a directory that was read, and will be mapped under the directory's name in the base Collection.

  • path is expected as a String, representing the path to the file.

  • recursive is expected as a Boolean, representing whether or not to recursively path through the directory. When recursive is true, each contained directory will be mapped as a Collection of that directory's file's contents.

    Disk.readFiles('/myFolder'); 

.appendFile(path, content)

Appends content to a file. Returns Promise that resolves with a Boolean representing whether or not the operation was successful.

  • path is expected as a String, representing the path to the file.

  • content is expected as a String, representing the content to append to the file.

    Disk.appendFile('/myFile.txt'); // .txt

.renameFile(path, name)

Renames a file. Returns a Promise that resolves with a Boolean representing whether or not the operation was successful.

  • path is expected as a String, representing the path to the file.

  • name is expected as a String, representing the new name of the file.

    Disk.appendFile('/myFile.txt');

.writeFile(path, [contents])

Writes/creates a file. Returns a Promise that resolves with a Boolean representing whether or not the operation was successful.

  • path is expected as a String, representing the path to the new file.

  • contents is an optional parameter, expected as a String, representing the contents of the new file.

    Disk.writeFile('/myFile.txt'); 

.deleteFile(path)

Deletes a file. Returns with a Promise that resolves with a Boolean representing whether or not the operation was successful.

  • path is expected as a String, representing the path to the file to delete.

    Disk.deleteFile('/myFile.txt'); 

.tryDirectory(path)

Attempts to access a directory. Returns a Promise that resolves with a Boolean representing whether access was granted.

  • path is expected as a String, representing the path to the directory.

    Disk.tryDirectory('/myFolder/'); 

.readDirectory(path)

Read the listing of a directory. Returns a Promise that resolves with an Array.<String>, each String being the name of a file or [further] directory within the directory that was read.

  • path is expected as a String, representing the path to the directory to read.

    Disk.readDirectory('/myFolder/'); 

.writeDirectory(path)

Creates a directory. Returns a Promise that resolves with a Boolean representing whether or not the operation was successful.

  • path is expected as a String representing the path to the new directory.

    Disk.writeDirectory('/myFolder/'); 

.deleteDirectory(path)

Deletes a directory. Returns a Promise that resolves with a Boolean representing whether or not the operation was a success, and rejects with an UnhandledPromiseRejection containing the Error thrown.

  • path is expected as a String, representing the path to the directory to delete.

    Disk.deleteDirectory('/myFolder/');