1
>
/*---------------------------------------------------------------------------------------------
preferencesValidation.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import * as nls from '../../../../nls.js';
7
>
import { JSONSchemaType } from '../../../../base/common/jsonSchema.js';
8
>
import { Color } from '../../../../base/common/color.js';
9
>
import { isObject, isUndefinedOrNull, isString, isStringArray } from '../../../../base/common/types.js';
10
>
import { IConfigurationPropertySchema } from '../../../../platform/configuration/common/configurationRegistry.js';
11
>
12
>
type Validator<T> = { enabled: boolean; isValid: (value: T) => boolean; message: string };
13
>
14
function canBeType(propTypes: (string | undefined)[], ...types: JSONSchemaType[]): boolean {
15
return types.some(t => propTypes.includes(t));
16
}
18
function isNullOrEmpty(value: unknown): boolean {
19
return value === '' || isUndefinedOrNull(value);
20
}
22
>
export function createValidator(prop: IConfigurationPropertySchema): (value: any) => (string | null) {
23
const type: (string | undefined)[] = Array.isArray(prop.type) ? prop.type : [prop.type];
24
const isNullable = canBeType(type, 'null');