1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/monaco-editor/monaco-validators.ts
Sebastian Malton 162741a7cc
Fix multi-document support in monaco editor (#4756)
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-01-27 07:13:41 -05:00

31 lines
584 B
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import yaml from "js-yaml";
export interface MonacoValidator {
(value: string): void;
}
export function yamlValidator(value: string) {
try {
yaml.loadAll(value);
} catch (error) {
throw String(error);
}
}
export function jsonValidator(value: string) {
try {
JSON.parse(value);
} catch (error) {
throw String(error);
}
}
export const monacoValidators = {
yaml: yamlValidator,
json: jsonValidator,
};