From c5f9cf0cc27a6822bc355b69816e818a7561900f Mon Sep 17 00:00:00 2001 From: Patrick Hensley Date: Thu, 16 Oct 2025 10:11:55 -0400 Subject: [PATCH] Add string support to count formatter --- __tests__/plugins/formatters.core.test.ts | 2 +- __tests__/plugins/resources/f-count-1.html | 2 +- src/plugins/formatters.core.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/plugins/formatters.core.test.ts b/__tests__/plugins/formatters.core.test.ts index 5c6ec66..3357a92 100644 --- a/__tests__/plugins/formatters.core.test.ts +++ b/__tests__/plugins/formatters.core.test.ts @@ -210,7 +210,7 @@ test('count', () => { vars = variables('hello'); Core.count.apply([], vars, CTX); - expect(vars[0].get()).toEqual(0); + expect(vars[0].get()).toEqual(5); vars = variables(true); Core.count.apply([], vars, CTX); diff --git a/__tests__/plugins/resources/f-count-1.html b/__tests__/plugins/resources/f-count-1.html index df2e818..543d161 100644 --- a/__tests__/plugins/resources/f-count-1.html +++ b/__tests__/plugins/resources/f-count-1.html @@ -21,5 +21,5 @@ :OUTPUT 4 3 -0 +2 0 \ No newline at end of file diff --git a/src/plugins/formatters.core.ts b/src/plugins/formatters.core.ts index 78ec5bd..14c1c29 100644 --- a/src/plugins/formatters.core.ts +++ b/src/plugins/formatters.core.ts @@ -81,7 +81,7 @@ export class CountFormatter extends Formatter { const node = first.node; if (node.type === Type.OBJECT) { first.set(Object.keys(node.value).length); - } else if (node.type === Type.ARRAY) { + } else if (node.type === Type.ARRAY || node.type === Type.STRING) { first.set(node.value.length); } else { first.set(0);