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

@scarafone/files-helper

v0.0.9

Published

File helper utility

Downloads

11

Readme

@scarafone/files-helper

Node utility wrapper around base file system functions to provide ease of use functionality for reading, writing and deleting files to the local system that are expected to be in JSON or JS format with utf-8 encoding.

You can pass options through to underlying functions and it will override the defaults. You can also pass false to the parseAsJSON boolean value and it will return the original buffer unchanged.

Usage Guide

The test cases should do a good job providing how the functions work if you need further details.

/// Import
const { 
    closeFile, 
    deleteFile,
    ensureDirectoryExistence,
    createDirectory,
    deleteDirectory,
    readDirectory, 
    readFile, 
    writeFile 
    } = require("@scarafone/files-helper")

/// Execution
// Functions are synchronous

// General use case is for JSON formatted objects, or JS files.
const fileLocation = "./test/location/results.json"

// Write File
// If true, will ensure filepath exists before writing file
const file = writeFile(filePath: fileLocation, data: JSON.stringify({ "key": "value" }), shouldEnsurePathExists: true)

// Read File
// If true, it will return an empty file
file = readFile(filePath: fileLocation, options: {...options}, parseAsJSON: true ) // Default is true

// Delete File
// If true, it won't fail, but path will be created and deleted
const isSuccess = deleteFile(filePath: fileLocation, shouldEnsurePathExists: true)

Wrap in try/catch blocks in order to catch exceptions raised. Generally speaking though if shouldEnsurePathExists is true the operation is not likely to fail in most cases.