本文整理匯總了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;
}
示例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' }])
});
示例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],
}));
}
示例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')
}
示例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+/)
};
});
}
示例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)
}
示例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 });
}
示例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');