Add account object interface.
Add new vcard parser.
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
export function parse(input) {
|
||||
const Re1 = /^(version|fn|title|org):(.+)$/i;
|
||||
const Re2 = /^([^:;]+);([^:]+):(.+)$/;
|
||||
const ReKey = /item\d{1,2}\./;
|
||||
let fields = {};
|
||||
|
||||
input.split(/\r\n|\r|\n/).forEach(function (line) {
|
||||
let results, key;
|
||||
|
||||
if (Re1.test(line)) {
|
||||
results = line.match(Re1);
|
||||
key = results[1].toLowerCase();
|
||||
fields[key] = results[2];
|
||||
} else if (Re2.test(line)) {
|
||||
results = line.match(Re2);
|
||||
key = results[1].replace(ReKey, '').toLowerCase();
|
||||
|
||||
let meta = {};
|
||||
results[2].split(';')
|
||||
.map(function (p, i) {
|
||||
const match = p.match(/([a-z]+)=(.*)/i);
|
||||
if (match) {
|
||||
return [match[1], match[2]];
|
||||
} else {
|
||||
return ["TYPE" + (i === 0 ? "" : i), p];
|
||||
}
|
||||
})
|
||||
.forEach(function (p) {
|
||||
meta[p[0]] = p[1];
|
||||
});
|
||||
|
||||
if (!fields[key]) fields[key] = [];
|
||||
|
||||
fields[key].push({
|
||||
meta: meta,
|
||||
value: results[3].split(';')
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
return fields;
|
||||
}
|
||||
Reference in New Issue
Block a user