[{"data":1,"prerenderedAt":19},["ShallowReactive",2],{"blog-post-en-transform-extracted-text-in-broma-with-javascript":3},{"slug":4,"lang":5,"title":6,"summary":7,"date":8,"tags":9,"tag_slugs":14,"thumbnail_url":15,"translations":16,"body":17,"asset_base":18},"transform-extracted-text-in-broma-with-javascript","en","Transform Extracted Text in Broma With JavaScript","Read text from a page, clean it with short JavaScript expressions, and pass the result into the next Broma step. No coding required beyond simple expressions.","2026-11-09",[10,11,12,13],"broma","javascript","data-cleaning","workflow",[10,11,12,13],"https:\u002F\u002Fblog-api.bromaapp.com\u002Fapi\u002Fblog\u002Fposts\u002Ftransform-extracted-text-in-broma-with-javascript\u002Fthumbnail.svg?lang=en",[5],"Web text is rarely ready for the next system. A page might show '$1,299.00', 'In stock: 14 units', or 'Updated March 5, 2024', but the form you type into often wants plain numbers, a specific date format, or a single word. Paste the raw text into a numeric price field and the form may reject it. Paste 'In stock: 14 units' into a quantity column and your report breaks.\n\nBroma is a Windows desktop app that runs workflows on your own computer. You can build these flows without code, and Broma also supports short JavaScript expressions between steps. Those expressions are the bridge between what a website shows and what your downstream tool accepts.\n\nThis guide shows how to read text from a page, clean or reformat it with a short JavaScript expression, and pass the result into the next step. It assumes you already have Broma installed and know how to add a Read Text step and a Type step.\n\n## Step 1: Read the raw text from the page\n\nOpen the page you want to monitor in Broma. Add a Read Text step and choose a selector that targets the element containing the value. Prefer selectors that survive minor page changes, such as an ID, a stable data attribute, or a combination of class and text content.\n\nExample selector:\n\n```\n#product-price\n```\n\nor\n\n```\n[data-testid=\"stock-count\"]\n```\n\nRun the flow once and inspect the captured value in the run log. Suppose the page shows:\n\n```\n$1,299.00\n```\n\nBroma stores that string as the output of the Read Text step. Before you use it, look at the raw output so you know exactly what characters you are dealing with, including hidden spaces or line breaks.\n\n## Step 2: Add a JavaScript expression step\n\nAfter the Read Text step, insert a JavaScript expression step. In Broma, this step receives the text from the previous step as its input. You write a short expression that transforms that input and returns a new string. You do not need to build a full script or install anything; the expression runs locally on your computer as part of the flow.\n\nHere are three common patterns.\n\n### Remove currency symbols and commas\n\nA price field often arrives as '$1,299.00'. To keep only digits and the decimal point:\n\n```javascript\nreturn text.replace(\u002F[^\\d.]\u002Fg, '');\n```\n\nThis returns `1299.00`, which most numeric form fields accept.\n\n### Extract the first number from a sentence\n\nStock indicators often read like 'Only 3 left in stock' or '14 units available'. To pull out the number:\n\n```javascript\nconst match = text.match(\u002F\\d+\u002F);\nreturn match ? match[0] : '';\n```\n\nIf the text is missing or contains no number, this returns an empty string instead of breaking the flow.\n\n### Trim whitespace and normalize line breaks\n\nAddresses or names copied from a page sometimes carry extra spaces or newline characters:\n\n```javascript\nreturn text.trim().replace(\u002F\\s+\u002Fg, ' ');\n```\n\nThis collapses multiple spaces into one and removes leading or trailing whitespace.\n\n## Step 3: Map the cleaned output into the next step\n\nOnce the expression step produces a clean string, use it in the following action. In Broma, add a Type step (or Click, or whatever the destination requires) and select the output of the JavaScript expression step as the value to type.\n\nConceptually, the mapping looks like this:\n\n1. Read Text -> captures '$1,299.00'\n2. JavaScript expression -> returns '1299.00'\n3. Type -> types '1299.00' into the target field\n\nIn the app, you choose the previous step's output from a dropdown or variable picker rather than retyping the value by hand. This means if the source page changes, you only update the Read Text selector, not every downstream step.\n\n## Real-world example: updating an internal price sheet\n\nImagine you check a supplier's product page every Monday and enter the current price into your company's internal dashboard.\n\n1. Open the supplier page in a Broma profile.\n2. Read Text from the price element: '$2,450.00'.\n3. JavaScript expression: `return text.replace(\u002F[^\\d.]\u002Fg, '');` -> '2450.00'.\n4. Type the result into the dashboard's Price field.\n5. Click Save.\n\nBecause the expression runs locally and the flow is saved in Broma, you can run it again next week with one click. If the supplier changes the page layout, you update the selector in step 1; the cleaning logic in step 2 stays the same.\n\n## Keeping expressions maintainable\n\nShort expressions are easier to debug than long ones. If you need several transformations, split them across multiple expression steps instead of nesting everything in one line. Name each step clearly, such as 'Strip currency' or 'Extract stock number', so anyone reviewing the run log knows what happened.\n\nAvoid expressions that reach outside the current input, such as fetching URLs or calling external APIs. Broma does not include a public API, SDK, or CLI, and flows run on your computer. Keep the logic local and limited to transforming the text you already captured.\n\n## Test with a few records before you schedule\n\nRun the flow manually on three or four different pages or products. Check that the expression handles sale prices, out-of-stock messages, and missing fields without stopping the flow. If one record fails, look at the run log to see whether the Read Text step captured the expected text or whether the expression returned an empty string. This quick check saves time later when the flow runs unattended.\n\n## What to do when the result is empty\n\nIf the next step receives an empty string, check three things:\n\n1. The selector in the Read Text step still matches an element on the page.\n2. The raw text actually contains the pattern your expression expects.\n3. The expression handles missing data gracefully, for example by returning an empty string instead of throwing an error.\n\nRun the flow with the run log open so you can compare the raw read value against the expression output.\n\n## When not to use an expression\n\nJavaScript expressions are for cleaning, formatting, and extracting values from text you already have. They are not a substitute for choosing a good selector, and they cannot click elements or read new parts of the page. If the information is not already in the DOM, add another Read Text step before the expression.\n\n## Summary\n\nBroma lets you move data between web tools without writing a full program, but web text is rarely in the perfect format for the next step. A short JavaScript expression between a Read Text step and a Type step lets you strip symbols, pull out numbers, and normalize whitespace locally on your Windows machine. Start with one transformation, test it on real page text, and add more steps only when the flow proves stable.\n","https:\u002F\u002Fblog-api.bromaapp.com\u002Fapi\u002Fblog\u002Fposts\u002Ftransform-extracted-text-in-broma-with-javascript\u002Fassets",1794729621060]