当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript jsonc-parser.parse函数代码示例

本文整理汇总了TypeScript中jsonc-parser.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: parse

 }).catch((err) => {
     // Provider will always create an launch.json file. Providing default C# configurations.
     // jsonc-parser's parse to convert to JSON object without comments. 
     return [
         parse(createLaunchConfiguration(
             "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll", 
             '${workspaceFolder}')), 
         parse(createWebLaunchConfiguration(
             "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll", 
             '${workspaceFolder}')),
         parse(createAttachConfiguration())
     ];
 });
开发者ID:gregg-miskelly,项目名称:omnisharp-vscode,代码行数:13,代码来源:configurationProvider.ts

示例2: validateConfig

export function validateConfig(config: Config | string) {
  if (typeof config === 'string') {
    config = parse(config) as Config;
  }

  // fs.writeFileSync('__parsed.json', JSON.stringify(config, undefined, 2), 'utf8');

  const originalConfig = JSON.parse(JSON.stringify(config)) as Config;

  // new instance required for empty error list
  const ajv = new Ajv({ useDefaults: true, allErrors: true });
  const validate = ajv.compile(schema);

  // validate and apply default values from schema
  const valid = validate(config);
  if (!valid) {
    throw new Error(JSON.stringify(validate.errors, undefined, 2));
  }

  const internalConfig = getInternalConfig(config as any, originalConfig);

  // fs.writeFileSync('__validated.json', JSON.stringify(internalConfig, undefined, 2), 'utf8');

  return internalConfig;
}
开发者ID:igor-bezkrovny,项目名称:texturer,代码行数:25,代码来源:config.ts

示例3: parseConfiguration

export function parseConfiguration(content: string): [ParseError[], any] {
  if (content.length == 0) return [[], {}]
  let errors: ParseError[] = []
  let data = parse(content, errors, { allowTrailingComma: true })
  function addProperty(current: object, key: string, remains: string[], value: any): void {
    if (remains.length == 0) {
      current[key] = convert(value)
    } else {
      if (!current[key]) current[key] = {}
      let o = current[key]
      let first = remains.shift()
      addProperty(o, first, remains, value)
    }
  }

  function convert(obj: any, split = false): any {
    if (!objectLiteral(obj)) return obj
    if (emptyObject(obj)) return {}
    let dest = {}
    for (let key of Object.keys(obj)) {
      if (split && key.indexOf('.') !== -1) {
        let parts = key.split('.')
        let first = parts.shift()
        addProperty(dest, first, parts, obj[key])
      } else {
        dest[key] = convert(obj[key])
      }
    }
    return dest
  }
  return [errors, convert(data, true)]
}
开发者ID:illarionvk,项目名称:dotfiles,代码行数:32,代码来源:util.ts

示例4: registerExtensionsCompletions

function registerExtensionsCompletions(): vscode.Disposable {
	return vscode.languages.registerCompletionItemProvider({ pattern: '**/extensions.json' }, {
		provideCompletionItems(document, position, token) {
			const location = getLocation(document.getText(), document.offsetAt(position));
			const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
			if (location.path[0] === 'recommendations') {
				const config = parse(document.getText());
				const alreadyEnteredExtensions = config && config.recommendations || [];
				if (Array.isArray(alreadyEnteredExtensions)) {
					return vscode.extensions.all
						.filter(e => !(
							e.id.startsWith('vscode.')
							|| e.id === 'Microsoft.vscode-markdown'
							|| alreadyEnteredExtensions.indexOf(e.id) > -1
						))
						.map(e => {
							const item = new vscode.CompletionItem(e.id);
							const insertText = `"${e.id}"`;
							item.kind = vscode.CompletionItemKind.Value;
							item.insertText = insertText;
							item.range = range;
							item.filterText = insertText;
							return item;
						});
				}
			}
			return [];
		}
	});
}
开发者ID:FabianLauer,项目名称:vscode,代码行数:30,代码来源:extension.ts

示例5: test

    test("Create launch.json for nested web project opened in workspace", () => {
        let rootPath = path.resolve('testRoot');
        let info = createDotNetWorkspaceInformation(path.join(rootPath, 'nested'), 'testApp.dll', 'netcoreapp1.0');
        let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath));
        let launchJson = parse(generator.createLaunchJson(/*isWebProject*/ true), undefined, { disallowComments: true });
        let programPath = launchJson[0].program;

        // ${workspaceFolder}/nested/bin/Debug/netcoreapp1.0/testApp.dll
        let segments = programPath.split(path.posix.sep);
        segments.should.deep.equal(['${workspaceFolder}', 'nested', 'bin', 'Debug', 'netcoreapp1.0', 'testApp.dll']);
    });
开发者ID:eamodio,项目名称:omnisharp-vscode,代码行数:11,代码来源:assets.test.ts

示例6: _getBestKey

  private static _getBestKey(configFile: string): string {
    const data = parse(fs.readFileSync(configFile, 'utf8'));
    const curDate = new Date();
    const curYear = curDate.getFullYear();
    const curMonth = curDate.getMonth() + 1;

    let best: any = null;
    data['tinypng-api-keys'].forEach(function(keyData: any) {
      // check if month passed
      if (curYear !== keyData.year || curMonth !== keyData.month) {
        keyData.used = 0;
        keyData.month = curMonth;
        keyData.year = curYear;
      }
      // check for best (less used) key
      if (best === null || keyData.used < best.used) {
        best = keyData;
      }
    });

    best.used++;
    fs.writeFileSync(configFile, JSON.stringify(data, null, '\t'));
    return best.key;
  }
开发者ID:igor-bezkrovny,项目名称:texturer,代码行数:24,代码来源:tinypng.ts


注:本文中的jsonc-parser.parse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。