本文整理匯總了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;
}