本文整理汇总了TypeScript中strip-json-comments.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript strip-json-comments.default方法的具体用法?TypeScript strip-json-comments.default怎么用?TypeScript strip-json-comments.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类strip-json-comments
的用法示例。
在下文中一共展示了strip-json-comments.default方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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');
}
});
示例2: 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');
}
});
示例3: 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;
}
示例4: 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
});
});
示例5: 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);
示例6: readJSONWithComments
public static readJSONWithComments(file: string) {
var jsons = fs.readFileSync(file, 'utf8');
return JSON.parse(json_comments(jsons));
}
示例7:
// 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
});