Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support v3 photo params #38

Merged
merged 2 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
`0.1.0` 2020-03-05
---------------------------------------
## `1.1.1`

- Add encoding to list of params to support PHOTO V3 and more

## `1.1.0`

- Add nickname

## `0.1.0` 2020-03-05

- Add url field to vcard and formatter
- Version bump

`0.0.5` 2019-01-19
---------------------------------------
## `0.0.5` 2019-01-19

- `Fixed` gitignore preventing js files from being published

`0.0.4` 2019-01-19
---------------------------------------
## `0.0.4` 2019-01-19

- `Added` photo field
58 changes: 40 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,91 +45,113 @@ Examples are written with Typescript in mind but you should be able to use it in

_Note: IParams refers to a javascript object containing parameters used in certain vCard properties. Some methods support this, some don't. Refer to the RFC aforementioned or source/examples of this project for more details._


### `setFullName(fullName: string)`

Set the FN property of the vcard. This is mandatory and unique. If it doesn't exist, one will be created from name components from the N property.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `addFirstName(firstName: string): VCard`

### `addMiddleName(middleName: string): VCard`

### `addLastName(lastName: string): VCard`

### `addPrefixName(pre: string): VCard`

### `addSuffixName(suf: string): VCard`

Add a first name, middle name, last name, honorific prefix or honorific suffix respectively in the N property. The N property is unique if it exists.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `addNickname(nickname: string, params?: IParams): VCard`

Add a nickname to a NICKNAME property.

---------------------------------------------------------------------------------------------------------------------------------------------------
### `addPhoto(uri: string, params?: IParams): VCard`
Add a photo to a PHOTO property. `uri` can be either a link to a site where the photo is hosted or a base64 data representation.
---

---------------------------------------------------------------------------------------------------------------------------------------------------
### `addPhoto(data: string, params?: IParams): VCard`

Add a photo to a PHOTO property. `data` can be either a link to a site where the photo is hosted or a base64 data representation.

---

### `addAddress(street: string, locality: string, region: string, postCode: string, country: string, params?: IParams): VCard`

Add an address as an ADR property. Fields not available should be null or undefined.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `addPhone(number: string, params?: IParams): VCard`

Add a phone number to a TEL property.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `addEmail(email: string, params?: IParams): VCard`

Add an email to an EMAIL property.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `addTitle(title: string, params?: IParams): VCard`

Add a title in the list of the TITLE property.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `addRole(role: string, params?: IParams): VCard`

Add a role in the list of the ROLE property.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `addOrganization(organization: string, organizationUnits: string[], params?: IParams): VCard`

Add an organization to an ORG property. Organization refers to the main name of the company and organizationUnits to second or more unit names.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `addNotes(notes: string, params?: IParams): VCard`

Add a notes entry in a NOTE property.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `addUrl(url: string, params?: IParams): VCard`

Add a url entry in a URL property

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `setRevision(rev: string, params?: IParams): VCard`

Set the revision for this vcard.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `setUID(uid: string, params?: IParams): VCard`

Set the user id for this vcard.

---------------------------------------------------------------------------------------------------------------------------------------------------
---

### `toString(forceV3 = false): string`

Takes a VCard object as created above and formats it into a string. Note that a forceV3 argument is included, which if true, sets the VERSION property to 3.0 .
This doesn't mean that this plugin supports 3.0 vcards or earlier, it's just a workaround to get your simple vcards read by older parsers found in various devices.
Care should be taken using this as the card might not be readable by 3.0 or older parsers.


## Not yet supported

The following vCard properties are not yet included but might be in the future.

```
SOURCE, KIND, XML, BDAY, ANNIVERSARY, GENDER, IMPP, LANG, TZ, GEO,
LOGO, MEMBER, RELATED, CATEGORIES, PRODID, SOUND, CLIENTPIDMAP, KEY, FBURL, CALADRURI, CALURI
```

## Contribute

Feel free to submit PRs or open issues with improvements or bug fixes.
Expand Down
64 changes: 35 additions & 29 deletions examples/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,56 @@ import { Formatter, VCard } from "../src/index";
const vcard = new VCard();

vcard
.addFirstName('John')
.addLastName('Doe')
.addLastName('Foo')
.addPrefixName('Dr.')
.addEmail('[email protected]')
.addEmail('[email protected]')
.setUID('urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')
.setRevision('1')
.addNotes('Jdoe\'s personal notes')
.addNickname('Jonny')
.addPhone('0-123456', { type: 'home', value: 'text'})
.addPhone('tel:123-456-789', { type: 'work', pref: '1', value: 'uri' })
.addTitle('Chief support officer')
.addOrganization('Smithsonian Inc.', ['North America'])
.addOrganization('Jdoe co.', [])
.addAddress('123 High Str.', '', '', 'AB-123', 'USA', { type: 'home', label: 'Doe Residence, 123 High Str., AB-123, US'})
.addRole('Support manager')
.addUrl('www.smithsonian.com');

.addFirstName("John")
.addLastName("Doe")
.addLastName("Foo")
.addPrefixName("Dr.")
.addEmail("[email protected]")
.addEmail("[email protected]")
.setUID("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6")
.setRevision("1")
.addNotes("Jdoe's personal notes")
.addNickname("Jonny")
.addPhone("0-123456", { type: "home", value: "text" })
.addPhone("tel:123-456-789", { type: "work", pref: "1", value: "uri" })
.addTitle("Chief support officer")
.addOrganization("Smithsonian Inc.", ["North America"])
.addOrganization("Jdoe co.", [])
.addAddress("123 High Str.", "", "", "AB-123", "USA", {
type: "home",
label: "Doe Residence, 123 High Str., AB-123, US",
})
.addRole("Support manager")
.addUrl("www.smithsonian.com")
.addPhoto(
"MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhvcNAQEEBQAwdzELMAkGA1UEBhMCVVMxLDAqBgNVBAoTI05ldHNjYXBlIENvbW11bmljYXRpb25zIENvcnBvcmF0aW9uMRwwGgYDVQQLExNJbmZvcm1hdGlvbi",
{ type: "image/jpeg", encoding: "b" }
);

// set the path
const path = "test.vcard";

// let it do it's thang
Export(vcard, path);


/**** HELPER ****/

function Export(vcard: VCard, filepath: string, ext = '.vcard') {
function Export(vcard: VCard, filepath: string, ext = ".vcard") {
const formatter = new Formatter();
const vcardString = formatter.format(vcard.toJSON());
if(!vcardString){
console.error('Empty string returned. Please check that your vcard is well defined');
if (!vcardString) {
console.error(
"Empty string returned. Please check that your vcard is well defined"
);
return;
}

if ((filepath.indexOf('.vcard') !== -1) || (filepath.indexOf('.vcf')))
writeFile(filepath, vcardString, errorHandler );
else
writeFile(filepath + ext, vcardString, errorHandler);
if (filepath.indexOf(".vcard") !== -1 || filepath.indexOf(".vcf"))
writeFile(filepath, vcardString, errorHandler);
else writeFile(filepath + ext, vcardString, errorHandler);
}

function errorHandler(err){
function errorHandler(err) {
if (err) throw err;
console.log('file written successfully');
console.log("file written successfully");
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@covve/easy-vcard",
"version": "1.1.0",
"version": "1.1.1",
"description": "Simple vcard formatter",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
Loading