@churchapps/apphelper
Version:
Library of helper functions for React and NextJS ChurchApps
58 lines • 2.29 kB
JavaScript
import { CommonEnvironmentHelper } from "@churchapps/helpers";
import { Locale } from "./Locale";
export class PersonHelper {
static getPhotoUrl(person) {
if (!person?.photo)
return "/images/sample-profile.png";
else
return (person?.photo?.startsWith("data:image/png;base64,") || person.photo?.indexOf("://") > -1)
? person.photo
: CommonEnvironmentHelper.ContentRoot + person.photo;
}
static getAge(birthdate) {
if (birthdate !== undefined && birthdate !== null) {
let ageDifMs = Date.now() - new Date(birthdate).getTime();
let ageDate = new Date(ageDifMs);
let years = Math.abs(ageDate.getUTCFullYear() - 1970);
return years + " " + Locale.label("person.years");
}
else
return "";
}
static getDisplayName(firstName, lastName, nickName) {
if (nickName !== undefined && nickName !== null && nickName.length > 0)
return firstName + ' "' + nickName + '" ' + lastName;
else
return firstName + " " + lastName;
}
static compareAddress(address1, address2) {
const displayAddress1 = this.addressToString(address1).trim();
const displayAddress2 = this.addressToString(address2).trim();
if (displayAddress1 !== displayAddress2) {
return true;
}
return false;
}
static addressToString(address) {
return `${address.address1 || ""} ${address.address2 || ""} ${address.city || ""}${(address.city && address.state) ? "," : ""} ${address.state || ""} ${address.zip || ""}`;
}
static changeOnlyAddress(contactInfo1, contactInfo2) {
const updatedAddress = {
...contactInfo1,
address1: contactInfo2.address1,
address2: contactInfo2.address2,
city: contactInfo2.city,
state: contactInfo2.state,
zip: contactInfo2.zip
};
return updatedAddress;
}
static checkAddressAvailabilty(person) {
const addressString = this.addressToString(person.contactInfo).trim();
if (addressString !== "") {
return true;
}
return false;
}
}
//# sourceMappingURL=PersonHelper.js.map