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

als-path-tree

v1.2.0

Published

A Node.js library for managing a virtual file system structure, offering functionalities for file and directory operations with a shared storage system.

Downloads

41

Readme

als-path-tree

als-path-tree is a Node.js library for managing a virtual file system structure. It provides functionality for creating, navigating, and managing files and directories in a virtual environment, while tracking the overall size.

Change log for v1.2

  • PathTree.objList
  • Some fixes with size

Installation

npm install als-path-tree

Usage

First, import the PathTree class from the library:

const PathTree = require('als-path-tree');

Create a new instance of PathTree:

const tree = new PathTree();

When specifying a directory in the constructor, the created PathTree instance operates only within that directory. If files and directories with similar paths are used in other instances, the effect applies to all instances due to the shared storage.

Add files to the tree:

tree.addFile('path/to/file.txt', 'fileContents');

Check if a file exists:

if (tree.exists('path/to/file.txt')) {
    console.log('File exists');
}

Retrieve a file:

const file = tree.get('path/to/file.txt');

List files in a directory:

const files = tree.listFiles('path/to/directory');

Remove a file or directory:

tree.remove('path/to/file.txt');

Reset the entire tree:

PathTree.reset();

API Reference

  • constructor(dir = ''): Initializes a new Path Tree.
  • addFile(path, file): Adds a file at the specified path.
  • exists(path): Checks if a file or directory exists at the specified path.
  • get(path): Retrieves a file or directory from the specified path.
  • listFiles(dir,directory=this.root,files = []): Lists all files in the specified directory.
  • remove(path): Removes a file or directory from the specified path, including any empty directories in the path.
  • PathTree.reset(): Resets the PathTree, clearing all data.
  • PathTree.store: Object with all nested structure.
  • PathTree.size: Actual size for all objects and directories
  • PathTree.objList: WeekSet object to include common objects for not counting their size

All paths utilize normalize, allowing for the use of both forward and backward slashes in paths.