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

@hilesystem/local

v1.1.0

Published

Filesystem abstraction layer and common function wrappers

Downloads

89

Readme

HileSystem Local

HileSystem Local

Filesystem abstraction layer and common function wrappers.

NPM Version NPM Downloads TypeScript Typings Maintainability Rating Codacy Badge

Usage

Import

import {
  HileSystemLocal,
  absolutePathFrom, pathFrom,
  createDirectory, createFile,
  readFileToBase64, readFileToBuffer, readFileToString,
  dirIsEmpty, dirIsExecutable, dirIsReadable, dirIsVisible, dirIsWritable,
  fileIsExecutable, fileIsReadable, fileIsVisible, fileIsWritable,
  getStatus, isDirExists, isFileExists, isPathExists,
  fileExtension, fileName, fileNameExt, filePath,
  listContents, listDirectories, listFiles,
  move,
  remove, removeNonBlocking, removeSilent,
  fileTruncate, writeFile, writeFileTail, writeJSON,
  hash, hashCrc32, hashMd5, hashSha1, hashSha256, hashSha512, size,
} from "@hilesystem/local";

Import all as named import

import * as hileSystem from "@hilesystem/local";
const isDirectoryCreated = await hileSystem.createDirectory("./test/");

Working with instance

If you prefer object-oriented style.

import { HileSystemLocal } from "@hilesystem/local";
const hileSystem = new HileSystemLocal();
const isDirectoryCreated = await hileSystem.createDirectory("./test/");

API

Path

const paths = ["path", "to", "file.txt"];
const str = absolutePathFrom(paths) // "/user/me/path/to/file.txt"
const str = fileExtension("path/to/file.txt"); // "txt"
const str = fileName("path/to/file.txt"); // "file"
const str = fileNameExt("path/to/file.txt"); // "file.txt"
const str = filePath("path/to/file.txt"); // "path/to"
const str = pathFrom(["path", "to", "file.txt"]) // "path/to/file.txt"

Create

const trueOrError = await createDirectory("path/to/dir", "0777", true);
const trueOrError = await createFile("path/to/dir", "0777");

Read

const stringOrError = await readFileToBase64("path/to/img.png");
const bufferOrError = await readFileToBuffer("path/to/file.txt");
const stringOrError = await readFileToString("path/to/file.txt");

Move

const trueOrError = await move("path/to/file.ext", "path/to-another/file.ext");

Write

const trueOrError = await fileTruncate("path/to/file.ext");
const filePath = "./file.txt";
const data = "Text";
const options = { encoding: "utf8" };
const trueOrError = await writeFile(filePath, data, options);
const filePath = "./file.txt";
const data = "Text to add to the end of the file.";
const options = { encoding: "utf8" };
const trueOrError = await writeFileTail(filePath, data, options);
const filePath = "./file.json";
const data = { key: "value" };
const options = { encoding: "utf8" };
const config = {
  sort: true,
  space: "\t"
};
const trueOrError = await writeJSON(filePath, data, options, config);

Delete

const voidOrError = await remove("path/to/file.txt");
removeNonBlocking("path/to/file.txt");
removeSilent("path/to/file.txt");

Information

const [status, error] = await getStatus("path/to/file.ext");
const trueOrFalse = await isDirExists("path/to/");
const trueOrFalse = await isFileExists("path/to/file.ext");
const trueOrFalse = await isPathExists("path/to/file_or_directory");

Check

const booleanOrError = await dirIsEmpty("path/to/dir", true);
const trueOrError = await dirIsExecutable("path/to/dir");
const trueOrError = await dirIsReadable("path/to/dir");
const trueOrError = await dirIsVisible("path/to/dir");
const trueOrError = await dirIsWritable("path/to/dir");
const trueOrError = await fileIsExecutable("path/to/file.ext");
const trueOrError = await fileIsReadable("path/to/file.ext");
const trueOrError = await fileIsVisible("path/to/file.ext");
const trueOrError = await fileIsWritable("path/to/file.ext");

List

const arrayOfStringsOrError = await listContents("path/to/dir");
const arrayOfStringsOrError = await listDirectories("path/to/dir");
const arrayOfStringsOrError = await listFiles("path/to/dir");

Calculate

const hash = await hash("path/to/file", "md5");
const hash = await hashCrc32("path/to/file");
const hash = await hashMd5("path/to/file");
const hash = await hashSha1("path/to/file");
const hash = await hashSha256("path/to/file");
const hash = await hashSha512("path/to/file");
const sizeInBytes = await size("path/to/file");
const sizeAsString = await size("path/to/file", true);

See also

My other projects