@creopse/utils 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/enums/account-status.d.ts +4 -0
- package/dist/enums/account-status.js +5 -0
- package/dist/enums/ad-content-type.d.ts +4 -0
- package/dist/enums/ad-content-type.js +5 -0
- package/dist/enums/auth-type.d.ts +8 -0
- package/dist/enums/auth-type.js +9 -0
- package/dist/enums/bool.d.ts +4 -0
- package/dist/enums/bool.js +5 -0
- package/dist/enums/content-type.d.ts +6 -0
- package/dist/enums/content-type.js +7 -0
- package/dist/enums/index.d.ts +16 -0
- package/dist/enums/index.js +16 -0
- package/dist/enums/media-file-type.d.ts +7 -0
- package/dist/enums/media-file-type.js +8 -0
- package/dist/enums/menu-item-target-type.d.ts +5 -0
- package/dist/enums/menu-item-target-type.js +6 -0
- package/dist/enums/news-article-status.d.ts +6 -0
- package/dist/enums/news-article-status.js +7 -0
- package/dist/enums/notification-source.d.ts +4 -0
- package/dist/enums/notification-source.js +5 -0
- package/dist/enums/notification-type.d.ts +3 -0
- package/dist/enums/notification-type.js +4 -0
- package/dist/enums/permalink-content-type.d.ts +6 -0
- package/dist/enums/permalink-content-type.js +7 -0
- package/dist/enums/profile-type.d.ts +3 -0
- package/dist/enums/profile-type.js +4 -0
- package/dist/enums/response-error-code.d.ts +18 -0
- package/dist/enums/response-error-code.js +20 -0
- package/dist/enums/user-role.d.ts +5 -0
- package/dist/enums/user-role.js +6 -0
- package/dist/enums/video-display-type.d.ts +4 -0
- package/dist/enums/video-display-type.js +5 -0
- package/dist/enums/video-item-source.d.ts +4 -0
- package/dist/enums/video-item-source.js +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/models/ad-identifier.d.ts +14 -0
- package/dist/models/ad-identifier.js +11 -0
- package/dist/models/ad.d.ts +21 -0
- package/dist/models/ad.js +16 -0
- package/dist/models/admin-profile.d.ts +7 -0
- package/dist/models/admin-profile.js +8 -0
- package/dist/models/app-information.d.ts +8 -0
- package/dist/models/app-information.js +9 -0
- package/dist/models/app-setting.d.ts +8 -0
- package/dist/models/app-setting.js +9 -0
- package/dist/models/content-model-item.d.ts +17 -0
- package/dist/models/content-model-item.js +12 -0
- package/dist/models/content-model.d.ts +18 -0
- package/dist/models/content-model.js +16 -0
- package/dist/models/index.d.ts +30 -0
- package/dist/models/index.js +30 -0
- package/dist/models/media-file.d.ts +23 -0
- package/dist/models/media-file.js +22 -0
- package/dist/models/menu-item-group.d.ts +8 -0
- package/dist/models/menu-item-group.js +9 -0
- package/dist/models/menu-item.d.ts +39 -0
- package/dist/models/menu-item.js +25 -0
- package/dist/models/menu-location.d.ts +8 -0
- package/dist/models/menu-location.js +9 -0
- package/dist/models/menu.d.ts +15 -0
- package/dist/models/menu.js +11 -0
- package/dist/models/news-article.d.ts +35 -0
- package/dist/models/news-article.js +23 -0
- package/dist/models/news-category.d.ts +20 -0
- package/dist/models/news-category.js +17 -0
- package/dist/models/news-comment.d.ts +18 -0
- package/dist/models/news-comment.js +15 -0
- package/dist/models/news-tag.d.ts +15 -0
- package/dist/models/news-tag.js +13 -0
- package/dist/models/newsletter-campaign.d.ts +17 -0
- package/dist/models/newsletter-campaign.js +13 -0
- package/dist/models/newsletter-email.d.ts +7 -0
- package/dist/models/newsletter-email.js +8 -0
- package/dist/models/newsletter-phone.d.ts +7 -0
- package/dist/models/newsletter-phone.js +8 -0
- package/dist/models/notification.d.ts +22 -0
- package/dist/models/notification.js +12 -0
- package/dist/models/page.d.ts +15 -0
- package/dist/models/page.js +15 -0
- package/dist/models/permalink.d.ts +14 -0
- package/dist/models/permalink.js +12 -0
- package/dist/models/permission.d.ts +9 -0
- package/dist/models/permission.js +10 -0
- package/dist/models/role.d.ts +11 -0
- package/dist/models/role.js +11 -0
- package/dist/models/section.d.ts +17 -0
- package/dist/models/section.js +12 -0
- package/dist/models/subscriber-profile.d.ts +7 -0
- package/dist/models/subscriber-profile.js +8 -0
- package/dist/models/user-session.d.ts +27 -0
- package/dist/models/user-session.js +12 -0
- package/dist/models/user.d.ts +36 -0
- package/dist/models/user.js +27 -0
- package/dist/models/video-item.d.ts +23 -0
- package/dist/models/video-item.js +22 -0
- package/dist/models/video-setting.d.ts +8 -0
- package/dist/models/video-setting.js +9 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/app-information.d.ts +41 -0
- package/dist/types/app-information.js +1 -0
- package/dist/types/common.d.ts +11 -0
- package/dist/types/common.js +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +4 -0
- package/dist/types/pagination.d.ts +26 -0
- package/dist/types/pagination.js +1 -0
- package/dist/types/props.d.ts +42 -0
- package/dist/types/props.js +1 -0
- package/dist/utils/chronos.d.ts +97 -0
- package/dist/utils/chronos.js +97 -0
- package/dist/utils/functions.d.ts +312 -0
- package/dist/utils/functions.js +574 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/package.json +48 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class UserModel {
|
|
2
|
+
constructor(avatar, avatarUrl, fullname, lastname, firstname, email, password, profileType, profileId, accountStatus, id, uid, emailVerifiedAt, phone, address, location, preferences, authType, lastLoggedInAt, rememberToken, deletedAt, createdAt, updatedAt) {
|
|
3
|
+
this.id = id;
|
|
4
|
+
this.uid = uid;
|
|
5
|
+
this.avatar = avatar;
|
|
6
|
+
this.avatarUrl = avatarUrl;
|
|
7
|
+
this.fullname = fullname;
|
|
8
|
+
this.lastname = lastname;
|
|
9
|
+
this.firstname = firstname;
|
|
10
|
+
this.email = email;
|
|
11
|
+
this.password = password;
|
|
12
|
+
this.phone = phone;
|
|
13
|
+
this.address = address;
|
|
14
|
+
this.location = location;
|
|
15
|
+
this.accountStatus = accountStatus;
|
|
16
|
+
this.emailVerifiedAt = emailVerifiedAt;
|
|
17
|
+
this.profileType = profileType;
|
|
18
|
+
this.profileId = profileId;
|
|
19
|
+
this.preferences = preferences;
|
|
20
|
+
this.authType = authType;
|
|
21
|
+
this.lastLoggedInAt = lastLoggedInAt;
|
|
22
|
+
this.rememberToken = rememberToken;
|
|
23
|
+
this.deletedAt = deletedAt;
|
|
24
|
+
this.createdAt = createdAt;
|
|
25
|
+
this.updatedAt = updatedAt;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { VideoDisplayType } from '../enums/video-display-type';
|
|
2
|
+
import { VideoItemSource } from '../enums/video-item-source';
|
|
3
|
+
import { UserModel } from './user';
|
|
4
|
+
export declare class VideoItemModel {
|
|
5
|
+
id?: number;
|
|
6
|
+
foreignId?: string | null;
|
|
7
|
+
publisherId?: number;
|
|
8
|
+
title: string;
|
|
9
|
+
slug?: string;
|
|
10
|
+
description?: string | null;
|
|
11
|
+
thumbnail?: string | null;
|
|
12
|
+
thumbnailUrl?: string | null;
|
|
13
|
+
path: string;
|
|
14
|
+
url?: string;
|
|
15
|
+
displayType: VideoDisplayType;
|
|
16
|
+
source: VideoItemSource;
|
|
17
|
+
visible: boolean;
|
|
18
|
+
publishedAt?: string | null;
|
|
19
|
+
createdAt?: string;
|
|
20
|
+
updatedAt?: string;
|
|
21
|
+
publisher?: UserModel;
|
|
22
|
+
constructor(title: string, path: string, source: VideoItemSource | undefined, displayType: VideoDisplayType | undefined, visible: boolean, id?: number, url?: string, slug?: string, publisherId?: number, foreignId?: string | null, description?: string | null, thumbnail?: string | null, thumbnailUrl?: string | null, publishedAt?: string | null, createdAt?: string, updatedAt?: string);
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { VideoDisplayType } from '../enums/video-display-type';
|
|
2
|
+
import { VideoItemSource } from '../enums/video-item-source';
|
|
3
|
+
export class VideoItemModel {
|
|
4
|
+
constructor(title, path, source = VideoItemSource.SELF_HOSTED, displayType = VideoDisplayType.HORIZONTAL, visible, id, url, slug, publisherId, foreignId, description, thumbnail, thumbnailUrl, publishedAt, createdAt, updatedAt) {
|
|
5
|
+
this.id = id;
|
|
6
|
+
this.foreignId = foreignId;
|
|
7
|
+
this.publisherId = publisherId;
|
|
8
|
+
this.title = title;
|
|
9
|
+
this.slug = slug;
|
|
10
|
+
this.description = description;
|
|
11
|
+
this.thumbnail = thumbnail;
|
|
12
|
+
this.thumbnailUrl = thumbnailUrl;
|
|
13
|
+
this.path = path;
|
|
14
|
+
this.url = url;
|
|
15
|
+
this.source = source;
|
|
16
|
+
this.visible = visible;
|
|
17
|
+
this.displayType = displayType;
|
|
18
|
+
this.publishedAt = publishedAt;
|
|
19
|
+
this.createdAt = createdAt;
|
|
20
|
+
this.updatedAt = updatedAt;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts","../src/enums/account-status.ts","../src/enums/ad-content-type.ts","../src/enums/auth-type.ts","../src/enums/bool.ts","../src/enums/content-type.ts","../src/enums/index.ts","../src/enums/media-file-type.ts","../src/enums/menu-item-target-type.ts","../src/enums/news-article-status.ts","../src/enums/notification-source.ts","../src/enums/notification-type.ts","../src/enums/permalink-content-type.ts","../src/enums/profile-type.ts","../src/enums/response-error-code.ts","../src/enums/user-role.ts","../src/enums/video-display-type.ts","../src/enums/video-item-source.ts","../src/models/ad-identifier.ts","../src/models/ad.ts","../src/models/admin-profile.ts","../src/models/app-information.ts","../src/models/app-setting.ts","../src/models/content-model-item.ts","../src/models/content-model.ts","../src/models/index.ts","../src/models/media-file.ts","../src/models/menu-item-group.ts","../src/models/menu-item.ts","../src/models/menu-location.ts","../src/models/menu.ts","../src/models/news-article.ts","../src/models/news-category.ts","../src/models/news-comment.ts","../src/models/news-tag.ts","../src/models/newsletter-campaign.ts","../src/models/newsletter-email.ts","../src/models/newsletter-phone.ts","../src/models/notification.ts","../src/models/page.ts","../src/models/permalink.ts","../src/models/permission.ts","../src/models/role.ts","../src/models/section.ts","../src/models/subscriber-profile.ts","../src/models/user-session.ts","../src/models/user.ts","../src/models/video-item.ts","../src/models/video-setting.ts","../src/types/app-information.ts","../src/types/common.ts","../src/types/index.ts","../src/types/pagination.ts","../src/types/props.ts","../src/utils/chronos.ts","../src/utils/functions.ts","../src/utils/index.ts"],"version":"5.8.3"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface AppInformationObject {
|
|
2
|
+
name: string;
|
|
3
|
+
icon: string;
|
|
4
|
+
oneColorIcon: string;
|
|
5
|
+
logo: string;
|
|
6
|
+
oneColorLogo: string;
|
|
7
|
+
phone: string;
|
|
8
|
+
email: string;
|
|
9
|
+
address: string;
|
|
10
|
+
postalCode: string;
|
|
11
|
+
description: string;
|
|
12
|
+
primaryColor: string;
|
|
13
|
+
secondaryColor: string;
|
|
14
|
+
accentColor: string;
|
|
15
|
+
facebook: string;
|
|
16
|
+
twitter: string;
|
|
17
|
+
instagram: string;
|
|
18
|
+
whatsapp: string;
|
|
19
|
+
linkedin: string;
|
|
20
|
+
youtube: string;
|
|
21
|
+
pinterest: string;
|
|
22
|
+
snapchat: string;
|
|
23
|
+
tiktok: string;
|
|
24
|
+
telegram: string;
|
|
25
|
+
discord: string;
|
|
26
|
+
reddit: string;
|
|
27
|
+
tumblr: string;
|
|
28
|
+
vimeo: string;
|
|
29
|
+
twitch: string;
|
|
30
|
+
github: string;
|
|
31
|
+
dribbble: string;
|
|
32
|
+
behance: string;
|
|
33
|
+
medium: string;
|
|
34
|
+
stackOverflow: string;
|
|
35
|
+
threads: string;
|
|
36
|
+
messenger: string;
|
|
37
|
+
playstore: string;
|
|
38
|
+
appstore: string;
|
|
39
|
+
additionalInfo: string;
|
|
40
|
+
}
|
|
41
|
+
export type AppInformationKey = keyof AppInformationObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Bool } from '../enums/bool';
|
|
2
|
+
export type SettingType = 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
3
|
+
export interface UserPrefs {
|
|
4
|
+
inAppNotifEnabled?: Bool;
|
|
5
|
+
emailNotifEnabled?: Bool;
|
|
6
|
+
locale?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Coords {
|
|
9
|
+
lat: number;
|
|
10
|
+
lng: number;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NewsArticleModel } from '../models/news-article';
|
|
2
|
+
export interface PaginationMeta {
|
|
3
|
+
current_page: number;
|
|
4
|
+
from: number;
|
|
5
|
+
last_page: number;
|
|
6
|
+
links: {
|
|
7
|
+
url: string;
|
|
8
|
+
label: string;
|
|
9
|
+
active: boolean;
|
|
10
|
+
}[];
|
|
11
|
+
path: string;
|
|
12
|
+
per_page: number;
|
|
13
|
+
to: number;
|
|
14
|
+
total: number;
|
|
15
|
+
}
|
|
16
|
+
export interface PaginationLinks {
|
|
17
|
+
first: string;
|
|
18
|
+
last: string;
|
|
19
|
+
prev: string;
|
|
20
|
+
next: string;
|
|
21
|
+
}
|
|
22
|
+
export interface PaginatedArticles {
|
|
23
|
+
data: NewsArticleModel[];
|
|
24
|
+
meta: PaginationMeta;
|
|
25
|
+
links: PaginationLinks;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AdModel } from '../models/ad';
|
|
2
|
+
import type { AdIdentifierModel } from '../models/ad-identifier';
|
|
3
|
+
import type { ContentModelModel } from '../models/content-model';
|
|
4
|
+
import type { ContentModelItemModel } from '../models/content-model-item';
|
|
5
|
+
import type { MenuModel } from '../models/menu';
|
|
6
|
+
import type { MenuItemGroupModel } from '../models/menu-item-group';
|
|
7
|
+
import type { MenuLocationModel } from '../models/menu-location';
|
|
8
|
+
import type { NewsArticleModel } from '../models/news-article';
|
|
9
|
+
import type { NewsCategoryModel } from '../models/news-category';
|
|
10
|
+
import type { NewsTagModel } from '../models/news-tag';
|
|
11
|
+
import type { PageModel } from '../models/page';
|
|
12
|
+
import type { SectionModel } from '../models/section';
|
|
13
|
+
import type { Page } from '@inertiajs/core';
|
|
14
|
+
import type { PaginatedArticles } from './pagination';
|
|
15
|
+
import { AppInformationModel } from '../models/app-information';
|
|
16
|
+
export interface SharedProps extends Page {
|
|
17
|
+
appLocale: string;
|
|
18
|
+
appFallbackLocale: string;
|
|
19
|
+
userData: any;
|
|
20
|
+
isUserLoggedIn: boolean;
|
|
21
|
+
pageData: PageModel | null;
|
|
22
|
+
sectionData: SectionModel | null;
|
|
23
|
+
articles?: NewsArticleModel[];
|
|
24
|
+
paginatedArticles?: PaginatedArticles;
|
|
25
|
+
categories?: NewsCategoryModel[];
|
|
26
|
+
tags?: NewsTagModel[];
|
|
27
|
+
article?: NewsArticleModel;
|
|
28
|
+
category?: NewsCategoryModel;
|
|
29
|
+
tag?: NewsTagModel;
|
|
30
|
+
contentModelItem?: ContentModelItemModel;
|
|
31
|
+
appInformation: AppInformationModel[];
|
|
32
|
+
adIdentifiers?: AdIdentifierModel[];
|
|
33
|
+
contentModels?: ContentModelModel[];
|
|
34
|
+
menus?: MenuModel[];
|
|
35
|
+
menuLocations?: MenuLocationModel[];
|
|
36
|
+
menuItemGroups?: MenuItemGroupModel[];
|
|
37
|
+
ads?: AdModel[];
|
|
38
|
+
query?: string;
|
|
39
|
+
data?: any;
|
|
40
|
+
youtubeChannelId?: string;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import 'moment/dist/locale/fr';
|
|
3
|
+
/**
|
|
4
|
+
* Waits for the given amount of milliseconds before resolving the promise.
|
|
5
|
+
* @param {number} ms - The time to wait in milliseconds.
|
|
6
|
+
* @returns {Promise<void>} - A promise that resolves after the specified time.
|
|
7
|
+
*/
|
|
8
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the current timestamp in seconds.
|
|
11
|
+
*
|
|
12
|
+
* @returns {number} The current timestamp in seconds.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getCurrentTimestamp(): number;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a timestamp in seconds into a formatted date string.
|
|
17
|
+
*
|
|
18
|
+
* @param {number} date - The timestamp in seconds to convert.
|
|
19
|
+
* @param {{locale?: string, pattern?: string}} options - Optional parameters for the conversion.
|
|
20
|
+
* @param {string} options.locale - The locale to use for the conversion. Defaults to 'en'.
|
|
21
|
+
* @param {string} options.pattern - The pattern to use for the conversion. Defaults to 'MM/DD/YYYY HH:mm'.
|
|
22
|
+
* @returns {string} The formatted date string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getDateFromTimestamp(date: number, { locale, pattern, }?: {
|
|
25
|
+
locale?: string;
|
|
26
|
+
pattern?: string;
|
|
27
|
+
}): string;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a date string or Date object from one format to another.
|
|
30
|
+
*
|
|
31
|
+
* @param {string | Date} date - The date string or Date object to convert.
|
|
32
|
+
* @param {{inPattern?: string, outPattern?: string, locale?: string}} options - Optional parameters for the conversion.
|
|
33
|
+
* @param {string} options.inPattern - The pattern of the input date string. Defaults to 'YYYY-MM-DD'.
|
|
34
|
+
* @param {string} options.outPattern - The pattern of the output date string. Defaults to 'DD MMM YYYY'.
|
|
35
|
+
* @param {string} options.locale - The locale to use for the conversion. Defaults to 'fr'.
|
|
36
|
+
* @returns {string} The converted date string.
|
|
37
|
+
*/
|
|
38
|
+
export declare function reformatDate(date: string | Date, { inPattern, outPattern, locale, }?: {
|
|
39
|
+
inPattern?: string;
|
|
40
|
+
outPattern?: string;
|
|
41
|
+
locale?: string;
|
|
42
|
+
}): string;
|
|
43
|
+
/**
|
|
44
|
+
* Converts a date string or Date object into a formatted date string.
|
|
45
|
+
*
|
|
46
|
+
* @param {string | Date} date - The date string or Date object to convert.
|
|
47
|
+
* @param {{outPattern?: string, locale?: string}} options - Optional parameters for the conversion.
|
|
48
|
+
* @param {string} options.outPattern - The pattern of the output date string. Defaults to 'DD MMM YYYY'.
|
|
49
|
+
* @param {string} options.locale - The locale to use for the conversion. Defaults to 'fr'.
|
|
50
|
+
* @returns {string} The formatted date string.
|
|
51
|
+
*/
|
|
52
|
+
export declare function formatDate(date: string | Date, { outPattern, locale, }?: {
|
|
53
|
+
outPattern?: string;
|
|
54
|
+
locale?: string;
|
|
55
|
+
}): string;
|
|
56
|
+
/**
|
|
57
|
+
* Calculates the difference between the given date and today in the given unit.
|
|
58
|
+
*
|
|
59
|
+
* @param {string | Date} date - The date to calculate the difference for.
|
|
60
|
+
* @param {{pattern?: string, unit?: moment.unitOfTime.Diff}} options - Optional parameters for the calculation.
|
|
61
|
+
* @param {string} options.pattern - The pattern of the input date string. Defaults to 'YYYY-MM-DD'.
|
|
62
|
+
* @param {moment.unitOfTime.Diff} options.unit - The unit of time to calculate the difference in. Defaults to 'days'.
|
|
63
|
+
* @returns {number} The difference between the given date and today in the given unit.
|
|
64
|
+
*/
|
|
65
|
+
export declare function differenceWithToday(date: string | Date, { pattern, unit, }?: {
|
|
66
|
+
pattern?: string;
|
|
67
|
+
unit?: moment.unitOfTime.Diff;
|
|
68
|
+
}): number;
|
|
69
|
+
/**
|
|
70
|
+
* Calculates the difference between two dates.
|
|
71
|
+
*
|
|
72
|
+
* @param {string | Date} startDate - The start date.
|
|
73
|
+
* @param {string | Date} endDate - The end date.
|
|
74
|
+
* @param {{startDatePattern?: string, endDatePattern?: string, unit?: moment.unitOfTime.Diff}} options - Optional parameters for the calculation.
|
|
75
|
+
* @param {string} options.startDatePattern - The pattern of the start date string. Defaults to 'YYYY-MM-DD'.
|
|
76
|
+
* @param {string} options.endDatePattern - The pattern of the end date string. Defaults to 'YYYY-MM-DD'.
|
|
77
|
+
* @param {moment.unitOfTime.Diff} options.unit - The unit of time to calculate the difference in. Defaults to 'days'.
|
|
78
|
+
* @returns {number} The difference between the start and end dates in the given unit.
|
|
79
|
+
*/
|
|
80
|
+
export declare function differenceBetweenDates(startDate: string | Date, endDate: string | Date, { startDatePattern, endDatePattern, unit, }?: {
|
|
81
|
+
startDatePattern?: string;
|
|
82
|
+
endDatePattern?: string;
|
|
83
|
+
unit?: moment.unitOfTime.Diff;
|
|
84
|
+
}): number;
|
|
85
|
+
/**
|
|
86
|
+
* Calculates the difference between the given date and now.
|
|
87
|
+
*
|
|
88
|
+
* @param {string | Date} date - The date to calculate the difference from.
|
|
89
|
+
* @param {{locale?: string, pattern?: string}} options - Optional parameters for the calculation.
|
|
90
|
+
* @param {string} options.locale - The locale to use for the calculation. Defaults to 'en'.
|
|
91
|
+
* @param {string} options.pattern - The pattern of the date string. Defaults to 'YYYY-MM-DD HH:mm:ss'.
|
|
92
|
+
* @returns {string} The difference between the given date and now, relative to the given locale.
|
|
93
|
+
*/
|
|
94
|
+
export declare function differenceFromNow(date: string | Date, { locale, pattern, }?: {
|
|
95
|
+
locale?: string;
|
|
96
|
+
pattern?: string;
|
|
97
|
+
}): string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import 'moment/dist/locale/fr';
|
|
3
|
+
/**
|
|
4
|
+
* Waits for the given amount of milliseconds before resolving the promise.
|
|
5
|
+
* @param {number} ms - The time to wait in milliseconds.
|
|
6
|
+
* @returns {Promise<void>} - A promise that resolves after the specified time.
|
|
7
|
+
*/
|
|
8
|
+
export function sleep(ms) {
|
|
9
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Returns the current timestamp in seconds.
|
|
13
|
+
*
|
|
14
|
+
* @returns {number} The current timestamp in seconds.
|
|
15
|
+
*/
|
|
16
|
+
export function getCurrentTimestamp() {
|
|
17
|
+
return Math.round(Number(new Date()) / 1000);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Converts a timestamp in seconds into a formatted date string.
|
|
21
|
+
*
|
|
22
|
+
* @param {number} date - The timestamp in seconds to convert.
|
|
23
|
+
* @param {{locale?: string, pattern?: string}} options - Optional parameters for the conversion.
|
|
24
|
+
* @param {string} options.locale - The locale to use for the conversion. Defaults to 'en'.
|
|
25
|
+
* @param {string} options.pattern - The pattern to use for the conversion. Defaults to 'MM/DD/YYYY HH:mm'.
|
|
26
|
+
* @returns {string} The formatted date string.
|
|
27
|
+
*/
|
|
28
|
+
export function getDateFromTimestamp(date, { locale = 'en', pattern = 'MM/DD/YYYY HH:mm', } = {}) {
|
|
29
|
+
return moment(new Date(date * 1000))
|
|
30
|
+
.locale(locale)
|
|
31
|
+
.format(pattern);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Converts a date string or Date object from one format to another.
|
|
35
|
+
*
|
|
36
|
+
* @param {string | Date} date - The date string or Date object to convert.
|
|
37
|
+
* @param {{inPattern?: string, outPattern?: string, locale?: string}} options - Optional parameters for the conversion.
|
|
38
|
+
* @param {string} options.inPattern - The pattern of the input date string. Defaults to 'YYYY-MM-DD'.
|
|
39
|
+
* @param {string} options.outPattern - The pattern of the output date string. Defaults to 'DD MMM YYYY'.
|
|
40
|
+
* @param {string} options.locale - The locale to use for the conversion. Defaults to 'fr'.
|
|
41
|
+
* @returns {string} The converted date string.
|
|
42
|
+
*/
|
|
43
|
+
export function reformatDate(date, { inPattern = 'YYYY-MM-DD', outPattern = 'DD MMM YYYY', locale = 'fr', } = {}) {
|
|
44
|
+
return date ? moment(date, inPattern).locale(locale).format(outPattern) : '';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Converts a date string or Date object into a formatted date string.
|
|
48
|
+
*
|
|
49
|
+
* @param {string | Date} date - The date string or Date object to convert.
|
|
50
|
+
* @param {{outPattern?: string, locale?: string}} options - Optional parameters for the conversion.
|
|
51
|
+
* @param {string} options.outPattern - The pattern of the output date string. Defaults to 'DD MMM YYYY'.
|
|
52
|
+
* @param {string} options.locale - The locale to use for the conversion. Defaults to 'fr'.
|
|
53
|
+
* @returns {string} The formatted date string.
|
|
54
|
+
*/
|
|
55
|
+
export function formatDate(date, { outPattern = 'DD MMM YYYY', locale = 'fr', } = {}) {
|
|
56
|
+
return date ? moment(date).locale(locale).format(outPattern) : '';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Calculates the difference between the given date and today in the given unit.
|
|
60
|
+
*
|
|
61
|
+
* @param {string | Date} date - The date to calculate the difference for.
|
|
62
|
+
* @param {{pattern?: string, unit?: moment.unitOfTime.Diff}} options - Optional parameters for the calculation.
|
|
63
|
+
* @param {string} options.pattern - The pattern of the input date string. Defaults to 'YYYY-MM-DD'.
|
|
64
|
+
* @param {moment.unitOfTime.Diff} options.unit - The unit of time to calculate the difference in. Defaults to 'days'.
|
|
65
|
+
* @returns {number} The difference between the given date and today in the given unit.
|
|
66
|
+
*/
|
|
67
|
+
export function differenceWithToday(date, { pattern = 'YYYY-MM-DD', unit = 'days', } = {}) {
|
|
68
|
+
return moment(date, pattern).diff(moment(), unit);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Calculates the difference between two dates.
|
|
72
|
+
*
|
|
73
|
+
* @param {string | Date} startDate - The start date.
|
|
74
|
+
* @param {string | Date} endDate - The end date.
|
|
75
|
+
* @param {{startDatePattern?: string, endDatePattern?: string, unit?: moment.unitOfTime.Diff}} options - Optional parameters for the calculation.
|
|
76
|
+
* @param {string} options.startDatePattern - The pattern of the start date string. Defaults to 'YYYY-MM-DD'.
|
|
77
|
+
* @param {string} options.endDatePattern - The pattern of the end date string. Defaults to 'YYYY-MM-DD'.
|
|
78
|
+
* @param {moment.unitOfTime.Diff} options.unit - The unit of time to calculate the difference in. Defaults to 'days'.
|
|
79
|
+
* @returns {number} The difference between the start and end dates in the given unit.
|
|
80
|
+
*/
|
|
81
|
+
export function differenceBetweenDates(startDate, endDate, { startDatePattern = 'YYYY-MM-DD', endDatePattern = 'YYYY-MM-DD', unit = 'days', } = {}) {
|
|
82
|
+
const start = moment(startDate, startDatePattern);
|
|
83
|
+
const end = moment(endDate, endDatePattern);
|
|
84
|
+
return start.diff(end, unit);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Calculates the difference between the given date and now.
|
|
88
|
+
*
|
|
89
|
+
* @param {string | Date} date - The date to calculate the difference from.
|
|
90
|
+
* @param {{locale?: string, pattern?: string}} options - Optional parameters for the calculation.
|
|
91
|
+
* @param {string} options.locale - The locale to use for the calculation. Defaults to 'en'.
|
|
92
|
+
* @param {string} options.pattern - The pattern of the date string. Defaults to 'YYYY-MM-DD HH:mm:ss'.
|
|
93
|
+
* @returns {string} The difference between the given date and now, relative to the given locale.
|
|
94
|
+
*/
|
|
95
|
+
export function differenceFromNow(date, { locale = 'en', pattern = 'YYYY-MM-DD HH:mm:ss', } = {}) {
|
|
96
|
+
return moment(date, pattern).locale(locale).fromNow();
|
|
97
|
+
}
|