Skip to content

Commit 5e0cf0d

Browse files
committed
docs: more jsdocs
1 parent f14f781 commit 5e0cf0d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

app-config-core/src/common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { logger } from '@app-config/logging';
33

44
export type KeyFormatter = (key: string, separator: string) => string;
55

6+
/** Strategy used in 'app-config vars' for variable names */
67
export function camelToScreamingCase(key: string, separator: string = '_'): string {
78
return key
89
.replace(/([^A-Z]+)([A-Z][a-z])/g, `$1${separator}$2`)
@@ -11,6 +12,7 @@ export function camelToScreamingCase(key: string, separator: string = '_'): stri
1112
.toUpperCase();
1213
}
1314

15+
/** Strategy used in 'app-config vars' to extract variable names from hierachy */
1416
export function flattenObjectTree(
1517
obj: JsonObject,
1618
prefix: string = '',
@@ -40,6 +42,7 @@ export function flattenObjectTree(
4042
}, {});
4143
}
4244

45+
/** Strategy for renaming keys, used for 'app-config vars' */
4346
export function renameInFlattenedTree(
4447
flattened: { [key: string]: string },
4548
renames: string[] = [],

app-config-core/src/parsed-value.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class ParsedValue {
107107
return parseValue(raw, new LiteralSource(raw), extensions);
108108
}
109109

110+
/** Deep merge two ParsedValue objects */
110111
static merge(a: ParsedValue, b: ParsedValue) {
111112
const meta = merge(a.meta, b.meta);
112113

@@ -161,6 +162,7 @@ export class ParsedValue {
161162
return new ParsedValue([...a.sources, ...b.sources], newRawValue, newValue).assignMeta(meta);
162163
}
163164

165+
/** Returns the first ConfigSource that is of some instance type */
164166
getSource<CS extends ConfigSource>(clazz: new (...args: any[]) => CS): CS | undefined {
165167
for (const source of this.sources) {
166168
if (source instanceof clazz) {
@@ -169,6 +171,7 @@ export class ParsedValue {
169171
}
170172
}
171173

174+
/** Returns the first ConfigSource that is of some instance type */
172175
assertSource<CS extends ConfigSource>(clazz: new (...args: any[]) => CS): CS {
173176
const source = this.getSource(clazz);
174177

@@ -179,6 +182,7 @@ export class ParsedValue {
179182
throw new AppConfigError(`Failed to find ConfigSource ${clazz.name}`);
180183
}
181184

185+
/** Returns all ConfigSource objects that contributed to this value (including nested) */
182186
allSources(): Set<ConfigSource> {
183187
const sources = new Set(this.sources);
184188

@@ -201,11 +205,13 @@ export class ParsedValue {
201205
return sources;
202206
}
203207

208+
/** Adds metadata to the ParsedValue */
204209
assignMeta(metadata: ParsedValueMetadata) {
205210
Object.assign(this.meta, metadata);
206211
return this;
207212
}
208213

214+
/** Removes metadata by key */
209215
removeMeta(key: string) {
210216
delete this.meta[key];
211217
return this;
@@ -226,38 +232,46 @@ export class ParsedValue {
226232
return this.value[key]?.property(rest);
227233
}
228234

235+
/** Returns JSON object if the value is one */
229236
asObject(): { [key: string]: ParsedValue } | undefined {
230237
if (typeof this.value === 'object' && this.value !== null && !Array.isArray(this.value)) {
231238
return this.value;
232239
}
233240
}
234241

242+
/** Returns JSON array if the value is one */
235243
asArray(): ParsedValue[] | undefined {
236244
if (Array.isArray(this.value)) return this.value;
237245
}
238246

247+
/** Returns JSON primitive value if the value is one */
239248
asPrimitive(): JsonPrimitive | undefined {
240249
if ((typeof this.value !== 'object' || this.value === null) && !Array.isArray(this.value)) {
241250
return this.value;
242251
}
243252
}
244253

254+
/** Returns if the underlying value is an object */
245255
isObject(): boolean {
246256
return this.asObject() !== undefined;
247257
}
248258

259+
/** Returns if the underlying value is an array */
249260
isArray(): boolean {
250261
return this.asArray() !== undefined;
251262
}
252263

264+
/** Returns if the underlying value is a primitive */
253265
isPrimitive(): boolean {
254266
return this.asPrimitive() !== undefined;
255267
}
256268

269+
/** Deep clones underlying value */
257270
clone(): ParsedValue {
258271
return this.cloneWhere(() => true);
259272
}
260273

274+
/** Deep clones underlying value, depending on a predicate function */
261275
cloneWhere(filter: (value: ParsedValue) => boolean): ParsedValue {
262276
if (Array.isArray(this.value)) {
263277
const filtered = this.value.filter(filter);
@@ -293,6 +307,7 @@ export class ParsedValue {
293307
return new ParsedValue(this.sources, this.raw, this.value);
294308
}
295309

310+
/** Calls the function, with every nested ParsedValue */
296311
visitAll(callback: (value: ParsedValue) => void) {
297312
callback(this);
298313

@@ -307,6 +322,7 @@ export class ParsedValue {
307322
}
308323
}
309324

325+
/** Extracts underlying JSON value from the wrapper */
310326
toJSON(): Json {
311327
if (Array.isArray(this.value)) {
312328
return this.value.map((v) => v.toJSON());

0 commit comments

Comments
 (0)