check-disk-space 2.0.0 → 2.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.
@@ -0,0 +1,4 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [Alex-D]
4
+ patreon: AlexandreDemode
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "check-disk-space",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Light multi-platform disk space checker without third party for Node.js",
5
5
  "main": "index.js",
6
- "engines" : {
7
- "node" : ">=8"
6
+ "engines": {
7
+ "node": ">=8"
8
8
  },
9
9
  "dependencies": {},
10
10
  "devDependencies": {
@@ -33,6 +33,7 @@
33
33
  "hdd",
34
34
  "free"
35
35
  ],
36
+ "types": "./typings/index.d.ts",
36
37
  "author": "Alex-D <contact@alex-d.fr> (http://alex-d.fr)",
37
38
  "license": "MIT",
38
39
  "bugs": {
@@ -0,0 +1,77 @@
1
+ declare module "check-disk-space" {
2
+ namespace checkDiskSpace {
3
+ /**
4
+ * The result of the disk space check
5
+ */
6
+ interface CheckDiskSpaceResult {
7
+ /**
8
+ * How much space is left
9
+ */
10
+ free: number;
11
+ /**
12
+ * The size of the path
13
+ */
14
+ size: number;
15
+ }
16
+
17
+ /**
18
+ * Error for invalid path
19
+ */
20
+ class InvalidPathError {
21
+ constructor(message: string);
22
+ /**
23
+ * The name of the error
24
+ */
25
+ name: "InvalidPathError";
26
+ /**
27
+ * The error message
28
+ */
29
+ message: string | "";
30
+ }
31
+
32
+ /**
33
+ * Error for path which do not match the actual file system
34
+ */
35
+ class NoMatchError {
36
+ constructor(message: any);
37
+ /**
38
+ * The name of the error
39
+ */
40
+ name: "NoMatchError";
41
+ /**
42
+ * The error message
43
+ */
44
+ message: string | "";
45
+ }
46
+
47
+ /**
48
+ * Get the first existing parent path
49
+ *
50
+ * @param {string} directoryPath The file/folder path from where we want to know disk space
51
+ * @returns {string} The first existing parent path
52
+ */
53
+ function getFirstExistingParentPath(directoryPath: string): string;
54
+ }
55
+
56
+ /**
57
+ * Build the check call for unix or win32
58
+ *
59
+ * @param {string} directoryPath The file/folder path from where we want to know disk space
60
+ * @return {Promise<CheckDiskSpaceResult>} The result of the check
61
+ *
62
+ * @example
63
+ * // On Windows
64
+ * const diskSpace = await checkDiskSpace('C:/blabla/bla');
65
+ * console.log(diskSpace); // { free: 12345678, size: 98756432 }
66
+ *
67
+ * @example
68
+ * const diskSpace = await checkDiskSpace('/mnt/mygames');
69
+ * console.log(diskSpace); // { free: 12345678, size: 98756432 }
70
+ *
71
+ * @throws {NoMatchError} In case the given path does not match with the actual file system
72
+ * @throws {InvalidPathError} In case the path is invalid
73
+ */
74
+ function checkDiskSpace(directoryPath: string): Promise<checkDiskSpace.CheckDiskSpaceResult>;
75
+
76
+ export = checkDiskSpace;
77
+ }
@@ -0,0 +1,19 @@
1
+ import * as checkDiskSpace from 'check-disk-space';
2
+
3
+ (async () => {
4
+ try {
5
+ const diskSpace = await checkDiskSpace('/mnt/mygames');
6
+ diskSpace.free;
7
+ diskSpace.size;
8
+ } catch (err) {
9
+ if (err instanceof checkDiskSpace.InvalidPathError) {
10
+ console.error('Invalid Path Error');
11
+ } else if (err instanceof checkDiskSpace.NoMatchError) {
12
+ console.error('No Match Error');
13
+ } else {
14
+ console.error('Error');
15
+ }
16
+ }
17
+ })();
18
+
19
+ checkDiskSpace.getFirstExistingParentPath('/path');