npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-plugin-field-formula

v1.0.3

Published

Strapi Plugin Field Formula - Custom Field for integration mathjs and Strapi

Downloads

30

Readme

A plugin for Strapi Headless CMS that provides an integration with powerful mathjs library.

Table of Contents

✨ Features

  • Strapi Custom Field for calculating the provided formula.
  • mathjs integration.
    • Supports numbers, big numbers, complex numbers, fractions, units, strings, arrays, and matrices.
    • Is compatible with JavaScript’s built-in Math library.
    • Contains a flexible expression parser.
    • Does symbolic computation.
    • Comes with a large set of built-in functions and constants.
  • Calculating the formula with the provided scope using the powerful mathjs.evaluate method. Read More.

🧰 Requirements

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

🦾 Installation

yarn add strapi-plugin-field-formula@latest

OR

npm 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:

yarn build
yarn develop

⚙️ Configuration

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:

// ./config/plugins.js`
module.exports = {
  // ...
  'field-formula': {
    enabled: true
  },
//...
}

My congratulation 😄! You have successfully installed and configured the Strapi Plugin Field Formula.

♾️ Usage

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 a scope 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.

Example 1

formula: sqrt(x^y + r^k)
scope: {
  "x": 2,
  "y": 3,
  "r": 4,
  "k": 5
}
result: 32.12475680841802

Example 2

formula: cos(x deg)
scope: { "x": 45 }
result: 0.7071067811865476

🛠️ Contributing

See the CONTRIBUTING.md document.

🗺️ Roadmap

  • Object response to unleash more difficult expressions.

❤️ Support or Donate

If you are enjoying this plugin and feel extra appreciative, you could buy me a book 📖 or 3 📖📖📖.

💕 Special Thanks

  • I want to say thank you to my wife Diana for her love, daily support, motivation and inspiration.