@devmm/puredocs-excel-formula 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -275,7 +275,7 @@ declare namespace FormulaHelper {
275
275
  * Everything else — comparisons, wildcards — only gets the compiled `test`.
276
276
  */
277
277
  interface CompiledCriteria {
278
- readonly kind: 'equalsNumber' | 'equalsText' | 'compareNumber' | 'other';
278
+ readonly kind: 'equalsNumber' | 'equalsText' | 'compareNumber' | 'blankness' | 'other';
279
279
  /** For `equalsNumber` and `compareNumber`: the number compared against. */
280
280
  readonly number?: number;
281
281
  /** For `equalsText`: the criterion, upper-cased (matching is case-insensitive). */
package/dist/index.d.ts CHANGED
@@ -275,7 +275,7 @@ declare namespace FormulaHelper {
275
275
  * Everything else — comparisons, wildcards — only gets the compiled `test`.
276
276
  */
277
277
  interface CompiledCriteria {
278
- readonly kind: 'equalsNumber' | 'equalsText' | 'compareNumber' | 'other';
278
+ readonly kind: 'equalsNumber' | 'equalsText' | 'compareNumber' | 'blankness' | 'other';
279
279
  /** For `equalsNumber` and `compareNumber`: the number compared against. */
280
280
  readonly number?: number;
281
281
  /** For `equalsText`: the criterion, upper-cased (matching is case-insensitive). */
package/dist/index.js CHANGED
@@ -280,7 +280,7 @@ var _FormulaValue = class _FormulaValue {
280
280
  if (value2 === null || value2 === void 0) return _FormulaValue.blank;
281
281
  if (typeof value2 === "number") return isNaN(value2) ? _FormulaValue.errorValue : _FormulaValue.number(value2);
282
282
  if (typeof value2 === "boolean") return _FormulaValue.boolean(value2);
283
- if (typeof value2 === "string") return value2 === "" ? _FormulaValue.blank : _FormulaValue.text(value2);
283
+ if (typeof value2 === "string") return _FormulaValue.text(value2);
284
284
  if (value2 instanceof Date) {
285
285
  return _FormulaValue.number(toOADate(value2));
286
286
  }
@@ -1818,11 +1818,14 @@ function count(a, c) {
1818
1818
  function countA(a, c) {
1819
1819
  return FormulaValue.number(FormulaHelper.flattenArgs(a, c).filter((v) => !v.isBlank).length);
1820
1820
  }
1821
+ function isCountBlank(v) {
1822
+ return v.isBlank || v.isText && v.textValue === "";
1823
+ }
1821
1824
  function countBlank(a, c) {
1822
1825
  const v = a[0].evaluate(c);
1823
- if (!v.isArray) return FormulaValue.number(v.isBlank ? 1 : 0);
1826
+ if (!v.isArray) return FormulaValue.number(isCountBlank(v) ? 1 : 0);
1824
1827
  let n = 0;
1825
- for (const item of v.arrayVal.values()) if (item.isBlank) n++;
1828
+ for (const item of v.arrayVal.values()) if (isCountBlank(item)) n++;
1826
1829
  return FormulaValue.number(n);
1827
1830
  }
1828
1831
  function countIf(a, c) {
@@ -1830,11 +1833,12 @@ function countIf(a, c) {
1830
1833
  if (range.isError) return range;
1831
1834
  const crit = a[1].evaluate(c);
1832
1835
  if (crit.isError) return crit;
1833
- const criteria = crit.asText();
1834
- if (!range.isArray) return FormulaValue.number(FormulaHelper.matchesCriteria(range, criteria) ? 1 : 0);
1836
+ const compiled = FormulaHelper.compileCriteria(crit.asText());
1837
+ if (!range.isArray) return FormulaValue.number(compiled.test(range) ? 1 : 0);
1838
+ const countBlanks = compiled.kind === "blankness";
1835
1839
  let n = 0;
1836
1840
  for (const item of range.arrayVal.values()) {
1837
- if (!item.isBlank && FormulaHelper.matchesCriteria(item, criteria)) n++;
1841
+ if ((countBlanks || !item.isBlank) && compiled.test(item)) n++;
1838
1842
  }
1839
1843
  return FormulaValue.number(n);
1840
1844
  }
@@ -4726,6 +4730,8 @@ var FormulaHelper;
4726
4730
  const rhsVal = parseFloat(rhs);
4727
4731
  const rhsNum = isNaN(rhsVal) ? null : rhsVal;
4728
4732
  const rhsValue = rhsNum !== null ? FormulaValue.number(rhsNum) : FormulaValue.text(rhs);
4733
+ if (rhs === "" && op === "=") return { kind: "blankness", test: (v) => v.isBlank };
4734
+ if (rhs === "" && op === "<>") return { kind: "other", test: (v) => !v.isBlank };
4729
4735
  if (op === "=") {
4730
4736
  return rhsNum !== null ? numberEquality(rhsNum) : textEquality(rhs);
4731
4737
  }
@@ -4741,6 +4747,9 @@ var FormulaHelper;
4741
4747
  const pattern = wildcardToRegex(trimmed);
4742
4748
  return { kind: "other", test: (v) => pattern.test(v.asText()) };
4743
4749
  }
4750
+ if (trimmed === "") {
4751
+ return { kind: "blankness", test: (v) => v.isBlank || v.isText && v.textValue === "" };
4752
+ }
4744
4753
  const num5 = parseFloat(trimmed);
4745
4754
  return isNaN(num5) ? textEquality(trimmed) : numberEquality(num5);
4746
4755
  }