本文整理汇总了TypeScript中csvtojson.Converter类的典型用法代码示例。如果您正苦于以下问题:TypeScript Converter类的具体用法?TypeScript Converter怎么用?TypeScript Converter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Converter类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Converter
.then(() => {
const tagContainer = data.tags;
const converter = new Converter({});
return new Promise<TagGroup[]>((resolve, reject) => {
converter.fromFile("./tests/tagGroup.csv", (err, result) => {
const promises: Promise<TagGroup>[] = [];
if (err) console.log(err);
for (const row of result) {
if (!row['name']) continue;
let tagGroup: TagGroup = new TagGroup(row['name']);
let tagPromises = [];
for (const key in row) {
if (key == "name" || !row[key]) continue;
tagPromises.push(tagContainer.getByName(row[key]));
}
promises.push(
Promise.all<Tag>(tagPromises).then((tags:Tag[]) => {
tagGroup.member = tags;
console.log(tagGroup);
return Promise.resolve(tagGroup);
})
);
}
Promise.all<TagGroup>(promises)
.then(tagGroups2 => resolve(tagGroups2));
});
});
})
示例2: Promise
new Promise((resolve, reject) => {
const converter = new Converter({});
converter.fromFile("./tests/tag.csv", (err, result) => {
if (err) {
console.log(err);
}
for (const row of result) {
let arr = [];
for (const key in row) {
if (row[key]) {
arr.push(row[key]);
}
}
if (arr.length > 0) tags.push(new Tag(arr));
}
resolve();
});
})
示例3: require
//Converter Class
var Converter = require("csvtojson").Converter;
var converter = new Converter({constructResult:false});
//record_parsed will be emitted each csv row being processed
converter.on("record_parsed", function (jsonObj:any) {
console.log(jsonObj); //here is your result json object
});
require("request").get("http://csvwebserver").pipe(converter);