本文整理汇总了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())
];
});
示例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;
}
示例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)]
}
示例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 [];
}
});
}
示例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']);
});
示例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;
}