1.1.0 • Published 10 months ago

@hilesystem/local v1.1.0

Weekly downloads
136
License
MIT
Repository
github
Last release
10 months ago

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

1.1.0

10 months ago

1.0.2

12 months ago

1.0.1

1 year ago

1.0.0

1 year ago

0.2.6

1 year ago

0.2.3

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.1.36

3 years ago

0.2.0

3 years ago

0.1.35

3 years ago

0.1.34

3 years ago

0.1.33

3 years ago

0.1.32

3 years ago

0.1.31

3 years ago

0.1.30

3 years ago

0.1.29

3 years ago

0.1.28

4 years ago

0.1.27

4 years ago

0.1.25

4 years ago

0.1.26

4 years ago

0.1.22

4 years ago

0.1.23

4 years ago

0.1.24

4 years ago

0.1.21

4 years ago

0.1.20

4 years ago

0.1.19

4 years ago

0.1.18

4 years ago

0.1.17

4 years ago

0.1.16

4 years ago

0.1.14

4 years ago

0.1.15

4 years ago

0.1.12

4 years ago

0.1.13

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago