1.0.1 • Published 6 months ago

@levihub/pathbuilder v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

Installation

npm i @levihub/pathbuilder

Declaration

const Path = require('@levihub/pathbuilder');
// or
import Path from '@levihub/pathbuilder';

Working with modules

// __dirname and __filename are not available in modules
// this can help you with the problem
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory

Usage/Examples

const SRC = new Path(__dirname); // to create a simple path
console.log(SRC.path); // to view a path

// get method returns the path with added info (like path.join)
// we can use it to set a new path
const SERVER = new Path(SRC.get('server'));
// or use the path property
const SERVER = new Path(SRC.path, 'server');

// get method can be used for files
// here a sample of file reading
const fs = require('fs');
const content = fs.readFileSync(SERVER.get('content.json'), 'utf8');
console.log(content);
1.0.1

6 months ago

1.0.0

6 months ago