@sme.up/doc-alchemist 1.0.0-SNAPSHOT-20250613100107
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 +129 -0
- package/dist/assets/sample-data.d.ts +21 -0
- package/dist/assets/sample-data.js +235 -0
- package/dist/assets/sample-data.js.map +1 -0
- package/dist/debug.d.ts +1 -0
- package/dist/debug.js +20 -0
- package/dist/debug.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/src/excel/excel-generator.d.ts +14 -0
- package/dist/src/excel/excel-generator.js +415 -0
- package/dist/src/excel/excel-generator.js.map +1 -0
- package/dist/src/excel/excel-generator.types.d.ts +21 -0
- package/dist/src/excel/excel-generator.types.js +26 -0
- package/dist/src/excel/excel-generator.types.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/pdf/pdf-generator.d.ts +6 -0
- package/dist/src/pdf/pdf-generator.js +5 -0
- package/dist/src/pdf/pdf-generator.js.map +1 -0
- package/dist/src/types/index.d.ts +38 -0
- package/dist/src/types/index.js +15 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/datastructure-utility.d.ts +2 -0
- package/dist/src/utils/datastructure-utility.js +5 -0
- package/dist/src/utils/datastructure-utility.js.map +1 -0
- package/dist/src/utils/dates-utility.d.ts +10 -0
- package/dist/src/utils/dates-utility.js +55 -0
- package/dist/src/utils/dates-utility.js.map +1 -0
- package/dist/src/utils/generator-utility.d.ts +31 -0
- package/dist/src/utils/generator-utility.js +113 -0
- package/dist/src/utils/generator-utility.js.map +1 -0
- package/dist/src/utils/math-utility.d.ts +10 -0
- package/dist/src/utils/math-utility.js +161 -0
- package/dist/src/utils/math-utility.js.map +1 -0
- package/dist/src/utils/objects-utility.d.ts +4 -0
- package/dist/src/utils/objects-utility.js +16 -0
- package/dist/src/utils/objects-utility.js.map +1 -0
- package/dist/src/utils/regex-utility.d.ts +1 -0
- package/dist/src/utils/regex-utility.js +4 -0
- package/dist/src/utils/regex-utility.js.map +1 -0
- package/dist/tests/excel-generator.test.d.ts +17 -0
- package/dist/tests/excel-generator.test.js +287 -0
- package/dist/tests/excel-generator.test.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datastructure-utility.js","sourceRoot":"","sources":["../../../src/utils/datastructure-utility.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAuB,EAAW,EAAE;IACjE,OAAO,CACL,CAAC,MAAM;QACP,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAC7E,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { SmeupDataColumn } from \"@sme.up/kokos-sdk-node\";\n\nexport const isColumnHidden = (column: SmeupDataColumn): boolean => {\n return (\n !column ||\n (Object.prototype.hasOwnProperty.call(column, \"visible\") && !column.visible)\n );\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import "dayjs/locale/es";
|
|
3
|
+
import "dayjs/locale/fr";
|
|
4
|
+
import "dayjs/locale/it";
|
|
5
|
+
import "dayjs/locale/pl";
|
|
6
|
+
import "dayjs/locale/ru";
|
|
7
|
+
import "dayjs/locale/zh";
|
|
8
|
+
export declare const datesFormat: (input: dayjs.ConfigType, locale: string, format?: string) => string;
|
|
9
|
+
export declare const datesIsIsoDate: (dateString: string) => boolean;
|
|
10
|
+
export declare const datesToDate: (input: dayjs.ConfigType, locale: string, format?: string) => Date;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import utc from "dayjs/plugin/utc";
|
|
3
|
+
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
4
|
+
import localizedFormat from "dayjs/plugin/localizedFormat";
|
|
5
|
+
import minMax from "dayjs/plugin/minMax";
|
|
6
|
+
import "dayjs/locale/es";
|
|
7
|
+
import "dayjs/locale/fr";
|
|
8
|
+
import "dayjs/locale/it";
|
|
9
|
+
import "dayjs/locale/pl";
|
|
10
|
+
import "dayjs/locale/ru";
|
|
11
|
+
import "dayjs/locale/zh";
|
|
12
|
+
import { DatesFormats } from "../types/index.js";
|
|
13
|
+
dayjs.extend(utc);
|
|
14
|
+
dayjs.extend(customParseFormat);
|
|
15
|
+
dayjs.extend(localizedFormat);
|
|
16
|
+
dayjs.extend(minMax);
|
|
17
|
+
export const datesFormat = (input, locale, format) => {
|
|
18
|
+
const _dayjs = dayjs;
|
|
19
|
+
_dayjs.locale(locale);
|
|
20
|
+
if (!format) {
|
|
21
|
+
format = "L"; // MM/DD/YYYY, DD/MM/YYYY depending on locale
|
|
22
|
+
}
|
|
23
|
+
return _dayjs.utc(input).format(format);
|
|
24
|
+
};
|
|
25
|
+
export const datesIsIsoDate = (dateString) => {
|
|
26
|
+
const isoDate = dayjs(dateString, [
|
|
27
|
+
DatesFormats.ISO_DATE,
|
|
28
|
+
DatesFormats.ISO_DATE_TIME,
|
|
29
|
+
"YYYY-MM-DDTHH:mm:ss.SSSZ",
|
|
30
|
+
]);
|
|
31
|
+
if (!isoDate.isValid()) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (Number(dateString.substring(0, 4)) != isoDate.year()) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (Number(dateString.substring(5, 7)) != isoDate.month() + 1) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (Number(dateString.substring(8, 10)) != isoDate.date()) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
export const datesToDate = (input, locale, format) => {
|
|
46
|
+
const _dayjs = dayjs;
|
|
47
|
+
_dayjs.locale(locale);
|
|
48
|
+
if (format && format != null) {
|
|
49
|
+
return _dayjs.utc(input, format).toDate();
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return _dayjs.utc(input).toDate();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=dates-utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates-utility.js","sourceRoot":"","sources":["../../../src/utils/dates-utility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,kBAAkB,CAAC;AACnC,OAAO,iBAAiB,MAAM,gCAAgC,CAAC;AAC/D,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAC3D,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAClB,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAChC,KAAK,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;AAC9B,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAErB,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,KAAuB,EACvB,MAAc,EACd,MAAe,EACP,EAAE;IACV,MAAM,MAAM,GAAG,KAAK,CAAC;IACrB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,GAAG,CAAC,CAAC,6CAA6C;IAC7D,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC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,MAAM,EAAE,CAAC;IACpC,CAAC;AACH,CAAC,CAAC","sourcesContent":["import dayjs from \"dayjs\";\nimport utc from \"dayjs/plugin/utc\";\nimport customParseFormat from \"dayjs/plugin/customParseFormat\";\nimport localizedFormat from \"dayjs/plugin/localizedFormat\";\nimport minMax from \"dayjs/plugin/minMax\";\nimport \"dayjs/locale/es\";\nimport \"dayjs/locale/fr\";\nimport \"dayjs/locale/it\";\nimport \"dayjs/locale/pl\";\nimport \"dayjs/locale/ru\";\nimport \"dayjs/locale/zh\";\nimport { DatesFormats } from \"../types/index.js\";\n\ndayjs.extend(utc);\ndayjs.extend(customParseFormat);\ndayjs.extend(localizedFormat);\ndayjs.extend(minMax);\n\nexport const datesFormat = (\n input: dayjs.ConfigType,\n locale: string,\n format?: string,\n): string => {\n const _dayjs = dayjs;\n _dayjs.locale(locale);\n if (!format) {\n format = \"L\"; // MM/DD/YYYY, DD/MM/YYYY depending on locale\n }\n return _dayjs.utc(input).format(format);\n};\n\nexport const datesIsIsoDate = (dateString: string): boolean => {\n const isoDate = dayjs(dateString, [\n DatesFormats.ISO_DATE,\n DatesFormats.ISO_DATE_TIME,\n \"YYYY-MM-DDTHH:mm:ss.SSSZ\",\n ]);\n if (!isoDate.isValid()) {\n return false;\n }\n\n if (Number(dateString.substring(0, 4)) != isoDate.year()) {\n return false;\n }\n if (Number(dateString.substring(5, 7)) != isoDate.month() + 1) {\n return false;\n }\n if (Number(dateString.substring(8, 10)) != isoDate.date()) {\n return false;\n }\n return true;\n};\n\nexport const datesToDate = (\n input: dayjs.ConfigType,\n locale: string,\n format?: string,\n): Date => {\n const _dayjs = dayjs;\n _dayjs.locale(locale);\n if (format && format != null) {\n return _dayjs.utc(input, format).toDate();\n } else {\n return _dayjs.utc(input).toDate();\n }\n};\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SmeupDataColumn, SmeupDataTable, SmeupDataCell } from "@sme.up/kokos-sdk-node";
|
|
2
|
+
import { ColumnFilter, WebupManagerData, SupportedExportFormats } from "../types/index.js";
|
|
3
|
+
export declare const getFilteredColumns: (columns: SmeupDataColumn[]) => SmeupDataColumn[];
|
|
4
|
+
/**
|
|
5
|
+
* By passing the map, length value and column name
|
|
6
|
+
* creates or updates a map record with
|
|
7
|
+
* @param map Contains columnNames and their longest cell's length
|
|
8
|
+
* @param text The text to use in length calculation
|
|
9
|
+
* @param colName The column to check
|
|
10
|
+
*/
|
|
11
|
+
export declare const updateMaxValueLength: (map: {
|
|
12
|
+
[key: string]: number;
|
|
13
|
+
}, text: string | undefined | null, colName: string) => void;
|
|
14
|
+
export declare const filterRows: (smeupDataTable: SmeupDataTable, filteredColumns: SmeupDataColumn[], filters: {
|
|
15
|
+
[key: string]: ColumnFilter;
|
|
16
|
+
}) => import("@sme.up/kokos-sdk-node").SmeupDataRow[];
|
|
17
|
+
/**
|
|
18
|
+
* Returns a converted and formatted cell value (string, date, number)
|
|
19
|
+
* @param cell - SmeupDataCell
|
|
20
|
+
* @param bookType - SupportedExportFormats
|
|
21
|
+
* @param webupManagerData - WebupManagerData
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export declare const calculateCellValue: (cell: SmeupDataCell, bookType: SupportedExportFormats, webupManagerData: WebupManagerData) => string | number | Date;
|
|
25
|
+
/**
|
|
26
|
+
* Conversion from Hexadecimal color to an AlphaRGB
|
|
27
|
+
* @param hex string - Hexadecimal value, it can bot have and don't have the # prefix
|
|
28
|
+
* @returns ARGB string code
|
|
29
|
+
*/
|
|
30
|
+
export declare const hexToArgb: (hex: string) => string;
|
|
31
|
+
export declare const convertToBuffer: (arrayBuffer: ArrayBuffer) => Buffer | Uint8Array;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { exportTypeSupportsFormatting } from "../excel/excel-generator.types.js";
|
|
2
|
+
import { datesIsIsoDate, datesToDate, datesFormat } from "./dates-utility.js";
|
|
3
|
+
import { mathNumberStringToFormattedString, mathCountDecimals, } from "./math-utility";
|
|
4
|
+
import { objectsIsVoCodVer, objectsIsDate, objectsIsNumber, } from "./objects-utility";
|
|
5
|
+
export const getFilteredColumns = (columns) => {
|
|
6
|
+
if (!columns)
|
|
7
|
+
return [];
|
|
8
|
+
return columns.filter(column => {
|
|
9
|
+
const dataObject = {
|
|
10
|
+
...column.obj,
|
|
11
|
+
k: "",
|
|
12
|
+
};
|
|
13
|
+
return column.obj?.t !== "J4" && !objectsIsVoCodVer(dataObject);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* By passing the map, length value and column name
|
|
18
|
+
* creates or updates a map record with
|
|
19
|
+
* @param map Contains columnNames and their longest cell's length
|
|
20
|
+
* @param text The text to use in length calculation
|
|
21
|
+
* @param colName The column to check
|
|
22
|
+
*/
|
|
23
|
+
export const updateMaxValueLength = (map, text, colName) => {
|
|
24
|
+
if (!map || !text || !colName)
|
|
25
|
+
return;
|
|
26
|
+
const value = Math.max(...text.split("\n").map(line => line.length));
|
|
27
|
+
if (map[colName]) {
|
|
28
|
+
if (map[colName] < value) {
|
|
29
|
+
map[colName] = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
map[colName] = value;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export const filterRows = (smeupDataTable, filteredColumns, filters) => {
|
|
37
|
+
if (filters) {
|
|
38
|
+
return smeupDataTable.rows.filter(row => {
|
|
39
|
+
return filteredColumns.every(col => {
|
|
40
|
+
const cellValue = row.cells?.[col.name]?.value;
|
|
41
|
+
const columnFilter = filters[col.name];
|
|
42
|
+
if (columnFilter?.checkBoxes?.length) {
|
|
43
|
+
const allowedValues = columnFilter.checkBoxes.map(item => item.value);
|
|
44
|
+
return (typeof cellValue === "string" && allowedValues.includes(cellValue));
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return smeupDataTable.rows;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Returns a converted and formatted cell value (string, date, number)
|
|
56
|
+
* @param cell - SmeupDataCell
|
|
57
|
+
* @param bookType - SupportedExportFormats
|
|
58
|
+
* @param webupManagerData - WebupManagerData
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
export const calculateCellValue = (cell, bookType, webupManagerData) => {
|
|
62
|
+
if (cell.obj && objectsIsDate(cell.obj) && datesIsIsoDate(cell.value)) {
|
|
63
|
+
return exportTypeSupportsFormatting[bookType]
|
|
64
|
+
? new Date(datesToDate(cell.value, webupManagerData.datesLocale))
|
|
65
|
+
: datesFormat(cell.value, webupManagerData.datesLocale);
|
|
66
|
+
}
|
|
67
|
+
if (cell.obj && objectsIsNumber(cell.obj)) {
|
|
68
|
+
if (!exportTypeSupportsFormatting[bookType]) {
|
|
69
|
+
return (mathNumberStringToFormattedString(cell.value, mathCountDecimals(Number(cell.value) || 0), "", webupManagerData.mathLocale) || "");
|
|
70
|
+
}
|
|
71
|
+
const numValue = Number(cell.value);
|
|
72
|
+
return !isNaN(numValue) ? numValue : "";
|
|
73
|
+
}
|
|
74
|
+
return cell?.value ?? "";
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Conversion from Hexadecimal color to an AlphaRGB
|
|
78
|
+
* @param hex string - Hexadecimal value, it can bot have and don't have the # prefix
|
|
79
|
+
* @returns ARGB string code
|
|
80
|
+
*/
|
|
81
|
+
export const hexToArgb = (hex) => {
|
|
82
|
+
// Hex validation
|
|
83
|
+
if (hex.startsWith("#"))
|
|
84
|
+
hex = hex.slice(1);
|
|
85
|
+
if (hex.length !== 6)
|
|
86
|
+
return "";
|
|
87
|
+
// Value Parse and return
|
|
88
|
+
const red = parseInt(hex.slice(0, 2), 16);
|
|
89
|
+
const green = parseInt(hex.slice(2, 4), 16);
|
|
90
|
+
const blue = parseInt(hex.slice(4, 6), 16);
|
|
91
|
+
return `FF${red.toString(16).padStart(2, "0")}${green
|
|
92
|
+
.toString(16)
|
|
93
|
+
.padStart(2, "0")}${blue.toString(16).padStart(2, "0")}`;
|
|
94
|
+
};
|
|
95
|
+
// Utility function to detect if Buffer is available
|
|
96
|
+
const isBufferAvailable = () => {
|
|
97
|
+
try {
|
|
98
|
+
return typeof Buffer !== "undefined" && typeof Buffer.from === "function";
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
// Utility function to convert ArrayBuffer to Buffer or Uint8Array
|
|
105
|
+
export const convertToBuffer = (arrayBuffer) => {
|
|
106
|
+
if (isBufferAvailable()) {
|
|
107
|
+
return Buffer.from(arrayBuffer);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return new Uint8Array(arrayBuffer);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=generator-utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator-utility.js","sourceRoot":"","sources":["../../../src/utils/generator-utility.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAOjF,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EACL,iCAAiC,EACjC,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAA0B,EAAE,EAAE;IAC/D,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;QAC7B,MAAM,UAAU,GAAG;YACjB,GAAG,MAAM,CAAC,GAAG;YACb,CAAC,EAAE,EAAE;SACU,CAAC;QAClB,OAAO,MAAM,CAA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AAI,KAAK,UAAU,CAAC;IAC5E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAEF,kEAAkE;AAClE,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,WAAwB,EACH,EAAE;IACvB,IAAI,iBAAiB,EAAE,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IACrC,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n SmeupDataColumn,\n SmeupDataTable,\n SmeupDataCell,\n} from \"@sme.up/kokos-sdk-node\";\nimport { exportTypeSupportsFormatting } from \"../excel/excel-generator.types.js\";\nimport {\n SmeupDataObj,\n ColumnFilter,\n WebupManagerData,\n SupportedExportFormats,\n} from \"../types/index.js\";\nimport { datesIsIsoDate, datesToDate, datesFormat } from \"./dates-utility.js\";\nimport {\n mathNumberStringToFormattedString,\n mathCountDecimals,\n} from \"./math-utility\";\nimport {\n objectsIsVoCodVer,\n objectsIsDate,\n objectsIsNumber,\n} from \"./objects-utility\";\n\nexport const getFilteredColumns = (columns: SmeupDataColumn[]) => {\n if (!columns) return [];\n\n return columns.filter(column => {\n const dataObject = {\n ...column.obj,\n k: \"\",\n } as SmeupDataObj;\n return column.obj?.t !== \"J4\" && !objectsIsVoCodVer(dataObject);\n });\n};\n\n/**\n * By passing the map, length value and column name\n * creates or updates a map record with\n * @param map Contains columnNames and their longest cell's length\n * @param text The text to use in length calculation\n * @param colName The column to check\n */\nexport const updateMaxValueLength = (\n map: { [key: string]: number },\n text: string | undefined | null,\n colName: string,\n) => {\n if (!map || !text || !colName) return;\n\n const value = Math.max(...text.split(\"\\n\").map(line => line.length));\n if (map[colName]) {\n if (map[colName] < value) {\n map[colName] = value;\n }\n } else {\n map[colName] = value;\n }\n};\n\nexport const filterRows = (\n smeupDataTable: SmeupDataTable,\n filteredColumns: SmeupDataColumn[],\n filters: { [key: string]: ColumnFilter },\n) => {\n if (filters) {\n return smeupDataTable.rows.filter(row => {\n return filteredColumns.every(col => {\n const cellValue = row.cells?.[col.name]?.value;\n const columnFilter = filters[col.name];\n if (columnFilter?.checkBoxes?.length) {\n const allowedValues = columnFilter.checkBoxes.map(item => item.value);\n return (\n typeof cellValue === \"string\" && allowedValues.includes(cellValue)\n );\n }\n return true;\n });\n });\n } else {\n return smeupDataTable.rows;\n }\n};\n\n/**\n * Returns a converted and formatted cell value (string, date, number)\n * @param cell - SmeupDataCell\n * @param bookType - SupportedExportFormats\n * @param webupManagerData - WebupManagerData\n * @returns\n */\nexport const calculateCellValue = (\n cell: SmeupDataCell,\n bookType: SupportedExportFormats,\n webupManagerData: WebupManagerData,\n) => {\n if (cell.obj && objectsIsDate(cell.obj) && datesIsIsoDate(cell.value)) {\n return exportTypeSupportsFormatting[bookType]\n ? new Date(datesToDate(cell.value, webupManagerData.datesLocale))\n : datesFormat(cell.value, webupManagerData.datesLocale);\n }\n\n if (cell.obj && objectsIsNumber(cell.obj)) {\n if (!exportTypeSupportsFormatting[bookType]) {\n return (\n mathNumberStringToFormattedString(\n cell.value,\n mathCountDecimals(Number(cell.value) || 0),\n \"\",\n webupManagerData.mathLocale,\n ) || \"\"\n );\n }\n\n const numValue = Number(cell.value);\n return !isNaN(numValue) ? numValue : \"\";\n }\n\n return cell?.value ?? \"\";\n};\n\n/**\n * Conversion from Hexadecimal color to an AlphaRGB\n * @param hex string - Hexadecimal value, it can bot have and don't have the # prefix\n * @returns ARGB string code\n */\nexport const hexToArgb = (hex: string): string => {\n // Hex validation\n if (hex.startsWith(\"#\")) hex = hex.slice(1);\n if (hex.length !== 6) return \"\";\n\n // Value Parse and return\n const red = parseInt(hex.slice(0, 2), 16);\n const green = parseInt(hex.slice(2, 4), 16);\n const blue = parseInt(hex.slice(4, 6), 16);\n return `FF${red.toString(16).padStart(2, \"0\")}${green\n .toString(16)\n .padStart(2, \"0\")}${blue.toString(16).padStart(2, \"0\")}`;\n};\n\n// Utility function to detect if Buffer is available\nconst isBufferAvailable = (): boolean => {\n try {\n return typeof Buffer !== \"undefined\" && typeof Buffer.from === \"function\";\n } catch {\n return false;\n }\n};\n\n// Utility function to convert ArrayBuffer to Buffer or Uint8Array\nexport const convertToBuffer = (\n arrayBuffer: ArrayBuffer,\n): Buffer | Uint8Array => {\n if (isBufferAvailable()) {\n return Buffer.from(arrayBuffer);\n } else {\n return new Uint8Array(arrayBuffer);\n }\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const mathCountDecimals: (value: number) => number;
|
|
2
|
+
export declare const mathNumberStringToFormattedString: (input: string, decimals: number, type: string, locale: string, decSeparator?: string) => string;
|
|
3
|
+
export declare const mathNumberToFormattedString: (input: number, decimals: number, type: string, locale: string) => string;
|
|
4
|
+
export declare const mathNumberify: (input: string | number, locale: string, inputIsLocalized?: boolean, type?: string, decFmt?: string) => number;
|
|
5
|
+
export declare const mathNumberifySafe: (input: string, locale: string, inputIsLocalized?: boolean, type?: string, decFmt?: string) => number;
|
|
6
|
+
export declare const mathDecimalSeparator: (locale: string) => string;
|
|
7
|
+
export declare const mathGroupSeparator: (locale: string) => string;
|
|
8
|
+
export declare const mathFormat: (input: string | number, locale: string, format?: string, inputIsLocalized?: boolean) => string;
|
|
9
|
+
export declare const mathCreateFormatPattern: (thousandPoint?: boolean, decimals?: number) => string;
|
|
10
|
+
export declare const mathGetNumericValueSuffix: (type: string) => string;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { getRegExpFromString } from "./regex-utility.js";
|
|
2
|
+
export const mathCountDecimals = (value) => {
|
|
3
|
+
if (Math.floor(value) === value)
|
|
4
|
+
return 0;
|
|
5
|
+
const stringValue = value.toString().split(".")[1];
|
|
6
|
+
if (stringValue) {
|
|
7
|
+
return stringValue.length ?? 0;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export const mathNumberStringToFormattedString = (input, decimals, type, locale, decSeparator) => {
|
|
14
|
+
let value = mathNumberToFormattedString(mathNumberifySafe(input, locale), decimals, type, locale);
|
|
15
|
+
if (!decSeparator) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
const browserDecSeparator = mathDecimalSeparator(locale);
|
|
19
|
+
if (browserDecSeparator == decSeparator) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
const browserGroupSeparator = mathGroupSeparator(locale);
|
|
23
|
+
value = value.replace(getRegExpFromString(browserGroupSeparator, "g"), "");
|
|
24
|
+
value = value.replace(getRegExpFromString(browserDecSeparator, "g"), decSeparator);
|
|
25
|
+
return value;
|
|
26
|
+
};
|
|
27
|
+
export const mathNumberToFormattedString = (input, decimals, type, locale) => {
|
|
28
|
+
if (input == null || isNaN(input)) {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
if (decimals == null || decimals == -1) {
|
|
32
|
+
decimals = mathCountDecimals(input);
|
|
33
|
+
}
|
|
34
|
+
let nstr = mathFormat(input, locale, mathCreateFormatPattern(true, decimals));
|
|
35
|
+
nstr = nstr + mathGetNumericValueSuffix(type);
|
|
36
|
+
return nstr;
|
|
37
|
+
};
|
|
38
|
+
export const mathNumberify = (input, locale, inputIsLocalized, type, decFmt) => {
|
|
39
|
+
if (typeof input != "number") {
|
|
40
|
+
if (type) {
|
|
41
|
+
const suffix = mathGetNumericValueSuffix(type);
|
|
42
|
+
if (suffix != "") {
|
|
43
|
+
input = input
|
|
44
|
+
.replace(getRegExpFromString(suffix.trim(), "g"), "")
|
|
45
|
+
.trim();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!decFmt) {
|
|
49
|
+
decFmt = inputIsLocalized ? mathDecimalSeparator(locale) : ".";
|
|
50
|
+
}
|
|
51
|
+
const groupSeparator = decFmt == "." ? "," : ".";
|
|
52
|
+
input = input.replace(getRegExpFromString(groupSeparator, "g"), "");
|
|
53
|
+
if (decFmt != ".") {
|
|
54
|
+
input = input.replace(getRegExpFromString(decFmt, "g"), ".");
|
|
55
|
+
}
|
|
56
|
+
input = Number(input);
|
|
57
|
+
}
|
|
58
|
+
const n = Number(input);
|
|
59
|
+
if (isNaN(n)) {
|
|
60
|
+
return NaN;
|
|
61
|
+
}
|
|
62
|
+
return n;
|
|
63
|
+
};
|
|
64
|
+
export const mathNumberifySafe = (input, locale, inputIsLocalized, type, decFmt) => {
|
|
65
|
+
if (!input || input == null || input.trim() == "") {
|
|
66
|
+
input = "0";
|
|
67
|
+
}
|
|
68
|
+
return mathNumberify(input, locale, inputIsLocalized, type, decFmt);
|
|
69
|
+
};
|
|
70
|
+
export const mathDecimalSeparator = (locale) => {
|
|
71
|
+
const numberWithGroupAndDecimalSeparator = 1000.1;
|
|
72
|
+
const decimalPart = Intl.NumberFormat(locale)
|
|
73
|
+
.formatToParts(numberWithGroupAndDecimalSeparator)
|
|
74
|
+
.find(part => part.type === "decimal");
|
|
75
|
+
return decimalPart ? decimalPart.value : ".";
|
|
76
|
+
};
|
|
77
|
+
export const mathGroupSeparator = (locale) => {
|
|
78
|
+
const numberWithGroupAndDecimalSeparator = 1000.1;
|
|
79
|
+
const parts = Intl.NumberFormat(locale).formatToParts(numberWithGroupAndDecimalSeparator);
|
|
80
|
+
const groupPart = parts.find(part => part.type === "group");
|
|
81
|
+
if (!groupPart) {
|
|
82
|
+
/** for some reason, today 19/03/2025 on US OS (mac and github), group is not present in parts!!! */
|
|
83
|
+
const decimalPart = parts.find(part => part.type === "decimal");
|
|
84
|
+
const decimalPartValue = decimalPart ? decimalPart.value : ".";
|
|
85
|
+
return decimalPartValue === "." ? "," : ".";
|
|
86
|
+
}
|
|
87
|
+
return groupPart.value;
|
|
88
|
+
};
|
|
89
|
+
export const mathFormat = (input, locale, format, inputIsLocalized) => {
|
|
90
|
+
const n = mathNumberify(input, locale, inputIsLocalized);
|
|
91
|
+
if (!format) {
|
|
92
|
+
const positiveN = Math.abs(n);
|
|
93
|
+
const decimals = positiveN - Math.floor(positiveN);
|
|
94
|
+
if (decimals) {
|
|
95
|
+
format = "0,0.00";
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
format = "0,0";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const options = mathParseNumberFormat(format);
|
|
102
|
+
return new Intl.NumberFormat(locale, options).format(n);
|
|
103
|
+
};
|
|
104
|
+
const mathParseNumberFormat = (format) => {
|
|
105
|
+
// Example format strings: '0,0.00', '0,0', '0.000', ...
|
|
106
|
+
// This parser is simplistic; it only checks for comma group
|
|
107
|
+
// and counts how many 0's come after '.' to set decimal digits.
|
|
108
|
+
const options = {};
|
|
109
|
+
// If there's a comma in the integer part, enable grouping
|
|
110
|
+
if (format.includes(",")) {
|
|
111
|
+
options.useGrouping = true;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
options.useGrouping = false;
|
|
115
|
+
}
|
|
116
|
+
// Count decimals from the part after '.'
|
|
117
|
+
const decimalIndex = format.indexOf(".");
|
|
118
|
+
if (decimalIndex > -1) {
|
|
119
|
+
const decimals = format.substring(decimalIndex + 1);
|
|
120
|
+
const digitCount = (decimals.match(/0/g) || []).length;
|
|
121
|
+
options.minimumFractionDigits = digitCount;
|
|
122
|
+
options.maximumFractionDigits = digitCount;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// If no dot, no decimal digits
|
|
126
|
+
options.minimumFractionDigits = 0;
|
|
127
|
+
options.maximumFractionDigits = 0;
|
|
128
|
+
}
|
|
129
|
+
return options;
|
|
130
|
+
};
|
|
131
|
+
export const mathCreateFormatPattern = (thousandPoint, decimals) => {
|
|
132
|
+
let format = "0";
|
|
133
|
+
if (thousandPoint) {
|
|
134
|
+
format += ",0";
|
|
135
|
+
}
|
|
136
|
+
if (decimals && decimals > 0) {
|
|
137
|
+
format += ".";
|
|
138
|
+
for (let i = 0; i < decimals; i++) {
|
|
139
|
+
format += "0";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return format;
|
|
143
|
+
};
|
|
144
|
+
export const mathGetNumericValueSuffix = (type) => {
|
|
145
|
+
type = type.toUpperCase();
|
|
146
|
+
let nstr = "";
|
|
147
|
+
if (type == "P") {
|
|
148
|
+
nstr = " %";
|
|
149
|
+
}
|
|
150
|
+
else if (type == "VE") {
|
|
151
|
+
nstr = " €";
|
|
152
|
+
}
|
|
153
|
+
else if (type == "VL") {
|
|
154
|
+
nstr = " £";
|
|
155
|
+
}
|
|
156
|
+
else if (type == "VV") {
|
|
157
|
+
nstr = " $";
|
|
158
|
+
}
|
|
159
|
+
return nstr;
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=math-utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math-utility.js","sourceRoot":"","sources":["../../../src/utils/math-utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAU,EAAE;IACzD,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK;QAAE,OAAO,CAAC,CAAC;IAC1C,MAAM,WAAW,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC,MAAM,IAAI,CAAC,CAAC;IACjC,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAC/C,KAAa,EACb,QAAgB,EAChB,IAAY,EACZ,MAAc,EACd,YAAqB,EACb,EAAE;IACV,IAAI,KAAK,GAAG,2BAA2B,CACrC,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,EAChC,Q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AI,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,GAAG,IAAI,CAAC;IACd,CAAC;SAAM,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,GAAG,IAAI,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["import { getRegExpFromString } from \"./regex-utility.js\";\n\nexport const mathCountDecimals = (value: number): number => {\n if (Math.floor(value) === value) return 0;\n const stringValue = value.toString().split(\".\")[1];\n if (stringValue) {\n return stringValue.length ?? 0;\n } else {\n return 0;\n }\n};\n\nexport const mathNumberStringToFormattedString = (\n input: string,\n decimals: number,\n type: string,\n locale: string,\n decSeparator?: string,\n): string => {\n let value = mathNumberToFormattedString(\n mathNumberifySafe(input, locale),\n decimals,\n type,\n locale,\n );\n\n if (!decSeparator) {\n return value;\n }\n const browserDecSeparator = mathDecimalSeparator(locale);\n if (browserDecSeparator == decSeparator) {\n return value;\n }\n const browserGroupSeparator = mathGroupSeparator(locale);\n value = value.replace(getRegExpFromString(browserGroupSeparator, \"g\"), \"\");\n value = value.replace(\n getRegExpFromString(browserDecSeparator, \"g\"),\n decSeparator,\n );\n\n return value;\n};\n\nexport const mathNumberToFormattedString = (\n input: number,\n decimals: number,\n type: string,\n locale: string,\n): string => {\n if (input == null || isNaN(input)) {\n return \"\";\n }\n if (decimals == null || decimals == -1) {\n decimals = mathCountDecimals(input);\n }\n let nstr = mathFormat(input, locale, mathCreateFormatPattern(true, decimals));\n nstr = nstr + mathGetNumericValueSuffix(type);\n return nstr;\n};\n\nexport const mathNumberify = (\n input: string | number,\n locale: string,\n inputIsLocalized?: boolean,\n type?: string,\n decFmt?: string,\n): number => {\n if (typeof input != \"number\") {\n if (type) {\n const suffix = mathGetNumericValueSuffix(type);\n if (suffix != \"\") {\n input = input\n .replace(getRegExpFromString(suffix.trim(), \"g\"), \"\")\n .trim();\n }\n }\n if (!decFmt) {\n decFmt = inputIsLocalized ? mathDecimalSeparator(locale) : \".\";\n }\n const groupSeparator = decFmt == \".\" ? \",\" : \".\";\n input = input.replace(getRegExpFromString(groupSeparator, \"g\"), \"\");\n if (decFmt != \".\") {\n input = input.replace(getRegExpFromString(decFmt, \"g\"), \".\");\n }\n\n input = Number(input);\n }\n\n const n = Number(input);\n if (isNaN(n)) {\n return NaN;\n }\n return n;\n};\n\nexport const mathNumberifySafe = (\n input: string,\n locale: string,\n inputIsLocalized?: boolean,\n type?: string,\n decFmt?: string,\n): number => {\n if (!input || input == null || input.trim() == \"\") {\n input = \"0\";\n }\n return mathNumberify(input, locale, inputIsLocalized, type, decFmt);\n};\n\nexport const mathDecimalSeparator = (locale: string): string => {\n const numberWithGroupAndDecimalSeparator = 1000.1;\n const decimalPart = Intl.NumberFormat(locale)\n .formatToParts(numberWithGroupAndDecimalSeparator)\n .find(part => part.type === \"decimal\");\n return decimalPart ? decimalPart.value : \".\";\n};\n\nexport const mathGroupSeparator = (locale: string): string => {\n const numberWithGroupAndDecimalSeparator = 1000.1;\n\n const parts = Intl.NumberFormat(locale).formatToParts(\n numberWithGroupAndDecimalSeparator,\n );\n\n const groupPart = parts.find(part => part.type === \"group\");\n\n if (!groupPart) {\n /** for some reason, today 19/03/2025 on US OS (mac and github), group is not present in parts!!! */\n const decimalPart = parts.find(part => part.type === \"decimal\");\n const decimalPartValue = decimalPart ? decimalPart.value : \".\";\n return decimalPartValue === \".\" ? \",\" : \".\";\n }\n return groupPart.value;\n};\n\nexport const mathFormat = (\n input: string | number,\n locale: string,\n format?: string,\n inputIsLocalized?: boolean,\n): string => {\n const n = mathNumberify(input, locale, inputIsLocalized);\n if (!format) {\n const positiveN = Math.abs(n);\n const decimals = positiveN - Math.floor(positiveN);\n if (decimals) {\n format = \"0,0.00\";\n } else {\n format = \"0,0\";\n }\n }\n const options = mathParseNumberFormat(format);\n return new Intl.NumberFormat(locale, options).format(n);\n};\n\nconst mathParseNumberFormat = (format: string): Intl.NumberFormatOptions => {\n // Example format strings: '0,0.00', '0,0', '0.000', ...\n // This parser is simplistic; it only checks for comma group\n // and counts how many 0's come after '.' to set decimal digits.\n const options: Intl.NumberFormatOptions = {};\n\n // If there's a comma in the integer part, enable grouping\n if (format.includes(\",\")) {\n options.useGrouping = true;\n } else {\n options.useGrouping = false;\n }\n\n // Count decimals from the part after '.'\n const decimalIndex = format.indexOf(\".\");\n if (decimalIndex > -1) {\n const decimals = format.substring(decimalIndex + 1);\n const digitCount = (decimals.match(/0/g) || []).length;\n options.minimumFractionDigits = digitCount;\n options.maximumFractionDigits = digitCount;\n } else {\n // If no dot, no decimal digits\n options.minimumFractionDigits = 0;\n options.maximumFractionDigits = 0;\n }\n\n return options;\n};\n\nexport const mathCreateFormatPattern = (\n thousandPoint?: boolean,\n decimals?: number,\n): string => {\n let format = \"0\";\n if (thousandPoint) {\n format += \",0\";\n }\n if (decimals && decimals > 0) {\n format += \".\";\n for (let i = 0; i < decimals; i++) {\n format += \"0\";\n }\n }\n return format;\n};\n\nexport const mathGetNumericValueSuffix = (type: string): string => {\n type = type.toUpperCase();\n let nstr = \"\";\n if (type == \"P\") {\n nstr = \" %\";\n } else if (type == \"VE\") {\n nstr = \" €\";\n } else if (type == \"VL\") {\n nstr = \" £\";\n } else if (type == \"VV\") {\n nstr = \" $\";\n }\n return nstr;\n};\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SmeupDataObj } from "../types/index.js";
|
|
2
|
+
export declare const objectsIsDate: (obj: Omit<SmeupDataObj, "k">) => boolean;
|
|
3
|
+
export declare const objectsIsNumber: (obj: Omit<SmeupDataObj, "k">) => boolean;
|
|
4
|
+
export declare const objectsIsVoCodVer: (obj: Omit<SmeupDataObj, "k">) => boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const objectsIsDate = (obj) => {
|
|
2
|
+
if (!obj)
|
|
3
|
+
return false;
|
|
4
|
+
return "D8" === obj.t;
|
|
5
|
+
};
|
|
6
|
+
export const objectsIsNumber = (obj) => {
|
|
7
|
+
if (!obj)
|
|
8
|
+
return false;
|
|
9
|
+
return "NR" === obj.t || "NP" === obj.t;
|
|
10
|
+
};
|
|
11
|
+
export const objectsIsVoCodVer = (obj) => {
|
|
12
|
+
if (!obj)
|
|
13
|
+
return false;
|
|
14
|
+
return "VO" == obj.t && "COD_VER" === obj.p;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=objects-utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objects-utility.js","sourceRoot":"","sources":["../../../src/utils/objects-utility.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAA4B,EAAW,EAAE;IACrE,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,OAAO,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAA4B,EAAW,EAAE;IACvE,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,OAAO,IAAI,KAAK,GAAG,CAAC,CAAC,IAAI,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAA4B,EAAW,EAAE;IACzE,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,OAAO,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["import { SmeupDataObj } from \"../types/index.js\";\n\nexport const objectsIsDate = (obj: Omit<SmeupDataObj, \"k\">): boolean => {\n if (!obj) return false;\n return \"D8\" === obj.t;\n};\n\nexport const objectsIsNumber = (obj: Omit<SmeupDataObj, \"k\">): boolean => {\n if (!obj) return false;\n return \"NR\" === obj.t || \"NP\" === obj.t;\n};\n\nexport const objectsIsVoCodVer = (obj: Omit<SmeupDataObj, \"k\">): boolean => {\n if (!obj) return false;\n return \"VO\" == obj.t && \"COD_VER\" === obj.p;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getRegExpFromString(s: string, flags?: string): RegExp;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex-utility.js","sourceRoot":"","sources":["../../../src/utils/regex-utility.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,CAAS,EAAE,KAAc;IAC3D,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,oCAAoC;AAC1G,CAAC","sourcesContent":["export function getRegExpFromString(s: string, flags?: string): RegExp {\n return new RegExp(s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"), flags); // $& means the whole matched string\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SmeupDataTable } from "@sme.up/kokos-sdk-node";
|
|
2
|
+
export declare const table_footer_actions: (action: string, groups: {
|
|
3
|
+
column: string;
|
|
4
|
+
visible: boolean;
|
|
5
|
+
}[], rowsNumber?: number, rowRepetitions?: number) => {
|
|
6
|
+
smeupDataTable: SmeupDataTable;
|
|
7
|
+
props: {
|
|
8
|
+
groups: {
|
|
9
|
+
column: string;
|
|
10
|
+
visible: boolean;
|
|
11
|
+
}[];
|
|
12
|
+
totals: never[] | {
|
|
13
|
+
[x: string]: string;
|
|
14
|
+
};
|
|
15
|
+
filter: never[];
|
|
16
|
+
};
|
|
17
|
+
};
|