1.1.0 • Published 2 years ago

@hilesystem/local v1.1.0

Weekly downloads
136
License
MIT
Repository
github
Last release
2 years 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

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.2.6

2 years ago

0.2.3

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.1.36

4 years ago

0.2.0

4 years ago

0.1.35

4 years ago

0.1.34

4 years ago

0.1.33

4 years ago

0.1.32

4 years ago

0.1.31

4 years ago

0.1.30

5 years ago

0.1.29

5 years ago

0.1.28

5 years ago

0.1.27

5 years ago

0.1.25

5 years ago

0.1.26

5 years ago

0.1.22

5 years ago

0.1.23

5 years ago

0.1.24

5 years ago

0.1.21

5 years ago

0.1.20

5 years ago

0.1.19

5 years ago

0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.14

5 years ago

0.1.15

5 years ago

0.1.12

5 years ago

0.1.13

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.2

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.4

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago