@8ms/helpers 3.0.23 → 3.0.24

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.
Files changed (66) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +1 -1
  2. package/dist/aws/glue/server/AwsGlue.cjs +2 -1
  3. package/dist/aws/glue/server/AwsGlue.mjs +2 -1
  4. package/dist/aws/lambda/server/AwsLambda.cjs +10 -8
  5. package/dist/aws/lambda/server/AwsLambda.mjs +10 -8
  6. package/dist/aws/s3/server/AwsS3.cjs +3 -2
  7. package/dist/aws/s3/server/AwsS3.mjs +3 -2
  8. package/dist/aws/ssm/server/AwsSsm.cjs +5 -4
  9. package/dist/aws/ssm/server/AwsSsm.mjs +5 -4
  10. package/dist/brightData/serpApi/server/buildGoogleSerpUrl.cjs +0 -2
  11. package/dist/brightData/serpApi/server/buildGoogleSerpUrl.mjs +0 -2
  12. package/dist/brightData/serpApi/server/buildGoogleTrendsUrl.cjs +0 -1
  13. package/dist/brightData/serpApi/server/buildGoogleTrendsUrl.mjs +0 -1
  14. package/dist/brightData/serpApi/server/getAsyncResults.cjs +7 -4
  15. package/dist/brightData/serpApi/server/getAsyncResults.mjs +7 -4
  16. package/dist/brightData/webScraperIde/server/getRealtime.cjs +10 -6
  17. package/dist/brightData/webScraperIde/server/getRealtime.mjs +10 -6
  18. package/dist/date/calculation.cjs +27 -24
  19. package/dist/date/calculation.mjs +27 -24
  20. package/dist/emsApi/awsTs/get.cjs +2 -1
  21. package/dist/emsApi/awsTs/get.mjs +2 -1
  22. package/dist/emsApi/awsTs/post.cjs +2 -1
  23. package/dist/emsApi/awsTs/post.mjs +2 -1
  24. package/dist/emsApi/vercel/get.cjs +2 -1
  25. package/dist/emsApi/vercel/get.mjs +2 -1
  26. package/dist/emsApi/vercel/post.cjs +2 -1
  27. package/dist/emsApi/vercel/post.mjs +2 -1
  28. package/dist/googleCloud/sheets/server/GoogleCloudSheets.d.cts +1 -1
  29. package/dist/googleCloud/sheets/server/GoogleCloudSheets.d.mts +1 -1
  30. package/dist/googlePageSpeed/server/GooglePageSpeed.cjs +2 -1
  31. package/dist/googlePageSpeed/server/GooglePageSpeed.mjs +2 -1
  32. package/dist/greenDomain/server/greenDomain.cjs +2 -1
  33. package/dist/greenDomain/server/greenDomain.mjs +2 -1
  34. package/dist/littleWarden/server/LittleWarden.cjs +2 -1
  35. package/dist/littleWarden/server/LittleWarden.mjs +2 -1
  36. package/dist/lumar/api/server/buildRequest.cjs +0 -1
  37. package/dist/lumar/api/server/buildRequest.mjs +0 -1
  38. package/dist/snapchat/server/Snapchat.cjs +3 -2
  39. package/dist/snapchat/server/Snapchat.mjs +3 -2
  40. package/dist/util/defaultTo.cjs +6 -3
  41. package/dist/util/defaultTo.mjs +6 -3
  42. package/dist/xlsx/cell.cjs +102 -0
  43. package/dist/xlsx/cell.d.cts +38 -0
  44. package/dist/xlsx/cell.d.mts +38 -0
  45. package/dist/xlsx/cell.mjs +97 -0
  46. package/dist/xlsx/column.cjs +37 -0
  47. package/dist/xlsx/column.d.cts +23 -0
  48. package/dist/xlsx/column.d.mts +23 -0
  49. package/dist/xlsx/column.mjs +35 -0
  50. package/dist/xlsx/createXlsx.cjs +138 -0
  51. package/dist/xlsx/createXlsx.d.cts +18 -0
  52. package/dist/xlsx/createXlsx.d.mts +18 -0
  53. package/dist/xlsx/createXlsx.mjs +136 -0
  54. package/dist/xlsx/index.cjs +18 -0
  55. package/dist/xlsx/index.d.cts +6 -0
  56. package/dist/xlsx/index.d.mts +6 -0
  57. package/dist/xlsx/index.mjs +6 -0
  58. package/dist/xlsx/modifyXlsx.cjs +125 -0
  59. package/dist/xlsx/modifyXlsx.d.cts +24 -0
  60. package/dist/xlsx/modifyXlsx.d.mts +24 -0
  61. package/dist/xlsx/modifyXlsx.mjs +124 -0
  62. package/dist/xlsx/sheet.cjs +36 -0
  63. package/dist/xlsx/sheet.d.cts +29 -0
  64. package/dist/xlsx/sheet.d.mts +29 -0
  65. package/dist/xlsx/sheet.mjs +34 -0
  66. package/package.json +97 -51
