本文整理汇总了TypeScript中toml.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
documents.onDidChangeContent((change) => {
let diagnostics: Diagnostic[] = [];
let input = change.document.getText();
try{
let output = toml.parse(input);
}catch(e){
// workaround for typescript limitation
const ex : TomlSyntaxError = e;
// content has invalid toml, send diagnostic to client
// toml parser give position in one based, but languageserver used zero based
// so we must convert it before send the position
const startPosition = {line: ex.line - 1, character: ex.column};
const endPosition = {line: ex.line - 1, character: ex.column + 1};
diagnostics.push({
severity: DiagnosticSeverity.Error,
range: {
start: startPosition,
end: endPosition
},
message: ex.message,
source: 'Toml Parser'
});
}
// Send the computed diagnostics to VS Code.
connection.sendDiagnostics({
uri: change.document.uri,
diagnostics
});
});
示例2: readFile
.run(err => {
if (err) throw err;
let pkg = JSON.parse(readFile(this.cwd, 'my-app/package.json'));
assert.propertyVal(pkg, 'name', 'my-app');
assert.propertyVal(pkg, 'version', '0.1.0');
assert.propertyVal(pkg, 'description', 'My new app!');
assert.propertyVal(pkg, 'license', 'MIT');
assert.deepProperty(pkg, 'dependencies.neon-cli');
let cargo = TOML.parse(readFile(this.cwd, 'my-app/native/Cargo.toml'));
assert.deepPropertyVal(cargo, 'package.name', 'my-app');
assert.deepPropertyVal(cargo, 'package.version', '0.1.0');
assert.deepPropertyVal(cargo, 'package.license', 'MIT');
assert.deepPropertyVal(cargo, 'lib.name', 'my_app');
assert.deepProperty(cargo, 'dependencies.neon');
let indexjs = readFile(this.cwd, 'my-app/lib/index.js');
assert.include(indexjs, `require('../native')`);
let librs = readFile(this.cwd, 'my-app/native/src/lib.rs');
assert.include(librs, `extern crate neon;`);
done();
});
示例3: loadLibName
function loadLibName(file: string): string {
let metadata = TOML.parse(readFileSync(file, 'utf8'));
if (!metadata || typeof metadata !== 'object' || !metadata.lib.name) {
throw new Error("Cargo.toml does not contain a [lib] section with a 'name' field");
}
return metadata.lib.name;
}
示例4: done
.run(err => {
if (err) throw err;
let pkg = JSON.parse(readFile(this.cwd, 'my-app/package.json'));
assert.propertyVal(pkg, 'description', 'Foo "bar"');
assert.deepPropertyVal(pkg, 'repository.url', 'http://www.example.com/foo.git?bar=%22baz%22');
assert.propertyVal(pkg, 'author', 'Foo "Bar" Baz <hughjass@example.com>');
let cargo = TOML.parse(readFile(this.cwd, 'my-app/native/Cargo.toml'));
assert.includeDeepMembers(cargo.package.authors, ['Foo "Bar" Baz <hughjass@example.com>'])
done();
});