dff-util 1.1.9 → 1.2.0
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 +50 -2
- package/dist/main/const-type.d.ts +16 -0
- package/dist/main/const-value.d.ts +9 -0
- package/dist/main/const-value.js +22 -0
- package/dist/main/util.d.ts +6 -1
- package/dist/main/util.js +85 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -136,6 +136,34 @@ ConstValue = {
|
|
|
136
136
|
STR_AND: 'AND',
|
|
137
137
|
STR_OR: 'OR',
|
|
138
138
|
STR_NOT: 'NOT',
|
|
139
|
+
|
|
140
|
+
ASC: 'ASC',
|
|
141
|
+
DESC: 'DESC',
|
|
142
|
+
|
|
143
|
+
LTR: 'ltr',
|
|
144
|
+
RTL: 'rtl',
|
|
145
|
+
|
|
146
|
+
AM: 'AM',
|
|
147
|
+
PM: 'PM',
|
|
148
|
+
|
|
149
|
+
LIGHT: 'light',
|
|
150
|
+
DARK: 'dark',
|
|
151
|
+
|
|
152
|
+
MonthNames: [
|
|
153
|
+
"Jan",
|
|
154
|
+
"Feb",
|
|
155
|
+
"Mar",
|
|
156
|
+
"Apr",
|
|
157
|
+
"May",
|
|
158
|
+
"Jun",
|
|
159
|
+
"Jul",
|
|
160
|
+
"Aug",
|
|
161
|
+
"Sep",
|
|
162
|
+
"Oct",
|
|
163
|
+
"Nov",
|
|
164
|
+
"Dec",
|
|
165
|
+
]
|
|
166
|
+
|
|
139
167
|
};
|
|
140
168
|
```
|
|
141
169
|
|
|
@@ -273,10 +301,26 @@ export type CountryType = {
|
|
|
273
301
|
};
|
|
274
302
|
```
|
|
275
303
|
|
|
276
|
-
## LangDirType, OrderType
|
|
304
|
+
## LangDirType, OrderType, ThemeType, UnixTimestampType, OptionType, FileType
|
|
277
305
|
```
|
|
278
306
|
export type LangDirType = "ltr" | "rtl";
|
|
279
307
|
export type OrderType = "ASC" | "DESC";
|
|
308
|
+
export type ThemeType = "light" | "dark";
|
|
309
|
+
export type UnixTimestampType = number & { __brand: "UnixTimestamp" };
|
|
310
|
+
|
|
311
|
+
export type OptionType = {
|
|
312
|
+
label: string;
|
|
313
|
+
key: string | number;
|
|
314
|
+
disabled?: boolean;
|
|
315
|
+
icon?: string;
|
|
316
|
+
lang?: Record<string, string>;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
export type FileType = {
|
|
320
|
+
filename: string;
|
|
321
|
+
mimetype: string;
|
|
322
|
+
url: string;
|
|
323
|
+
};
|
|
280
324
|
```
|
|
281
325
|
## LanguageType
|
|
282
326
|
```
|
|
@@ -304,6 +348,8 @@ export type LangCountryType = {
|
|
|
304
348
|
};
|
|
305
349
|
```
|
|
306
350
|
|
|
351
|
+
|
|
352
|
+
|
|
307
353
|
## ConstMessages
|
|
308
354
|
|
|
309
355
|
```
|
|
@@ -760,4 +806,6 @@ export type AllLanguageCodesType =
|
|
|
760
806
|
| "ar-YE"
|
|
761
807
|
| "en-ZM"
|
|
762
808
|
| "en-ZW";
|
|
763
|
-
```
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
### Available methods TruncateText, DateTime24HrFormat,DateTime12HrFormat, DateAndTime, TimeAgo
|
|
@@ -44,6 +44,22 @@ export type CountryType = {
|
|
|
44
44
|
};
|
|
45
45
|
export type LangDirType = "ltr" | "rtl";
|
|
46
46
|
export type OrderType = "ASC" | "DESC";
|
|
47
|
+
export type ThemeType = "light" | "dark";
|
|
48
|
+
export type UnixTimestampType = number & {
|
|
49
|
+
__brand: "UnixTimestamp";
|
|
50
|
+
};
|
|
51
|
+
export type OptionType = {
|
|
52
|
+
label: string;
|
|
53
|
+
key: string | number;
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
icon?: string;
|
|
56
|
+
lang?: Record<string, string>;
|
|
57
|
+
};
|
|
58
|
+
export type FileType = {
|
|
59
|
+
filename: string;
|
|
60
|
+
mimetype: string;
|
|
61
|
+
url: string;
|
|
62
|
+
};
|
|
47
63
|
export type LanguageType = {
|
|
48
64
|
lang: string;
|
|
49
65
|
code: string;
|
|
@@ -33,4 +33,13 @@ export declare const ConstValue: {
|
|
|
33
33
|
STR_AND: string;
|
|
34
34
|
STR_OR: string;
|
|
35
35
|
STR_NOT: string;
|
|
36
|
+
ASC: string;
|
|
37
|
+
DESC: string;
|
|
38
|
+
LTR: string;
|
|
39
|
+
RTL: string;
|
|
40
|
+
AM: string;
|
|
41
|
+
PM: string;
|
|
42
|
+
LIGHT: string;
|
|
43
|
+
DARK: string;
|
|
44
|
+
MonthNames: string[];
|
|
36
45
|
};
|
package/dist/main/const-value.js
CHANGED
|
@@ -40,4 +40,26 @@ exports.ConstValue = {
|
|
|
40
40
|
STR_AND: 'AND',
|
|
41
41
|
STR_OR: 'OR',
|
|
42
42
|
STR_NOT: 'NOT',
|
|
43
|
+
ASC: 'ASC',
|
|
44
|
+
DESC: 'DESC',
|
|
45
|
+
LTR: 'ltr',
|
|
46
|
+
RTL: 'rtl',
|
|
47
|
+
AM: 'AM',
|
|
48
|
+
PM: 'PM',
|
|
49
|
+
LIGHT: 'light',
|
|
50
|
+
DARK: 'dark',
|
|
51
|
+
MonthNames: [
|
|
52
|
+
"Jan",
|
|
53
|
+
"Feb",
|
|
54
|
+
"Mar",
|
|
55
|
+
"Apr",
|
|
56
|
+
"May",
|
|
57
|
+
"Jun",
|
|
58
|
+
"Jul",
|
|
59
|
+
"Aug",
|
|
60
|
+
"Sep",
|
|
61
|
+
"Oct",
|
|
62
|
+
"Nov",
|
|
63
|
+
"Dec",
|
|
64
|
+
]
|
|
43
65
|
};
|
package/dist/main/util.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ export declare const AppCode: (name: string) => string | null;
|
|
|
6
6
|
export declare const AppDaysBack: (date: Date, backValue: number, isDays?: boolean) => Date;
|
|
7
7
|
export declare const AppAddDays: (date: Date, addDays: number, isDays?: boolean) => Date;
|
|
8
8
|
export declare const AppUUID4: () => string;
|
|
9
|
+
export declare const TruncateText: (input: string, maxLength: number) => string;
|
|
10
|
+
export declare const DateTime24HrFormat: (time: string) => string;
|
|
11
|
+
export declare const DateTime12HrFormat: (timestamp: Date, showDate?: boolean, showTime?: boolean) => string;
|
|
12
|
+
export declare const DateAndTime: (dateString: string, timeString: string) => Date | null;
|
|
13
|
+
export declare const TimeAgo: (date: Date) => string;
|
|
9
14
|
export declare const LangText: (data: string, source: string, target: string) => Promise<any>;
|
|
10
|
-
export declare const CurrencyConvert: (from: string, to: string) => Promise<number>;
|
|
11
15
|
export declare const LangCountryCode: (lang: string) => LangCountryType;
|
|
16
|
+
export declare const CurrencyConvert: (from: string, to: string) => Promise<number>;
|
package/dist/main/util.js
CHANGED
|
@@ -9,11 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.CurrencyConvert = exports.LangCountryCode = exports.LangText = exports.TimeAgo = exports.DateAndTime = exports.DateTime12HrFormat = exports.DateTime24HrFormat = exports.TruncateText = exports.AppUUID4 = exports.AppAddDays = exports.AppDaysBack = exports.AppCode = exports.AppCodeByType = exports.AppUniqueCode = exports.AppRandomString = void 0;
|
|
13
13
|
const randomstring_1 = require("randomstring");
|
|
14
14
|
const reg_exr_1 = require("./reg-exr");
|
|
15
15
|
const countries_1 = require("./countries");
|
|
16
16
|
const languages_1 = require("./languages");
|
|
17
|
+
const const_value_1 = require("./const-value");
|
|
17
18
|
const AppRandomString = (length, charset) => {
|
|
18
19
|
return (0, randomstring_1.generate)({ length: length, charset: charset });
|
|
19
20
|
};
|
|
@@ -85,6 +86,72 @@ const AppUUID4 = () => {
|
|
|
85
86
|
});
|
|
86
87
|
};
|
|
87
88
|
exports.AppUUID4 = AppUUID4;
|
|
89
|
+
const TruncateText = (input, maxLength) => {
|
|
90
|
+
if ((input === null || input === void 0 ? void 0 : input.length) > maxLength) {
|
|
91
|
+
return input.substring(0, maxLength) + "...";
|
|
92
|
+
}
|
|
93
|
+
return input;
|
|
94
|
+
};
|
|
95
|
+
exports.TruncateText = TruncateText;
|
|
96
|
+
const DateTime24HrFormat = (time) => {
|
|
97
|
+
const [timeStr, modifier] = time.split(" ");
|
|
98
|
+
let [hours, minutes] = timeStr.split(":").map(Number);
|
|
99
|
+
if (modifier === "AM") {
|
|
100
|
+
if (hours === 12)
|
|
101
|
+
hours = 0;
|
|
102
|
+
}
|
|
103
|
+
else if (modifier === "PM") {
|
|
104
|
+
if (hours !== 12)
|
|
105
|
+
hours += 12;
|
|
106
|
+
}
|
|
107
|
+
return `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:00`;
|
|
108
|
+
};
|
|
109
|
+
exports.DateTime24HrFormat = DateTime24HrFormat;
|
|
110
|
+
const DateTime12HrFormat = (timestamp, showDate = true, showTime) => {
|
|
111
|
+
const newDate = new Date(timestamp);
|
|
112
|
+
const months = const_value_1.ConstValue.MonthNames;
|
|
113
|
+
const day = String(newDate.getDate()).padStart(2, "0");
|
|
114
|
+
const month = months[newDate.getMonth()];
|
|
115
|
+
const year = newDate.getFullYear();
|
|
116
|
+
let hours = newDate.getHours();
|
|
117
|
+
const minutes = String(newDate.getMinutes()).padStart(2, "0");
|
|
118
|
+
const ampm = hours >= 12 ? "PM" : "AM";
|
|
119
|
+
hours = hours % 12;
|
|
120
|
+
hours = hours ? hours : 12;
|
|
121
|
+
const date = showDate ? `${day} ${month} ${year}` : "";
|
|
122
|
+
const time = showTime ? `${hours}:${minutes} ${ampm}` : "";
|
|
123
|
+
return `${date} ${time}`;
|
|
124
|
+
};
|
|
125
|
+
exports.DateTime12HrFormat = DateTime12HrFormat;
|
|
126
|
+
const DateAndTime = (dateString, timeString) => {
|
|
127
|
+
if (!dateString)
|
|
128
|
+
return null;
|
|
129
|
+
const validTimeString = timeString || "00:00:00";
|
|
130
|
+
const combined = new Date(`${dateString}T${validTimeString}Z`);
|
|
131
|
+
return isNaN(combined.getTime()) ? null : combined;
|
|
132
|
+
};
|
|
133
|
+
exports.DateAndTime = DateAndTime;
|
|
134
|
+
const TimeAgo = (date) => {
|
|
135
|
+
const now = new Date().getTime();
|
|
136
|
+
const diff = now - new Date(date).getTime();
|
|
137
|
+
const minutes = Math.floor(diff / 60000);
|
|
138
|
+
const hours = Math.floor(diff / 3600000);
|
|
139
|
+
const days = Math.floor(diff / 86400000);
|
|
140
|
+
if (days > 1)
|
|
141
|
+
return `${days} days ago`;
|
|
142
|
+
if (days === 1)
|
|
143
|
+
return "1 day ago";
|
|
144
|
+
if (hours > 1)
|
|
145
|
+
return `${hours} hours ago`;
|
|
146
|
+
if (hours === 1)
|
|
147
|
+
return "1 hour ago";
|
|
148
|
+
if (minutes > 1)
|
|
149
|
+
return `${minutes} minutes ago`;
|
|
150
|
+
if (minutes === 1)
|
|
151
|
+
return "1 minute ago";
|
|
152
|
+
return "Just now";
|
|
153
|
+
};
|
|
154
|
+
exports.TimeAgo = TimeAgo;
|
|
88
155
|
const LangText = (data, source, target) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
156
|
if (!data || !source || !target) {
|
|
90
157
|
throw new Error("Invalid input: data, source, or target is missing");
|
|
@@ -109,6 +176,23 @@ const LangText = (data, source, target) => __awaiter(void 0, void 0, void 0, fun
|
|
|
109
176
|
return json.translation || "";
|
|
110
177
|
});
|
|
111
178
|
exports.LangText = LangText;
|
|
179
|
+
const LangCountryCode = (lang) => {
|
|
180
|
+
const countryCode = lang.split("-")[1];
|
|
181
|
+
const country = countries_1.countries.find((c) => c.code === countryCode) || {};
|
|
182
|
+
const language = languages_1.languages.find((l) => l.lang === lang) || {};
|
|
183
|
+
return {
|
|
184
|
+
lang: lang,
|
|
185
|
+
country: countryCode,
|
|
186
|
+
name: language.name,
|
|
187
|
+
locale: language.locale,
|
|
188
|
+
currencyCode: country.currencyCode,
|
|
189
|
+
currency: country.currency,
|
|
190
|
+
telCode: country.telCode,
|
|
191
|
+
flag: country.flag,
|
|
192
|
+
dir: language.dir,
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
exports.LangCountryCode = LangCountryCode;
|
|
112
196
|
const CurrencyConvert = (from, to) => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
197
|
if (!from || !to) {
|
|
114
198
|
throw new Error("Invalid input: from or to is missing");
|
|
@@ -132,20 +216,3 @@ const CurrencyConvert = (from, to) => __awaiter(void 0, void 0, void 0, function
|
|
|
132
216
|
}
|
|
133
217
|
});
|
|
134
218
|
exports.CurrencyConvert = CurrencyConvert;
|
|
135
|
-
const LangCountryCode = (lang) => {
|
|
136
|
-
const countryCode = lang.split("-")[1];
|
|
137
|
-
const country = countries_1.countries.find((c) => c.code === countryCode) || {};
|
|
138
|
-
const language = languages_1.languages.find((l) => l.lang === lang) || {};
|
|
139
|
-
return {
|
|
140
|
-
lang: lang,
|
|
141
|
-
country: countryCode,
|
|
142
|
-
name: language.name,
|
|
143
|
-
locale: language.locale,
|
|
144
|
-
currencyCode: country.currencyCode,
|
|
145
|
-
currency: country.currency,
|
|
146
|
-
telCode: country.telCode,
|
|
147
|
-
flag: country.flag,
|
|
148
|
-
dir: language.dir,
|
|
149
|
-
};
|
|
150
|
-
};
|
|
151
|
-
exports.LangCountryCode = LangCountryCode;
|