本文整理汇总了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;未经允许,请勿转载。 |
请发表评论