• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript json5.parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中json5.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: readKitsFile

export async function readKitsFile(filepath: string): Promise<Kit[]> {
  if (!await fs.exists(filepath)) {
    log.debug(`Not reading non-existent kits file: ${filepath}`);
    return [];
  }
  log.debug('Reading kits file', filepath);
  const content_str = await fs.readFile(filepath);
  let kits_raw: object[] = [];
  try {
    kits_raw = json5.parse(content_str.toLocaleString());
  } catch (e) {
    log.error('Failed to parse cmake-kits.json:', e);
    return [];
  }
  const validator = await loadSchema('schemas/kits-schema.json');
  const is_valid = validator(kits_raw);
  if (!is_valid) {
    const errors = validator.errors!;
    log.error(`Invalid cmake-kits.json (${filepath}):`);
    for (const err of errors) {
      log.error(` >> ${err.dataPath}: ${err.message}`);
    }
    return [];
  }
  const kits = kits_raw as Kit[];
  log.info(`Successfully loaded ${kits.length} kits from ${filepath}`);
  return dropNulls(kits);
}
开发者ID:vector-of-bool,项目名称:vscode-cmake-tools,代码行数:28,代码来源:kit.ts


示例2: handleObjectData

 params.forEach(param => {
     if (typeof param === 'object') {
         handleObjectData(param, level)
     } else if (isObjectAfterStringify(param)) {
         handleObjectData(JSON5.parse(param), level)
     } else {
         consoleLog(param, level);
     }
 })
开发者ID:darekf77,项目名称:ng2-logger,代码行数:9,代码来源:backend-logging.ts


示例3: readFableConfigOptions

/** Reads options from fableconfig.json, requires json5 */
function readFableConfigOptions(opts: any) {
    opts.workingDir = path.resolve(opts.workingDir || process.cwd());
    if (typeof opts.projFile === "string") {
        opts.projFile = [opts.projFile];
    }
    var cfgFile = fableLib.pathJoin(opts.workingDir, constants.FABLE_CONFIG_FILE);

    if (Array.isArray(opts.projFile) && opts.projFile.length === 1) {
        var fullProjFile = fableLib.pathJoin(opts.workingDir, opts.projFile[0]);
        var projDir = fs.statSync(fullProjFile).isDirectory()
                        ? fullProjFile
                        : path.dirname(fullProjFile);
        cfgFile = fableLib.pathJoin(projDir, constants.FABLE_CONFIG_FILE);

        // Delete projFile from opts if it isn't a true F# project
        if (!fableLib.isFSharpProject(fullProjFile)) {
            delete opts.projFile;
        }
    }

    if (fs.existsSync(cfgFile)) {
        // Change workingDir to where fableconfig.json is if necessary
        if (opts.workingDir !== path.dirname(cfgFile)) {
            for (var key in opts) {
                opts[key] = resolvePath(key, opts[key], opts.workingDir);
            }
            opts.workingDir = path.dirname(cfgFile);
        }

        var cfg = json5.parse(fs.readFileSync(cfgFile).toString());
        for (var key in cfg) {
            if (key in opts === false)
                opts[key] = cfg[key];
        }
        // Check if a target is requested
        if (opts.debug) { opts.target = "debug" }
        if (opts.production) { opts.target = "production" }
        if (opts.target) {
            if (!opts.targets || !opts.targets[opts.target]) {
                throw "Target " + opts.target + " is missing";
            }
            cfg = opts.targets[opts.target];
            for (key in cfg) {
                if ((typeof cfg[key] === "object") && !Array.isArray(cfg[key]) &&
                    (typeof opts[key] === "object") && !Array.isArray(opts[key])) {
                    for (var key2 in cfg[key])
                        opts[key][key2] = cfg[key][key2];
                }
                else {
                    opts[key] = cfg[key];
                }
            }
        }
    }
    return opts;
}
开发者ID:fdcastel,项目名称:Fable,代码行数:57,代码来源:options.ts


示例4: isObjectAfterStringify

function isObjectAfterStringify(s: string) {
    //#region @backend
    try {
        const json = JSON5.parse(s);
        return true;
    } catch (error) {
        return false;
    }
    //#endregion
}
开发者ID:darekf77,项目名称:ng2-logger,代码行数:10,代码来源:backend-logging.ts


示例5: default

export default ( value ) => {
  if ( typeof value === "string" ) {
    let param;
    try {
      param = JSON5.parse( value );
    } catch ( e ) {
      errorMessage( 'Format of "' + value + '" is incorrect. Please correct the format JSON5.' );
      param = {};
    }
    return param;
  } else {
    return value;
  }
};
开发者ID:luca3104,项目名称:solufa,代码行数:14,代码来源:_string2Json.ts


示例6: readConfigFile

export function readConfigFile(pathToFile: string, dontThrowOnError?: boolean){
  var resolvedPath = path.resolve(pathToFile);
  var tsdFile;
  try {
    tsdFile = fs.readFileSync(resolvedPath,'utf8');
  } catch(e) {
    if(!dontThrowOnError) throw e;
    return null;
  }
  var content = json.parse(tsdFile) || {};

  var tsdConfigFile = makeTsdConfigFileBase(pathToFile);
  tsdConfigFile.content = content;
  if(content.path){
    tsdConfigFile.definitionPath = path.resolve(tsdConfigFile.dir,content.path);
  }

  return tsdConfigFile;
}
开发者ID:Cellule,项目名称:tsd-link,代码行数:19,代码来源:utils.ts


