@hypernym/utils 3.0.1 → 3.1.0

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,12 +1,22 @@
1
- # @hypernym/utils
1
+ <h1 align="center">Hyperutils</h1>
2
2
 
3
- A collection of reusable utilities.
3
+ <p align="center">A collection of reusable utilities.</p>
4
4
 
5
- <sub><a href="https://github.com/hypernym-studio/utils">Repository</a> | <a href="https://www.npmjs.com/package/@hypernym/utils">Package</a> | <a href="https://github.com/hypernym-studio/utils/releases">Releases</a> | <a href="https://github.com/hypernym-studio/utils/discussions">Discussions</a></sub>
5
+ <p align="center">
6
+ <a href="https://github.com/hypernym-studio/utils">Repository</a>
7
+ <span>+</span>
8
+ <a href="https://www.npmjs.com/package/@hypernym/utils">Package</a>
9
+ <span>+</span>
10
+ <a href="https://github.com/hypernym-studio/utils/releases">Releases</a>
11
+ <span>+</span>
12
+ <a href="https://github.com/hypernym-studio/utils/discussions">Discussions</a>
13
+ </p>
6
14
 
7
- ```sh
8
- pnpm add @hypernym/utils
9
- ```
15
+ <pre align="center">pnpm add @hypernym/utils</pre>
16
+
17
+ <h4 align="center">Hypernym Studio</h4>
18
+
19
+ <br>
10
20
 
11
21
  ## Features
12
22
 
package/dist/fs/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { access, constants, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
1
+ import { access, constants, mkdir, writeFile as writeFile$1, cp } from 'node:fs/promises';
2
2
  import { dirname } from 'node:path';
3
+ import { isString, isURL } from '../index.mjs';
3
4
 
4
5
  async function exists(path) {
5
6
  return await access(path, constants.F_OK).then(() => true).catch(() => false);
@@ -10,4 +11,15 @@ async function writeFile(path, data, options) {
10
11
  return await writeFile$1(path, data, options);
11
12
  }
12
13
 
13
- export { exists, writeFile };
14
+ async function copy(source, destination, options) {
15
+ const { recursive = true, filter } = options;
16
+ const sources = isString(source) || isURL(source) ? [source] : source;
17
+ for (const src of sources) {
18
+ await cp(src, destination, {
19
+ recursive,
20
+ filter
21
+ });
22
+ }
23
+ }
24
+
25
+ export { copy, exists, writeFile };
@@ -8,7 +8,7 @@ import { writeFile as writeFile$1 } from 'node:fs/promises';
8
8
  * ```ts
9
9
  * import { exists } from '@hypernym/utils/fs'
10
10
  *
11
- * exists('dir/file.ts') // => true
11
+ * await exists('dir/file.ts') // => true
12
12
  * ```
13
13
  */
14
14
  declare function exists(path: string): Promise<boolean>;
@@ -21,9 +21,40 @@ declare function exists(path: string): Promise<boolean>;
21
21
  * ```ts
22
22
  * import { writeFile } from '@hypernym/utils/fs'
23
23
  *
24
- * writeFile('dir/subdir/file.ts', `console.log('Hello World!')`)
24
+ * await writeFile('dir/subdir/file.ts', `console.log('Hello World!')`)
25
25
  * ```
26
26
  */
27
27
  declare function writeFile(path: string, data: Parameters<typeof writeFile$1>[1], options?: Parameters<typeof writeFile$1>[2]): Promise<void>;
28
28
 
29
- export { exists, writeFile };
29
+ interface CopyOptions {
30
+ /**
31
+ * Copies files or directories recursively.
32
+ *
33
+ * @default true
34
+ */
35
+ recursive?: boolean;
36
+ /**
37
+ * Filters copied `files` or `directories`.
38
+ *
39
+ * Returns `true` to copy the item, `false` to ignore it.
40
+ *
41
+ * @default undefined
42
+ */
43
+ filter?(source: string, destination: string): boolean | Promise<boolean>;
44
+ }
45
+ /**
46
+ * Copies `files` or `directories` recursively.
47
+ *
48
+ * Accepts a single source or a range of sources.
49
+ *
50
+ * @example
51
+ *
52
+ * ```ts
53
+ * import { copy } from '@hypernym/utils/fs'
54
+ *
55
+ * await copy('src/subdir/file.ts', './dist/subdir')
56
+ * ```
57
+ */
58
+ declare function copy(source: string | URL | (string | URL)[], destination: string | URL, options: CopyOptions): Promise<void>;
59
+
60
+ export { type CopyOptions, copy, exists, writeFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypernym/utils",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "author": "Hypernym Studio",
5
5
  "description": "A collection of reusable utilities.",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "prepublishOnly": "npm run build"
46
46
  },
47
47
  "sideEffects": false,
48
- "packageManager": "pnpm@9.9.0",
48
+ "packageManager": "pnpm@9.10.0",
49
49
  "engines": {
50
50
  "node": ">=20.0.0",
51
51
  "pnpm": ">=9.0.0"
@@ -63,14 +63,14 @@
63
63
  }
64
64
  },
65
65
  "devDependencies": {
66
- "@hypernym/bundler": "^0.10.0",
66
+ "@hypernym/bundler": "^0.11.0",
67
67
  "@hypernym/eslint-config": "^3.5.0",
68
68
  "@hypernym/prettier-config": "^3.2.0",
69
69
  "@hypernym/tsconfig": "^2.3.0",
70
- "@types/node": "^20.16.5",
70
+ "@types/node": "^22.5.5",
71
71
  "eslint": "^9.10.0",
72
72
  "prettier": "^3.3.3",
73
73
  "typescript": "^5.5.4",
74
- "vitest": "^2.0.5"
74
+ "vitest": "^2.1.1"
75
75
  }
76
76
  }