@qrvey/utils 1.3.0-0 → 1.3.0-3
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/dist/cjs/dates/adapters/dateToHms.d.ts +6 -0
- package/dist/cjs/dates/adapters/dateToHms.js +18 -0
- package/dist/cjs/dates/adapters/dateToMdyDate.d.ts +6 -0
- package/dist/cjs/dates/adapters/dateToMdyDate.js +19 -0
- package/dist/cjs/dates/adapters/dateToMonthYear.d.ts +6 -0
- package/dist/cjs/dates/adapters/dateToMonthYear.js +18 -0
- package/dist/cjs/dates/adapters/dateToQuarterYear.d.ts +6 -0
- package/dist/cjs/dates/adapters/dateToQuarterYear.js +19 -0
- package/dist/cjs/dates/adapters/dateToWeekYear.d.ts +6 -0
- package/dist/cjs/dates/adapters/dateToWeekYear.js +19 -0
- package/dist/cjs/dates/adapters/dateToYear.d.ts +6 -0
- package/dist/cjs/dates/adapters/dateToYear.js +17 -0
- package/dist/cjs/dates/adapters/mdyDateToDate.d.ts +1 -1
- package/dist/cjs/dates/adapters/monthYearToDate.d.ts +1 -1
- package/dist/cjs/dates/adapters/quarterYearToDate.d.ts +1 -1
- package/dist/cjs/dates/adapters/weekYearToDate.d.ts +1 -1
- package/dist/cjs/dates/adapters/yearToDate.d.ts +1 -1
- package/dist/cjs/dates/helpers/getDateByDateFormat.d.ts +1 -1
- package/dist/cjs/dates/helpers/getFormattedDateByFormat.d.ts +8 -0
- package/dist/cjs/dates/helpers/getFormattedDateByFormat.js +36 -0
- package/dist/cjs/dates/helpers/includeDateTokens.d.ts +9 -0
- package/dist/cjs/dates/helpers/includeDateTokens.js +29 -0
- package/dist/cjs/dates/helpers/index.d.ts +3 -0
- package/dist/cjs/dates/helpers/index.js +3 -0
- package/dist/cjs/general/string/index.d.ts +2 -0
- package/dist/cjs/general/string/index.js +2 -0
- package/dist/cjs/general/string/padLeadingZeros.d.ts +1 -0
- package/dist/cjs/general/string/padLeadingZeros.js +12 -0
- package/dist/cjs/globalization/service/i18nextBuilder.d.ts +9 -0
- package/dist/cjs/globalization/service/i18nextBuilder.js +3 -0
- package/dist/dates/adapters/dateToHms.d.ts +6 -0
- package/dist/dates/adapters/dateToHms.js +14 -0
- package/dist/dates/adapters/dateToMdyDate.d.ts +6 -0
- package/dist/dates/adapters/dateToMdyDate.js +15 -0
- package/dist/dates/adapters/dateToMonthYear.d.ts +6 -0
- package/dist/dates/adapters/dateToMonthYear.js +14 -0
- package/dist/dates/adapters/dateToQuarterYear.d.ts +6 -0
- package/dist/dates/adapters/dateToQuarterYear.js +15 -0
- package/dist/dates/adapters/dateToWeekYear.d.ts +6 -0
- package/dist/dates/adapters/dateToWeekYear.js +15 -0
- package/dist/dates/adapters/dateToYear.d.ts +6 -0
- package/dist/dates/adapters/dateToYear.js +13 -0
- package/dist/dates/adapters/mdyDateToDate.d.ts +1 -1
- package/dist/dates/adapters/monthYearToDate.d.ts +1 -1
- package/dist/dates/adapters/quarterYearToDate.d.ts +1 -1
- package/dist/dates/adapters/weekYearToDate.d.ts +1 -1
- package/dist/dates/adapters/yearToDate.d.ts +1 -1
- package/dist/dates/helpers/getDateByDateFormat.d.ts +1 -1
- package/dist/dates/helpers/getFormattedDateByFormat.d.ts +8 -0
- package/dist/dates/helpers/getFormattedDateByFormat.js +32 -0
- package/dist/dates/helpers/includeDateTokens.d.ts +9 -0
- package/dist/dates/helpers/includeDateTokens.js +25 -0
- package/dist/dates/helpers/index.d.ts +3 -0
- package/dist/dates/helpers/index.js +3 -0
- package/dist/general/string/index.d.ts +2 -0
- package/dist/general/string/index.js +2 -0
- package/dist/general/string/padLeadingZeros.d.ts +1 -0
- package/dist/general/string/padLeadingZeros.js +8 -0
- package/dist/globalization/service/i18nextBuilder.d.ts +9 -0
- package/dist/globalization/service/i18nextBuilder.js +3 -0
- package/package.json +10 -13
- package/scripts/generating-docs/index.js +2 -2
- package/src/dates/adapters/dateToHms.ts +15 -0
- package/src/dates/adapters/dateToMdyDate.ts +16 -0
- package/src/dates/adapters/dateToMonthYear.ts +15 -0
- package/src/dates/adapters/dateToQuarterYear.ts +16 -0
- package/src/dates/adapters/dateToWeekYear.ts +16 -0
- package/src/dates/adapters/dateToYear.ts +14 -0
- package/src/dates/adapters/mdyDateToDate.ts +1 -1
- package/src/dates/adapters/monthYearToDate.ts +1 -1
- package/src/dates/adapters/quarterYearToDate.ts +1 -1
- package/src/dates/adapters/weekYearToDate.ts +1 -1
- package/src/dates/adapters/yearToDate.ts +1 -1
- package/src/dates/helpers/getDateByDateFormat.ts +1 -1
- package/src/dates/helpers/getFormattedDateByFormat.ts +29 -0
- package/src/dates/helpers/includeDateTokens.ts +26 -0
- package/src/dates/helpers/index.ts +3 -0
- package/src/general/string/index.ts +3 -1
- package/src/general/string/padLeadingZeros.ts +7 -0
- package/src/globalization/service/i18nextBuilder.ts +10 -0
- package/tsconfig.doc.json +4 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateToHms = void 0;
|
|
4
|
+
const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
5
|
+
const padLeadingZeros_1 = require("../../general/string/padLeadingZeros");
|
|
6
|
+
const isTokenLabel_1 = require("../../tokens/isTokenLabel");
|
|
7
|
+
/**
|
|
8
|
+
* * Transform a Date to [HH:mm:ss] date format.
|
|
9
|
+
* @param date String, object or millisencond number of the date
|
|
10
|
+
* @returns string of [HH:mm:ss] date format
|
|
11
|
+
*/
|
|
12
|
+
function dateToHms(date) {
|
|
13
|
+
if ((0, isEmpty_1.isEmpty)(date) || (0, isTokenLabel_1.isTokenLabel)(date))
|
|
14
|
+
return date;
|
|
15
|
+
const dt = new Date(date.valueOf());
|
|
16
|
+
return (0, padLeadingZeros_1.padLeadingZeros)(dt.getHours(), 2).slice(-2) + ':' + (0, padLeadingZeros_1.padLeadingZeros)(dt.getMinutes(), 2).slice(-2) + ':' + (0, padLeadingZeros_1.padLeadingZeros)(dt.getSeconds(), 2).slice(-2);
|
|
17
|
+
}
|
|
18
|
+
exports.dateToHms = dateToHms;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform a Date to [mm/dd/yyyy] date format.
|
|
3
|
+
* @param date String, object or millisencond number of the date
|
|
4
|
+
* @returns string of [mm/dd/yyyy] date format
|
|
5
|
+
*/
|
|
6
|
+
export declare function dateToMdyDate(date: string | Date | number, includeTime?: boolean): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateToMdyDate = void 0;
|
|
4
|
+
const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
5
|
+
const padLeadingZeros_1 = require("../../general/string/padLeadingZeros");
|
|
6
|
+
const isTokenLabel_1 = require("../../tokens/isTokenLabel");
|
|
7
|
+
const dateToHms_1 = require("./dateToHms");
|
|
8
|
+
/**
|
|
9
|
+
* Transform a Date to [mm/dd/yyyy] date format.
|
|
10
|
+
* @param date String, object or millisencond number of the date
|
|
11
|
+
* @returns string of [mm/dd/yyyy] date format
|
|
12
|
+
*/
|
|
13
|
+
function dateToMdyDate(date, includeTime) {
|
|
14
|
+
if ((0, isEmpty_1.isEmpty)(date) || (0, isTokenLabel_1.isTokenLabel)(date))
|
|
15
|
+
return date;
|
|
16
|
+
const dt = new Date(date.valueOf());
|
|
17
|
+
return (0, padLeadingZeros_1.padLeadingZeros)(dt.getMonth() + 1, 2).slice(-2) + '/' + (0, padLeadingZeros_1.padLeadingZeros)(dt.getDate(), 2).slice(-2) + '/' + (0, padLeadingZeros_1.padLeadingZeros)(dt.getFullYear(), 4) + (includeTime ? ' ' + (0, dateToHms_1.dateToHms)(date) : '');
|
|
18
|
+
}
|
|
19
|
+
exports.dateToMdyDate = dateToMdyDate;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateToMonthYear = void 0;
|
|
4
|
+
const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
5
|
+
const isTokenLabel_1 = require("../../tokens/isTokenLabel");
|
|
6
|
+
const DATE_YEAR_MONTHS_1 = require("../constants/DATE_YEAR_MONTHS");
|
|
7
|
+
/**
|
|
8
|
+
* Transform a Date to [Month Year] date format.
|
|
9
|
+
* @param date String, object or millisencond number of the date
|
|
10
|
+
* @returns string of [Month Year] date format
|
|
11
|
+
*/
|
|
12
|
+
function dateToMonthYear(date) {
|
|
13
|
+
if ((0, isEmpty_1.isEmpty)(date) || (0, isTokenLabel_1.isTokenLabel)(date))
|
|
14
|
+
return date;
|
|
15
|
+
const dt = new Date(date.valueOf());
|
|
16
|
+
return DATE_YEAR_MONTHS_1.DATE_YEAR_MONTHS[dt.getMonth()] + ' ' + dt.getFullYear();
|
|
17
|
+
}
|
|
18
|
+
exports.dateToMonthYear = dateToMonthYear;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateToQuarterYear = void 0;
|
|
4
|
+
const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
5
|
+
const isTokenLabel_1 = require("../../tokens/isTokenLabel");
|
|
6
|
+
const DATE_YEAR_QUARTERS_1 = require("../constants/DATE_YEAR_QUARTERS");
|
|
7
|
+
/**
|
|
8
|
+
* Transform a Date to [Quarter Year] date format.
|
|
9
|
+
* @param date String, object or millisencond number of the date
|
|
10
|
+
* @returns string of [Quarter Year] date format
|
|
11
|
+
*/
|
|
12
|
+
function dateToQuarterYear(date) {
|
|
13
|
+
if ((0, isEmpty_1.isEmpty)(date) || (0, isTokenLabel_1.isTokenLabel)(date))
|
|
14
|
+
return date;
|
|
15
|
+
const dt = new Date(date.valueOf());
|
|
16
|
+
const quarter = Math.ceil((dt.getMonth() + 1) / 3);
|
|
17
|
+
return DATE_YEAR_QUARTERS_1.DATE_YEAR_QUARTERS[quarter - 1] + ' ' + dt.getFullYear();
|
|
18
|
+
}
|
|
19
|
+
exports.dateToQuarterYear = dateToQuarterYear;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateToWeekYear = void 0;
|
|
4
|
+
const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
5
|
+
const isTokenLabel_1 = require("../../tokens/isTokenLabel");
|
|
6
|
+
const getWeek_1 = require("../helpers/getWeek");
|
|
7
|
+
/**
|
|
8
|
+
* Transform a Date to [W# Year] date format.
|
|
9
|
+
* @param date String, object or millisencond number of the date
|
|
10
|
+
* @returns string of [W# Year] date format
|
|
11
|
+
*/
|
|
12
|
+
function dateToWeekYear(date) {
|
|
13
|
+
if ((0, isEmpty_1.isEmpty)(date) || (0, isTokenLabel_1.isTokenLabel)(date))
|
|
14
|
+
return date;
|
|
15
|
+
const dt = new Date(date.valueOf());
|
|
16
|
+
const weekObj = (0, getWeek_1.getWeek)(dt);
|
|
17
|
+
return `W${weekObj.week} ${weekObj.year}`;
|
|
18
|
+
}
|
|
19
|
+
exports.dateToWeekYear = dateToWeekYear;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateToYear = void 0;
|
|
4
|
+
const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
5
|
+
const isTokenLabel_1 = require("../../tokens/isTokenLabel");
|
|
6
|
+
/**
|
|
7
|
+
* Transform a Date to [Year] date format.
|
|
8
|
+
* @param date String, object or millisencond number of the date
|
|
9
|
+
* @returns string of [Year] date format
|
|
10
|
+
*/
|
|
11
|
+
function dateToYear(date) {
|
|
12
|
+
if ((0, isEmpty_1.isEmpty)(date) || (0, isTokenLabel_1.isTokenLabel)(date))
|
|
13
|
+
return date;
|
|
14
|
+
const dt = new Date(date.valueOf());
|
|
15
|
+
return String(dt.getFullYear());
|
|
16
|
+
}
|
|
17
|
+
exports.dateToYear = dateToYear;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param time Flag to parse the object date to milliseconds.
|
|
5
5
|
* @returns The date object or the date in milliseconds
|
|
6
6
|
*/
|
|
7
|
-
export declare function mdyDateToDate(date: string, time?: boolean): string |
|
|
7
|
+
export declare function mdyDateToDate(date: string, time?: boolean): string | Date | number;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param time Flag to parse the object date to milliseconds.
|
|
5
5
|
* @returns The date object or the date in milliseconds
|
|
6
6
|
*/
|
|
7
|
-
export declare function monthYearToDate(monthYearDate: string, time?: boolean): string |
|
|
7
|
+
export declare function monthYearToDate(monthYearDate: string, time?: boolean): string | Date | number;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param time Flag to parse the object date to milliseconds.
|
|
5
5
|
* @returns The date object or the date in milliseconds
|
|
6
6
|
*/
|
|
7
|
-
export declare function quarterYearToDate(quarterYearDate: string, time?: boolean): string |
|
|
7
|
+
export declare function quarterYearToDate(quarterYearDate: string, time?: boolean): string | Date | number;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param time Flag to parse the object date to milliseconds.
|
|
5
5
|
* @returns The date object or the date in milliseconds
|
|
6
6
|
*/
|
|
7
|
-
export declare function weekYearToDate(weekYear: string, time?: boolean): string |
|
|
7
|
+
export declare function weekYearToDate(weekYear: string, time?: boolean): string | Date | number;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param time Flag to parse the object date to milliseconds.
|
|
5
5
|
* @returns The date object or the date in milliseconds
|
|
6
6
|
*/
|
|
7
|
-
export declare function yearToDate(yearDate: string, time?: boolean): string |
|
|
7
|
+
export declare function yearToDate(yearDate: string, time?: boolean): string | Date | number;
|
|
@@ -6,4 +6,4 @@ import { IDateFormat } from "../interfaces/IDateFormat";
|
|
|
6
6
|
* @param time flag to convert the formatted date to miliseconds
|
|
7
7
|
* @returns a Date object, milisecond time or the same value if date format does not match.
|
|
8
8
|
*/
|
|
9
|
-
export declare function getDateByDateFormat(date: string, format: IDateFormat, time?: boolean): string |
|
|
9
|
+
export declare function getDateByDateFormat(date: string, format: IDateFormat, time?: boolean): string | Date | number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IDateFormat } from "../interfaces/IDateFormat";
|
|
2
|
+
/**
|
|
3
|
+
* A Date object, string or millisecond number are gotten in order to convert it in an formatted string date
|
|
4
|
+
* @param date String with a formatted date
|
|
5
|
+
* @param format The date format
|
|
6
|
+
* @returns a formmatted date or the same value if format does not match
|
|
7
|
+
*/
|
|
8
|
+
export declare function getFormattedDateByFormat(date: string | Date | number, format: IDateFormat): string | Date | number;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFormattedDateByFormat = void 0;
|
|
4
|
+
const dateToMdyDate_1 = require("../adapters/dateToMdyDate");
|
|
5
|
+
const dateToMonthYear_1 = require("../adapters/dateToMonthYear");
|
|
6
|
+
const dateToQuarterYear_1 = require("../adapters/dateToQuarterYear");
|
|
7
|
+
const dateToWeekYear_1 = require("../adapters/dateToWeekYear");
|
|
8
|
+
const dateToYear_1 = require("../adapters/dateToYear");
|
|
9
|
+
const DATE_FORMAT_1 = require("../constants/DATE_FORMAT");
|
|
10
|
+
/**
|
|
11
|
+
* A Date object, string or millisecond number are gotten in order to convert it in an formatted string date
|
|
12
|
+
* @param date String with a formatted date
|
|
13
|
+
* @param format The date format
|
|
14
|
+
* @returns a formmatted date or the same value if format does not match
|
|
15
|
+
*/
|
|
16
|
+
function getFormattedDateByFormat(date, format) {
|
|
17
|
+
if (format === DATE_FORMAT_1.DATE_FORMAT.QUARTER) {
|
|
18
|
+
return (0, dateToQuarterYear_1.dateToQuarterYear)(date);
|
|
19
|
+
}
|
|
20
|
+
else if (format === DATE_FORMAT_1.DATE_FORMAT.MONTH) {
|
|
21
|
+
return (0, dateToMonthYear_1.dateToMonthYear)(date);
|
|
22
|
+
}
|
|
23
|
+
else if (format === DATE_FORMAT_1.DATE_FORMAT.YEAR) {
|
|
24
|
+
return (0, dateToYear_1.dateToYear)(date);
|
|
25
|
+
}
|
|
26
|
+
else if (format === DATE_FORMAT_1.DATE_FORMAT.WEEK) {
|
|
27
|
+
return (0, dateToWeekYear_1.dateToWeekYear)(date);
|
|
28
|
+
}
|
|
29
|
+
else if (format === DATE_FORMAT_1.DATE_FORMAT.DAY) {
|
|
30
|
+
return (0, dateToMdyDate_1.dateToMdyDate)(date);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return date;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.getFormattedDateByFormat = getFormattedDateByFormat;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IDateFormat } from "../interfaces/IDateFormat";
|
|
2
|
+
/**
|
|
3
|
+
* Determines if the given date has tokens. The date is splitted depending on date format.
|
|
4
|
+
* Undefined date is returning false.
|
|
5
|
+
* @param date The string of the date. It may contain tokens.
|
|
6
|
+
* @param format The date format
|
|
7
|
+
* @returns true: include tokens; false: otherwise
|
|
8
|
+
*/
|
|
9
|
+
export declare function includeDateTokens(date: string, format: IDateFormat): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.includeDateTokens = void 0;
|
|
4
|
+
const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
5
|
+
const isTokenLabel_1 = require("../../tokens/isTokenLabel");
|
|
6
|
+
const getSeparatorByDateFormat_1 = require("./getSeparatorByDateFormat");
|
|
7
|
+
/**
|
|
8
|
+
* Determines if the given date has tokens. The date is splitted depending on date format.
|
|
9
|
+
* Undefined date is returning false.
|
|
10
|
+
* @param date The string of the date. It may contain tokens.
|
|
11
|
+
* @param format The date format
|
|
12
|
+
* @returns true: include tokens; false: otherwise
|
|
13
|
+
*/
|
|
14
|
+
function includeDateTokens(date, format) {
|
|
15
|
+
let hasTokens = false;
|
|
16
|
+
if (!(0, isEmpty_1.isEmpty)(date)) {
|
|
17
|
+
if ((0, isTokenLabel_1.isTokenLabel)(date))
|
|
18
|
+
hasTokens = true;
|
|
19
|
+
else {
|
|
20
|
+
const separator = (0, getSeparatorByDateFormat_1.getSeparatorByDateFormat)(format);
|
|
21
|
+
if (separator != null) {
|
|
22
|
+
const tokens = date.split(separator);
|
|
23
|
+
hasTokens = tokens.some(token => (0, isTokenLabel_1.isTokenLabel)(token));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return hasTokens;
|
|
28
|
+
}
|
|
29
|
+
exports.includeDateTokens = includeDateTokens;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
export * from './getDateByDateFormat';
|
|
1
2
|
export * from './getDateFormatByProperty';
|
|
2
3
|
export * from './getDateFormatRegularExpressionInArray';
|
|
4
|
+
export * from './getFormattedDateByFormat';
|
|
3
5
|
export * from './getSeparatorByDateFormat';
|
|
6
|
+
export * from './includeDateTokens';
|
|
4
7
|
export * from './getWeek';
|
|
5
8
|
export * from './validateDate';
|
|
6
9
|
export * from './validateDateByDateFormat';
|
|
@@ -14,9 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./getDateByDateFormat"), exports);
|
|
17
18
|
__exportStar(require("./getDateFormatByProperty"), exports);
|
|
18
19
|
__exportStar(require("./getDateFormatRegularExpressionInArray"), exports);
|
|
20
|
+
__exportStar(require("./getFormattedDateByFormat"), exports);
|
|
19
21
|
__exportStar(require("./getSeparatorByDateFormat"), exports);
|
|
22
|
+
__exportStar(require("./includeDateTokens"), exports);
|
|
20
23
|
__exportStar(require("./getWeek"), exports);
|
|
21
24
|
__exportStar(require("./validateDate"), exports);
|
|
22
25
|
__exportStar(require("./validateDateByDateFormat"), exports);
|
|
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./capitalize"), exports);
|
|
18
|
+
__exportStar(require("./padLeadingZeros"), exports);
|
|
19
|
+
__exportStar(require("./parseUrl"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function padLeadingZeros(num: number | string, size?: number): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.padLeadingZeros = void 0;
|
|
4
|
+
function padLeadingZeros(num, size = 0) {
|
|
5
|
+
if (isNaN(Number(num)))
|
|
6
|
+
return String(num);
|
|
7
|
+
let s = num + "";
|
|
8
|
+
while (s.length < size)
|
|
9
|
+
s = "0" + s;
|
|
10
|
+
return s;
|
|
11
|
+
}
|
|
12
|
+
exports.padLeadingZeros = padLeadingZeros;
|
|
@@ -5,6 +5,15 @@ export declare class I18nServiceBuilder {
|
|
|
5
5
|
private static _initI18n;
|
|
6
6
|
static setTranslations(i18nDefault: any, i18nResource: II18nResource): II18nResource;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* This class allows to use the translation service of the i18next library
|
|
10
|
+
*/
|
|
8
11
|
export declare abstract class I18nService {
|
|
12
|
+
/**
|
|
13
|
+
* This method by means of the key searches in the configuration object, replaces the values received by means of the options parameter and returns the translated text. Ex: <b>translate('the_value_is {{number}}',{number: 1});</b>
|
|
14
|
+
* @param key String used as key
|
|
15
|
+
* @param options Object of type II18nServiceTranslateOption that contains the dynamic parameters to replace
|
|
16
|
+
* @returns The translated text Ex: <b>The value is: 1</b>
|
|
17
|
+
*/
|
|
9
18
|
abstract translate(key: string, options?: II18nServiceTranslateOption): string;
|
|
10
19
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { padLeadingZeros } from "../../general/string/padLeadingZeros";
|
|
3
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
4
|
+
/**
|
|
5
|
+
* * Transform a Date to [HH:mm:ss] date format.
|
|
6
|
+
* @param date String, object or millisencond number of the date
|
|
7
|
+
* @returns string of [HH:mm:ss] date format
|
|
8
|
+
*/
|
|
9
|
+
export function dateToHms(date) {
|
|
10
|
+
if (isEmpty(date) || isTokenLabel(date))
|
|
11
|
+
return date;
|
|
12
|
+
const dt = new Date(date.valueOf());
|
|
13
|
+
return padLeadingZeros(dt.getHours(), 2).slice(-2) + ':' + padLeadingZeros(dt.getMinutes(), 2).slice(-2) + ':' + padLeadingZeros(dt.getSeconds(), 2).slice(-2);
|
|
14
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform a Date to [mm/dd/yyyy] date format.
|
|
3
|
+
* @param date String, object or millisencond number of the date
|
|
4
|
+
* @returns string of [mm/dd/yyyy] date format
|
|
5
|
+
*/
|
|
6
|
+
export declare function dateToMdyDate(date: string | Date | number, includeTime?: boolean): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { padLeadingZeros } from "../../general/string/padLeadingZeros";
|
|
3
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
4
|
+
import { dateToHms } from "./dateToHms";
|
|
5
|
+
/**
|
|
6
|
+
* Transform a Date to [mm/dd/yyyy] date format.
|
|
7
|
+
* @param date String, object or millisencond number of the date
|
|
8
|
+
* @returns string of [mm/dd/yyyy] date format
|
|
9
|
+
*/
|
|
10
|
+
export function dateToMdyDate(date, includeTime) {
|
|
11
|
+
if (isEmpty(date) || isTokenLabel(date))
|
|
12
|
+
return date;
|
|
13
|
+
const dt = new Date(date.valueOf());
|
|
14
|
+
return padLeadingZeros(dt.getMonth() + 1, 2).slice(-2) + '/' + padLeadingZeros(dt.getDate(), 2).slice(-2) + '/' + padLeadingZeros(dt.getFullYear(), 4) + (includeTime ? ' ' + dateToHms(date) : '');
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
3
|
+
import { DATE_YEAR_MONTHS } from "../constants/DATE_YEAR_MONTHS";
|
|
4
|
+
/**
|
|
5
|
+
* Transform a Date to [Month Year] date format.
|
|
6
|
+
* @param date String, object or millisencond number of the date
|
|
7
|
+
* @returns string of [Month Year] date format
|
|
8
|
+
*/
|
|
9
|
+
export function dateToMonthYear(date) {
|
|
10
|
+
if (isEmpty(date) || isTokenLabel(date))
|
|
11
|
+
return date;
|
|
12
|
+
const dt = new Date(date.valueOf());
|
|
13
|
+
return DATE_YEAR_MONTHS[dt.getMonth()] + ' ' + dt.getFullYear();
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
3
|
+
import { DATE_YEAR_QUARTERS } from "../constants/DATE_YEAR_QUARTERS";
|
|
4
|
+
/**
|
|
5
|
+
* Transform a Date to [Quarter Year] date format.
|
|
6
|
+
* @param date String, object or millisencond number of the date
|
|
7
|
+
* @returns string of [Quarter Year] date format
|
|
8
|
+
*/
|
|
9
|
+
export function dateToQuarterYear(date) {
|
|
10
|
+
if (isEmpty(date) || isTokenLabel(date))
|
|
11
|
+
return date;
|
|
12
|
+
const dt = new Date(date.valueOf());
|
|
13
|
+
const quarter = Math.ceil((dt.getMonth() + 1) / 3);
|
|
14
|
+
return DATE_YEAR_QUARTERS[quarter - 1] + ' ' + dt.getFullYear();
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
3
|
+
import { getWeek } from "../helpers/getWeek";
|
|
4
|
+
/**
|
|
5
|
+
* Transform a Date to [W# Year] date format.
|
|
6
|
+
* @param date String, object or millisencond number of the date
|
|
7
|
+
* @returns string of [W# Year] date format
|
|
8
|
+
*/
|
|
9
|
+
export function dateToWeekYear(date) {
|
|
10
|
+
if (isEmpty(date) || isTokenLabel(date))
|
|
11
|
+
return date;
|
|
12
|
+
const dt = new Date(date.valueOf());
|
|
13
|
+
const weekObj = getWeek(dt);
|
|
14
|
+
return `W${weekObj.week} ${weekObj.year}`;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
3
|
+
/**
|
|
4
|
+
* Transform a Date to [Year] date format.
|
|
5
|
+
* @param date String, object or millisencond number of the date
|
|
6
|
+
* @returns string of [Year] date format
|
|
7
|
+
*/
|
|
8
|
+
export function dateToYear(date) {
|
|
9
|
+
if (isEmpty(date) || isTokenLabel(date))
|
|
10
|
+
return date;
|
|
11
|
+
const dt = new Date(date.valueOf());
|
|
12
|
+
return String(dt.getFullYear());
|
|
13
|
+
}
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param time Flag to parse the object date to milliseconds.
|
|
5
5
|
* @returns The date object or the date in milliseconds
|
|
6
6
|
*/
|
|
7
|
-
export declare function mdyDateToDate(date: string, time?: boolean): string |
|
|
7
|
+
export declare function mdyDateToDate(date: string, time?: boolean): string | Date | number;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param time Flag to parse the object date to milliseconds.
|
|
5
5
|
* @returns The date object or the date in milliseconds
|
|
6
6
|
*/
|
|
7
|
-
export declare function monthYearToDate(monthYearDate: string, time?: boolean): string |
|
|
7
|
+
export declare function monthYearToDate(monthYearDate: string, time?: boolean): string | Date | number;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param time Flag to parse the object date to milliseconds.
|
|
5
5
|
* @returns The date object or the date in milliseconds
|
|
6
6
|
*/
|
|
7
|
-
export declare function quarterYearToDate(quarterYearDate: string, time?: boolean): string |
|
|
7
|
+
export declare function quarterYearToDate(quarterYearDate: string, time?: boolean): string | Date | number;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param time Flag to parse the object date to milliseconds.
|
|
5
5
|
* @returns The date object or the date in milliseconds
|
|
6
6
|
*/
|
|
7
|
-
export declare function weekYearToDate(weekYear: string, time?: boolean): string |
|
|
7
|
+
export declare function weekYearToDate(weekYear: string, time?: boolean): string | Date | number;
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @param time Flag to parse the object date to milliseconds.
|
|
5
5
|
* @returns The date object or the date in milliseconds
|
|
6
6
|
*/
|
|
7
|
-
export declare function yearToDate(yearDate: string, time?: boolean): string |
|
|
7
|
+
export declare function yearToDate(yearDate: string, time?: boolean): string | Date | number;
|
|
@@ -6,4 +6,4 @@ import { IDateFormat } from "../interfaces/IDateFormat";
|
|
|
6
6
|
* @param time flag to convert the formatted date to miliseconds
|
|
7
7
|
* @returns a Date object, milisecond time or the same value if date format does not match.
|
|
8
8
|
*/
|
|
9
|
-
export declare function getDateByDateFormat(date: string, format: IDateFormat, time?: boolean): string |
|
|
9
|
+
export declare function getDateByDateFormat(date: string, format: IDateFormat, time?: boolean): string | Date | number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IDateFormat } from "../interfaces/IDateFormat";
|
|
2
|
+
/**
|
|
3
|
+
* A Date object, string or millisecond number are gotten in order to convert it in an formatted string date
|
|
4
|
+
* @param date String with a formatted date
|
|
5
|
+
* @param format The date format
|
|
6
|
+
* @returns a formmatted date or the same value if format does not match
|
|
7
|
+
*/
|
|
8
|
+
export declare function getFormattedDateByFormat(date: string | Date | number, format: IDateFormat): string | Date | number;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { dateToMdyDate } from "../adapters/dateToMdyDate";
|
|
2
|
+
import { dateToMonthYear } from "../adapters/dateToMonthYear";
|
|
3
|
+
import { dateToQuarterYear } from "../adapters/dateToQuarterYear";
|
|
4
|
+
import { dateToWeekYear } from "../adapters/dateToWeekYear";
|
|
5
|
+
import { dateToYear } from "../adapters/dateToYear";
|
|
6
|
+
import { DATE_FORMAT } from "../constants/DATE_FORMAT";
|
|
7
|
+
/**
|
|
8
|
+
* A Date object, string or millisecond number are gotten in order to convert it in an formatted string date
|
|
9
|
+
* @param date String with a formatted date
|
|
10
|
+
* @param format The date format
|
|
11
|
+
* @returns a formmatted date or the same value if format does not match
|
|
12
|
+
*/
|
|
13
|
+
export function getFormattedDateByFormat(date, format) {
|
|
14
|
+
if (format === DATE_FORMAT.QUARTER) {
|
|
15
|
+
return dateToQuarterYear(date);
|
|
16
|
+
}
|
|
17
|
+
else if (format === DATE_FORMAT.MONTH) {
|
|
18
|
+
return dateToMonthYear(date);
|
|
19
|
+
}
|
|
20
|
+
else if (format === DATE_FORMAT.YEAR) {
|
|
21
|
+
return dateToYear(date);
|
|
22
|
+
}
|
|
23
|
+
else if (format === DATE_FORMAT.WEEK) {
|
|
24
|
+
return dateToWeekYear(date);
|
|
25
|
+
}
|
|
26
|
+
else if (format === DATE_FORMAT.DAY) {
|
|
27
|
+
return dateToMdyDate(date);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return date;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IDateFormat } from "../interfaces/IDateFormat";
|
|
2
|
+
/**
|
|
3
|
+
* Determines if the given date has tokens. The date is splitted depending on date format.
|
|
4
|
+
* Undefined date is returning false.
|
|
5
|
+
* @param date The string of the date. It may contain tokens.
|
|
6
|
+
* @param format The date format
|
|
7
|
+
* @returns true: include tokens; false: otherwise
|
|
8
|
+
*/
|
|
9
|
+
export declare function includeDateTokens(date: string, format: IDateFormat): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
3
|
+
import { getSeparatorByDateFormat } from "./getSeparatorByDateFormat";
|
|
4
|
+
/**
|
|
5
|
+
* Determines if the given date has tokens. The date is splitted depending on date format.
|
|
6
|
+
* Undefined date is returning false.
|
|
7
|
+
* @param date The string of the date. It may contain tokens.
|
|
8
|
+
* @param format The date format
|
|
9
|
+
* @returns true: include tokens; false: otherwise
|
|
10
|
+
*/
|
|
11
|
+
export function includeDateTokens(date, format) {
|
|
12
|
+
let hasTokens = false;
|
|
13
|
+
if (!isEmpty(date)) {
|
|
14
|
+
if (isTokenLabel(date))
|
|
15
|
+
hasTokens = true;
|
|
16
|
+
else {
|
|
17
|
+
const separator = getSeparatorByDateFormat(format);
|
|
18
|
+
if (separator != null) {
|
|
19
|
+
const tokens = date.split(separator);
|
|
20
|
+
hasTokens = tokens.some(token => isTokenLabel(token));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return hasTokens;
|
|
25
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
export * from './getDateByDateFormat';
|
|
1
2
|
export * from './getDateFormatByProperty';
|
|
2
3
|
export * from './getDateFormatRegularExpressionInArray';
|
|
4
|
+
export * from './getFormattedDateByFormat';
|
|
3
5
|
export * from './getSeparatorByDateFormat';
|
|
6
|
+
export * from './includeDateTokens';
|
|
4
7
|
export * from './getWeek';
|
|
5
8
|
export * from './validateDate';
|
|
6
9
|
export * from './validateDateByDateFormat';
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
export * from './getDateByDateFormat';
|
|
1
2
|
export * from './getDateFormatByProperty';
|
|
2
3
|
export * from './getDateFormatRegularExpressionInArray';
|
|
4
|
+
export * from './getFormattedDateByFormat';
|
|
3
5
|
export * from './getSeparatorByDateFormat';
|
|
6
|
+
export * from './includeDateTokens';
|
|
4
7
|
export * from './getWeek';
|
|
5
8
|
export * from './validateDate';
|
|
6
9
|
export * from './validateDateByDateFormat';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function padLeadingZeros(num: number | string, size?: number): string;
|
|
@@ -5,6 +5,15 @@ export declare class I18nServiceBuilder {
|
|
|
5
5
|
private static _initI18n;
|
|
6
6
|
static setTranslations(i18nDefault: any, i18nResource: II18nResource): II18nResource;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* This class allows to use the translation service of the i18next library
|
|
10
|
+
*/
|
|
8
11
|
export declare abstract class I18nService {
|
|
12
|
+
/**
|
|
13
|
+
* This method by means of the key searches in the configuration object, replaces the values received by means of the options parameter and returns the translated text. Ex: <b>translate('the_value_is {{number}}',{number: 1});</b>
|
|
14
|
+
* @param key String used as key
|
|
15
|
+
* @param options Object of type II18nServiceTranslateOption that contains the dynamic parameters to replace
|
|
16
|
+
* @returns The translated text Ex: <b>The value is: 1</b>
|
|
17
|
+
*/
|
|
9
18
|
abstract translate(key: string, options?: II18nServiceTranslateOption): string;
|
|
10
19
|
}
|
|
@@ -40,6 +40,9 @@ export class I18nServiceBuilder {
|
|
|
40
40
|
return mergeDeep(i18nResource, i18nDefault, { mergeExistingValues: false });
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* This class allows to use the translation service of the i18next library
|
|
45
|
+
*/
|
|
43
46
|
export class I18nService {
|
|
44
47
|
}
|
|
45
48
|
class I18nServiceConcrete extends I18nService {
|
package/package.json
CHANGED
|
@@ -1,42 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qrvey/utils",
|
|
3
|
-
"version": "1.3.0-
|
|
3
|
+
"version": "1.3.0-3",
|
|
4
4
|
"description": "Helper, Utils for all Qrvey Projects",
|
|
5
5
|
"homepage": "https://bitbucket.org/qrvey/qrvey_utils/wiki/Home",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc && tsc -m commonjs --outDir dist/cjs",
|
|
9
9
|
"build-clean": "node ./scripts/clean-build",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"compodoc": "npx compodoc -p tsconfig.doc.json",
|
|
11
|
+
"compodoc:server": "./node_modules/.bin/compodoc -p ./tsconfig.doc.json -s --port=4400",
|
|
12
12
|
"lint": "eslint src --quiet --exit-on-fatal-error --ext .ts,.js",
|
|
13
13
|
"lint-dev": "eslint src --debug --ext .ts,.tsx",
|
|
14
14
|
"publishing-old": "node ./scripts/prepare-publish && np",
|
|
15
15
|
"publishing-prerelease-old": "node ./scripts/prepare-publish && np --any-branch --tag=$npm_config_tag",
|
|
16
16
|
"publishing-beta-1": "node ./scripts/publishing --np-new-version=$npm_config_np_new_version --np-any-branch=$npm_config_np_any_branch --np-tag=$npm_config_np_tag",
|
|
17
|
-
"publishing-beta-2": "node ./scripts/clean-build && node ./scripts/generating-docs && np --any-branch --
|
|
17
|
+
"publishing-beta-2": "node ./scripts/clean-build && node ./scripts/generating-docs --np-new-version=$npm_config_np_new_version && np $npm_config_np_new_version --any-branch --tag=$npm_config_np_tag",
|
|
18
18
|
"test": "jest test",
|
|
19
19
|
"test:watch": "jest --watch test"
|
|
20
20
|
},
|
|
21
21
|
"author": "Qrvey Inc",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@types/jest": "27.4.1",
|
|
25
|
-
"@typescript-eslint/eslint-plugin": "5.22.0",
|
|
26
|
-
"@typescript-eslint/parser": "5.22.0",
|
|
27
|
-
"doxdox": "3.0.0",
|
|
28
24
|
"eslint": "8.14.0",
|
|
29
25
|
"jest": "27.5.1",
|
|
30
|
-
"jsdoc": "3.6.10",
|
|
31
26
|
"np": "7.6.1",
|
|
32
27
|
"typedoc": "0.22.15",
|
|
33
|
-
"typescript": "4.6.4"
|
|
28
|
+
"typescript": "4.6.4",
|
|
29
|
+
"@compodoc/compodoc": "1.1.19",
|
|
30
|
+
"@types/jest": "27.4.1",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "5.22.0",
|
|
32
|
+
"@typescript-eslint/parser": "5.22.0"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
35
|
"d3": "6.3.1",
|
|
36
|
+
"dayjs": "1.11.1",
|
|
37
37
|
"i18next": "21.6.16"
|
|
38
|
-
},
|
|
39
|
-
"peerDependencies": {
|
|
40
|
-
"dayjs": ">=1.11.1 <1.12.0"
|
|
41
38
|
}
|
|
42
39
|
}
|
|
@@ -67,9 +67,9 @@ async function startGeneratingDocs(settings) {
|
|
|
67
67
|
await pushingChanges(settings);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
async function generatingDocument(
|
|
70
|
+
async function generatingDocument(_settings) {
|
|
71
71
|
console.log('==>>> Generating Document...');
|
|
72
|
-
await execute(
|
|
72
|
+
await execute('npm run compodoc');
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
async function changingVersion(settings) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { padLeadingZeros } from "../../general/string/padLeadingZeros";
|
|
3
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* * Transform a Date to [HH:mm:ss] date format.
|
|
7
|
+
* @param date String, object or millisencond number of the date
|
|
8
|
+
* @returns string of [HH:mm:ss] date format
|
|
9
|
+
*/
|
|
10
|
+
export function dateToHms(date: string | Date | number) {
|
|
11
|
+
if (isEmpty(date) || isTokenLabel(date as any)) return date as any;
|
|
12
|
+
|
|
13
|
+
const dt = new Date(date.valueOf());
|
|
14
|
+
return padLeadingZeros(dt.getHours(), 2).slice(-2) + ':' + padLeadingZeros(dt.getMinutes(), 2).slice(-2) + ':' + padLeadingZeros(dt.getSeconds(), 2).slice(-2);
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { padLeadingZeros } from "../../general/string/padLeadingZeros";
|
|
3
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
4
|
+
import { dateToHms } from "./dateToHms";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Transform a Date to [mm/dd/yyyy] date format.
|
|
8
|
+
* @param date String, object or millisencond number of the date
|
|
9
|
+
* @returns string of [mm/dd/yyyy] date format
|
|
10
|
+
*/
|
|
11
|
+
export function dateToMdyDate(date: string | Date | number, includeTime?: boolean): string{
|
|
12
|
+
if (isEmpty(date) || isTokenLabel(date as any)) return date as any;
|
|
13
|
+
|
|
14
|
+
const dt = new Date(date.valueOf());
|
|
15
|
+
return padLeadingZeros(dt.getMonth() + 1, 2).slice(-2) + '/' + padLeadingZeros(dt.getDate(), 2).slice(-2) + '/' + padLeadingZeros(dt.getFullYear(), 4) + (includeTime ? ' ' + dateToHms(date) : '');
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
3
|
+
import { DATE_YEAR_MONTHS } from "../constants/DATE_YEAR_MONTHS";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transform a Date to [Month Year] date format.
|
|
7
|
+
* @param date String, object or millisencond number of the date
|
|
8
|
+
* @returns string of [Month Year] date format
|
|
9
|
+
*/
|
|
10
|
+
export function dateToMonthYear(date: string | Date | number): string {
|
|
11
|
+
if (isEmpty(date) || isTokenLabel(date as any)) return date as any;
|
|
12
|
+
|
|
13
|
+
const dt = new Date(date.valueOf());
|
|
14
|
+
return DATE_YEAR_MONTHS[dt.getMonth()] + ' ' + dt.getFullYear();
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
3
|
+
import { DATE_YEAR_QUARTERS } from "../constants/DATE_YEAR_QUARTERS";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transform a Date to [Quarter Year] date format.
|
|
7
|
+
* @param date String, object or millisencond number of the date
|
|
8
|
+
* @returns string of [Quarter Year] date format
|
|
9
|
+
*/
|
|
10
|
+
export function dateToQuarterYear(date: string | Date | number): string {
|
|
11
|
+
if (isEmpty(date) || isTokenLabel(date as any)) return date as any;
|
|
12
|
+
|
|
13
|
+
const dt = new Date(date.valueOf());
|
|
14
|
+
const quarter = Math.ceil((dt.getMonth() + 1) / 3);
|
|
15
|
+
return DATE_YEAR_QUARTERS[quarter - 1] + ' ' + dt.getFullYear();
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
3
|
+
import { getWeek } from "../helpers/getWeek";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transform a Date to [W# Year] date format.
|
|
7
|
+
* @param date String, object or millisencond number of the date
|
|
8
|
+
* @returns string of [W# Year] date format
|
|
9
|
+
*/
|
|
10
|
+
export function dateToWeekYear(date: string | Date | number): string {
|
|
11
|
+
if (isEmpty(date) || isTokenLabel(date as any)) return date as any;
|
|
12
|
+
|
|
13
|
+
const dt = new Date(date.valueOf());
|
|
14
|
+
const weekObj = getWeek(dt);
|
|
15
|
+
return `W${weekObj.week} ${weekObj.year}`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Transform a Date to [Year] date format.
|
|
6
|
+
* @param date String, object or millisencond number of the date
|
|
7
|
+
* @returns string of [Year] date format
|
|
8
|
+
*/
|
|
9
|
+
export function dateToYear(date: string | Date | number): string {
|
|
10
|
+
if (isEmpty(date) || isTokenLabel(date as any)) return date as any;
|
|
11
|
+
|
|
12
|
+
const dt = new Date(date.valueOf());
|
|
13
|
+
return String(dt.getFullYear());
|
|
14
|
+
}
|
|
@@ -9,7 +9,7 @@ import { validateDate } from "../helpers/validateDate";
|
|
|
9
9
|
* @param time Flag to parse the object date to milliseconds.
|
|
10
10
|
* @returns The date object or the date in milliseconds
|
|
11
11
|
*/
|
|
12
|
-
export function mdyDateToDate (date: string, time = false) {
|
|
12
|
+
export function mdyDateToDate (date: string, time = false): string | Date | number {
|
|
13
13
|
if (isEmpty(date) || isTokenLabel(date)) return date;
|
|
14
14
|
|
|
15
15
|
if (validateDate(date, DATE_FORMAT.DAY)) {
|
|
@@ -10,7 +10,7 @@ import { validateDate } from "../helpers/validateDate";
|
|
|
10
10
|
* @param time Flag to parse the object date to milliseconds.
|
|
11
11
|
* @returns The date object or the date in milliseconds
|
|
12
12
|
*/
|
|
13
|
-
export function monthYearToDate(monthYearDate: string, time = false) {
|
|
13
|
+
export function monthYearToDate(monthYearDate: string, time = false): string | Date | number {
|
|
14
14
|
if (isEmpty(monthYearDate) || isTokenLabel(monthYearDate)) return monthYearDate;
|
|
15
15
|
|
|
16
16
|
if (validateDate(monthYearDate, DATE_FORMAT.MONTH)) {
|
|
@@ -10,7 +10,7 @@ import { validateDate } from "../helpers/validateDate";
|
|
|
10
10
|
* @param time Flag to parse the object date to milliseconds.
|
|
11
11
|
* @returns The date object or the date in milliseconds
|
|
12
12
|
*/
|
|
13
|
-
export function quarterYearToDate (quarterYearDate: string, time = false) {
|
|
13
|
+
export function quarterYearToDate (quarterYearDate: string, time = false): string | Date | number {
|
|
14
14
|
if (isEmpty(quarterYearDate) || isTokenLabel(quarterYearDate)) return quarterYearDate;
|
|
15
15
|
|
|
16
16
|
if (validateDate(quarterYearDate, DATE_FORMAT.QUARTER)) {
|
|
@@ -10,7 +10,7 @@ import { validateDate } from "../helpers/validateDate";
|
|
|
10
10
|
* @param time Flag to parse the object date to milliseconds.
|
|
11
11
|
* @returns The date object or the date in milliseconds
|
|
12
12
|
*/
|
|
13
|
-
export function weekYearToDate(weekYear: string, time = false) {
|
|
13
|
+
export function weekYearToDate(weekYear: string, time = false): string | Date | number {
|
|
14
14
|
if (isEmpty(weekYear) || isTokenLabel(weekYear)) return weekYear;
|
|
15
15
|
|
|
16
16
|
if (validateDate(weekYear, DATE_FORMAT.WEEK)) {
|
|
@@ -10,7 +10,7 @@ import { validateDate } from "../helpers/validateDate";
|
|
|
10
10
|
* @param time Flag to parse the object date to milliseconds.
|
|
11
11
|
* @returns The date object or the date in milliseconds
|
|
12
12
|
*/
|
|
13
|
-
export function yearToDate(yearDate: string, time = false) {
|
|
13
|
+
export function yearToDate(yearDate: string, time = false): string | Date | number {
|
|
14
14
|
if (isEmpty(yearDate) || isTokenLabel(yearDate)) return yearDate;
|
|
15
15
|
|
|
16
16
|
if (validateDate(yearDate, DATE_FORMAT.YEAR)) {
|
|
@@ -13,7 +13,7 @@ import { mdyDateToDate } from "../adapters/mdyDateToDate";
|
|
|
13
13
|
* @param time flag to convert the formatted date to miliseconds
|
|
14
14
|
* @returns a Date object, milisecond time or the same value if date format does not match.
|
|
15
15
|
*/
|
|
16
|
-
export function getDateByDateFormat(date: string, format: IDateFormat, time = false) {
|
|
16
|
+
export function getDateByDateFormat(date: string, format: IDateFormat, time = false): string | Date | number {
|
|
17
17
|
switch (format) {
|
|
18
18
|
case DATE_FORMAT.YEAR:
|
|
19
19
|
return yearToDate(date, time);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { dateToMdyDate } from "../adapters/dateToMdyDate";
|
|
2
|
+
import { dateToMonthYear } from "../adapters/dateToMonthYear";
|
|
3
|
+
import { dateToQuarterYear } from "../adapters/dateToQuarterYear";
|
|
4
|
+
import { dateToWeekYear } from "../adapters/dateToWeekYear";
|
|
5
|
+
import { dateToYear } from "../adapters/dateToYear";
|
|
6
|
+
import { DATE_FORMAT } from "../constants/DATE_FORMAT";
|
|
7
|
+
import { IDateFormat } from "../interfaces/IDateFormat";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A Date object, string or millisecond number are gotten in order to convert it in an formatted string date
|
|
11
|
+
* @param date String with a formatted date
|
|
12
|
+
* @param format The date format
|
|
13
|
+
* @returns a formmatted date or the same value if format does not match
|
|
14
|
+
*/
|
|
15
|
+
export function getFormattedDateByFormat(date: string | Date | number, format: IDateFormat): string | Date | number {
|
|
16
|
+
if (format === DATE_FORMAT.QUARTER) {
|
|
17
|
+
return dateToQuarterYear(date);
|
|
18
|
+
} else if (format === DATE_FORMAT.MONTH) {
|
|
19
|
+
return dateToMonthYear(date);
|
|
20
|
+
} else if (format === DATE_FORMAT.YEAR) {
|
|
21
|
+
return dateToYear(date);
|
|
22
|
+
} else if (format === DATE_FORMAT.WEEK) {
|
|
23
|
+
return dateToWeekYear(date);
|
|
24
|
+
} else if (format === DATE_FORMAT.DAY) {
|
|
25
|
+
return dateToMdyDate(date);
|
|
26
|
+
} else {
|
|
27
|
+
return date;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
3
|
+
import { IDateFormat } from "../interfaces/IDateFormat";
|
|
4
|
+
import { getSeparatorByDateFormat } from "./getSeparatorByDateFormat";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Determines if the given date has tokens. The date is splitted depending on date format.
|
|
8
|
+
* Undefined date is returning false.
|
|
9
|
+
* @param date The string of the date. It may contain tokens.
|
|
10
|
+
* @param format The date format
|
|
11
|
+
* @returns true: include tokens; false: otherwise
|
|
12
|
+
*/
|
|
13
|
+
export function includeDateTokens(date: string, format: IDateFormat) {
|
|
14
|
+
let hasTokens = false;
|
|
15
|
+
if (!isEmpty(date)) {
|
|
16
|
+
if (isTokenLabel(date)) hasTokens = true;
|
|
17
|
+
else {
|
|
18
|
+
const separator = getSeparatorByDateFormat(format);
|
|
19
|
+
if (separator != null) {
|
|
20
|
+
const tokens = date.split(separator);
|
|
21
|
+
hasTokens = tokens.some(token => isTokenLabel(token));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return hasTokens;
|
|
26
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
export * from './getDateByDateFormat';
|
|
1
2
|
export * from './getDateFormatByProperty';
|
|
2
3
|
export * from './getDateFormatRegularExpressionInArray';
|
|
4
|
+
export * from './getFormattedDateByFormat';
|
|
3
5
|
export * from './getSeparatorByDateFormat';
|
|
6
|
+
export * from './includeDateTokens';
|
|
4
7
|
export * from './getWeek';
|
|
5
8
|
export * from './validateDate';
|
|
6
9
|
export * from './validateDateByDateFormat';
|
|
@@ -35,7 +35,17 @@ export class I18nServiceBuilder {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* This class allows to use the translation service of the i18next library
|
|
40
|
+
*/
|
|
38
41
|
export abstract class I18nService {
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* This method by means of the key searches in the configuration object, replaces the values received by means of the options parameter and returns the translated text. Ex: <b>translate('the_value_is {{number}}',{number: 1});</b>
|
|
45
|
+
* @param key String used as key
|
|
46
|
+
* @param options Object of type II18nServiceTranslateOption that contains the dynamic parameters to replace
|
|
47
|
+
* @returns The translated text Ex: <b>The value is: 1</b>
|
|
48
|
+
*/
|
|
39
49
|
abstract translate(key: string, options?: II18nServiceTranslateOption): string;
|
|
40
50
|
}
|
|
41
51
|
|