当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript sync.default函数代码示例

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


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

示例1: parseRegions

function parseRegions(fileContent: string): RegionMap {
  const questionRows: Row[] = parse(fileContent);
  const regions = questionRows.slice(1).map(row => ({
    id: row[0],
    name: row[1]
  }));
  return R.indexBy(r => r.id, regions) as RegionMap;
}
开发者ID:shybyte,项目名称:wahlomat,代码行数:8,代码来源:convert.ts

示例2: it

 it('parse', () => {
     const lines = parse("Nom,Entreprise,Commentaire,Interet\n" +
         "Karim Sanglan ,Orange,Tu dois le faire,5\n", {columns:true})
     expect(lines).eql([{ Nom: 'Karim Sanglan ',
         Entreprise: 'Orange',
         Commentaire: 'Tu dois le faire',
         Interet: '5' }])
 });
开发者ID:martinsson,项目名称:martinsson.github.io,代码行数:8,代码来源:to-html.spec.ts

示例3: parseQuestions

function parseQuestions(fileContent: string): Question[] {
  const questionRows: Row[] = parse(fileContent);
  return questionRows.slice(1).map(row => ({
    id: row[0],
    initiative: (row[3] || 'anonym').replace('annonym', 'anonym'),
    initiativeAnswer: ANSWER.yes,
    initiativeReason: row[2],
    text: row[1],
  }));
}
开发者ID:shybyte,项目名称:wahlomat,代码行数:10,代码来源:convert.ts

示例4: toHtml

export async function toHtml(csvContent: string) {
    const lins = parse(csvContent, {columns:true})
    return lins.map((line: any) => {
        const phrase = line.Commentaire.replace("\n", '<br>' )
        const name = line.Nom.trim()
        const company = line.Entreprise
        return "<blockquote>\n" +
            `${phrase}\n<span>${name} - ${company}</span>\n` +
            "</blockquote>"
    }).join('\n')

}
开发者ID:martinsson,项目名称:martinsson.github.io,代码行数:12,代码来源:to-html.ts

示例5: parseCandidateAnswers

function parseCandidateAnswers(fileContent: string): Candidate[] {
  const rows: string[][] = parse(fileContent);
  const rowsByCandidate = R.groupBy(row => row[AnswerFileCols.NAME], rows.slice(1));
  const candidateRowPairs: [string, Row[]][] = R.toPairs(rowsByCandidate) as any;
  return candidateRowPairs.map((candidateAndAnswerRows: [string, Row[]]) => {
    const candidateName = candidateAndAnswerRows[0];
    const answerRows = candidateAndAnswerRows[1];
    const oneRow = answerRows[0];
    return {
      answers: getAnswerMapFromRows(answerRows),
      id: candidateName,
      name: candidateName,
      party: oneRow[AnswerFileCols.PARTY],
      reasons: getReasonsMapFromRows(answerRows),
      regions: oneRow[AnswerFileCols.REGION].split(/,\s+/)
    };
  });
}
开发者ID:shybyte,项目名称:wahlomat,代码行数:18,代码来源:convert.ts

示例6: jsonParse

export const csvParse = (csvContent, options) => {
  const { hasCategory } = options

  const mergeRows = (acc, { question, answer, answer2, category, action }) => {
    const [prevRow] = acc.slice(-1)
    const isSameAnswer = prevRow && (prevRow.answer === answer && (!answer2 || answer2 === prevRow.answer2))
    if (isSameAnswer) {
      return [...acc.slice(0, acc.length - 1), { ...prevRow, questions: [...prevRow.questions, question] }]
    }
    const categoryWrapper = hasCategory ? { category } : {}
    return [...acc, { answer, answer2, action, ...categoryWrapper, questions: [question] }]
  }
  const categoryWrapper = hasCategory ? ['category'] : []
  const rows = parseCsvToJson(csvContent, {
    columns: ['question', 'action', 'answer', 'answer2', ...categoryWrapper]
  }).reduce(mergeRows, [])

  // We trim the header if detected in the first row
  if (get(rows, '0.action') === 'action') {
    rows.splice(0, 1)
  }

  return jsonParse(rows, options)
}
开发者ID:alexsandrocruz,项目名称:botpress,代码行数:24,代码来源:parsers.ts

示例7: require

};
*/
declare var process: any;
declare var require: any;
declare var __dirname: any;
declare var exports: any;
declare var self: any;
if (typeof process === 'object')
{
	var parse = require("csv-parse/lib/sync");
	var iconv = require("iconv-lite");
	var fs = require('fs');
	var assert = require('assert');

	//读取任务模板
	var task_lib_records = parse(iconv.decode(fs.readFileSync(__dirname + '/WeeklyTaskLib.csv'), 'gbk'));
	TASK_LIB = [];
	TASK_LIB.push(null);
	for (let i = 1; i < task_lib_records.length; ++i)
	{
		var line = task_lib_records[i];
		var type = line[0];
		var count = parseInt(line[1]);
		var failCount = parseInt(line[2]);
		var desc = line[3];
		assert(TASK_LIST1.some(x => x.type === type), `任务类型type一定要有效的,type=${type}`);
		assert(count >= 0, 'count must be number >= 0');
		assert(failCount >= 0 && failCount <= 5, 'failCount must be a number >= 0 && <= 5');
		assert(typeof desc === 'string', 'desc must be a string');
		TASK_LIB.push({ type: type, maxCount: count, failCount: failCount, desc: desc });
	}
开发者ID:hUangDDD,项目名称:bally,代码行数:31,代码来源:WeeklyTaskDefine.ts

示例8: require

	14,
	13,
]*/

declare var process: any;
declare var require: any;
declare var __dirname: any;
declare var exports: any;
declare var self:any;
if (typeof process === 'object')
{
	var parse = require("csv-parse/lib/sync");
	var iconv = require("iconv-lite");
	var fs = require('fs');
	var assert = require('assert');
	var records = parse(iconv.decode(fs.readFileSync(__dirname + '/PetRules.csv'), 'gbk'));
	assert(records.length === MAX_PET_COUNT + 1);
	PET_NAMES = [];
	PET_REAL_COLORS = [];
	PET_BASE_SCORE = [];
	PET_UP_SCORE = [];
	PET_SKILL = [];
	for (let i = 0; i < MAX_PET_COUNT; ++i)
	{
		let line = records[i + 1];
		PET_NAMES.push(line[0]);
		PET_REAL_COLORS.push(line[1]);
		let skill = parseInt(line[2]);
		let baseScore = parseInt(line[3]);
		let upScore = parseInt(line[4]);
		assert(typeof skill === 'number');
开发者ID:hUangDDD,项目名称:bally,代码行数:31,代码来源:PetRules.ts


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