A Custom Field plugin for Strapi Headless CMS that provides an integration with powerful math library.
A plugin for Strapi Headless CMS that provides an integration with powerful mathjs library.
formula
with the provided scope
using the powerful mathjs.evaluate
method. Read More.strapi@4.X.X
Complete installation requirements are exact the same as for Strapi itself and could be found in the official Strapi documentation.
Before installing Strapi, the following requirements must be installed on your computer:
- Node.js: Only Maintenance and LTS versions are supported (v16, v18, and v20).
- Node v18.x is recommended for Strapi v4.3.9 and above
- Node v16.x is recommended for Strapi v4.0.x to v4.3.8.
- Your preferred Node.js package manager:
- npm (v6 and above)
- yarn
1yarn add strapi-plugin-field-formula@latest
OR
1npm install strapi-plugin-field-formula@latest
After successful installation you could re-build the Strapi instance. You could use the next commands (default) inside your Strapi project:
1yarn build
2yarn develop
As a next step you must configure the plugin following the official Strapi documentation.
We need to enable the plugin by adding it to the Strapi plugin config file located in ./config/plugins.js
of your Strapi
project. If this file does not exist yer, you have to create it manually.
Copy and paste the following config into you ./config/plugins.js
file:
1// ./config/plugins.js`
2module.exports = {
3 // ...
4 'field-formula': {
5 enabled: true
6 },
7//...
8}
My congratulation 😄! You have successfully installed and configured the Strapi Plugin Field Formula.
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices. Powerful and easy to use.
Here is some examples, but to use this plugin on the full 100%, you have to read the official Mathjs
documentation, and especially the expressions part as formula
is
the same thing as mathjs.evaluate
method 🤫
Function
evaluate
accepts a single (in our case)expression
or an array with expressions as the first argument and has an optional second argument containing ascope
with variables and functions. The scope can be a regular JavaScript Object, or Map (JSON in our case). The scope will be used to resolve symbols, and to write assigned variables or function.
1formula: sqrt(x^y + r^k)
2scope: {
3 "x": 2,
4 "y": 3,
5 "r": 4,
6 "k": 5
7}
8result: 32.12475680841802
1formula: cos(x deg)
2scope: { "x": 45 }
3result: 0.7071067811865476
See the CONTRIBUTING.md document.
If you are enjoying this plugin and feel extra appreciative, you could buy me a book 📖 or 3 📖📖📖.
npm install strapi-plugin-field-formula
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.