Skip to content

Commit fee884d

Browse files
committed
docs: add documentation for all exported symbols
1 parent c9c546b commit fee884d

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

src/glob.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function match(pattern: string, text: string) {
2020
* A helper function to match input against [pattern-list](https://www.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5#PATTERNS).
2121
* According to `man ssh_config`, negated patterns shall be matched first.
2222
*
23-
* @param {string|string[]} patternList
24-
* @param {string} str
23+
* @param {string|string[]} patternList one or more glob patterns to match
24+
* @param {string} text the text to match
2525
*/
2626
function glob(patternList: string | string[], text: string): boolean {
2727
const patterns = Array.isArray(patternList) ? patternList : patternList.split(/,/)

src/ssh-config.ts

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,127 @@ const RE_MULTI_VALUE_DIRECTIVE = /^(GlobalKnownHostsFile|Host|IPQoS|SendEnv|User
1010
const RE_QUOTE_DIRECTIVE = /^(?:CertificateFile|IdentityFile|IdentityAgent|User)$/i
1111
const RE_SINGLE_LINE_DIRECTIVE = /^(Include|IdentityFile)$/i
1212

13+
/**
14+
* A type of line in an ssh-config file. Differentiates between directives,
15+
* comments, and empty lines.
16+
*/
1317
export enum LineType {
18+
/** line with a directive in an ssh-config file */
1419
DIRECTIVE = 1,
20+
/** line with a comment in an ssh-config file */
1521
COMMENT = 2,
22+
/** empty line in an ssh-config file */
1623
EMPTY = 3
1724
}
1825

26+
/** A separator character in a directive. */
1927
export type Separator = ' ' | '=' | '\t';
2028

2129
type Space = ' ' | '\t' | '\n';
2230

31+
/**
32+
* A directive in an ssh-config file. This is the main type of element in the
33+
* file. The directive primarily consists of a
34+
* {@link Directive.param | parameter}, and a {@link Directive.value | value},
35+
* much like a key-value pair.
36+
*
37+
* We additionally keep track of a few other fields in order to print out a
38+
* directive exactly as it was read, even though the used syntax is equivalent.
39+
*/
2340
export interface Directive {
41+
/** type of line, always {@link LineType.DIRECTIVE} */
2442
type: LineType.DIRECTIVE;
43+
/** unrelated string encountered before this directive */
2544
before: string;
45+
/** unrelated string encountered after this directive */
2646
after: string;
47+
/** parameter name of this directive */
2748
param: string;
49+
/** separator char used in this directive */
2850
separator: Separator;
51+
/** the actual value of this directive */
2952
value: string | { val: string, separator: string, quoted?: boolean }[];
53+
/** whether or not quotes were used for the directive value */
3054
quoted?: boolean;
3155
}
3256

57+
/**
58+
* A section is a Host or Match directive in an ssh-config file. It includes a
59+
* reference to the contained config via {@link Section.config}.
60+
*/
3361
export interface Section extends Directive {
62+
/** the config contained in this section */
3463
config: SSHConfig;
3564
}
3665

66+
/**
67+
* Represents a Match directive in an ssh-config file. It includes a reference
68+
* to the contained config via {@link Section.config}, and a map of all match
69+
* criteria via {@link Match.criteria}.
70+
*/
3771
export interface Match extends Section {
38-
criteria: Record<string, string | { val: string, separator: string, quoted?: boolean }[]>
72+
/** the match criteria contained in this Match section */
73+
criteria: Record<string, string | {
74+
/** the value of this match criterion */
75+
val: string,
76+
/** separator used for this match criterion */
77+
separator: string,
78+
/** whether this match criterion was quoted */
79+
quoted?: boolean
80+
}[]>
3981
}
4082

83+
/**
84+
* A comment in an ssh-config file. Stores the content of the comment as a
85+
* string in {@link Comment.content}.
86+
*/
4187
export interface Comment {
88+
/** type of line, always {@link LineType.COMMENT} */
4289
type: LineType.COMMENT;
90+
/** unrelated string encountered before this directive */
4391
before: string;
92+
/** unrelated string encountered after this directive */
4493
after: string;
94+
/** content of the comment */
4595
content: string;
4696
}
4797

98+
/**
99+
* An empty or whitespace-only line in an ssh-config file. This is mainly used
100+
* to represent empty config ssh-config files. The actual whitespace characters
101+
* is usually stored in the {@link Empty.before | before} field. Storing it in
102+
* the {@link Empty.after | after} field is permitted, too.
103+
*/
48104
export interface Empty {
105+
/** type of line, always {@link LineType.COMMENT} */
49106
type: LineType.EMPTY
107+
/** unrelated string encountered before this directive */
50108
before: string,
109+
/** unrelated string encountered after this directive */
51110
after: string
52111
}
53112

113+
/**
114+
* A single line in an ssh-config file. The union can be discrimiated via its
115+
* `type` property of type {@link LineType}.
116+
*/
54117
export type Line = Match | Section | Directive | Comment | Empty
55118

119+
/**
120+
* Options for finding a {@link Section} via Host or Match.
121+
*/
56122
export interface FindOptions {
123+
/** the host to look for */
57124
Host?: string;
58125
}
59126

127+
/**
128+
* Options for querying an SSH config via host and user.
129+
*/
60130
export interface MatchOptions {
131+
/** the host of the query */
61132
Host: string;
133+
/** the user of the query */
62134
User?: string;
63135
}
64136

@@ -142,9 +214,17 @@ function match(criteria: Match['criteria'], context: ComputeContext): boolean {
142214
return true
143215
}
144216

217+
/**
218+
* Represents parsed SSH config. Main element of this library.
219+
*
220+
* A parsed SSH config is modelled as an array of {@link Line}s.
221+
*/
145222
export default class SSHConfig extends Array<Line> {
223+
/** shortcut to access {@link LineType.DIRECTIVE} */
146224
static readonly DIRECTIVE: LineType.DIRECTIVE = LineType.DIRECTIVE
225+
/** shortcut to access {@link LineType.COMMENT} */
147226
static readonly COMMENT: LineType.COMMENT = LineType.COMMENT
227+
/** shortcut to access {@link LineType.EMPTY} */
148228
static readonly EMPTY: LineType.EMPTY = LineType.EMPTY
149229

150230
/**
@@ -331,6 +411,9 @@ export default class SSHConfig extends Array<Line> {
331411
if (index >= 0) return this.splice(index, 1)
332412
}
333413

414+
/**
415+
* Convert this SSH config to its textual presentation via {@link stringify}.
416+
*/
334417
public override toString(): string {
335418
return stringify(this)
336419
}

0 commit comments

Comments
 (0)