示例7:

		let workspaceFolders = vscode.workspace.workspaceFolders.filter((folder) =>
		{
			let asconfigPath = path.resolve(folder.uri.fsPath, "asconfig.json");
			if(!fs.existsSync(asconfigPath) || fs.statSync(asconfigPath).isDirectory())
			{
				return false;
			}
			try
			{
				let contents = fs.readFileSync(asconfigPath, "utf8");
				let result = json5.parse(contents);
				if ("type" in result && result.type !== "app")
				{
					return false;
				}
			}
			catch(error)
			{
				return false;
			}
			return true;
		});
开发者ID:BowlerHatLLC,项目名称:vscode-nextgenas,代码行数:22,代码来源:quickCompileAndLaunch.ts


示例8: initTemplates

    private initTemplates(location) {

        let parsedJSON;
        try {
            parsedJSON = json5.parse(fs.readFileSync(location).toString()); // invalid JSON or permission issue can happen here
        } catch (error) {
            console.error(error);
            return;
        }

        if (parsedJSON) {

            const variables: IPlDocVariablesCustom = {
                author: this.plDocAuthor,
                date: new Date()
            };

            Object.keys(parsedJSON).forEach(key => {
                // Doc
                if (key === 'pldoc') {
                    if (this.plDocEnable && parsedJSON.pldoc.body) {
                        this.plDocTemplate = parsedJSON.pldoc;
                        this.addTemplateInfo(this.plDocTemplate);
                    }
                    else
                        this.plDocTemplate = null;
                } else { // Other custom snippet
                    const snippet = parsedJSON[key];
                    snippet.body.forEach( (text, index) =>
                        snippet.body[index] = this.replaceText(variables, text)
                    );
                    if (!this.plDocSnippets)
                        this.plDocSnippets = [];
                    this.plDocSnippets.push(snippet);
                }
            });
        }
    }
开发者ID:zabel-xyz,项目名称:plsql-language,代码行数:38,代码来源:pldoc.controller.ts


示例9: _parseCondition

  private static _parseCondition(source: string): ConditionBlock[] {
    let ret: ConditionBlock[] = [];
    const found = source.indexOf("@Condition(", 0);
    if (found < 0) {
      ret.push(ConditionBlock._createPlain(source));
      return ret; // When there was no more found
    }

    let beginConditionPoint = found + 10;
    const endConditionPoint: number = ConditionBlock._getEndBracketIndex(source, beginConditionPoint, "(", ")");
    if (endConditionPoint < 1) {
      // error no bracket matching
      console.error("Invalid bracket matching!");
      return null;
    }
    let beginContentPoint = source.indexOf("{", endConditionPoint);
    if (beginContentPoint < 0) {
      // error no bracket matching
      console.error("Invalid bracket matching!");
      return null;
    }
    const endContentPoint = ConditionBlock._getEndBracketIndex(source, beginContentPoint, "{", "}");
    if (endContentPoint < 0) {
      // error no bracket matching
      console.error("Invalid bracket matching!");
      return null;
    }
    let before: string = source.substring(0, found);
    let condition: string = source.substring(beginConditionPoint + 1, endConditionPoint);
    let jsonCondition: JSON = JSON5.parse(condition);
    let content: string = source.substring(beginContentPoint + 1, endContentPoint);
    let after: string = source.substring(endContentPoint + 1, source.length);
    ret.push(ConditionBlock._createPlain(before));
    ret.push(new ConditionBlock(jsonCondition, ConditionBlock._parseCondition(content), false, null));
    ret = ret.concat(ConditionBlock._parseCondition(after));
    return ret;
  }
开发者ID:kyasbal-1994,项目名称:jThree,代码行数:37,代码来源:ConditionBlock.ts


示例10: getAnimateFile

function getAnimateFile(folder: vscode.WorkspaceFolder)
{
	let asconfigPath = path.resolve(folder.uri.fsPath, "asconfig.json");
	if(!fs.existsSync(asconfigPath) || fs.statSync(asconfigPath).isDirectory())
	{
		return null;
	}
	try
	{
		let contents = fs.readFileSync(asconfigPath, "utf8");
		let result = json5.parse(contents);
		if ("type" in result && result.type !== "app")
		{
			return null;
		}
		if(!("animateOptions" in result))
		{
			return null;
		}
		let animateOptions = result.animateOptions;
		if(!("file" in animateOptions))
		{
			return null;
		}
		let flaPath = animateOptions.file;
		if(path.isAbsolute(flaPath))
		{
			return flaPath;
		}
		return path.resolve(folder.uri.fsPath, flaPath);
	}
	catch(error)
	{
		return null;
	}
}
开发者ID:BowlerHatLLC,项目名称:vscode-nextgenas,代码行数:36,代码来源:quickCompileAndLaunch.ts



注:本文中的json5.parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript json8.equal函数代码示例发布时间:2022-05-25
下一篇:
TypeScript json2typescript.JsonConvert类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap