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