@fullstackunicorn/filesystem 1.0.0 → 1.0.3

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 ADDED
@@ -0,0 +1,4 @@
1
+ // JS BUILT IN
2
+ export * as fsSync from 'fs'
3
+ export * as fsAsync from 'fs/promises'
4
+ export { constants } from 'fs'
package/index.js CHANGED
@@ -1,65 +1,2 @@
1
- import * as fsSync from 'fs'
2
- import * as fsAsync from 'fs/promises'
3
- import { constants } from 'fs'
4
-
5
- export const fss = {
6
- exists: (...args) => fsSync.existsSync(...args),
7
- readFile: (...args) => fss.exists(...args) ? fsSync.readFileSync(...args) : null,
8
- readText: (path) => fss.exists(path) ? fsSync.readFileSync(path, 'utf8') : null,
9
- readJSON: (...args) => {
10
- try { return fss.exists(...args) ? JSON.parse(fsSync.readFileSync(...args), 'utf8') : {} }
11
- catch { return {} }
12
- },
13
- writeJSON: (path, json) => fsSync.writeFileSync(path, JSON.stringify(json, null, 2)),
14
- readDir: (...args) => fss.exists(...args) ? fsSync.readdirSync(...args) : [],
15
- readDirVisible: (path) => (
16
- fss.readDir(path, { withFileTypes: true }) || []
17
- ).filter(e => e.isDirectory() && !e.name.startsWith('.')).map(e => e.name),
18
- isDir: (path) => {
19
- try { return fsSync.statSync(path).isDirectory() }
20
- catch { return false }
21
- },
22
- ensureDir: (path) => { if (!fss.exists(path)) fsSync.mkdirSync(path, { recursive: true }) },
23
- writeText: (path, text) => fsSync.writeFileSync(path, text),
24
- listFiles: (path, ext = null) => fss.readDir(path).filter(f => !ext || f.endsWith(ext)),
25
- safeUnlink: (path) => { if (fss.exists(path)) fsSync.unlinkSync(path) },
26
- safeRemove: (path) => { if (fss.exists(path)) fsSync.rmSync(path, { recursive: true, force: true }) },
27
- copyFile: fsSync.copyFileSync,
28
- remove: fsSync.rmSync,
29
- writeDir: fsSync.mkdirSync,
30
- unlink: fsSync.unlinkSync,
31
- stat: fsSync.statSync,
32
- writeFile: fsSync.writeFileSync
33
- }
34
-
35
- export const fsa = {
36
- exists: async (path) => {
37
- try { await fsAsync.access(path, constants.F_OK); return true }
38
- catch { return false }
39
- },
40
- readFile: async (path) => await fsa.exists(path) ? await fsAsync.readFile(path) : null,
41
- readText: async (path) => await fsa.exists(path) ? await fsAsync.readFile(path, 'utf8') : null,
42
- readJSON: async (path) => {
43
- try { return await fsa.exists(path) ? JSON.parse(await fsAsync.readFile(path, 'utf8')) : {} }
44
- catch { return {} }
45
- },
46
- writeJSON: async (path, json) => await fsAsync.writeFile(path, JSON.stringify(json, null, 2)),
47
- readDir: async (path, opts) => await fsa.exists(path) ? await fsAsync.readdir(path, opts) : [],
48
- readDirVisible: async (path) => (await fsa.readDir(path, { withFileTypes: true }))
49
- .filter(e => e.isDirectory() && !e.name.startsWith('.')).map(e => e.name),
50
- isDir: async (path) => {
51
- try { return (await fsAsync.stat(path)).isDirectory() }
52
- catch { return false }
53
- },
54
- ensureDir: async (path) => { if (!await fsa.exists(path)) await fsAsync.mkdir(path, { recursive: true }) },
55
- writeText: async (path, text) => await fsAsync.writeFile(path, text),
56
- listFiles: async (path, ext = null) => (await fsa.readDir(path)).filter(f => !ext || f.endsWith(ext)),
57
- safeUnlink: async (path) => { if (await fsa.exists(path)) await fsAsync.unlink(path) },
58
- safeRemove: async (path) => { if (await fsa.exists(path)) await fsAsync.rm(path, { recursive: true, force: true }) },
59
- copyFile: fsAsync.copyFile,
60
- remove: fsAsync.rm,
61
- writeDir: fsAsync.mkdir,
62
- unlink: fsAsync.unlink,
63
- stat: fsAsync.stat,
64
- writeFile: fsAsync.writeFile
65
- }
1
+ export { fsa } from '#@/modules/fsa.js'
2
+ export { fss } from '#@/modules/fss.js'
package/modules/fsa.js ADDED
@@ -0,0 +1,35 @@
1
+ import { fsAsync, constants } from '#@/index.dep.js'
2
+
3
+ export const fsa = {
4
+ chmod: fsAsync.chmod,
5
+ exists: async (path) => {
6
+ try { await fsAsync.access(path, constants.F_OK); return true }
7
+ catch { return false }
8
+ },
9
+ readFile: async (path) => await fsa.exists(path) ? await fsAsync.readFile(path) : null,
10
+ readText: async (path) => await fsa.exists(path) ? await fsAsync.readFile(path, 'utf8') : null,
11
+ readJSON: async (path) => {
12
+ try { return await fsa.exists(path) ? JSON.parse(await fsAsync.readFile(path, 'utf8')) : {} }
13
+ catch { return {} }
14
+ },
15
+ writeJSON: async (path, json) => await fsAsync.writeFile(path, JSON.stringify(json, null, 4)),
16
+ readDir: async (path, opts) => await fsa.exists(path) ? await fsAsync.readdir(path, opts) : [],
17
+ readDirVisible: async (path) => (await fsa.readDir(path, { withFileTypes: true }))
18
+ .filter(e => e.isDirectory() && !e.name.startsWith('.')).map(e => e.name),
19
+ isDir: async (path) => {
20
+ try { return (await fsAsync.stat(path)).isDirectory() }
21
+ catch { return false }
22
+ },
23
+ ensureDir: async (path) => { if (!await fsa.exists(path)) await fsAsync.mkdir(path, { recursive: true }) },
24
+ writeText: async (path, text) => await fsAsync.writeFile(path, text),
25
+ listFiles: async (path, ext = null) => (await fsa.readDir(path)).filter(f => !ext || f.endsWith(ext)),
26
+ safeUnlink: async (path) => { if (await fsa.exists(path)) await fsAsync.unlink(path) },
27
+ safeRemove: async (path) => { if (await fsa.exists(path)) await fsAsync.rm(path, { recursive: true, force: true }) },
28
+ append: async (path, buffer) => await fsAsync.appendFile(path, buffer),
29
+ copyFile: fsAsync.copyFile,
30
+ remove: fsAsync.rm,
31
+ writeDir: fsAsync.mkdir,
32
+ unlink: fsAsync.unlink,
33
+ stat: fsAsync.stat,
34
+ writeFile: fsAsync.writeFile
35
+ }
package/modules/fss.js ADDED
@@ -0,0 +1,32 @@
1
+ import { fsSync } from '#@/index.dep.js'
2
+
3
+ export const fss = {
4
+ exists: (...args) => fsSync.existsSync(...args),
5
+ readFile: (...args) => fss.exists(...args) ? fsSync.readFileSync(...args) : null,
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') : {} }
9
+ catch { return {} }
10
+ },
11
+ writeJSON: (path, json) => fsSync.writeFileSync(path, JSON.stringify(json, null, 4)),
12
+ readDir: (...args) => fss.exists(...args) ? fsSync.readdirSync(...args) : [],
13
+ readDirVisible: (path) => (
14
+ fss.readDir(path, { withFileTypes: true }) || []
15
+ ).filter(e => e.isDirectory() && !e.name.startsWith('.')).map(e => e.name),
16
+ isDir: (path) => {
17
+ try { return fsSync.statSync(path).isDirectory() }
18
+ catch { return false }
19
+ },
20
+ ensureDir: (path) => { if (!fss.exists(path)) fsSync.mkdirSync(path, { recursive: true }) },
21
+ writeText: (path, text) => fsSync.writeFileSync(path, text),
22
+ listFiles: (path, ext = null) => fss.readDir(path).filter(f => !ext || f.endsWith(ext)),
23
+ safeUnlink: (path) => { if (fss.exists(path)) fsSync.unlinkSync(path) },
24
+ safeRemove: (path) => { if (fss.exists(path)) fsSync.rmSync(path, { recursive: true, force: true }) },
25
+ copyFile: fsSync.copyFileSync,
26
+ remove: fsSync.rmSync,
27
+ writeDir: fsSync.mkdirSync,
28
+ unlink: fsSync.unlinkSync,
29
+ stat: fsSync.statSync,
30
+ writeFile: fsSync.writeFileSync,
31
+ writeStream: (...args) => fsSync.createWriteStream(...args),
32
+ }
package/package.json CHANGED
@@ -1,21 +1,34 @@
1
1
  {
2
+ "version": "1.0.3",
2
3
  "name": "@fullstackunicorn/filesystem",
3
- "author": "lucanigido[](https://fullstackunicorn.dev/author/lucanigido)",
4
- "version": "1.0.0",
5
- "main": "index.js",
6
- "type": "module",
4
+ "author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
5
+ "description": "A simple sync/async file system wrapper for Node.js",
7
6
  "license": "MIT",
7
+ "type": "module",
8
8
  "private": false,
9
- "description": "A simple sync/async file system wrapper for Node.js",
10
- "keywords": ["filesystem", "fs", "node", "sync", "async"],
9
+ "readme": "package.readme.md",
10
+ "main": "index.js",
11
+ "files": [
12
+ "index.js",
13
+ "index.dep.js",
14
+ "modules/"
15
+ ],
11
16
  "repository": {
12
17
  "type": "git",
13
18
  "url": "https://gitlab.com/fullstackunicorn/filesystem.git"
14
19
  },
15
- "files": [
16
- "index.js"
20
+ "keywords": [
21
+ "filesystem",
22
+ "fs",
23
+ "node",
24
+ "sync",
25
+ "async"
17
26
  ],
27
+ "imports": {
28
+ "#@": "./",
29
+ "#@/*": "./*"
30
+ },
18
31
  "scripts": {
19
- "test": "echo \"Error: no test specified\" && exit 1"
32
+ "test": "exit 1"
20
33
  }
21
- }
34
+ }