當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript toml.parse函數代碼示例

本文整理匯總了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 <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();
        });
開發者ID:kodeballer,項目名稱:neon,代碼行數:13,代碼來源:new.ts


注:本文中的toml.parse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。