@hypernym/utils 3.3.0 → 3.4.1

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/README.md CHANGED
@@ -1,22 +1,20 @@
1
- <h1 align="center">Hyperutils</h1>
1
+ <h1 align="center">Hypernym Utils</h1>
2
2
 
3
3
  <p align="center">A collection of reusable utilities.</p>
4
4
 
5
5
  <p align="center">
6
6
  <a href="https://github.com/hypernym-studio/utils">Repository</a>
7
- <span>+</span>
7
+ <span>✦</span>
8
8
  <a href="https://www.npmjs.com/package/@hypernym/utils">Package</a>
9
- <span>+</span>
9
+ <span>✦</span>
10
10
  <a href="https://github.com/hypernym-studio/utils/releases">Releases</a>
11
- <span>+</span>
11
+ <span>✦</span>
12
12
  <a href="https://github.com/hypernym-studio/utils/discussions">Discussions</a>
13
13
  </p>
14
14
 
15
- <pre align="center">pnpm add @hypernym/utils</pre>
15
+ <br>
16
16
 
17
- <p align="center">
18
- <strong>Hypernym Studio</strong>
19
- </p>
17
+ <pre align="center">pnpm add @hypernym/utils</pre>
20
18
 
21
19
  <br>
22
20
 
@@ -119,7 +117,7 @@ isString('@hypernym/utils') // => true
119
117
 
120
118
  ### exists
121
119
 
122
- Checks if the file or directory exists.
120
+ Checks if the `file` or `directory` exists.
123
121
 
124
122
  ```ts
125
123
  import { exists } from '@hypernym/utils/fs'
@@ -129,7 +127,7 @@ await exists('dir/file.ts') // => true
129
127
 
130
128
  ### read
131
129
 
132
- Reads the entire contents of a file.
130
+ Reads the entire contents of a `file`.
133
131
 
134
132
  ```ts
135
133
  import { read } from '@hypernym/utils/fs'
@@ -137,9 +135,19 @@ import { read } from '@hypernym/utils/fs'
137
135
  await read('dir/subdir/file.ts')
138
136
  ```
139
137
 
138
+ ### readdir
139
+
140
+ Reads the contents of a `directory` recursively.
141
+
142
+ ```ts
143
+ import { readdir } from '@hypernym/utils/fs'
144
+
145
+ await readdir('dir/subdir')
146
+ ```
147
+
140
148
  ### write
141
149
 
142
- Writes data to a file recursively.
150
+ Writes data to a `file` recursively.
143
151
 
144
152
  ```ts
145
153
  import { write } from '@hypernym/utils/fs'
package/dist/fs/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { access, constants, readFile, mkdir as mkdir$1, writeFile as writeFile$1, cp, rm } from 'node:fs/promises';
1
+ import { access, constants, readFile, readdir as readdir$1, mkdir as mkdir$1, writeFile as writeFile$1, cp, rm } from 'node:fs/promises';
2
2
  import { dirname } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { isURL, isString } from '../index.mjs';
@@ -12,6 +12,15 @@ async function read(path, options = {}) {
12
12
  return await readFile(path, { encoding, ...options });
13
13
  }
14
14
 
