2.0.5 • Published 1 year ago

math-dbl v2.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Description

This package is created by Mohammed Ali and is used to perform basic mathematical operations using Maths object.

Example

  • 1st Example
var Mathematics = require('intelligent-mathjs');

var {add, calculator} = Mathematics;

calculator(2, 4, add);

 ' = 2 + 4';
  • 2nd Example
var 
{
    Maths
} = require('intelligent-mathjs'),
{
    add,
    subtract, 
    multiplication, 
    division, 
    calculator, 
    power, 
    cube, 
    square, 
    sqrt, 
    cbrt,
    money,
    units,
    Temperature,
    floor,
    abs,
    acos,
    Table
} = Maths;

Table(7);

units.Volume
units.Area
units.Distance
units.speed

Installation

To install this package, try

npm i intelligent-mathjs@latest

Code

All the code written in main file.

unit, Temprature and money are properties.

/**
 * @param {...any} data Console data
 */

function $(data) {
    return console.log(data)
}

var Maths = {
    money: {
        Supported_currencies: [
            'USD', 
            'INR', 
            'SAR', 
            'EUR'
        ],

        profit: {
            getProfit(cost_price, selling_price) {
                var profit = {
                    CP: cost_price,
                    SP: selling_price
                };

                const { CP, SP } = profit

                if (SP < CP) {
                    $("Selling_price must be greater than Cost_price");
                } else {
                    var Profit = SP - CP

                    $(`
                        ------------------
                        Profit: ${Profit}
                        ------------------
                    `);
                }
            },

            profitPercentFromProfit(profit, CP) {
                var Profits = profit
                var Cost_price = CP

                var ProfitPercent = (Profits / Cost_price) * 100;
                var Selling_price = Profits + Cost_price;
                // var Profit = Selling_price - Cost_price


                $(`
                    Selling_price: ${Selling_price}
                    Profit%: ${ProfitPercent}%
                `)
            },

            profitFromProfitPercent(profitpercent, CP) {
                var profit = (profitpercent * CP) / 100
                var selling_price = CP + profit


                $(
                    `
                    Profit: ${profit}
                    Selling_price: ${selling_price}
                    `
                );
            },

            getCost_price(Profit, SP) {
                $(`
                    CP: ${SP - Profit}
                `)
            },

            getSelling_price(Profit, CP) {
                $(`
                    SP: ${CP + Profit}
                `)
            }
        },

        Loss: {
            getLoss(Selling_price, Cost_price) {
                var loss = {
                    CP: Cost_price,
                    SP: Selling_price
                }

                const { CP, SP } = loss;

                if (SP > CP) {
                    $("SP number should lesser than CP number");
                } else {
                    const loss = CP - SP;

                    $(`
                        -----------------------------
                        Loss: ${loss}
                        -----------------------------
                    `)
                }
            },

            LossPercentFromLoss(Loss, CP) {
                $(`
                    Profit: ${(Loss / CP) * 100},
                    Selling_price: ${CP - Loss}
                `)
            },

            LossFromLossPercent(LossPercent, CP) {
                var Loss = (LossPercent * CP) / 100

                $(`
                    Loss: ${Loss},
                    Selling_price: ${CP - Loss}
                `)
            },

            getCost_price(Loss, SP) {
                $(`
                    CP: ${SP + Loss}
                `)
            },

            getSelling_price(Loss, CP) {
                $(`
                    SP: ${CP - Loss}
                `)
            }
        }
    },

    /**
     * only metric
     */

    units: {
        speed: {
            KilometersPerHourToMetersPerSec(KMH) {
                var mps = KMH * (1000 / 3600);
                $(mps);
            },

            KilometersPerHourToMetersPerMin(KMH) {
                var mpm = KMH * (1000 / 60);
                $(mpm);
            },

            MetersPerSecToKilometersPerHour(MPS) {
                var KMH = MPS * (3600 / 1000);
                $(KMH);
            },

            MetersPerMinToKilometersPerHour(MPM) {
                var KMH = MPM * (60 / 1000);
                $(KMH);
            },

            MilesPerHourToKilometersPerHour(MPH) {
                var KMH = MPH * 1.6092;
                $(KMH);
            },

            KilometersPerHourToMilesPerHour(KMH) {
                var MPH = KMH / 1.6092;
                $(MPH);
            },
        },

        Distance: {
            KM_To_Meters(KM) {
                var Meters = KM * 1000
                $(Meters)
            },

            Meters_To_KM(Meters) {
                var KM = Meters / 1000;
                $(KM)
            },

            Miles_To_KM(Miles) {
                var KM = Miles * 1.609344;
                $(KM);
            },

            KM_To_Miles(KM) {
                var Miles = KM / 1.609344
                $(Miles)
            },

            KM_To_Centimeters(KM) {
                var Centimeters = KM * 100000;
                $(Centimeters);
            },

            Centimeters_To_KM(Centimeters) {
                var KM = Centimeters / 100000;
                $(KM);
            },

            Meters_To_Centimeters(Meters) {
                var Centimeters = Meters * 100;
                $(Centimeters);
            },

            Centimeters_To_Meters(Centimeters) {
                var Meters = Centimeters / 100;
                $(Meters);
            },

            Millimeters_To_Centimeters(Millimeters) {
                var Centimeters = Millimeters / 10;
                $(Centimeters);
            },

            Centimeters_To_Millimeters(Centimeters) {
                $(Centimeters * 10);
            },

            Millimeters_To_Meters(Millimeters) {
                $(Millimeters / 1000);
            },

            Meters_To_Millimeters(Meters) {
                $(Meters * 1000);
            },

            Millimeters_To_Kilometers(Millimeters) {
                $(Millimeters / 1000000);
            },

            Kilometers_To_Millimeters(Kilometers) {
                $(Kilometers * 1000000);
            }
        },

        Volume: {
            volume_of_cube(side) {
                $(Maths.cube(side));
            },

            /**
             * Get volume of cuboid
             * 
             * @param {number} l length
             * @param {number} b breadth
             * @param {number} h height
             */

            volume_of_cuboid(l, b, h) {
                $(l * b * h);
            },

            volume_of_cylender(radius, height) {
                $(3.14 * Maths.square(radius) * height);
            },

            volume_of_cone(radius, height) {
                $((1 / 3) * 3.14 * Maths.square(radius) * height);
            },

            volume_of_sphere(radius) {
                $((4 / 3) * 3.14 * Maths.cube(radius))
            },

            volume_of_hemisphere(radius) {
                $((2 / 3) * 3.14 * Maths.cube(radius));
            },

            cubeMeter_to_cubeCentimeter(cubeMeter) {
                $(((cubeMeter * 100) * 100) * 100);
            },

            cubeCentimeter_to_cubeMeter(cubeCentimeter) {
                $(((cubeCentimeter / 100) / 100) / 100)
            },

            cubeMillimeter_to_cubeCentimeter(cubeMillimeter) {
                $(((cubeMillimeter / 10) / 10) / 10)
            },

            cubeCentimeter_to_cubeMillimeter(cubeCentimeter) {
                $(((cubeCentimeter * 10) * 10) * 10)
            }
        },

        Area: {
            Area_of_Square(side) {
                $(Maths.square(side));
            },

            /**
             * Get area of rectangle
             * 
             * @param {number} l length
             * @param {number} b breadth
             */

            Area_of_rectangle(l, b) {
                $(l * b);
            },

            Area_of_parallelogram(Base, height) {
                $(Base * height);
            },

            Area_of_triangle(Base, height) {
                $((1 / 2) * Base * height)
            },

            Area_of_circle(radius) {
                $(3.14 * Maths.square(radius));
            },

            Area_of_rhombus(diagonal1, diagonal2) {
                $((1 / 2) * (diagonal1 * diagonal2));
            },

            Area_of_equilateral_triangle(side) {
                $((Maths.sqrt(3) / 4) * Maths.square(side));
            }
        }
    },

    /**
     * 
     * @param {number} num 
     * @param {number} num2 
     */

    add(num, num2) {
        $(num + num2);
    },

    /**
     * 
     * @param {number} num 
     * @param {number} num2 
     */

    subtract(num, num2) {
        $(num - num2)
    },

    /**
     * 
     * @param {number} num 
     * @param {number} num2 
     */

    multiplication(num, num2) {
        $(`${num} × ${num2} = ${num * num2}`)
    },

    /**
     * This function is used for remembering tables
     * 
     * @example
     * ```
     * Table(8, 20);
     * 'This is = 8 * 1 = 8... 8 * 20 = 160';
     * ```
     * 
     * @param {number} number 
     * @param {number} upto 
     */

    Table(number, upto){
        for(var num = 1; num <= upto; num++) {
            $(`${number} * ${num} = ${number * num}`)
        }
    },

    /**
     * 
     * @param {number} num 
     * @param {number} num2 
     */

    division(num, num2) {
        $(num / num2)
    },

    /**
     * 
     * @param {number} num1 first number
     * @param {number} num2 second number
     * @param {function} selector function to evalulate `num1` and `num2`
     * 
     * @example
     * 
     * ```
     * 
     * var {calculator} = Maths;
     * 
     * calculator(13, 32, Maths.add);
     * 
     * "this results 13 + 32 = 45"
     * 
     * ```
     * 
     * 
     */

    calculator(num1, num2, selector) {
        selector(num1, num2)
    },

    /**
     * 
     * @param {number} base The number to be powered
     * @param {number} exponent The number to power the base number
     * 
     * @example
     * 
     * ```
     * 
     * power(2, 5);
     * 
     * "this results 2 x 2 x 2 x 2 x 2"
     * 
     * ```
     */

    power(base, exponent) {
        $(base ** exponent);
    },




    Temperature: {
        toCelsius(farenheit) {
            $((farenheit - 32) * (5 / 9))
        },

        toFarenheit(celsius) {
            $(((9 / 5) * celsius) + 32)
        }
    },

    /**
     * @param {number} number Number to get square
     */

    square(number) {
        Maths.power(number, 2)
    },

    /**
     * @param {number} number Number to get Cube
     */

    cube(number) {
        Maths.power(number, 3)
    },

    /**
     * @param {number} number number to get square root
     */

    sqrt(number) {
        var square = 1, i = 0;

        while (true) {
            i = i + 1;
            square = (number / square + square) / 2;
            if (i == number + 1) { break; }
        }

        $(square);
    },

    floor(number) {
        $(Math.floor(number))
    },

    abs(number) {
        $(Math.abs(number));
    },

    acos(number) {
        $(Maths.acos(number));
    },

    /**
     * @param {number} number number to get cube root
     */

    cbrt(number) {
        const heron3 = (number, x) => (2 * x + number / (x * x)) / 3;

        var x = number / 4;
        var x1 = x;

        do {
            x1 = heron3(number, x = x1);
        } while (Math.abs(x - x1) > Number.EPSILON)
        $(x1);
    }
}

var Numberconstructor = Number
var Mathematics = {
    Maths,
    Numberconstructor,
    // JSON part
    "version": "2.0.3",
    "name": "Mathematics",
    "description":`
        A good package containing Basic Mathematics operations like addition, etc. This package
        may be helpful to programmers because they can Easily calculate Mathematics operations using
        Maths object. This is written in pure js, not in type-script;
    `,
    "author": {
        "Full_name": "Mohammed Ali Imran Sayyed",
        "Age": 12,
        "School": "St. Augustine English School, Parbhani, India",
        "Vacation_home": "Saudi Arabia",
        "Nationality": "Indian",
        "Address": "Ghalib Nagar, Dargah road, Parbhani-431401, Maharashtra, India",
        "Phone_number": 9921825374,
        "Class": "6th"
    },

    "keywords": [
        "math",
        "programmers"
    ],

    "license": "MIT",
    "scripts": {
        "test": "node index.js"
    }
};
module.exports = Mathematics;

I actually don't have any website because I'm only 12 years old. That's why I don't give any website link. Please download my Package because this is first package I have created in summer vacations. It took one 1 month to create this package. Check it, IF there is any problem, please email me at sayyedmohammed1312@gmail.com.

HAPPY CODING;

2.0.5

1 year ago