Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

sp-math

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sp-math

Common Math Functions

latest
Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
5
66.67%
Maintainers
1
Weekly downloads
 
Created
Source

sp-math

Common Math Functions

Install

  npm i sp-math //or yarn add sp-math

CDN

  <script src="https://unpkg.com/sp-math/dist/index.min.js"></script>
  <script>

  </script>

Usage

  const {
    abs,
    acos,
    asin,
    atan,
    ceil,
    degreeToRotate,
    devideFloat,
    isFloat,
    rotateToDegree,
    cos,
    distance,
    floor,
    comma,
    rotateByDegree,
    pow,
    round,
    sin,
    sqrt,
    tan
  } = require("sp-math")
  • abs(val)

    • {Number} val
      abs(-10);
      // return 10
    
  • ceil(val)

    • {Number} val
      ceil(1.25);
      // return 2
    
  • cos(val)

    • {Number} val
      cos(60);
      // return 0.5000000000000001
    
  • sin(val)

    • {Number} val
      sin(30);
      // return 0.49999999999999994
    
  • tan(val)

    • {Number} val
      sin(45);
      // return 0.9999999999999999
    
  • acos(val)

    • {Number} val
      acos(0.5);
      // return 60.00000000000001
    
  • asin(val)

    • {Number} val
      asin(0.5);
      // return 30.000000000000004
    
  • atan(val)

    • {Number} val
      atan(1);
      // return 45
    
  • degreeToRotate(val)

    • {Number} val
      degreeToRotate(180);
      // return 3.141592653589793 Math.PI
    
  • rotateToDegree(val)

    • {Number} val
      rotateToDegree(Math.PI);
      // return 180
    
  • distance(p1, p2)

    • {Array} p1 = [0, 0]
    • {Array} p2 = [0, 0]
      distance([1, 1], [2, 2]);
      // return 1.41
    
  • floor(val)

    • {Number} val
      floor(1.25);
      // return 1
    
  • pow(x, y, isDeep = false)

    • {Number} x
    • {Number} y
    • {Boolean} isDeep
      pow(2, 5);
      // return 32
      pow(-2, 5);
      // return -32
      pow(4, 0.5, true);
      // return [2, -2]
    
  • round(val)

    • {Number} val
      round(2.53)
      // return 3
      round(2.15);
      // return 2
    
  • sqrt(val)

    • {Number} val
    • {Boolean} isDeep
      sqrt(4)
      // return 2
      sqrt(4, true);
      // return [2, -2]
    
  • devideFloat(val)

    • {Number} val
      devideFloat(4)
      // return [ 4, 1 ] 4/1 = 4
      devideFloat(1.8);
      // return [ 9, 5 ] 9/5 = 1.8
    
  • comma(val, obj = {fixed:2, hasComma = false})

    • {Number} val
    • {Object} obj
    • {Number} obj.fixed
    • {Boolean} obj.hasComma
      comma('12345.33',{
        fixed: 3
      });
      // return '12345.330'
      comma('12345.33',{
        fixed: 3,
        hasComma: true
      });
      // return '12,345.330'
      comma('12,345.330',{
        fixed: 4,
        hasComma: false
      });
      // return '12345.3300'
    

Keywords

math

FAQs

Package last updated on 27 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts