@fullstackunicorn/filesystem 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.dep.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // NODE BUILT IN
2
2
  export * as fsSync from 'fs'
3
3
  export * as fsAsync from 'fs/promises'
4
- export { constants } from 'fs'
4
+ export { constants } from 'fs'
5
+ export { default as path } from 'node:path'
package/modules/fsa.js CHANGED
@@ -1,4 +1,4 @@
1
- import { fsAsync, constants } from '#@/index.dep.js'
1
+ import { fsAsync, constants, path } from '#@/index.dep.js'
2
2
 
3
3
  export const fsa = {
4
4
  chmod: fsAsync.chmod,
@@ -21,6 +21,10 @@ export const fsa = {
21
21
  catch { return false }
22
22
  },
23
23
  ensureDir: async (path) => { if (!await fsa.exists(path)) await fsAsync.mkdir(path, { recursive: true }) },
24
+ ensureFileDir: async (filePath) => {
25
+ const dirPath = path.dirname(filePath)
26
+ if (!await fsa.exists(dirPath)) await fsAsync.mkdir(dirPath, { recursive: true })
27
+ },
24
28
  writeText: async (path, text) => await fsAsync.writeFile(path, text),
25
29
  listFiles: async (path, ext = null) => (await fsa.readDir(path)).filter(f => !ext || f.endsWith(ext)),
26
30
  safeUnlink: async (path) => { if (await fsa.exists(path)) await fsAsync.unlink(path) },
package/modules/fss.js CHANGED
@@ -1,11 +1,11 @@
1
- import { fsSync } from '#@/index.dep.js'
1
+ import { fsSync, path } from '#@/index.dep.js'
2
2
 
3
3
  export const fss = {
4
4
  exists: (...args) => fsSync.existsSync(...args),
5
5
  readFile: (...args) => fss.exists(...args) ? fsSync.readFileSync(...args) : null,
6
6
  readText: (path) => fss.exists(path) ? fsSync.readFileSync(path, 'utf8') : null,
7
- readJSON: (...args) => {
8
- try { return fss.exists(...args) ? JSON.parse(fsSync.readFileSync(...args), 'utf8') : {} }
7
+ readJSON: (path) => {
8
+ try { return fss.exists(path) ? JSON.parse(fsSync.readFileSync(path, 'utf8')) : {} }
9
9
  catch { return {} }
10
10
  },
11
11
  writeJSON: (path, json) => fsSync.writeFileSync(path, JSON.stringify(json, null, 4)),
@@ -18,6 +18,10 @@ export const fss = {
18
18
  catch { return false }
19
19
  },
20
20
  ensureDir: (path) => { if (!fss.exists(path)) fsSync.mkdirSync(path, { recursive: true }) },
21
+ ensureFileDir: (filePath) => {
22
+ const dirPath = path.dirname(filePath)
23
+ if (!fss.exists(dirPath)) fsSync.mkdirSync(dirPath, { recursive: true })
24
+ },
21
25
  writeText: (path, text) => fsSync.writeFileSync(path, text),
22
26
  listFiles: (path, ext = null) => fss.readDir(path).filter(f => !ext || f.endsWith(ext)),
23
27
  safeUnlink: (path) => { if (fss.exists(path)) fsSync.unlinkSync(path) },
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.4",
2
+ "version": "1.0.5",
3
3
  "name": "@fullstackunicorn/filesystem",
4
4
  "author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
5
5
  "description": "A simple sync/async file system wrapper for Node.js",