Skip to content

Commit f9ad0e2

Browse files
committed
refactor: move isJsonObject to json namespace
1 parent 055a157 commit f9ad0e2

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

packages/angular/cli/models/json-schema.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { JsonObject, JsonValue, parseJson } from '@angular-devkit/core';
8+
import { JsonObject, isJsonObject, parseJson } from '@angular-devkit/core';
99
import * as jsonSchemaTraverse from 'json-schema-traverse';
1010
import { Option, OptionSmartDefault } from './command';
1111

@@ -42,7 +42,7 @@ function getOptions(schemaText: string, onlyRootProperties = true): Promise<Opti
4242
}
4343
}
4444
let $default: OptionSmartDefault | undefined = undefined;
45-
if (schema.$default !== null && JsonValue.isJsonObject(schema.$default)) {
45+
if (schema.$default !== null && isJsonObject(schema.$default)) {
4646
$default = <OptionSmartDefault> schema.$default;
4747
}
4848
let required = false;
@@ -98,7 +98,7 @@ function isPropertyNested(jsonPath: string): boolean {
9898

9999
export function parseSchema(schema: string): JsonObject | null {
100100
const parsedSchema = parseJson(schema);
101-
if (parsedSchema === null || !JsonValue.isJsonObject(parsedSchema)) {
101+
if (parsedSchema === null || !isJsonObject(parsedSchema)) {
102102
return null;
103103
}
104104

packages/angular_devkit/core/src/json/interface.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ export interface JsonAstComment extends JsonAstNodeBase {
110110

111111
export type JsonValue = JsonAstNode['value'];
112112

113-
export const JsonValue = {
114-
isJsonObject(value: JsonValue): value is JsonObject {
115-
return value != null && typeof value === 'object' && !Array.isArray(value);
116-
},
117-
};
113+
export function isJsonObject(value: JsonValue): value is JsonObject {
114+
return value != null && typeof value === 'object' && !Array.isArray(value);
115+
}
116+
117+
export function isJsonArray(value: JsonValue): value is JsonArray {
118+
return Array.isArray(value);
119+
}

packages/angular_devkit/core/src/json/schema/transforms.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { JsonObject, JsonValue } from '../interface';
8+
import { JsonObject, JsonValue, isJsonObject } from '../interface';
99
import { JsonPointer } from './interface';
1010

1111
const allTypes = ['string', 'integer', 'number', 'object', 'array', 'boolean', 'null'];
@@ -24,7 +24,7 @@ function findTypes(schema: JsonObject): Set<string> {
2424
potentials = new Set(allTypes);
2525
}
2626

27-
if (JsonValue.isJsonObject(schema.not)) {
27+
if (isJsonObject(schema.not)) {
2828
const notTypes = findTypes(schema.not);
2929
potentials = new Set([...potentials].filter(p => !notTypes.has(p)));
3030
}
@@ -97,13 +97,13 @@ export function addUndefinedDefaults(
9797
let newValue;
9898
if (value == undefined) {
9999
newValue = {} as JsonObject;
100-
} else if (JsonValue.isJsonObject(value)) {
100+
} else if (isJsonObject(value)) {
101101
newValue = value;
102102
} else {
103103
return value;
104104
}
105105

106-
if (!JsonValue.isJsonObject(schema.properties)) {
106+
if (!isJsonObject(schema.properties)) {
107107
return newValue;
108108
}
109109

0 commit comments

Comments
 (0)