@thi.ng/file-io
Advanced tools
Comparing version 1.2.7 to 1.3.0
# Change Log | ||
- **Last updated**: 2024-02-10T08:59:56Z | ||
- **Last updated**: 2024-02-19T15:50:26Z | ||
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub) | ||
@@ -12,2 +12,8 @@ | ||
## [1.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@1.3.0) (2024-02-19) | ||
#### 🚀 Features | ||
- add ensureDir() ([8ca3085](https://github.com/thi-ng/umbrella/commit/8ca3085)) | ||
## [1.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@1.2.0) (2024-01-26) | ||
@@ -14,0 +20,0 @@ |
10
dir.d.ts
/** | ||
* Assumes given path is to a directory. Checks if the dir exists and if not | ||
* attempts to create it and then returns true. Otherwise returns false. | ||
* | ||
* @param dir | ||
*/ | ||
export declare const ensureDir: (dir: string) => boolean; | ||
/** | ||
* Checks if the directory for given file `path` already exists, and if not the | ||
@@ -13,3 +20,4 @@ * case, creates it. Returns true if the latter case. | ||
/** | ||
* Returns true if `path` is a directory (assumes path exists). | ||
* Returns true if `path` is a directory (assumes path exists, if not throws an | ||
* error). | ||
* | ||
@@ -16,0 +24,0 @@ * @param path |
import { existsSync, mkdirSync, statSync } from "fs"; | ||
import { sep } from "path"; | ||
const ensureDirForFile = (path) => { | ||
const dir = path.substring(0, path.lastIndexOf(sep)); | ||
return dir.length > 0 && !existsSync(dir) ? (mkdirSync(dir, { recursive: true }), true) : false; | ||
}; | ||
import { dirname } from "path"; | ||
const ensureDir = (dir) => dir.length > 0 && !existsSync(dir) ? (mkdirSync(dir, { recursive: true }), true) : false; | ||
const ensureDirForFile = (path) => ensureDir(dirname(path)); | ||
const isDirectory = (path) => statSync(path).isDirectory(); | ||
export { | ||
ensureDir, | ||
ensureDirForFile, | ||
isDirectory | ||
}; |
{ | ||
"name": "@thi.ng/file-io", | ||
"version": "1.2.7", | ||
"version": "1.3.0", | ||
"description": "Assorted file I/O utils (with logging support) for NodeJS", | ||
@@ -123,3 +123,3 @@ "type": "module", | ||
}, | ||
"gitHead": "25ee18f7db6d03f0b76787267ab071d16df94888\n" | ||
"gitHead": "ea2ec2e4f14c572bbfac00c43953a6c4033da09e\n" | ||
} |
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
39602
600
34