@20baht/export 0.1.3 → 0.1.4

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 CHANGED
@@ -110,8 +110,8 @@ const page: LaidSheet = {
110
110
  const bytes = await xlsx([page, expenses]); // beside sheets of rows, a tab each
111
111
  ```
112
112
 
113
- A cell is its value (`string | number | boolean | Date | null`) or `{ value, bold, italic, underline, color, shade, fill, border, wrap, center, align, format }`
114
- (`color` and `fill` as `#rrggbb`; `align` is `left` / `center` / `right`; `border` is `true` or the sides, `['top', 'bottom']`). With `formula` (Excel's spelling, `SUM(A1:A9)`), the cell is
113
+ A cell is its value (`string | number | boolean | Date | null`) or `{ value, bold, italic, underline, color, shade, fill, border, wrap, center, align, valign, format }`
114
+ (`color` and `fill` as `#rrggbb`; `align` is `left` / `center` / `right`, `valign` `top` / `middle` / `bottom`; `border` is `true` or the sides, `['top', 'bottom']`). With `formula` (Excel's spelling, `SUM(A1:A9)`), the cell is
115
115
  that formula and `value` is what it had when the file was written: the workbook asks its reader to work it out again.
116
116
  `@20baht/spreadsheet`'s `bookWorkbook` lays a book out this way.
117
117
  `@20baht/sheet`'s `sheetWorkbook(sheet, data)` lays a filled sheet out this way.
package/dist/sheet.d.ts CHANGED
@@ -47,6 +47,8 @@ export interface CellLook {
47
47
  center?: boolean;
48
48
  /** Across only: left, centre or right. It wins over `center`'s across; up and down stays as it is. */
49
49
  align?: 'left' | 'center' | 'right';
50
+ /** Up and down only: top, middle or bottom. It wins over `center`'s and `wrap`'s up and down. */
51
+ valign?: 'top' | 'middle' | 'bottom';
50
52
  /** An Excel number format for a number or a date: `'#,##0.00'`, `'dd/mm/yyyy hh:mm'`. */
51
53
  format?: string;
52
54
  }
package/dist/xlsx.js CHANGED
@@ -37,6 +37,11 @@ const rgb = (colour) => {
37
37
  return colour.slice(1).toUpperCase();
38
38
  };
39
39
  const SIDES = ['left', 'right', 'top', 'bottom'];
40
+ const VERTICAL = {
41
+ top: 'top',
42
+ middle: 'center',
43
+ bottom: 'bottom',
44
+ };
40
45
  const sidesOf = (border) => border === true
41
46
  ? SIDES.join(',')
42
47
  : SIDES.filter((side) => border !== undefined && border !== false && border.includes(side)).join(',');
@@ -62,8 +67,9 @@ class Styles {
62
67
  look.fill ?? '',
63
68
  look.align ?? '',
64
69
  look.border === true ? '' : sidesOf(look.border),
70
+ look.valign ?? '',
65
71
  ].join('|');
66
- const key = flags + (more === '|||||' ? '' : `${more}|`) + (format ?? '');
72
+ const key = flags + (more === '||||||' ? '' : `${more}|`) + (format ?? '');
67
73
  if (key === '00000')
68
74
  return 0;
69
75
  if (key === '10000')
@@ -130,8 +136,9 @@ class Styles {
130
136
  const font = this.#font(look);
131
137
  const fill = this.#fill(look);
132
138
  const across = look.align ?? (look.center === true ? 'center' : undefined);
133
- const upDown = look.wrap === true || look.center === true;
134
- const aligned = upDown || across !== undefined;
139
+ const middle = look.center === true ? 'center' : undefined;
140
+ const upDown = VERTICAL[look.valign ?? ''] ?? middle ?? (look.wrap === true ? 'top' : undefined);
141
+ const aligned = upDown !== undefined || across !== undefined;
135
142
  const attrs = `numFmtId="${String(this.#numFmt(format))}" fontId="${String(font)}"` +
136
143
  ` fillId="${String(fill)}" borderId="${String(border)}" xfId="0"` +
137
144
  on(format !== undefined, ' applyNumberFormat="1"') +
@@ -142,7 +149,7 @@ class Styles {
142
149
  if (!aligned)
143
150
  return `<xf ${attrs}/>`;
144
151
  const alignment = (across === undefined ? '' : ` horizontal="${across}"`) +
145
- on(upDown, ` vertical="${on(look.center, 'center') || 'top'}"`) +
152
+ (upDown === undefined ? '' : ` vertical="${upDown}"`) +
146
153
  on(look.wrap, ' wrapText="1"');
147
154
  return `<xf ${attrs}><alignment${alignment}/></xf>`;
148
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@20baht/export",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=20.19.0"