本文整理汇总了TypeScript中csvtojson.Converter.fromFile方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Converter.fromFile方法的具体用法?TypeScript Converter.fromFile怎么用?TypeScript Converter.fromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类csvtojson.Converter
的用法示例。
在下文中一共展示了Converter.fromFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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();
});
})
示例2: Converter
.then(() => {
const funcs:(() => Promise<void>)[] = [];
const converter = new Converter({});
let promise:any = Promise.resolve();
converter.fromFile("./tests/tagging.csv", (err, result) => {
for (const row of result) {
let arr = [];
for (const key in row) {
arr.push(row[key]);
}
promise = promise.then(() => data.tagging.addDummyByNames(arr[0], arr[1], arr[2]));
}
console.log(funcs.length);
});
/*
* Promise.allするのが理想だが、件数次第ではコネクションを待機件数が多すぎ、メモリを使い果たして死ぬ
* 仕方ないので一件一件放り込んでいく
*/
return promise;
})
示例3: TagGroup
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));
});
});