mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-16 17:51:43 +10:00
🚀 release: v3.0.0
This commit is contained in:
58
apps/client/utils/template.ts
Normal file
58
apps/client/utils/template.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import { ListItem, Location, PhotoFilters } from '@reactive-resume/schema';
|
||||
import clsx from 'clsx';
|
||||
import get from 'lodash/get';
|
||||
import isArray from 'lodash/isArray';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
|
||||
export type PageProps = {
|
||||
page: number;
|
||||
};
|
||||
|
||||
export const formatLocation = (location: Location): string => {
|
||||
const locationArr = [location.address, location.city, location.region, location.postalCode, location.country];
|
||||
const filteredLocationArr = locationArr.filter((x) => !isEmpty(x));
|
||||
|
||||
return filteredLocationArr.join(', ');
|
||||
};
|
||||
|
||||
export const addHttp = (url: string) => {
|
||||
if (url.search(/^http[s]?:\/\//) == -1) {
|
||||
url = 'http://' + url;
|
||||
}
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
export const isValidUrl = (string: string): boolean => {
|
||||
let url: URL;
|
||||
|
||||
try {
|
||||
url = new URL(string);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return url.protocol === 'http:' || url.protocol === 'https:';
|
||||
};
|
||||
|
||||
type Separator = ', ' | ' / ' | ' | ';
|
||||
|
||||
export const parseListItemPath = (item: ListItem, path: string | string[], separator: Separator = ', '): string => {
|
||||
if (isArray(path)) {
|
||||
const value = path.map((_path) => get(item, _path));
|
||||
|
||||
return value.join(separator);
|
||||
} else {
|
||||
const value = get(item, path);
|
||||
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
export const getPhotoClassNames = (filters: PhotoFilters) =>
|
||||
clsx({
|
||||
grayscale: filters.grayscale,
|
||||
'!border-[4px] !border-solid': filters.border,
|
||||
'rounded-lg': filters.shape === 'rounded-square',
|
||||
'rounded-full': filters.shape === 'circle',
|
||||
});
|
||||
Reference in New Issue
Block a user