{"id":21435790,"url":"https://github.com/elistone/mathematical_field","last_synced_at":"2026-04-29T10:33:38.526Z","repository":{"id":98455518,"uuid":"230482489","full_name":"elistone/mathematical_field","owner":"elistone","description":"A Drupal 8 module that allows adding mathematical calculations into a field and output the result.","archived":false,"fork":false,"pushed_at":"2019-12-28T11:07:59.000Z","size":1159,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-03T14:51:45.163Z","etag":null,"topics":["drupal","drupal-8","drupal-module"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elistone.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-12-27T17:07:52.000Z","updated_at":"2019-12-28T11:08:01.000Z","dependencies_parsed_at":"2023-06-01T18:30:58.737Z","dependency_job_id":null,"html_url":"https://github.com/elistone/mathematical_field","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/elistone/mathematical_field","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elistone%2Fmathematical_field","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elistone%2Fmathematical_field/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elistone%2Fmathematical_field/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elistone%2Fmathematical_field/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elistone","download_url":"https://codeload.github.com/elistone/mathematical_field/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elistone%2Fmathematical_field/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32421875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T06:29:02.080Z","status":"ssl_error","status_checked_at":"2026-04-29T06:29:00.631Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drupal","drupal-8","drupal-module"],"created_at":"2024-11-22T23:46:10.229Z","updated_at":"2026-04-29T10:33:38.520Z","avatar_url":"https://github.com/elistone.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mathematical Field\n\nThe Mathematical Field module gives you the ability to type mathematical calculations into a plain text field and have its result displayed.\n\nFor example, entering the calculation `10 + 20 - 30 + 15 * 5` would return the result `75`.\n\nThis module can currently handle the following inputs:\n\n- Whole numbers e.g `0`, `1`, `2`, `3`, `4`\n- Negative numbers e.g. `-1`, `-2`, `-3`, `-4`, `-5`\n- Decimal numbers e.g. `1.0`, `1.1`, `1.2`, `1.3`, `1.4`, `1.5`\n- Operators `+`, `-`, `/`, `*`\n\nThe module comes with various ways to display this result, more information about this can be found under the `Display Options` section.\n\n\n## Install\n\nInstalling this module is much like any other Drupal module:\n\n1. Download / clone this repo.\n2. Move the folder so it is under `modules/contrib`.\n3. On Drupal navigate to Extend (`/admin/modules`).\n4. Search for `Mathematical Field` and enable it.\n\nYou are now ready to use the Mathematical Field module!\n\n\n## Usage\n\nOnce installed (see `Install` section), using the module is very easy.\n\nThis module does not create its own field type instead it extends the `Text (plain)` \u0026 `Text (plain, long)` fields, adding in a new format for display called `Mathematical`.\n\nYou can add the field in 3 easy steps:\n\n1. Choose the content type you would like to add a `Mathematical Field` too.\n2. Add a new field of either `Text (plain)` \u0026 `Text (plain, long)`\n3. On the `Manage display` tab set the new fields format to `Mathematical`.\n\nThat's it! Now the new field is ready for mathematical calculating.\n\nYou can also upgrade any existing `Text (plain)` \u0026 `Text (plain, long)` by simply following step 3 of usage.\n\n## Display Options\n\nThere are two display options within this module.\n\n1. Mathematical - This is the simplest display option, it can be as simple as just showing the result or as complex as showing input, result number, result words and display result on hover.  \n2. Mathematical (Jumble) - This outputs the field as part of a React application and gives you the ability to change the equation using the values from the set input.\n\n### Mathematical\n\nThe Mathematical format will display your calculation result and has options to show more information.\n\nSettings for the field formatter can be found on the `Manage display` page and include the following:\n\n1. `Display input` - As well as showing the result you can display the calculation.\n2. `Display in words` - As well as showing the result as a number you can display it as a word.\n3. `Hover for results` - Instead of just showing the result as a number it will display the calculation and on hover show the result.\n\n![Mathematical Example](https://i.imgur.com/NYlnvOk.png)\n\nAn example of the full output.\n\n![Mathematical Hover Example](https://media.giphy.com/media/JROqIgxwwJArHoHnMQ/giphy.gif)\n\nAn example of the full output with hover for results enabled.\n\n### Mathematical (Jumble)\n\nThe Mathematical (Jumble) format gives a more interactive way to display the calculation, with the ability to move numbers and operators around to see what happens to the result in real time.\n\nThere are currently no settings for this formatter.\n\n![Mathematical Jumble Example](https://media.giphy.com/media/TL6epnb9u2QZSWe9mo/giphy.gif)\n\nAn example of the jumble field being used.\n\n\n## Service\n\nThis module contains two services which if so required can be used in 3rd-party applications.\n\nThe Lexer, which converts a calculation into a format that the Parser can use to work out the result, can do the following: tokenize the string, sort the precedence and convert from infix to postfix.\n\nThe Parser uses the Lexer and then takes this information to return a result.\n\n\n### Lexer\n\nTo use the Lexer you can use the following:\n\n```php\n$string = \"1 + 1\";\n\n$mathematicalLexer = \\Drupal::service('mathematical_field.lexer');\n\n$tokenize = $mathematicalLexer-\u003etokenizer($string);\n$sorted = $tokenize-\u003esortPrecedence();\n$postfix = $sorted-\u003egetPostfix()-\u003egetResultString();\n\nprint $postfix; // returns 11+\n```\n\n### Parser\n\nTo calculate results from string you can simply use:\n\n```php\n$input = \"1 + 1\";\n\n$mathematicalParser = \\Drupal::service('mathematical_field.parser');\n\ntry {\n  // get the result\n  $result = $mathematicalParser-\u003ecalculate($input)-\u003egetResult();\n} catch (\\Exception $e) {\n  // if error set the error variable and result to the error message\n  $result = $this-\u003et($e-\u003egetMessage());\n}\n\nprint $result; // returns 2\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felistone%2Fmathematical_field","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felistone%2Fmathematical_field","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felistone%2Fmathematical_field/lists"}