15
+ async function readdir(path, options = {}) {
16
+ const { encoding = "utf-8", recursive = true } = options;
17
+ return await readdir$1(path, {
18
+ encoding,
19
+ recursive,
20
+ ...options
21
+ });
22
+ }
23
+
15
24
  async function write(path, data, options) {
16
25
  await mkdir$1(dirname(isURL(path) ? fileURLToPath(path) : path), {
17
26
  recursive: true
@@ -47,4 +56,4 @@ async function remove(path, options = {}) {
47
56
  }
48
57
  }
49
58
 
50
- export { copy, exists, mkdir, read, remove, write, writeFile };
59
+ export { copy, exists, mkdir, read, readdir, remove, write, writeFile };
@@ -1,7 +1,8 @@
1
+ import { Dirent } from 'node:fs';
1
2
  import { writeFile as writeFile$1 } from 'node:fs/promises';
2
3
 
3
4
  /**
4
- * Checks if the file or directory exists.
5
+ * Checks if the `file` or `directory` exists.
5
6
  *
6
7
  * @example
7
8
  *
@@ -37,7 +38,7 @@ interface ReadOptions<T extends ReadEncodingType> {
37
38
  flag?: number | string;
38
39
  }
39
40
  /**
40
- * Reads the entire contents of a file.
41
+ * Reads the entire contents of a `file`.
41
42
  *
42
43
  * @example
43
44
  *
@@ -49,9 +50,46 @@ interface ReadOptions<T extends ReadEncodingType> {
49
50
  */
50
51
  declare function read<T extends ReadEncodingType = BufferEncoding>(path: ReadPath, options?: ReadOptions<T>): Promise<ReadType<T>>;
51
52
 
53
+ type ReaddirPath = string | URL;
54
+ type ReaddirEncodingType = BufferEncoding | null | 'buffer' | undefined;
55
+ type ReaddirWithFileType = true | undefined;
56
+ type ReaddirType<E, F> = F extends true ? Dirent : E extends BufferEncoding | undefined ? string : E extends null | 'buffer' ? Buffer : never;
57
+ interface ReaddirOptions<E extends ReaddirEncodingType, F extends ReaddirWithFileType> {
58
+ /**
59
+ * If the encoding is set to `'buffer'` or `null`, the filenames returned will be passed as `Buffer` objects.
60
+ *
61
+ * @default 'utf-8'
62
+ */
63
+ encoding?: E;
64
+ /**
65
+ * If `withFileTypes` is set to `true`, the returned array will contain `fs.Dirent` objects.
66
+ *
67
+ * @default undefined
68
+ */
69
+ withFileTypes?: F;
70
+ /**
71
+ * Reads the directory recursively.
72
+ *
73
+ * @default true
74
+ */
75
+ recursive?: boolean;
76
+ }
77
+ /**
78
+ * Reads the contents of a `directory` recursively.
79
+ *
80
+ * @example
81
+ *
82
+ * ```ts
83
+ * import { readdir } from '@hypernym/utils/fs'
84
+ *
85
+ * await readdir('dir/subdir')
86
+ * ```
87
+ */
88
+ declare function readdir<E extends ReaddirEncodingType = BufferEncoding, F extends ReaddirWithFileType = undefined>(path: ReaddirPath, options?: ReaddirOptions<E, F>): Promise<ReaddirType<E, F>[]>;
89
+
52
90
  type WritePath = string | URL;
53
91
  /**
54
- * Writes data to a file recursively.
92
+ * Writes data to a `file` recursively.
55
93
  *
56
94
  * @example
57
95
  *
@@ -182,4 +220,4 @@ interface RemoveOptions {
182
220
  */
183
221
  declare function remove(path: RemovePath | RemovePath[], options?: RemoveOptions): Promise<void>;
184
222
 
185
- export { type CopyDestination, type CopyOptions, type CopySource, type MakeDirOptions, type MakeDirPath, type ReadEncodingType, type ReadOptions, type ReadPath, type ReadType, type RemoveOptions, type RemovePath, type WritePath, copy, exists, mkdir, read, remove, write, writeFile };
223
+ export { type CopyDestination, type CopyOptions, type CopySource, type MakeDirOptions, type MakeDirPath, type ReadEncodingType, type ReadOptions, type ReadPath, type ReadType, type ReaddirEncodingType, type ReaddirOptions, type ReaddirPath, type ReaddirType, type ReaddirWithFileType, type RemoveOptions, type RemovePath, type WritePath, copy, exists, mkdir, read, readdir, remove, write, writeFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypernym/utils",
3
- "version": "3.3.0",
3
+ "version": "3.4.1",
4
4
  "author": "Hypernym Studio",
5
5
  "description": "A collection of reusable utilities.",
6
6
  "license": "MIT",
@@ -10,11 +10,11 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
13
- "types": "./dist/types/index.d.ts",
13
+ "types": "./dist/types/index.d.mts",
14
14
  "import": "./dist/index.mjs"
15
15
  },
16
16
  "./fs": {
17
- "types": "./dist/types/fs/index.d.ts",
17
+ "types": "./dist/types/fs/index.d.mts",
18
18
  "import": "./dist/fs/index.mjs"
19
19
  }
20
20
  },
@@ -34,18 +34,7 @@
34
34
  "js",
35
35
  "ts"
36
36
  ],
37
- "scripts": {
38
- "dev:browser": "vite playgrounds/browser",
39
- "dev:server": "bun --watch playgrounds/server/main.ts",
40
- "build": "hyperbundler",
41
- "test:types": "vitest --typecheck.only",
42
- "lint": "eslint .",
43
- "lint:fix": "eslint --fix .",
44
- "format": "prettier --write .",
45
- "prepublishOnly": "npm run build"
46
- },
47
37
  "sideEffects": false,
48
- "packageManager": "pnpm@9.10.0",
49
38
  "engines": {
50
39
  "node": ">=20.0.0",
51
40
  "pnpm": ">=9.0.0"
@@ -63,14 +52,23 @@
63
52
  }
64
53
  },
65
54
  "devDependencies": {
66
- "@hypernym/bundler": "^0.11.0",
67
- "@hypernym/eslint-config": "^3.5.0",
55
+ "@hypernym/bundler": "^0.14.0",
56
+ "@hypernym/eslint-config": "^3.5.1",
68
57
  "@hypernym/prettier-config": "^3.2.0",
69
58
  "@hypernym/tsconfig": "^2.4.0",
70
- "@types/node": "^22.5.5",
71
- "eslint": "^9.10.0",
59
+ "@types/node": "^22.8.6",
60
+ "eslint": "^9.14.0",
72
61
  "prettier": "^3.3.3",
73
- "typescript": "^5.5.4",
74
- "vitest": "^2.1.1"
62
+ "typescript": "^5.6.3",
63
+ "vitest": "^2.1.4"
64
+ },
65
+ "scripts": {
66
+ "dev:browser": "vite playgrounds/browser",
67
+ "dev:server": "bun --watch playgrounds/server/main.ts",
68
+ "build": "hyperbundler",
69
+ "test:types": "vitest --typecheck.only",
70
+ "lint": "eslint .",
71
+ "lint:fix": "eslint --fix .",
72
+ "format": "prettier --write ."
75
73
  }
76
- }
74
+ }
File without changes