0.0.0 • Published 6 years ago

@expo/contact-utils v0.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

expo-contact-utils

NPM

Methods

parseDate

parseDate({ year, month, day, format }): Date

Return a JS Date given a native calendar date.

Parameters

NameTypeDescription
calendarFormatCalendarFormatThe shape containing calendar information.

Returns

NameTypeDescription
dateDateA javascript date.

Example

const date = ContactUtils.parseDate({ year, month, day, format });

formatAddress

formatAddress(address: Address): string

Return a readable name from native address information.

Parameters

NameTypeDescription
addressAddressThe shape containing postal address information.

Returns

NameTypeDescription
formatAddressstringA readable address name.

Example

const address = ContactUtils.formatAddress({
  city,
  country,
  postalCode,
  region,
  street,
});

nameForFieldAsync

nameForFieldAsync(key: ContactField, strings = STRINGS): ?string

Get a localized name for a Contact.Fields key.

Only supported language is en (US-English) currently.

Parameters

NameTypeDescription
keyContactFieldThe field you want to get a name for.
strings{ [en]: { [ContactField]: string } }An alternative list of localized strings.

Returns

NameTypeDescription
name?stringThe name of a supplied ContactField.

Example

const name = await nameForFieldAsync(Contacts.Fields.FirstName);

getPrimaryEntry

getPrimaryEntry(items: Array): ?Object

Given a list of contact entries, (like emails) this will find the primary entry.

Parameters

NameTypeDescription
itemsArray<{ label, id, isPrimary, ...data }>An array of contact entry data.

Returns

NameTypeDescription
item?{ label, id, isPrimary, ...data }A contact field entry that is the assumed primary value.

Example

const primary = getPrimaryEntry(phoneNumbers);

getGroupWithNameAsync

iOS only

getGroupWithNameAsync(groupName: string): Promise<?Group>

Gets the first group with a given name.

Parameters

NameTypeDescription
groupNamestringName of the group you want to query.

Returns

NameTypeDescription
group?GroupA group with a name matching the provided query.

Example

const contactGroup = await getGroupWithNameAsync("Expo Programmers")

duplicateContactWithIdAsync

iOS only

duplicateContactWithIdAsync(contactId: string): Promise<string>

Creates a clone of an existing system contact.

Parameters

NameTypeDescription
contactIdstringID of the existing contact you want to duplicate.

Returns

NameTypeDescription
contactIdstringID of the new contact.

Example

const cloneId = await duplicateContactWithIdAsync(contactId)

ensureGroupWithNameExistsAsync

iOS only

ensureGroupWithNameExistsAsync(groupName: string): Promise<string>

Tries to retrieve a contact group, if it cannot be found, create a new contact group with the provided name.

Parameters

NameTypeDescription
groupNamestringName of the group you wish to get.

Returns

NameTypeDescription
groupIdstringID of the group you ensured.

Example

const groupId = await ensureGroupWithNameExistsAsync("Expo programmers")

deleteGroupWithNameAsync

iOS only

deleteGroupWithNameAsync(groupName: string): Promise<any>

Query a group by name, and delete it.

Parameters

NameTypeDescription
groupNamestringName of the group you want to delete.

Example

await deleteGroupWithNameAsync("Xamarin programmers")

removeAllChildrenFromGroupWithNameAsync

iOS only

removeAllChildrenFromGroupWithNameAsync(groupName: string): Promise<any>

Delete all the contacts from a group.

Parameters | Name | Type | Description | | ------- | --------- | ------------------------------------------------ | | groupName | string | Name of the target group. |

Example

await removeAllChildrenFromGroupWithNameAsync("Xamarin Devs")

presentNewContactFormAsync

presentNewContactFormAsync(options: ContactFormOptions): Promise<any>

Present a native modal for adding a new system contact.

Parameters

NameTypeDescription
optionsContactFormOptionsThe configuration used for customizing the modal.

Example

await presentNewContactFormAsync({ contact, options })

presentUnknownContactFormAsync

presentUnknownContactFormAsync(options: ContactFormOptions): Promise<any>

Present a native modal for an unknown contact.

Parameters

NameTypeDescription
optionsContactFormOptionsThe configuration used for customizing the modal.

Example

const data = await presentUnknownContactFormAsync({ contact, options })

presentContactInfoFormAsync

presentContactInfoFormAsync(options: ContactFormOptions): Promise<any>

Present a native modal for inspecting contact information.

Parameters

NameTypeDescription
optionsContactFormOptionsThe configuration used for customizing the modal.

Example

await presentContactInfoFormAsync({ contact, options })

Types

ContactFormOptions

NameTypeDescription
contactContactContact information for the modal.
optionsObjectConfiguration data for the modal.