本文整理汇总了TypeScript中vs/base/common/json.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: readFile
readFile(launchConfig, (err, contents) => {
if (err) {
return resolve([]);
}
const errors: ParseError[] = [];
const json = parse(contents.toString(), errors);
if (errors.length) {
console.log(`Unable to parse ${launchConfig}`);
return resolve([]);
}
if (json['configurations']) {
for (const each of json['configurations']) {
const type = each['type'];
if (type) {
if (launchConfigs.has(type)) {
launchConfigs.set(type, launchConfigs.get(type)! + 1);
} else {
launchConfigs.set(type, 1);
}
}
}
}
return resolve(asSortedItems(launchConfigs));
});
示例2: assertInvalidParse
function assertInvalidParse(input: string, expected: any, options?: ParseOptions): void {
var errors: { error: ParseErrorCode }[] = [];
var actual = parse(input, errors, options);
assert(errors.length > 0);
assert.deepEqual(actual, expected);
}
示例3: assertInvalidParse
function assertInvalidParse(input:string, expected:any) : void {
var errors : ParseError[] = [];
var actual = parse(input, errors);
assert(errors.length > 0);
assert.deepEqual(actual, expected);
}
示例4: assertValidParse
function assertValidParse(input: string, expected: any, options?: ParseOptions): void {
var errors: { error: ParseErrorCode }[] = [];
var actual = parse(input, errors, options);
if (errors.length !== 0) {
assert(false, getParseErrorMessage(errors[0].error));
}
assert.deepEqual(actual, expected);
}
示例5: assertValidParse
function assertValidParse(input:string, expected:any) : void {
var errors : string[] = [];
var actual = parse(input, errors);
if (errors.length !== 0) {
assert(false, errors[0]);
}
assert.deepEqual(actual, expected);
}
示例6: doParseStoredWorkspace
function doParseStoredWorkspace(path: URI, contents: string): IStoredWorkspace {
// Parse workspace file
let storedWorkspace: IStoredWorkspace = json.parse(contents); // use fault tolerant parser
// Filter out folders which do not have a path or uri set
if (Array.isArray(storedWorkspace.folders)) {
storedWorkspace.folders = storedWorkspace.folders.filter(folder => isStoredWorkspaceFolder(folder));
}
// Validate
if (!Array.isArray(storedWorkspace.folders)) {
throw new Error(`${path} looks like an invalid workspace file.`);
}
return storedWorkspace;
}