@Sebastian . Thanks for the same.
How do I round the value. Using the wordcount I wish to calculate the reading time of the article
None of these Work in Script Code (All give Javascript Errors) - Please can you refer me to the documentation where I can use basic math functions in script in Squidex
toInteger()
ctx.data.time.en = toInteger(wordCount(html2Text(ctx.data.body.en))/200)
Math.round()
ctx.data.time.en = Math.round(wordCount(html2Text(ctx.data.body.en))/200)
round()
ctx.data.time.en = round(wordCount(html2Text(ctx.data.body.en))/200)
stepUp()
ctx.data.time.en = stepUp(wordCount(html2Text(ctx.data.body.en))/200)
ceil()
ctx.data.time.en = ceil(wordCount(html2Text(ctx.data.body.en))/200)
PS: I checked other online word/character counter with basic algos they seem to match your formulas
https://wordcounter.net/ and https://www.chineseconverter.com/en/convert/chinese-character-count
Can you post the exact error? Math is available,
here you can find a list of all functions: https://github.com/sebastienros/jint/blob/dev/Jint/Native/Math/MathInstance.cs#L34
But I recommend not to calculate it inside Squidex, because it is easier and faster to solve in the frontend.
1 Like
Can you create a feature request for the word count improvement?
Hi, I made a first attempt:
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using Xunit;
namespace Squidex.Text.Tests
{
public class WordsTests
{
[Fact]
public void Should_count_zero_words_for_empty_text()
{
Assert.Equal(0, Words.Count(string.Empty));
}
[Fact]
This file has been truncated. show original
Can you have to the tests and see if you will find another use case that should be tested.