VCard是电子名片的文件格式标准。它一般附加在电子邮件之后,但也可以用于其它场合(如在网际网路上相互交换)。
| Files | Last commit | Last update |
|---|---|---|
| 10 months ago | ||
| 10 months ago | ||
| 2 years ago | ||
| 9 months ago | ||
| 3 years ago | ||
| 3 years ago | ||
| 10 months ago | ||
| 4 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 10 months ago | ||
| 10 months ago | ||
| 1 year ago | ||
| 3 years ago | ||
| 3 years ago | ||
| 3 years ago | ||
| 10 months ago | ||
| 10 months ago | ||
| 10 months ago |
vCard
Introduction
vCard, a file format standard for electronic business cards, is often attached to e-mail messages, and also can be exchanged in other ways, such as on the World Wide Web. It contains information such as names, addresses, phone numbers, URLs, logos, and photos. This library supports vCard standard 2.0 and 3.0.
How to Install
ohpm install @ohos/vcard
For details about the OpenHarmony ohpm environment configuration, see OpenHarmony HAR.
How to Use
Generating a vCard
import {contact,VCardBuilder,VCardConfig} from "@ohos/vcard";
let myCard= new contact.Contact();
let nickName = new contact.NickName();
nickName.nickName ="Nickname";
myCard.nickName = nickName;
let builder = new VCardBuilder(VCardConfig.VCARD_TYPE_V21_GENERIC,"UTF-8");
builder.appendNickNames(myCard);
let result = builder.toString();
Parsing a vCard Text
VCard parsing supports two methods: file-based parsing and content-based parsing.
Example 1: Parsing VCard files
import fileio from "@ohos.fileio";
import {VCardParserImpI_V20,VCardEntry,VCardInterpreter,VCardProperty} from "@ohos/vcard";
let vCardEntry = new VCardEntry()
class MyVCardInterpreter implements VCardInterpreter{
onVCardStarted(): void {
}
onVCardEnded(): void {
}
onEntryStarted(): void {
}
onEntryEnded(): void {
}
onPropertyCreated(property: VCardProperty): void {
vCardEntry.addProperty(property)
}
}
let myParser = new VCardParserImpl_V20()
myParser.addInterpreter(new MyVCardInterpreter() )
let fileDescriptor = fileio.openSync("./pathTo/00002.vcf", 0o100|0o2,0o666)
myParser.parse(fileDescriptor)
vCardEntry.consolidateFields()
let displayName = vCardEntry.getDisplayName()
let emails= vCardEntry.getEmailList()
Example 2: Parsing VCard content
import {VCardParserImpI_V20,VCardEntry,VCardInterpreter,VCardProperty} from "@ohos/vcard";
const vcardContent = `BEGIN:VCARD
VERSION:2.1
N:Smith;John;;;
FN:John Smith
TEL;TYPE=CELL:+1-555-123-4567
END:VCARD`;
let vCardEntry = new VCardEntry()
class MyVCardInterpreter implements VCardInterpreter{
onVCardStarted(): void {
}
onVCardEnded(): void {
}
onEntryStarted(): void {
}
onEntryEnded(): void {
}
onPropertyCreated(property: VCardProperty): void {
vCardEntry.addProperty(property)
}
}
let myParser = new VCardParserImpl_V20()
myParser.addInterpreter(new MyVCardInterpreter())
myParser.parseVCardText(vcardContent)
vCardEntry.consolidateFields()
let displayName = vCardEntry.getDisplayName()
let emails= vCardEntry.getEmailList()
Available APIs
let builder=new VCardBuilder(VCardConfig.VCARD_TYPE_V21_GENERIC,"UTF-8");
- Appends nicknames.
builder.appendNickNames() - Appends names.
builder.appendNameProperties() - Appends phone numbers.
builder.appendPhones() - Appends emails.
builder.appendEmails() - Appends addresses.
builder.appendPostals() - Appends social networking tools.
builder.appendIms() - Appends website addresses.
builder.appendWebsites() - Appends organizations.
builder.appendOrganizations() - Appends photo addresses.
builder.appendPhotos() - Appends remarks.
builder.appendNotes() - Appends groups.
builder.appendGroupMemberShip() - Appends events.
builder.appendEvents() - Appends relationships.
builder.appendRelation()
About obfuscation
- Code obfuscation, please seeCode Obfuscation
- If you want the vcard library not to be obfuscated during code obfuscation, you need to add corresponding exclusion rules in the obfuscation rule configuration file obfuscation-rules.txt:
-keep
./oh_modules/@ohos/vcard
Constraints
This project has been verified in the following versions:
- DevEco Studio: 4.1 Canary (4.1.3.317), OpenHarmony SDK: API 11 (4.1.0.36)
Directory Structure
|---- VCard
| |---- entry # Sample code
| |---- library # vCard library
| |---- index.ets # External APIs
| |---- README.MD # Readme
How to Contribute
If you find any problem when using the project, submit an issue or a PR.
License
This project is licensed under the terms of the Apache License 2.0.
