13 lines
480 B
TypeScript
13 lines
480 B
TypeScript
// Type guards for values read from JSON, which arrive as `unknown`.
|
|
export type JsonObject = NodeJS.Dict<unknown>;
|
|
|
|
// Any non-null object, arrays included: reading a missing key yields undefined.
|
|
export function isObject(value: unknown): value is JsonObject {
|
|
return typeof value === "object" && value !== null;
|
|
}
|
|
|
|
// A plain mapping, which an array is not.
|
|
export function isMapping(value: unknown): value is JsonObject {
|
|
return isObject(value) && !Array.isArray(value);
|
|
}
|