1.0.0 • Published 5 months ago

nodejsacorepathfinder v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

ACore JS PathFinder

The ACore JS PathFinder provides a set of classes and utilities for working with file paths, directories, and operating systems in TypeScript projects.

Table of Contents

Introduction

The File System Utility Library simplifies file and directory management tasks by offering a unified interface for different operating systems. It includes classes for exploring directories, listing files, retrieving file stats, and more.

Installation

To install the File System Utility Library, you can use npm:

npm install nodejsacorepathfinder

Usage

Exploring Directories

import { ExploredDirectory } from 'file-system-utility';

const dir = new ExploredDirectory('/path/to/directory');
const fileList = dir.allRecursive();

console.log('Files and directories:', fileList.get());

Retrieving File Stats

import { FilesUtil } from 'file-system-utility';

const fileStats = FilesUtil.getFileStats('/path/to/file.txt');
if (fileStats) {
    console.log('File Path:', fileStats.filePath);
    console.log('File Size:', fileStats.fileSize);
    console.log('Is File:', fileStats.isFile);
    console.log('Is Folder:', fileStats.isFolder);
}

Resolving Operating System

import { PathFinderAPI } from 'file-system-utility';

const pathFinder = PathFinderAPI.resolveCurrent();
if (pathFinder) {
    if (pathFinder.acFolderExist()) {
        console.log('ACORE_FOLDER exists.');
    } else {
        pathFinder.createAcFolder();
        console.log('ACORE_FOLDER created.');
    }
} else {
    console.error('Unsupported operating system.');
}

Certainly! Here's an improved "API Documentation" section for your README.md that provides more detailed information about each class and interface:

API Documentation

The File System Utility Library provides a comprehensive set of classes and interfaces to simplify working with file paths, directories, and operating systems.

Classes

ExploredDirectory

Represents an explored directory, providing methods to retrieve information about its contents.

Constructor
const directory: string = "/path/to/directory";
new ExploredDirectory(directory);
Methods
  • allRecursive(): FileList: Returns a list of all files and directories in the directory and its subdirectories.
  • list(): FileList: Returns a list of files and directories in the directory.
  • sub(directory: string): ExploredDirectory: Returns a new instance of ExploredDirectory representing a subdirectory.
  • getFile(file: string): string: Returns the contents of a specified file.
  • subs(): FileList: Returns a list of subdirectories in the directory.
  • files(): FileList: Returns a list of files in the directory.
  • get(): string: Returns the path of the explored directory.

FilesUtil

Provides utility methods for working with files and directories.

Methods
  • listRecursive(directory: string): string[]: Returns a list of all files and directories in the directory and its subdirectories.
  • get(root: string, file: string): string: Returns the full path of a file.
  • dir(root: string, dir: string): string: Returns the full path of a subdirectory.
  • list(directory: string): string[]: Returns a list of files and directories in the directory.
  • listRecursiveWithNames(directory: string, filenames: string[]): string[]: Returns a list of files with specific filenames in the directory and its subdirectories.

PathFinderAPI

Utility class for resolving and interacting with path finders based on the current operating system.

Methods
  • resolveCurrent(): IPathFinder | null: Resolves the appropriate path finder based on the current operating system.
  • createAcFolder(): void: Creates the ACORE_FOLDER directory if it doesn't exist.

Interfaces

IStats

Represents the statistics of a file or directory.

Properties
  • filePath: string: The path of the file or directory.
  • fileSize: number: The size of the file in bytes.
  • isFolder: boolean: Indicates whether the entry is a folder (directory).
  • isFile: boolean: Indicates whether the entry is a file.

IPathFinder

Represents a utility for finding paths on different operating systems.

Methods
  • acFolderExist(): boolean: Checks if the ACORE_FOLDER directory exists.
  • exist(relativePath: string): boolean: Checks if a file or directory exists at the specified relative path.
  • isFolder(relativeFolderPath: string): boolean: Checks if a specified relative path points to a directory.
  • isFile(relativeFilePath: string): boolean: Checks if a specified relative path points to a file.
  • getFileStats(relativeFilePath: string): IStats | null: Retrieves statistics of a file or directory.
  • find(): string: Finds the base path.
  • findFile(relativePath: string): string: Finds the full path to a file.

APathFinder

Abstract class providing base functionality for path finding on different operating systems.

Methods
  • acFolderExist(): boolean: Checks if the ACORE_FOLDER directory exists.
  • exist(relativePath: string): boolean: Checks if a file or directory exists at the specified relative path.
  • isFolder(relativeFolderPath: string): boolean: Checks if a specified relative path points to a directory.
  • isFile(relativeFilePath: string): boolean: Checks if a specified relative path points to a file.
  • getFileStats(relativeFilePath: string): IStats | null: Retrieves statistics of a file or directory.

Operating System Implementations

WindowsPathFinder, LinuxPathFinder, MacosPathFinder

Provides methods to resolve paths and interact with the specific operating system.

1.0.0

5 months ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.0.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago