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

fsify

v5.0.0

Published

Convert an array of objects into a persistent or temporary directory structure

Downloads

6,155

Readme

fsify

Build Coverage Status

Convert an array of objects into a persistent or temporary directory structure.

Contents

Description

fsify creates a persistent or temporary directory structure from an array of objects. It's like the opposite of the Linux and Unix tree command.

Install

npm install fsify

Usage

Structure with content

.
├── dirname
│   └── filename
└── filename
const fsify = require('fsify')()

const structure = [
	{
		type: fsify.DIRECTORY,
		name: 'dirname',
		contents: [
			{
				type: fsify.FILE,
				name: 'filename',
				contents: 'data'
			}
		]
	},
	{
		type: fsify.FILE,
		name: 'filename',
		contents: 'data'
	}
]

fsify(structure)
	.then((structure) => console.log(structure))
	.catch((error) => console.error(error))

Deeply nested structure

.
└── dirname
    └── dirname
        └── filename
const fsify = require('fsify')()

const structure = [
	{
		type: fsify.DIRECTORY,
		name: 'dirname',
		contents: [
			{
				type: fsify.DIRECTORY,
				name: 'dirname',
				contents: [
					{
						type: fsify.FILE,
						name: 'filename'
					}
				]
			}
		]
	}
]

fsify(structure)
	.then((structure) => console.log(structure))
	.catch((error) => console.error(error))

Temporary file in existing directory

dirname/
└── filename
const fsify = require('fsify')({
	cwd: 'dirname/',
	persistent: false
})

const structure = [
	{
		type: fsify.FILE,
		name: 'filename'
	}
]

fsify(structure)
	.then((structure) => console.log(structure))
	.catch((error) => console.error(error))

Structure from tree

tree is a Linux and Unix command that lists the contents of directories in a tree-like format. It's a helpful CLI to view the structure of your file system.

tree -J --noreport ./* > tree.json
const fs = require('fs')
const fsify = require('fsify')()

const structure = require('./tree')

fsify(structure)
	.then((structure) => console.log(structure))
	.catch((error) => console.error(error))

API

Usage

const fsify = require('fsify')()
const fsify = require('fsify')({
	cwd: process.cwd(),
	persistent: true,
	force: false
})

Parameters

  • options {?Object} Options.
    • cwd {?String} - Custom relative or absolute path. Defaults to process.cwd().
    • persistent {?Boolean} - Keep directories and files even when the process exists. Defaults to true.
    • force {?Boolean} - Allow deleting the current working directory and outside. Defaults to false.

Returns

Instance API

Usage

const structure = [
	{
		type: fsify.FILE,
		name: 'filename'
	}
]

fsify(structure)
	.then((structure) => console.log(structure))
	.catch((error) => console.error(error))

Parameters

  • structure {?Array} Array of objects containing information about a directory or file.

Returns

  • {Promise<Array>} A promise that resolves a structure. Equal to the input structure, but parsed and with a absolute path as the name.

Structure

A structure is an array of objects that represents a directory structure. Each object must contain information about a directory or file.

The structure …

.
├── dirname
│   └── filename
└── filename

… is equal to …

[
	{
		type: fsify.DIRECTORY,
		name: 'dirname',
		contents: [
			{
				type: fsify.FILE,
				name: 'filename',
				contents: 'data'
			}
		]
	},
	{
		type: fsify.FILE,
		name: 'filename',
		contents: 'data'
	}
]

Directory

A directory must have the type of a directory and a name. It can also contain another nested structure in its contents and a mode.

{
	type: fsify.DIRECTORY,
	name: 'dirname',
	mode: 0o777,
	contents: []
}

File

A file must have the type of a file and a name. It can also contain contents (data of the file). encoding, mode and flag will be passed directly to fs.writeFile.

{
	type: fsify.FILE,
	name: 'filename',
	contents: 'data',
	encoding: 'utf8',
	mode: 0o666,
	flag: 'w'
}