@zauru-sdk/common 1.0.120 → 2.0.2
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/CHANGELOG.md +24 -0
- package/dist/common.d.ts +38 -0
- package/dist/esm/common.js +66 -1
- package/package.json +3 -3
- package/src/common.ts +74 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.2](https://github.com/intuitiva/zauru-typescript-sdk/compare/v2.0.1...v2.0.2) (2024-10-03)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @zauru-sdk/common
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.0.1](https://github.com/intuitiva/zauru-typescript-sdk/compare/v2.0.0...v2.0.1) (2024-09-27)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @zauru-sdk/common
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [2.0.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.120...v2.0.0) (2024-09-27)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @zauru-sdk/common
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
6
30
|
## [1.0.120](https://github.com/intuitiva/zauru-typescript-sdk/compare/v1.0.119...v1.0.120) (2024-09-26)
|
|
7
31
|
|
|
8
32
|
**Note:** Version bump only for package @zauru-sdk/common
|
package/dist/common.d.ts
CHANGED
|
@@ -68,6 +68,7 @@ export declare const stringDateToParsedUTCDate: (date: string) => Date;
|
|
|
68
68
|
export declare function todayLongString(hours?: boolean): string;
|
|
69
69
|
export declare function isToday(dateStr: string): boolean;
|
|
70
70
|
export declare const getDatePickerCurrentDate: () => string;
|
|
71
|
+
export declare const obtenerFechaActualConZonaHoraria: (zonaHoraria: "America/Guatemala") => string;
|
|
71
72
|
export declare const getTimePickerCurrentTime: () => string;
|
|
72
73
|
export declare const getDateAfterDays: (daysAfterToday: number) => string;
|
|
73
74
|
export declare const getPayeeFormated: (payee?: PayeeGraphQL) => string;
|
|
@@ -163,3 +164,40 @@ export declare function calculateTimeDifference(timestamp: string): {
|
|
|
163
164
|
minutes: number;
|
|
164
165
|
label: string;
|
|
165
166
|
};
|
|
167
|
+
/**
|
|
168
|
+
* Creates a unique code with a compact date format in uppercase.
|
|
169
|
+
*
|
|
170
|
+
* @param {string | null} suffix - An optional prefix to add to the code.
|
|
171
|
+
* @returns {string} A unique code consisting of a timestamp and an optional suffix.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* // Without suffix
|
|
175
|
+
* createCode(null); // Returns something like "1A2B3C4D"
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* // With suffix
|
|
179
|
+
* createCode("INV"); // Returns something like "INV-1A2B3C4D"
|
|
180
|
+
*/
|
|
181
|
+
export declare function createCode(suffix: string | null): string;
|
|
182
|
+
/**
|
|
183
|
+
* Parses a code generated by createCode function to extract its components.
|
|
184
|
+
*
|
|
185
|
+
* @param {string} code - The code to parse.
|
|
186
|
+
* @returns {Object} An object containing the parsed date and suffix (if any).
|
|
187
|
+
* @property {Date} date - The date represented by the timestamp in the code.
|
|
188
|
+
* @property {string | null} suffix - The suffix of the code, if present; otherwise null.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* // Parsing a code without suffix
|
|
192
|
+
* parseCode("1A2B3C4D");
|
|
193
|
+
* // Returns { date: Date object, suffix: null }
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* // Parsing a code with suffix
|
|
197
|
+
* parseCode("INV-1A2B3C4D");
|
|
198
|
+
* // Returns { date: Date object, suffix: "INV" }
|
|
199
|
+
*/
|
|
200
|
+
export declare function parseCode(code: string): {
|
|
201
|
+
date: Date;
|
|
202
|
+
suffix: string | null;
|
|
203
|
+
};
|
package/dist/esm/common.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parsedObject = exports.sortByProperty = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.ZAURU_REGEX = exports.arrayToObject = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.getDatePickerCurrentDate = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.getBasketsSchema = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
|
|
6
|
+
exports.parsedObject = exports.sortByProperty = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.ZAURU_REGEX = exports.arrayToObject = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.obtenerFechaActualConZonaHoraria = exports.getDatePickerCurrentDate = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.getBasketsSchema = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
|
|
7
7
|
exports.generateClientUUID = generateClientUUID;
|
|
8
8
|
exports.extractValueBetweenTags = extractValueBetweenTags;
|
|
9
9
|
exports.isJsonArray = isJsonArray;
|
|
@@ -20,6 +20,8 @@ exports.capitalLetter = capitalLetter;
|
|
|
20
20
|
exports.handlePossibleAxiosErrors = handlePossibleAxiosErrors;
|
|
21
21
|
exports.createPostgresUrl = createPostgresUrl;
|
|
22
22
|
exports.calculateTimeDifference = calculateTimeDifference;
|
|
23
|
+
exports.createCode = createCode;
|
|
24
|
+
exports.parseCode = parseCode;
|
|
23
25
|
const moment_1 = __importDefault(require("moment"));
|
|
24
26
|
require("moment-timezone");
|
|
25
27
|
const types_1 = require("@zauru-sdk/types");
|
|
@@ -234,6 +236,19 @@ const getDatePickerCurrentDate = () => {
|
|
|
234
236
|
return `${year}-${month}-${day}`;
|
|
235
237
|
};
|
|
236
238
|
exports.getDatePickerCurrentDate = getDatePickerCurrentDate;
|
|
239
|
+
const obtenerFechaActualConZonaHoraria = (zonaHoraria) => {
|
|
240
|
+
const fecha = new Date();
|
|
241
|
+
const opciones = {
|
|
242
|
+
year: "numeric",
|
|
243
|
+
month: "2-digit",
|
|
244
|
+
day: "2-digit",
|
|
245
|
+
timeZone: zonaHoraria,
|
|
246
|
+
};
|
|
247
|
+
const fechaFormateada = new Intl.DateTimeFormat("es-ES", opciones).format(fecha);
|
|
248
|
+
const [dia, mes, anio] = fechaFormateada.split("/");
|
|
249
|
+
return `${anio}-${mes}-${dia}`;
|
|
250
|
+
};
|
|
251
|
+
exports.obtenerFechaActualConZonaHoraria = obtenerFechaActualConZonaHoraria;
|
|
237
252
|
const getTimePickerCurrentTime = () => {
|
|
238
253
|
const date = new Date();
|
|
239
254
|
const hours = String(date.getHours()).padStart(2, "0");
|
|
@@ -601,3 +616,53 @@ function calculateTimeDifference(timestamp) {
|
|
|
601
616
|
label: `${hours > 0 ? `${hours} ${hours > 1 ? "horas" : "hora"}` : ""}${hours > 0 && minutes > 0 ? " y " : ""}${minutes > 0 ? `${minutes} ${minutes > 1 ? "minutos" : "minuto"}` : ""}.`,
|
|
602
617
|
};
|
|
603
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* Creates a unique code with a compact date format in uppercase.
|
|
621
|
+
*
|
|
622
|
+
* @param {string | null} suffix - An optional prefix to add to the code.
|
|
623
|
+
* @returns {string} A unique code consisting of a timestamp and an optional suffix.
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* // Without suffix
|
|
627
|
+
* createCode(null); // Returns something like "1A2B3C4D"
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
630
|
+
* // With suffix
|
|
631
|
+
* createCode("INV"); // Returns something like "INV-1A2B3C4D"
|
|
632
|
+
*/
|
|
633
|
+
function createCode(suffix) {
|
|
634
|
+
const timestamp = Math.floor(Date.now() / 1000)
|
|
635
|
+
.toString(36)
|
|
636
|
+
.toUpperCase(); // Timestamp in base 36 and converted to uppercase
|
|
637
|
+
const code = `${timestamp}`;
|
|
638
|
+
return suffix ? `${suffix}-${code}` : code;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Parses a code generated by createCode function to extract its components.
|
|
642
|
+
*
|
|
643
|
+
* @param {string} code - The code to parse.
|
|
644
|
+
* @returns {Object} An object containing the parsed date and suffix (if any).
|
|
645
|
+
* @property {Date} date - The date represented by the timestamp in the code.
|
|
646
|
+
* @property {string | null} suffix - The suffix of the code, if present; otherwise null.
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* // Parsing a code without suffix
|
|
650
|
+
* parseCode("1A2B3C4D");
|
|
651
|
+
* // Returns { date: Date object, suffix: null }
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* // Parsing a code with suffix
|
|
655
|
+
* parseCode("INV-1A2B3C4D");
|
|
656
|
+
* // Returns { date: Date object, suffix: "INV" }
|
|
657
|
+
*/
|
|
658
|
+
function parseCode(code) {
|
|
659
|
+
// Check if the code has a suffix
|
|
660
|
+
const hasSuffix = code.includes("-") && isNaN(Number(code.split("-")[0]));
|
|
661
|
+
const [suffixOrTimestamp, timestamp] = code.split("-");
|
|
662
|
+
const dateTimestamp = hasSuffix ? timestamp : suffixOrTimestamp;
|
|
663
|
+
const date = new Date(parseInt(dateTimestamp, 36) * 1000); // Convert the timestamp back to milliseconds
|
|
664
|
+
return {
|
|
665
|
+
date: date,
|
|
666
|
+
suffix: hasSuffix ? suffixOrTimestamp : null, // Only return the suffix if it exists
|
|
667
|
+
};
|
|
668
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Funciones de uso común en el desarrollo de webapps en Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@remix-run/node": "^2.8.1",
|
|
23
|
-
"@zauru-sdk/types": "^
|
|
23
|
+
"@zauru-sdk/types": "^2.0.0",
|
|
24
24
|
"moment": "^2.30.1",
|
|
25
25
|
"moment-timezone": "^0.5.45"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "5caadc022d1be3bbcaf6e73de37524a6b06c806c"
|
|
28
28
|
}
|
package/src/common.ts
CHANGED
|
@@ -249,6 +249,25 @@ export const getDatePickerCurrentDate = () => {
|
|
|
249
249
|
return `${year}-${month}-${day}`;
|
|
250
250
|
};
|
|
251
251
|
|
|
252
|
+
export const obtenerFechaActualConZonaHoraria = (
|
|
253
|
+
zonaHoraria: "America/Guatemala"
|
|
254
|
+
) => {
|
|
255
|
+
const fecha = new Date();
|
|
256
|
+
const opciones: Intl.DateTimeFormatOptions = {
|
|
257
|
+
year: "numeric",
|
|
258
|
+
month: "2-digit",
|
|
259
|
+
day: "2-digit",
|
|
260
|
+
timeZone: zonaHoraria,
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const fechaFormateada = new Intl.DateTimeFormat("es-ES", opciones).format(
|
|
264
|
+
fecha
|
|
265
|
+
);
|
|
266
|
+
const [dia, mes, anio] = fechaFormateada.split("/");
|
|
267
|
+
|
|
268
|
+
return `${anio}-${mes}-${dia}`;
|
|
269
|
+
};
|
|
270
|
+
|
|
252
271
|
export const getTimePickerCurrentTime = () => {
|
|
253
272
|
const date = new Date();
|
|
254
273
|
const hours = String(date.getHours()).padStart(2, "0");
|
|
@@ -684,3 +703,58 @@ export function calculateTimeDifference(timestamp: string): {
|
|
|
684
703
|
}${minutes > 0 ? `${minutes} ${minutes > 1 ? "minutos" : "minuto"}` : ""}.`,
|
|
685
704
|
};
|
|
686
705
|
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Creates a unique code with a compact date format in uppercase.
|
|
709
|
+
*
|
|
710
|
+
* @param {string | null} suffix - An optional prefix to add to the code.
|
|
711
|
+
* @returns {string} A unique code consisting of a timestamp and an optional suffix.
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* // Without suffix
|
|
715
|
+
* createCode(null); // Returns something like "1A2B3C4D"
|
|
716
|
+
*
|
|
717
|
+
* @example
|
|
718
|
+
* // With suffix
|
|
719
|
+
* createCode("INV"); // Returns something like "INV-1A2B3C4D"
|
|
720
|
+
*/
|
|
721
|
+
export function createCode(suffix: string | null): string {
|
|
722
|
+
const timestamp = Math.floor(Date.now() / 1000)
|
|
723
|
+
.toString(36)
|
|
724
|
+
.toUpperCase(); // Timestamp in base 36 and converted to uppercase
|
|
725
|
+
const code = `${timestamp}`;
|
|
726
|
+
|
|
727
|
+
return suffix ? `${suffix}-${code}` : code;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* Parses a code generated by createCode function to extract its components.
|
|
732
|
+
*
|
|
733
|
+
* @param {string} code - The code to parse.
|
|
734
|
+
* @returns {Object} An object containing the parsed date and suffix (if any).
|
|
735
|
+
* @property {Date} date - The date represented by the timestamp in the code.
|
|
736
|
+
* @property {string | null} suffix - The suffix of the code, if present; otherwise null.
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* // Parsing a code without suffix
|
|
740
|
+
* parseCode("1A2B3C4D");
|
|
741
|
+
* // Returns { date: Date object, suffix: null }
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* // Parsing a code with suffix
|
|
745
|
+
* parseCode("INV-1A2B3C4D");
|
|
746
|
+
* // Returns { date: Date object, suffix: "INV" }
|
|
747
|
+
*/
|
|
748
|
+
export function parseCode(code: string) {
|
|
749
|
+
// Check if the code has a suffix
|
|
750
|
+
const hasSuffix = code.includes("-") && isNaN(Number(code.split("-")[0]));
|
|
751
|
+
const [suffixOrTimestamp, timestamp] = code.split("-");
|
|
752
|
+
|
|
753
|
+
const dateTimestamp = hasSuffix ? timestamp : suffixOrTimestamp;
|
|
754
|
+
const date = new Date(parseInt(dateTimestamp, 36) * 1000); // Convert the timestamp back to milliseconds
|
|
755
|
+
|
|
756
|
+
return {
|
|
757
|
+
date: date,
|
|
758
|
+
suffix: hasSuffix ? suffixOrTimestamp : null, // Only return the suffix if it exists
|
|
759
|
+
};
|
|
760
|
+
}
|