Skip to content

Commit 1fe0791

Browse files
docs: add jsdoc for path()
1 parent e3089ec commit 1fe0791

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

src/core/types.ts

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,61 @@ export type FileSystem = typeof nodefs;
1010
export type PathFn = typeof path;
1111

1212
/**
13-
* Emmmm
13+
* Get a new instance of `PathNice` or `PathNiceArr`.
14+
*
15+
* If the argurment is a string or a `PathNice`, a `PathNice` is returned. A `PathNice`
16+
* instance is a wrapper of the raw path string, so that the path can be easily used to
17+
* generate additional paths or manipulate files.
18+
*
19+
* If there are more than 1 arguments or the only argument is an `Array`, a `PathNiceArr`
20+
* is returned. The class `PathNiceArr` extends the base class `Array`, adding methods for
21+
* copying, moving, removing, watching files in a holistic manner.
22+
*
23+
* For details, please refer to the documents of [PathNice]()
24+
* and [PathNiceArr]().
25+
*
26+
* @example
27+
*
28+
* Get a PathNice instance:
29+
*
30+
* ```ts
31+
* $ let src: PathNice = path('./src')
32+
* ```
33+
*
34+
* Get the raw path string from PathNice:
35+
*
36+
* ```ts
37+
* $ src.raw
38+
* './src'
39+
* ```
40+
*
41+
* Use `src` to generate another path:
42+
*
43+
* ```ts
44+
* $ src.join('index.ts')
45+
* PathNice { raw: 'src/index.ts' } // on POSIX
46+
* PathNice { raw: 'src\\index.ts' } // on Windows
47+
* ```
48+
*
49+
* Use `src` to write a file:
50+
*
51+
* ```ts
52+
* $ src.join('index.ts').writeFile('export default 42;')
53+
* Promise { <pending> ... }
54+
* ```
55+
*
56+
* Get a PathNiceArr instance:
57+
*
58+
* ```ts
59+
* let arr = path('./README.md', './package.json', './tsconfig.json');
60+
* ```
61+
*
62+
* Filter json files from the array and copy to another folder:
63+
*
64+
* ```ts
65+
* arr.filter(f => f.ext() === '.json')
66+
* .copyToDir('./config')
67+
* ```
1468
*/
1569
export declare function path<T extends string>(path: T): PathNice<T>;
1670
export declare function path<T extends string>(path: PathNice<T>): PathNice<T>;
@@ -19,7 +73,9 @@ export declare function path(
1973
path_1: string | PathNice,
2074
...paths_rest: (string | PathNice)[]
2175
): PathNiceArr;
22-
export declare function path(paths: Array<string | PathNice> | PathNiceArr): PathNiceArr;
76+
export declare function path(
77+
paths: ReadonlyArray<string | PathNice> | PathNiceArr,
78+
): PathNiceArr;
2379

2480
export declare namespace path {
2581
/**

0 commit comments

Comments
 (0)