@@ -32,7 +32,6 @@ const buildRequest = (props) => {
32
32
  url += `/projects/${props.projectId}/crawls/${props.crawlId}/reports/${props.subReport}`;
33
33
  if (report.REPORT_ROWS === props.report) url += `/report_rows`;
34
34
  else if (report.REPORT_STATISTICS === props.report) url += `/statistics`;
35
- break;
36
35
  }
37
36
  url += -1 === url.indexOf("?") ? "?" : "&";
38
37
  url += `per_page=${props.limit}`;
@@ -10,9 +10,10 @@ var Snapchat = class extends require__class_BaseNamespace.BaseNamespace {
10
10
  init = async (config) => {
11
11
  if (!this.client) {
12
12
  this.config = config;
13
- const apiResponse = await require_api_post.post(`https://accounts.snapchat.com/login/oauth2/access_token?client_id=${this.config.clientId}&client_secret=${this.config.clientSecret}&grant_type=refresh_token&refresh_token=${this.config.refreshToken}`);
13
+ const url = `https://accounts.snapchat.com/login/oauth2/access_token?client_id=${this.config.clientId}&client_secret=${this.config.clientSecret}&grant_type=refresh_token&refresh_token=${this.config.refreshToken}`;
14
+ const apiResponse = await require_api_post.post(url);
14
15
  if (apiResponse.isSuccess()) this.client = {
15
- expires: luxon.DateTime.now().toUnixInteger() + 10800 * 1e3,
16
+ expires: luxon.DateTime.now().toUnixInteger() + 108e5,
16
17
  refreshToken: apiResponse.getBodyDefaultTo(["data", "access_token"], null)
17
18
  };
18
19
  }
@@ -9,9 +9,10 @@ var Snapchat = class extends BaseNamespace {
9
9
  init = async (config) => {
10
10
  if (!this.client) {
11
11
  this.config = config;
12
- const apiResponse = await post(`https://accounts.snapchat.com/login/oauth2/access_token?client_id=${this.config.clientId}&client_secret=${this.config.clientSecret}&grant_type=refresh_token&refresh_token=${this.config.refreshToken}`);
12
+ const url = `https://accounts.snapchat.com/login/oauth2/access_token?client_id=${this.config.clientId}&client_secret=${this.config.clientSecret}&grant_type=refresh_token&refresh_token=${this.config.refreshToken}`;
13
+ const apiResponse = await post(url);
13
14
  if (apiResponse.isSuccess()) this.client = {
14
- expires: DateTime.now().toUnixInteger() + 10800 * 1e3,
15
+ expires: DateTime.now().toUnixInteger() + 108e5,
15
16
  refreshToken: apiResponse.getBodyDefaultTo(["data", "access_token"], null)
16
17
  };
17
18
  }
@@ -11,9 +11,12 @@ const defaultTo = (instance, keys, defaultValue = null) => {
11
11
  let pointer = instance;
12
12
  if ("undefined" === typeof instance || null === pointer) found = false;
13
13
  else keysArray.forEach((key) => {
14
- if (found) if (require_lodash_isObject.isObject(pointer)) if ("undefined" === typeof pointer[key] || null === pointer[key]) found = false;
15
- else pointer = pointer[key];
16
- else found = false;
14
+ if (found) {
15
+ if (require_lodash_isObject.isObject(pointer)) {
16
+ if ("undefined" === typeof pointer[key] || null === pointer[key]) found = false;
17
+ else pointer = pointer[key];
18
+ } else found = false;
19
+ }
17
20
  });
18
21
  return found ? pointer : defaultValue;
19
22
  };
@@ -10,9 +10,12 @@ const defaultTo = (instance, keys, defaultValue = null) => {
10
10
  let pointer = instance;
11
11
  if ("undefined" === typeof instance || null === pointer) found = false;
12
12
  else keysArray.forEach((key) => {
13
- if (found) if (isObject(pointer)) if ("undefined" === typeof pointer[key] || null === pointer[key]) found = false;
14
- else pointer = pointer[key];
15
- else found = false;
13
+ if (found) {
14
+ if (isObject(pointer)) {
15
+ if ("undefined" === typeof pointer[key] || null === pointer[key]) found = false;
16
+ else pointer = pointer[key];
17
+ } else found = false;
18
+ }
16
19
  });
17
20
  return found ? pointer : defaultValue;
18
21
  };
@@ -0,0 +1,102 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xlsx_column = require("./column.cjs");
3
+ //#region src/xlsx/cell.ts
4
+ /**
5
+ * Parse the 1-based column number out of an Excel cell reference.
6
+ *
7
+ * Examples: "A1" → 1, "B3" → 2, "AA1" → 27.
8
+ */
9
+ const getCellColNum = (ref) => {
10
+ const letters = ref.match(/^([A-Z]+)/)?.[1] ?? "A";
11
+ let colNum = 0;
12
+ for (const char of letters) colNum = colNum * 26 + (char.charCodeAt(0) - 64);
13
+ return colNum;
14
+ };
15
+ /**
16
+ * Excel only understands finite numbers inside a <v> element — NaN or Infinity
17
+ * produce a file it offers to "repair". Those fall back to text instead.
18
+ */
19
+ const getCellValue = (value) => {
20
+ if (null === value || void 0 === value) return "";
21
+ if ("number" === typeof value) return Number.isFinite(value) ? value : String(value);
22
+ return value;
23
+ };
24
+ /**
25
+ * Escape the reserved XML characters so a plain string is safe to embed in an
26
+ * attribute value or a text node.
27
+ */
28
+ const getEscapedXml = (text) => {
29
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
30
+ };
31
+ /**
32
+ * Build the raw <c> (cell) XML for a single spreadsheet cell.
33
+ *
34
+ * Numbers use the <v> value element; strings are written as an inline string so
35
+ * there is no shared-strings table to maintain.
36
+ *
37
+ * styleAttr must be either empty or a pre-formatted attribute such as ` s="3"`.
38
+ */
39
+ const buildCellXml = (ref, value, styleAttr) => {
40
+ if ("number" === typeof value) return `<c r="${ref}"${styleAttr}><v>${value}</v></c>`;
41
+ return `<c r="${ref}"${styleAttr} t="inlineStr"><is><t>${getEscapedXml(String(value))}</t></is></c>`;
42
+ };
43
+ /**
44
+ * Insert a <c> snippet into raw row XML, keeping the cells in ascending column
45
+ * order. If a cell with a higher column number already exists the new cell goes
46
+ * before it, otherwise it is appended.
47
+ */
48
+ const insertCellInRow = (rowContent, ref, cellXml) => {
49
+ const newCol = getCellColNum(ref);
50
+ const cellPat = /<c r="([A-Z]+\d+)"(?:[^>]*\/>|[^>]*>[\s\S]*?<\/c>)/g;
51
+ const cells = [];
52
+ let match;
53
+ while (null !== (match = cellPat.exec(rowContent))) cells.push({
54
+ full: match[0],
55
+ col: getCellColNum(match[1])
56
+ });
57
+ const cellAfter = cells.find((cell) => {
58
+ return cell.col > newCol;
59
+ });
60
+ if (cellAfter) return rowContent.replace(cellAfter.full, () => {
61
+ return `${cellXml}${cellAfter.full}`;
62
+ });
63
+ return rowContent + cellXml;
64
+ };
65
+ /**
66
+ * Set a cell value in raw worksheet XML.
67
+ *
68
+ * - If the cell exists, its content is replaced and its style attribute (s="N")
69
+ * is preserved, so a template's formatting survives.
70
+ * - If the row exists but the cell does not, the cell is inserted in column order.
71
+ * - If neither exists, a new row is appended before </sheetData>.
72
+ */
73
+ const setCell = (xml, row, col, value) => {
74
+ const ref = `${require_xlsx_column.getColumLetter(col)}${row}`;
75
+ const cellPat = new RegExp(`<c r="${ref}"([^>]*?)(?:\\s*/>|>[\\s\\S]*?<\\/c>)`);
76
+ const cellMatch = cellPat.exec(xml);
77
+ if (cellMatch) {
78
+ const style = /\bs="(\d+)"/.exec(cellMatch[1]);
79
+ const cellXml = buildCellXml(ref, value, style ? ` s="${style[1]}"` : "");
80
+ return xml.replace(cellPat, () => {
81
+ return cellXml;
82
+ });
83
+ }
84
+ const rowPat = new RegExp(`(<row[^>]+r="${row}"[^>]*>)([\\s\\S]*?)(<\/row>)`);
85
+ const rowMatch = rowPat.exec(xml);
86
+ if (rowMatch) {
87
+ const content = insertCellInRow(rowMatch[2], ref, buildCellXml(ref, value, ""));
88
+ return xml.replace(rowPat, () => {
89
+ return `${rowMatch[1]}${content}${rowMatch[3]}`;
90
+ });
91
+ }
92
+ const newRow = `<row r="${row}">${buildCellXml(ref, value, "")}</row>`;
93
+ return xml.replace("</sheetData>", () => {
94
+ return `${newRow}</sheetData>`;
95
+ });
96
+ };
97
+ //#endregion
98
+ exports.buildCellXml = buildCellXml;
99
+ exports.getCellColNum = getCellColNum;
100
+ exports.getCellValue = getCellValue;
101
+ exports.getEscapedXml = getEscapedXml;
102
+ exports.setCell = setCell;
@@ -0,0 +1,38 @@
1
+ //#region src/xlsx/cell.d.ts
2
+ type XlsxCellValue = string | number | null | undefined;
3
+ /**
4
+ * Parse the 1-based column number out of an Excel cell reference.
5
+ *
6
+ * Examples: "A1" → 1, "B3" → 2, "AA1" → 27.
7
+ */
8
+ declare const getCellColNum: (ref: string) => number;
9
+ /**
10
+ * Excel only understands finite numbers inside a <v> element — NaN or Infinity
11
+ * produce a file it offers to "repair". Those fall back to text instead.
12
+ */
13
+ declare const getCellValue: (value: XlsxCellValue) => string | number;
14
+ /**
15
+ * Escape the reserved XML characters so a plain string is safe to embed in an
16
+ * attribute value or a text node.
17
+ */
18
+ declare const getEscapedXml: (text: string) => string;
19
+ /**
20
+ * Build the raw <c> (cell) XML for a single spreadsheet cell.
21
+ *
22
+ * Numbers use the <v> value element; strings are written as an inline string so
23
+ * there is no shared-strings table to maintain.
24
+ *
25
+ * styleAttr must be either empty or a pre-formatted attribute such as ` s="3"`.
26
+ */
27
+ declare const buildCellXml: (ref: string, value: string | number, styleAttr: string) => string;
28
+ /**
29
+ * Set a cell value in raw worksheet XML.
30
+ *
31
+ * - If the cell exists, its content is replaced and its style attribute (s="N")
32
+ * is preserved, so a template's formatting survives.
33
+ * - If the row exists but the cell does not, the cell is inserted in column order.
34
+ * - If neither exists, a new row is appended before </sheetData>.
35
+ */
36
+ declare const setCell: (xml: string, row: number, col: number, value: string | number) => string;
37
+ //#endregion
38
+ export { XlsxCellValue, buildCellXml, getCellColNum, getCellValue, getEscapedXml, setCell };
@@ -0,0 +1,38 @@
1
+ //#region src/xlsx/cell.d.ts
2
+ type XlsxCellValue = string | number | null | undefined;
3
+ /**
4
+ * Parse the 1-based column number out of an Excel cell reference.
5
+ *
6
+ * Examples: "A1" → 1, "B3" → 2, "AA1" → 27.
7
+ */
8
+ declare const getCellColNum: (ref: string) => number;
9
+ /**
10
+ * Excel only understands finite numbers inside a <v> element — NaN or Infinity
11
+ * produce a file it offers to "repair". Those fall back to text instead.
12
+ */
13
+ declare const getCellValue: (value: XlsxCellValue) => string | number;
14
+ /**
15
+ * Escape the reserved XML characters so a plain string is safe to embed in an
16
+ * attribute value or a text node.
17
+ */
18
+ declare const getEscapedXml: (text: string) => string;
19
+ /**
20
+ * Build the raw <c> (cell) XML for a single spreadsheet cell.
21
+ *
22
+ * Numbers use the <v> value element; strings are written as an inline string so
23
+ * there is no shared-strings table to maintain.
24
+ *
25
+ * styleAttr must be either empty or a pre-formatted attribute such as ` s="3"`.
26
+ */
27
+ declare const buildCellXml: (ref: string, value: string | number, styleAttr: string) => string;
28
+ /**
29
+ * Set a cell value in raw worksheet XML.
30
+ *
31
+ * - If the cell exists, its content is replaced and its style attribute (s="N")
32
+ * is preserved, so a template's formatting survives.
33
+ * - If the row exists but the cell does not, the cell is inserted in column order.
34
+ * - If neither exists, a new row is appended before </sheetData>.
35
+ */
36
+ declare const setCell: (xml: string, row: number, col: number, value: string | number) => string;
37
+ //#endregion
38
+ export { XlsxCellValue, buildCellXml, getCellColNum, getCellValue, getEscapedXml, setCell };
@@ -0,0 +1,97 @@
1
+ import { getColumLetter } from "./column.mjs";
2
+ //#region src/xlsx/cell.ts
3
+ /**
4
+ * Parse the 1-based column number out of an Excel cell reference.
5
+ *
6
+ * Examples: "A1" → 1, "B3" → 2, "AA1" → 27.
7
+ */
8
+ const getCellColNum = (ref) => {
9
+ const letters = ref.match(/^([A-Z]+)/)?.[1] ?? "A";
10
+ let colNum = 0;
11
+ for (const char of letters) colNum = colNum * 26 + (char.charCodeAt(0) - 64);
12
+ return colNum;
13
+ };
14
+ /**
15
+ * Excel only understands finite numbers inside a <v> element — NaN or Infinity
16
+ * produce a file it offers to "repair". Those fall back to text instead.
17
+ */
18
+ const getCellValue = (value) => {
19
+ if (null === value || void 0 === value) return "";
20
+ if ("number" === typeof value) return Number.isFinite(value) ? value : String(value);
21
+ return value;
22
+ };
23
+ /**
24
+ * Escape the reserved XML characters so a plain string is safe to embed in an
25
+ * attribute value or a text node.
26
+ */
27
+ const getEscapedXml = (text) => {
28
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
29
+ };
30
+ /**
31
+ * Build the raw <c> (cell) XML for a single spreadsheet cell.
32
+ *
33
+ * Numbers use the <v> value element; strings are written as an inline string so
34
+ * there is no shared-strings table to maintain.
35
+ *
36
+ * styleAttr must be either empty or a pre-formatted attribute such as ` s="3"`.
37
+ */
38
+ const buildCellXml = (ref, value, styleAttr) => {
39
+ if ("number" === typeof value) return `<c r="${ref}"${styleAttr}><v>${value}</v></c>`;
40
+ return `<c r="${ref}"${styleAttr} t="inlineStr"><is><t>${getEscapedXml(String(value))}</t></is></c>`;
41
+ };
42
+ /**
43
+ * Insert a <c> snippet into raw row XML, keeping the cells in ascending column
44
+ * order. If a cell with a higher column number already exists the new cell goes
45
+ * before it, otherwise it is appended.
46
+ */
47
+ const insertCellInRow = (rowContent, ref, cellXml) => {
48
+ const newCol = getCellColNum(ref);
49
+ const cellPat = /<c r="([A-Z]+\d+)"(?:[^>]*\/>|[^>]*>[\s\S]*?<\/c>)/g;
50
+ const cells = [];
51
+ let match;
52
+ while (null !== (match = cellPat.exec(rowContent))) cells.push({
53
+ full: match[0],
54
+ col: getCellColNum(match[1])
55
+ });
56
+ const cellAfter = cells.find((cell) => {
57
+ return cell.col > newCol;
58
+ });
59
+ if (cellAfter) return rowContent.replace(cellAfter.full, () => {
60
+ return `${cellXml}${cellAfter.full}`;
61
+ });
62
+ return rowContent + cellXml;
63
+ };
64
+ /**
65
+ * Set a cell value in raw worksheet XML.
66
+ *
67
+ * - If the cell exists, its content is replaced and its style attribute (s="N")
68
+ * is preserved, so a template's formatting survives.
69
+ * - If the row exists but the cell does not, the cell is inserted in column order.
70
+ * - If neither exists, a new row is appended before </sheetData>.
71
+ */
72
+ const setCell = (xml, row, col, value) => {
73
+ const ref = `${getColumLetter(col)}${row}`;
74
+ const cellPat = new RegExp(`<c r="${ref}"([^>]*?)(?:\\s*/>|>[\\s\\S]*?<\\/c>)`);
75
+ const cellMatch = cellPat.exec(xml);
76
+ if (cellMatch) {
77
+ const style = /\bs="(\d+)"/.exec(cellMatch[1]);
78
+ const cellXml = buildCellXml(ref, value, style ? ` s="${style[1]}"` : "");
79
+ return xml.replace(cellPat, () => {
80
+ return cellXml;
81
+ });
82
+ }
83
+ const rowPat = new RegExp(`(<row[^>]+r="${row}"[^>]*>)([\\s\\S]*?)(<\/row>)`);
84
+ const rowMatch = rowPat.exec(xml);
85
+ if (rowMatch) {
86
+ const content = insertCellInRow(rowMatch[2], ref, buildCellXml(ref, value, ""));
87
+ return xml.replace(rowPat, () => {
88
+ return `${rowMatch[1]}${content}${rowMatch[3]}`;
89
+ });
90
+ }
91
+ const newRow = `<row r="${row}">${buildCellXml(ref, value, "")}</row>`;
92
+ return xml.replace("</sheetData>", () => {
93
+ return `${newRow}</sheetData>`;
94
+ });
95
+ };
96
+ //#endregion
97
+ export { buildCellXml, getCellColNum, getCellValue, getEscapedXml, setCell };
@@ -0,0 +1,37 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xlsx_cell = require("./cell.cjs");
3
+ //#region src/xlsx/column.ts
4
+ /** Bounds for widths derived from content, so nothing is cramped or absurd. */
5
+ const COLUMN_WIDTH_MIN = 10;
6
+ const COLUMN_WIDTH_MAX = 60;
7
+ /**
8
+ * Convert a 1-based column number to an Excel column letter string.
9
+ *
10
+ * Examples: 1 → "A", 2 → "B", 26 → "Z", 27 → "AA", 28 → "AB".
11
+ */
12
+ const getColumLetter = (colNum) => {
13
+ let result = "";
14
+ let remaining = colNum;
15
+ while (remaining > 0) {
16
+ remaining--;
17
+ result = String.fromCharCode(65 + remaining % 26) + result;
18
+ remaining = Math.floor(remaining / 26);
19
+ }
20
+ return result;
21
+ };
22
+ /**
23
+ * Width in Excel character units, taken from the widest value in the column
24
+ * (header included) and clamped. Heading lines are excluded on purpose: they sit
25
+ * in column A and overflow into the empty cells beside them, so letting them
26
+ * drive the width would stretch the first column for no benefit.
27
+ */
28
+ const getColumnWidth = (column, data) => {
29
+ if (column?.width) return column.width;
30
+ const longest = data.reduce((widest, row) => {
31
+ return Math.max(widest, String(require_xlsx_cell.getCellValue(row?.[column.id])).length);
32
+ }, column.displayName.length);
33
+ return Math.min(COLUMN_WIDTH_MAX, Math.max(COLUMN_WIDTH_MIN, longest + 2));
34
+ };
35
+ //#endregion
36
+ exports.getColumLetter = getColumLetter;
37
+ exports.getColumnWidth = getColumnWidth;
@@ -0,0 +1,23 @@
1
+ import { XlsxCellValue } from "./cell.cjs";
2
+ //#region src/xlsx/column.d.ts
3
+ type XlsxColumn = {
4
+ id: string;
5
+ displayName: string;
6
+ /** Column width in Excel character units. Derived from the content when omitted. */
7
+ width?: number;
8
+ };
9
+ /**
10
+ * Convert a 1-based column number to an Excel column letter string.
11
+ *
12
+ * Examples: 1 → "A", 2 → "B", 26 → "Z", 27 → "AA", 28 → "AB".
13
+ */
14
+ declare const getColumLetter: (colNum: number) => string;
15
+ /**
16
+ * Width in Excel character units, taken from the widest value in the column
17
+ * (header included) and clamped. Heading lines are excluded on purpose: they sit
18
+ * in column A and overflow into the empty cells beside them, so letting them
19
+ * drive the width would stretch the first column for no benefit.
20
+ */
21
+ declare const getColumnWidth: (column: XlsxColumn, data: Record<string, XlsxCellValue>[]) => number;
22
+ //#endregion
23
+ export { XlsxColumn, getColumLetter, getColumnWidth };
@@ -0,0 +1,23 @@
1
+ import { XlsxCellValue } from "./cell.mjs";
2
+ //#region src/xlsx/column.d.ts
3
+ type XlsxColumn = {
4
+ id: string;
5
+ displayName: string;
6
+ /** Column width in Excel character units. Derived from the content when omitted. */
7
+ width?: number;
8
+ };
9
+ /**
10
+ * Convert a 1-based column number to an Excel column letter string.
11
+ *
12
+ * Examples: 1 → "A", 2 → "B", 26 → "Z", 27 → "AA", 28 → "AB".
13
+ */
14
+ declare const getColumLetter: (colNum: number) => string;
15
+ /**
16
+ * Width in Excel character units, taken from the widest value in the column
17
+ * (header included) and clamped. Heading lines are excluded on purpose: they sit
18
+ * in column A and overflow into the empty cells beside them, so letting them
19
+ * drive the width would stretch the first column for no benefit.
20
+ */
21
+ declare const getColumnWidth: (column: XlsxColumn, data: Record<string, XlsxCellValue>[]) => number;
22
+ //#endregion
23
+ export { XlsxColumn, getColumLetter, getColumnWidth };
@@ -0,0 +1,35 @@
1
+ import { getCellValue } from "./cell.mjs";
2
+ //#region src/xlsx/column.ts
3
+ /** Bounds for widths derived from content, so nothing is cramped or absurd. */
4
+ const COLUMN_WIDTH_MIN = 10;
5
+ const COLUMN_WIDTH_MAX = 60;
6
+ /**
7
+ * Convert a 1-based column number to an Excel column letter string.
8
+ *
9
+ * Examples: 1 → "A", 2 → "B", 26 → "Z", 27 → "AA", 28 → "AB".
10
+ */
11
+ const getColumLetter = (colNum) => {
12
+ let result = "";
13
+ let remaining = colNum;
14
+ while (remaining > 0) {
15
+ remaining--;
16
+ result = String.fromCharCode(65 + remaining % 26) + result;
17
+ remaining = Math.floor(remaining / 26);
18
+ }
19
+ return result;
20
+ };
21
+ /**
22
+ * Width in Excel character units, taken from the widest value in the column
23
+ * (header included) and clamped. Heading lines are excluded on purpose: they sit
24
+ * in column A and overflow into the empty cells beside them, so letting them
25
+ * drive the width would stretch the first column for no benefit.
26
+ */
27
+ const getColumnWidth = (column, data) => {
28
+ if (column?.width) return column.width;
29
+ const longest = data.reduce((widest, row) => {
30
+ return Math.max(widest, String(getCellValue(row?.[column.id])).length);
31
+ }, column.displayName.length);
32
+ return Math.min(COLUMN_WIDTH_MAX, Math.max(COLUMN_WIDTH_MIN, longest + 2));
33
+ };
34
+ //#endregion
35
+ export { getColumLetter, getColumnWidth };
@@ -0,0 +1,138 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xlsx_column = require("./column.cjs");
3
+ const require_xlsx_cell = require("./cell.cjs");
4
+ const require_xlsx_sheet = require("./sheet.cjs");
5
+ //#region src/xlsx/createXlsx.ts
6
+ /**
7
+ * Builds a complete .xlsx workbook from scratch, using jszip and hand-written
8
+ * OOXML rather than a spreadsheet library.
9
+ *
10
+ * Nothing here touches `fs`, so it runs in the browser as happily as on the
11
+ * server — a page can turn data it has already loaded straight into a download.
12
+ *
13
+ * jszip is an optional peer dependency imported dynamically, so consumers that
14
+ * never build a workbook neither install it nor pay for it in their bundle.
15
+ */
16
+ /** Style index of the bold row within the cellXfs list built by buildStylesXml. */
17
+ const HEADER_STYLE_INDEX = 1;
18
+ const XML_DECLARATION = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`;
19
+ const CONTENT_TYPE = {
20
+ SHEET: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
21
+ STYLES: "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",
22
+ WORKSHEET: "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
23
+ };
24
+ const REL_TYPE = {
25
+ OFFICE_DOCUMENT: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
26
+ STYLES: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
27
+ WORKSHEET: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
28
+ };
29
+ const NAMESPACES = {
30
+ MAIN: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
31
+ RELATIONSHIP: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
32
+ PACKAGE_REL: "http://schemas.openxmlformats.org/package/2006/relationships",
33
+ CONTENT_TYPES: "http://schemas.openxmlformats.org/package/2006/content-types"
34
+ };
35
+ /**
36
+ * Minimal but valid styles part. Excel requires at least one border, one
37
+ * cellStyleXf and two fills (index 0 "none", index 1 "gray125") even when
38
+ * nothing references them. cellXfs index 1 is the bold header.
39
+ */
40
+ const buildStylesXml = () => {
41
+ return XML_DECLARATION + `<styleSheet xmlns="${NAMESPACES.MAIN}"><fonts count="2"><font><sz val="11"/><name val="Calibri"/></font><font><b/><sz val="11"/><name val="Calibri"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders><cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs><cellXfs count="2"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/><xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="0" applyFont="1"/></cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles></styleSheet>`;
42
+ };
43
+ /**
44
+ * One worksheet part: column widths, an optional heading block, a bold header row
45
+ * from the column display names, then one row per data object in column order.
46
+ *
47
+ * <cols> must precede <sheetData> or Excel treats the file as corrupt.
48
+ */
49
+ const buildWorksheetXml = (sheet) => {
50
+ const heading = sheet?.heading || [];
51
+ const headerRow = 0 === heading.length ? 1 : heading.length + 2;
52
+ const colsXml = sheet.columns.map((column, index) => {
53
+ const position = index + 1;
54
+ return `<col min="${position}" max="${position}" width="${require_xlsx_column.getColumnWidth(column, sheet.data)}" customWidth="1"/>`;
55
+ }).join("");
56
+ const headingXml = heading.map((line, index) => {
57
+ const styleAttr = 0 === index ? ` s="${HEADER_STYLE_INDEX}"` : "";
58
+ return `<row r="${index + 1}">${require_xlsx_cell.buildCellXml(`A${index + 1}`, line, styleAttr)}</row>`;
59
+ }).join("");
60
+ const headerXml = sheet.columns.map((column, index) => {
61
+ return require_xlsx_cell.buildCellXml(`${require_xlsx_column.getColumLetter(index + 1)}${headerRow}`, column.displayName, ` s="${HEADER_STYLE_INDEX}"`);
62
+ }).join("");
63
+ const rowsXml = sheet.data.map((row, rowIndex) => {
64
+ const rowNumber = headerRow + rowIndex + 1;
65
+ return `<row r="${rowNumber}">${sheet.columns.map((column, columnIndex) => {
66
+ return require_xlsx_cell.buildCellXml(`${require_xlsx_column.getColumLetter(columnIndex + 1)}${rowNumber}`, require_xlsx_cell.getCellValue(row?.[column.id]), "");
67
+ }).join("")}</row>`;
68
+ }).join("");
69
+ return XML_DECLARATION + `<worksheet xmlns="${NAMESPACES.MAIN}">` + (colsXml ? `<cols>${colsXml}</cols>` : "") + `<sheetData>${headingXml}<row r="${headerRow}">${headerXml}</row>${rowsXml}</sheetData></worksheet>`;
70
+ };
71
+ const buildContentTypesXml = (sheetCount) => {
72
+ const overrides = Array.from({ length: sheetCount }, (unused, index) => {
73
+ return `<Override PartName="/xl/worksheets/sheet${index + 1}.xml" ContentType="${CONTENT_TYPE.WORKSHEET}"/>`;
74
+ }).join("");
75
+ return XML_DECLARATION + `<Types xmlns="${NAMESPACES.CONTENT_TYPES}"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="${CONTENT_TYPE.SHEET}"/><Override PartName="/xl/styles.xml" ContentType="${CONTENT_TYPE.STYLES}"/>` + overrides + `</Types>`;
76
+ };
77
+ const buildWorkbookXml = (sheetNames) => {
78
+ const sheetsXml = sheetNames.map((name, index) => {
79
+ return `<sheet name="${require_xlsx_cell.getEscapedXml(name)}" sheetId="${index + 1}" r:id="rId${index + 1}"/>`;
80
+ }).join("");
81
+ return XML_DECLARATION + `<workbook xmlns="${NAMESPACES.MAIN}" xmlns:r="${NAMESPACES.RELATIONSHIP}"><sheets>${sheetsXml}</sheets></workbook>`;
82
+ };
83
+ const buildWorkbookRelsXml = (sheetCount) => {
84
+ const sheetRels = Array.from({ length: sheetCount }, (unused, index) => {
85
+ return `<Relationship Id="rId${index + 1}" Type="${REL_TYPE.WORKSHEET}" Target="worksheets/sheet${index + 1}.xml"/>`;
86
+ }).join("");
87
+ return XML_DECLARATION + `<Relationships xmlns="${NAMESPACES.PACKAGE_REL}">` + sheetRels + `<Relationship Id="rId${sheetCount + 1}" Type="${REL_TYPE.STYLES}" Target="styles.xml"/></Relationships>`;
88
+ };
89
+ const buildPackageRelsXml = () => {
90
+ return XML_DECLARATION + `<Relationships xmlns="${NAMESPACES.PACKAGE_REL}"><Relationship Id="rId1" Type="${REL_TYPE.OFFICE_DOCUMENT}" Target="xl/workbook.xml"/></Relationships>`;
91
+ };
92
+ /**
93
+ * Assemble the workbook parts. Shared by the Blob and byte-array entry points so
94
+ * the two can never drift.
95
+ */
96
+ const buildWorkbook = async (sheets) => {
97
+ if (0 === sheets.length) throw new Error("createXlsx requires at least one sheet.");
98
+ const JSZip = (await import("jszip")).default;
99
+ const zip = new JSZip();
100
+ const names = require_xlsx_sheet.getUniqueSheetNames(sheets);
101
+ zip.file("[Content_Types].xml", buildContentTypesXml(sheets.length));
102
+ zip.file("_rels/.rels", buildPackageRelsXml());
103
+ zip.file("xl/workbook.xml", buildWorkbookXml(names));
104
+ zip.file("xl/_rels/workbook.xml.rels", buildWorkbookRelsXml(sheets.length));
105
+ zip.file("xl/styles.xml", buildStylesXml());
106
+ sheets.forEach((sheet, index) => {
107
+ zip.file(`xl/worksheets/sheet${index + 1}.xml`, buildWorksheetXml(sheet));
108
+ });
109
+ return zip;
110
+ };
111
+ /**
112
+ * Build an .xlsx workbook with one worksheet per entry in `sheets`, returned as a
113
+ * Blob ready to hand to a browser download.
114
+ *
115
+ * Every sheet gets a bold header row from its column display names, and each data
116
+ * row reads values by column `id` — so key order in the source objects does not
117
+ * matter and a missing key becomes an empty cell.
118
+ */
119
+ const createXlsx = async (sheets) => {
120
+ return (await buildWorkbook(sheets)).generateAsync({
121
+ type: "blob",
122
+ compression: "DEFLATE",
123
+ mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
124
+ });
125
+ };
126
+ /**
127
+ * As createXlsx, but returns raw bytes instead of a Blob — for server-side
128
+ * callers that need to stream or write the workbook rather than download it.
129
+ */
130
+ const createXlsxBytes = async (sheets) => {
131
+ return (await buildWorkbook(sheets)).generateAsync({
132
+ type: "uint8array",
133
+ compression: "DEFLATE"
134
+ });
135
+ };
136
+ //#endregion
137
+ exports.createXlsx = createXlsx;
138
+ exports.createXlsxBytes = createXlsxBytes;
@@ -0,0 +1,18 @@
1
+ import { XlsxSheet } from "./sheet.cjs";
2
+ //#region src/xlsx/createXlsx.d.ts
3
+ /**
4
+ * Build an .xlsx workbook with one worksheet per entry in `sheets`, returned as a
5
+ * Blob ready to hand to a browser download.
6
+ *
7
+ * Every sheet gets a bold header row from its column display names, and each data
8
+ * row reads values by column `id` — so key order in the source objects does not
9
+ * matter and a missing key becomes an empty cell.
10
+ */
11
+ declare const createXlsx: (sheets: XlsxSheet[]) => Promise<Blob>;
12
+ /**
13
+ * As createXlsx, but returns raw bytes instead of a Blob — for server-side
14
+ * callers that need to stream or write the workbook rather than download it.
15
+ */
16
+ declare const createXlsxBytes: (sheets: XlsxSheet[]) => Promise<Uint8Array>;
17
+ //#endregion
18
+ export { createXlsx, createXlsxBytes };
@@ -0,0 +1,18 @@
1
+ import { XlsxSheet } from "./sheet.mjs";
2
+ //#region src/xlsx/createXlsx.d.ts
3
+ /**
4
+ * Build an .xlsx workbook with one worksheet per entry in `sheets`, returned as a
5
+ * Blob ready to hand to a browser download.
6
+ *
7
+ * Every sheet gets a bold header row from its column display names, and each data
8
+ * row reads values by column `id` — so key order in the source objects does not
9
+ * matter and a missing key becomes an empty cell.
10
+ */
11
+ declare const createXlsx: (sheets: XlsxSheet[]) => Promise<Blob>;
12
+ /**
13
+ * As createXlsx, but returns raw bytes instead of a Blob — for server-side
14
+ * callers that need to stream or write the workbook rather than download it.
15
+ */
16
+ declare const createXlsxBytes: (sheets: XlsxSheet[]) => Promise<Uint8Array>;
17
+ //#endregion
18
+ export { createXlsx, createXlsxBytes };