easypathutil
Advanced tools
Comparing version 1.0.2 to 1.1.0
{ | ||
"name": "easypathutil", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Fluent filepaths, made simple.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,4 +22,9 @@ <div align="center"> | ||
npm install easypathutil | ||
npm install easypathutil@1.1.0 | ||
## New in 1.1.0 | ||
• Provide your own JSON, path, or fs objects | ||
• More reliable path support (slash vs backslash) | ||
### Two-Part Motivation | ||
@@ -33,5 +38,5 @@ • Avoid a nesting problem of excessive '../../../../../foo/bar' when you can use a fluent object in projects with a more invariant file structure. | ||
• Easily check for existence of a file or folder, read, get stats, or require. | ||
• Easily check for existence of or load a file or folder, read, get stats, or require. | ||
• Lightweight: Package size is around 6kB | ||
• Lightweight: Package size under 7kB | ||
@@ -69,5 +74,12 @@ The tutorial below aims to demonstrate the core functionality of this package. | ||
// Provide the full path: | ||
// Or provide the full path: | ||
const myfolder = new Builder('/root/home/projects/myfolder'); | ||
// Or (for more advanced users) provide custom JSON, path and fs object: | ||
const myfolder = new Builder('/root/home/projects/myfolder', { | ||
JSON: someJsonPackage || global.JSON, | ||
fs: someFsPackage || require('fs'), | ||
path: somePathPackage || require('path'), | ||
}); | ||
const myfolderstring = myfolder(); // '/root/home/projects/myfolder' | ||
@@ -123,2 +135,10 @@ const samefolderstring = myfolder.toString(); // toString property turns it back into the path string | ||
**Read directory recursively, returning an array of absolute paths to files (.$read_dir, .$read_dir_sync) | ||
const filearray = myfolder.$read_dir_sync | ||
myfolder.$read_dir.then(filearray2 => { | ||
// same array contents as filearray | ||
}); | ||
// Aliases .$readdir, .$readDirsync, etc. as always, "." or "_" are optional and case insensitive | ||
**New object shortcut (.$new, .$new_default)** | ||
@@ -125,0 +145,0 @@ |
'use strict'; | ||
Reflect.defineProperty(exports, '__esModule', { value: true }); | ||
const fs = require('fs'); | ||
exports.default = (path, stringprop) => { | ||
exports.default = (path, stringprop, fs) => { | ||
try { | ||
@@ -8,0 +6,0 @@ const bigInt = !stringprop.toLowerCase().includes('legacy') && !stringprop.toLowerCase().includes('number'); |
@@ -6,10 +6,17 @@ 'use strict'; | ||
function PathBuilder(base = process.cwd(), parts = []) { | ||
if (!(this instanceof PathBuilder)) return new PathBuilder(base); | ||
function PathBuilder(base = process.cwd(), { | ||
JSON = global.JSON, | ||
path = require('path'), | ||
fs = require('fs'), | ||
} = {}, parts = []) { | ||
if (!(this instanceof PathBuilder)) return new PathBuilder(base, { JSON, path, fs }, parts); | ||
this.base = base; | ||
this.parts = parts; | ||
this._JSON = JSON; | ||
this._path = path; | ||
this._fs = fs; | ||
const proxy = this.proxy = new Proxy((arga => { | ||
if (!arga) return `${this.base}/${this.parts.join('/')}`.replace(/\/$/, ''); | ||
return new PathBuilder(this.base, [...this.parts, arga.toString()]); | ||
if (!arga) return this._path.join(this.base, ...this.parts); | ||
return new PathBuilder(this.base, { JSON, path, fs }, [...this.parts, arga.toString()]); | ||
}).bind(this), { has: has.bind(this), get: get.bind(this) }); | ||
@@ -16,0 +23,0 @@ return proxy; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21140
10
110
183
2