import { DateTime } from "luxon"; import { IPaginateResult, IPagination } from "./interface"; export class LontaraHelper { static stringToBoolean(str: string): boolean { const _posibleTrue = ['y', 'yes', 'true', '1']; if (_posibleTrue.includes(str.toLocaleLowerCase())) { return true; } return false; } static isDateExpired(inactiveDate: Date|string): boolean { const today = DateTime.now(); let inactive: DateTime; if (inactiveDate instanceof Date) { inactive = DateTime.fromJSDate(inactiveDate); } else { inactive = DateTime.fromISO(inactiveDate); } if (today > inactive) { return true; } return false; } static generatePaginationMeta(data: IPaginateResult): IPagination { return { currentPage: data.page, limit: data.limit, totalData: data.totalDocs, totalPages: data.totalPages, hasNextPage: data.hasNextPage, hasPrevPage: data.hasPrevPage, }; } }