本文整理汇总了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
});
});
开发者ID:digitaltoad,项目名称:dotfiles,代码行数:35,代码来源:tomlServerMain.ts
示例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();
});
开发者ID:kodeballer,项目名称:neon,代码行数:25,代码来源:new.ts
示例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;
}
开发者ID:kodeballer,项目名称:neon,代码行数:9,代码来源:crate.ts
示例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 <[email protected]>');
let cargo = TOML.parse(readFile(this.cwd, 'my-app/native/Cargo.toml'));
assert.includeDeepMembers(cargo.package.authors, ['Foo "Bar" Baz <[email protected]>'])
done();
});
开发者ID:kodeballer,项目名称:neon,代码行数:13,代码来源:new.ts
注:本文中的toml.parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论