本文整理匯總了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);