當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。