-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.js
56 lines (36 loc) · 981 Bytes
/
convert.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const node_xj = require("xls-to-json");
const fs = require('fs');
const argv = require('minimist')(process.argv.slice(2));
const opts = {};
opts.input = argv.input;
opts.output = "output.json";
argv.sheet ? opts.sheet = argv.sheet : null;
console.log(opts);
node_xj(opts, function(err, result) {
if (err) {
console.error(err);
return false
}
debugger;
let card = '';
let cards = '';
result.map(item => {
card += `BEGIN:VCARD\n`;
card += `VERSION:2.1\n`;
card += `N:;${item.name};;;\n`;
card += `FN:${item.name}\n`;
card += `TEL;CELL;PREF:${item.home}\n`;
if (item.cell !== '') {card += `TEL;HOME:${item.cell}\n`;}
if (item.work !== '') {card += `TEL;HOME:${item.work}\n`;}
card += `END:VCARD\n`;
cards += card;
card = "";
})
;
fs.writeFile(__dirname + "/" + argv.output, cards, function(err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
});