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


TypeScript strip-json-comments類代碼示例

本文整理匯總了TypeScript中strip-json-comments的典型用法代碼示例。如果您正苦於以下問題:TypeScript strip-json-comments類的具體用法?TypeScript strip-json-comments怎麽用?TypeScript strip-json-comments使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了strip-json-comments類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

// Type definitions for strip-json-comments
// Project: https://github.com/sindresorhus/strip-json-comments
// Definitions by: Dylan R. E. Moonfire <https://github.com/dmoonfire/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import * as stripJsonComments from "strip-json-comments";

const json = '{/*rainbows*/"unicorn":"cake"}';

JSON.parse(stripJsonComments(json));
//=> {unicorn: 'cake'}

stripJsonComments(json, {});
stripJsonComments(json, {
    whitespace: true
});
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:16,代碼來源:strip-json-comments-tests.ts

示例2: function

	it('configure launch json', async function () {
		if (skip) {
			this.skip();
			return;
		}

		const app = this.app as SpectronApplication;

		await app.workbench.debug.openDebugViewlet();
		await app.workbench.quickopen.openFile('app.js');
		await app.workbench.debug.configure();

		const launchJsonPath = path.join(app.workspacePath, '.vscode', 'launch.json');
		const content = fs.readFileSync(launchJsonPath, 'utf8');
		const config = JSON.parse(stripJsonComments(content));
		config.configurations[0].protocol = 'inspector';
		fs.writeFileSync(launchJsonPath, JSON.stringify(config, undefined, 4), 'utf8');

		await app.workbench.editor.waitForEditorContents('launch.json', contents => /"protocol": "inspector"/.test(contents));
		await app.screenCapturer.capture('launch.json file');

		assert.equal(config.configurations[0].request, 'launch');
		assert.equal(config.configurations[0].type, 'node');
		if (process.platform === 'win32') {
			assert.equal(config.configurations[0].program, '${workspaceFolder}\\bin\\www');
		} else {
			assert.equal(config.configurations[0].program, '${workspaceFolder}/bin/www');
		}
	});
開發者ID:AlexxNica,項目名稱:sqlopsstudio,代碼行數:29,代碼來源:debug.test.ts

示例3: function

		it('configure launch json', async function () {
			const app = this.app as Application;

			await app.workbench.debug.openDebugViewlet();
			await app.workbench.quickopen.openFile('app.js');
			await app.workbench.debug.configure();

			const launchJsonPath = path.join(app.workspacePathOrFolder, '.vscode', 'launch.json');
			const content = fs.readFileSync(launchJsonPath, 'utf8');
			const config = JSON.parse(stripJsonComments(content));
			config.configurations[0].protocol = 'inspector';
			fs.writeFileSync(launchJsonPath, JSON.stringify(config, undefined, 4), 'utf8');

			// force load from disk since file events are sometimes missing
			await app.workbench.quickopen.runCommand('File: Revert File');
			await app.workbench.editor.waitForEditorContents('launch.json', contents => /"protocol": "inspector"/.test(contents));

			assert.equal(config.configurations[0].request, 'launch');
			assert.equal(config.configurations[0].type, 'node');
			if (process.platform === 'win32') {
				assert.equal(config.configurations[0].program, '${workspaceFolder}\\bin\\www');
			} else {
				assert.equal(config.configurations[0].program, '${workspaceFolder}/bin/www');
			}
		});
開發者ID:PKRoma,項目名稱:vscode,代碼行數:25,代碼來源:debug.test.ts

示例4: loadTsconfig

export function loadTsconfig(
  configFilePath: string,
  existsSync: (path: string) => boolean = fs.existsSync,
  readFileSync: (filename: string) => string = (filename: string) =>
    fs.readFileSync(filename, "utf8")
): Tsconfig | undefined {
  if (!existsSync(configFilePath)) {
    return undefined;
  }

  const configString = readFileSync(configFilePath);
  const cleanedJson = StripBom(StripJsonComments(configString));
  const config: Tsconfig = JSON.parse(cleanedJson);
  let extendedConfig = config.extends;

  if (extendedConfig) {
    if (
      typeof extendedConfig === "string" &&
      extendedConfig.indexOf(".json") === -1
    ) {
      extendedConfig += ".json";
    }

    const currentDir = path.dirname(configFilePath);
    const base =
      loadTsconfig(
        path.join(currentDir, extendedConfig),
        existsSync,
        readFileSync
      ) || {};

    // baseUrl should be interpreted as relative to the base tsconfig,
    // but we need to update it so it is relative to the original tsconfig being loaded
    if (base && base.compilerOptions && base.compilerOptions.baseUrl) {
      const extendsDir = path.dirname(extendedConfig);
      base.compilerOptions.baseUrl = path.join(
        extendsDir,
        base.compilerOptions.baseUrl
      );
    }

    return deepmerge(base, config);
  }
  return config;
}
開發者ID:christoffer,項目名稱:tsconfig-paths,代碼行數:45,代碼來源:tsconfig-loader.ts

示例5: catch

  let disposable = commands.registerCommand('extension.prettifyJSON', () => {

    const editor = window.activeTextEditor;

    if (!editor) {
      return;
    }

    const raw = editor.document.getText();
    let json = null;

    try {
      json = jsonlint.parse(stripComments(raw));
    } catch (jsonLintError) {
      const message: string = jsonLintError.message;
      const lineNumber = parseInt(message.substring(message.indexOf('line ') + 5, message.indexOf(':')), 10);


      return;
    }

    let pretty = JSON.stringify(json, null, JSON_SPACE);

    editor.edit(builder=> {
      const start = new Position(0, 0);
      const lines = raw.split(LINE_SEPERATOR);
      const end = new Position(lines.length, lines[lines.length - 1].length);
      const allRange = new Range(start, end);
      builder.replace(allRange, pretty);
    }).then(success=> {

      // TODO: unselect the text

    });

  });
開發者ID:gongfuPanada,項目名稱:vscode-prettify-json,代碼行數:36,代碼來源:extension.ts

示例6: getRepos

  GITHUB_TOKEN = fs.readFileSync('token', 'utf8').trim();
} catch (e) {
  console.error(`
You need to create a github token and place it in a file named 'token'.
The token only needs the 'public repos' permission.

Generate a token here:   https://github.com/settings/tokens
`);
  process.exit(1);
}

interface Config {
  passes?: CleanupConfig;
}
const config: Config =
    JSON.parse(stripJsonComments(fs.readFileSync('config.json', 'utf8')));


const github = connectToGithub();

const progressMessageWidth = 40;
const progressBarWidth = 45;

/**
 * Returns a Promise of a list of Polymer github repos to automatically
 * cleanup / transform.
 */
async function getRepos(): Promise<GitHub.Repo[]> {
  const per_page = 100;
  const getFromOrg = promisify(github.repos.getFromOrg);
  const getRepo = promisify(github.repos.get);
開發者ID:TimvdLippe,項目名稱:tedium,代碼行數:31,代碼來源:tedium.ts

示例7: readJSONWithComments

 public static readJSONWithComments(file: string) {
   var jsons = fs.readFileSync(file, 'utf8');
   return JSON.parse(json_comments(jsons));
 }
開發者ID:do5,項目名稱:mcgen,代碼行數:4,代碼來源:utils.ts


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