New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@cdjs/js-math

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cdjs/js-math - npm Package Compare versions

Comparing version
1.0.0
to
1.0.1
+1
-1
dist/index.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.jsMath=e():t.jsMath=e()}(window,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";r.r(e),r.d(e,"add",(function(){return o})),r.d(e,"subtract",(function(){return u})),r.d(e,"multiply",(function(){return l})),r.d(e,"devide",(function(){return a})),r.d(e,"round",(function(){return s}));var n=function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),i=0;for(e=0;e<r;e++)for(var o=arguments[e],u=0,l=o.length;u<l;u++,i++)n[i]=o[u];return n},i=new(function(){function t(){this.result=NaN,this.precision=12,this.needCheck=!1}return t.prototype.setPrecision=function(t){this.precision=t},t.prototype.enableCheck=function(t){this.needCheck=t},t.prototype.check=function(t){this.needCheck&&(t<Number.MIN_SAFE_INTEGER||t>Number.MAX_SAFE_INTEGER)&&console.warn(t+" is beyond boundary when transfer to integer, the results may not be accurate")},t.prototype.strip=function(t,e){return void 0===e&&(e=this.precision),Number.parseFloat(t.toPrecision(e))},t.prototype.digitDecimalLength=function(t){var e=String(t).split(/[eE]/),r=(e[0].split(".")[1]||"").length-+(e[1]||0);return r>0?r:0},t.prototype.floatToInteger=function(t){if(!String(t).includes("e"))return Number(String(t).replace(".",""));var e=this.digitDecimalLength(t);return e>0?this.strip(t*Math.pow(10,e)):t},t.prototype.init=function(t){return void 0===t&&(t=0),this.result=t,this},t.prototype.value=function(){var t=this.result;return this.result=NaN,t},t.prototype._handle=function(t,e){return Object.is(this.result,NaN)?this.result=t[0]:t.unshift(this.result),t.length>=2&&(this.result=e.call.apply(e,n([this,t[0],t[1]],t.slice(2)))),this},t.prototype._multiply=function(t,e){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];if(r.length>0)return this._multiply.apply(this,n([this._multiply(t,e),r[0]],r.slice(1)));var o=this.digitDecimalLength(t)+this.digitDecimalLength(e),u=this.floatToInteger(t)*this.floatToInteger(e);return this.check(u),u/Math.pow(10,o)},t.prototype.multiply=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._handle(t,this._multiply)},t.prototype._add=function(t,e){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];if(r.length>0)return this._add.apply(this,n([this._add(t,e),r[0]],r.slice(1)));var o=Math.pow(10,Math.max(this.digitDecimalLength(t),this.digitDecimalLength(e)));return(this._multiply(t,o)+this._multiply(e,o))/o},t.prototype.add=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._handle(t,this._add)},t.prototype._subtract=function(t,e){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];if(r.length>0)return this._subtract.apply(this,n([this._subtract(t,e),r[0]],r.slice(1)));var o=Math.pow(10,Math.max(this.digitDecimalLength(t),this.digitDecimalLength(e)));return(this._multiply(t,o)-this._multiply(e,o))/o},t.prototype.subtract=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._handle(t,this._subtract)},t.prototype._devide=function(t,e){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];if(r.length>0)return this._devide.apply(this,n([this._devide(t,e),r[0]],r.slice(1)));var o=this.floatToInteger(t)/this.floatToInteger(e),u=Math.pow(10,this.digitDecimalLength(e)-this.digitDecimalLength(t));return this._multiply(o,u)},t.prototype.devide=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._handle(t,this._devide)},t.prototype.round=function(t){void 0===t&&(t=2);var e=Math.pow(10,t);return this.result=Math.round(this.multiply(e).result),this.devide(e)},t}()),o=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i.add.apply(i,t).value()},u=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i.subtract.apply(i,t).value()},l=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i.multiply.apply(i,t).value()},a=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i.devide.apply(i,t).value()},s=function(t,e){return i.init(e).round(t).value()};e.default=i}])}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.jsMath=e():t.jsMath=e()}(this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";r.r(e),r.d(e,"add",(function(){return o})),r.d(e,"subtract",(function(){return u})),r.d(e,"multiply",(function(){return l})),r.d(e,"devide",(function(){return a})),r.d(e,"round",(function(){return s}));var n=function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),i=0;for(e=0;e<r;e++)for(var o=arguments[e],u=0,l=o.length;u<l;u++,i++)n[i]=o[u];return n},i=new(function(){function t(){this.result=NaN,this.precision=12,this.needCheck=!1}return t.prototype.setPrecision=function(t){this.precision=t},t.prototype.enableCheck=function(t){this.needCheck=t},t.prototype.check=function(t){this.needCheck&&(t<Number.MIN_SAFE_INTEGER||t>Number.MAX_SAFE_INTEGER)&&console.warn(t+" is beyond boundary when transfer to integer, the results may not be accurate")},t.prototype.strip=function(t,e){return void 0===e&&(e=this.precision),Number.parseFloat(t.toPrecision(e))},t.prototype.digitDecimalLength=function(t){var e=String(t).split(/[eE]/),r=(e[0].split(".")[1]||"").length-+(e[1]||0);return r>0?r:0},t.prototype.floatToInteger=function(t){if(!String(t).includes("e"))return Number(String(t).replace(".",""));var e=this.digitDecimalLength(t);return e>0?this.strip(t*Math.pow(10,e)):t},t.prototype.init=function(t){return void 0===t&&(t=0),this.result=t,this},t.prototype.value=function(){var t=this.result;return this.result=NaN,t},t.prototype._handle=function(t,e){return Object.is(this.result,NaN)?this.result=t[0]:t.unshift(this.result),t.length>=2&&(this.result=e.call.apply(e,n([this,t[0],t[1]],t.slice(2)))),this},t.prototype._multiply=function(t,e){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];if(r.length>0)return this._multiply.apply(this,n([this._multiply(t,e),r[0]],r.slice(1)));var o=this.digitDecimalLength(t)+this.digitDecimalLength(e),u=this.floatToInteger(t)*this.floatToInteger(e);return this.check(u),u/Math.pow(10,o)},t.prototype.multiply=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._handle(t,this._multiply)},t.prototype._add=function(t,e){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];if(r.length>0)return this._add.apply(this,n([this._add(t,e),r[0]],r.slice(1)));var o=Math.pow(10,Math.max(this.digitDecimalLength(t),this.digitDecimalLength(e)));return(this._multiply(t,o)+this._multiply(e,o))/o},t.prototype.add=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._handle(t,this._add)},t.prototype._subtract=function(t,e){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];if(r.length>0)return this._subtract.apply(this,n([this._subtract(t,e),r[0]],r.slice(1)));var o=Math.pow(10,Math.max(this.digitDecimalLength(t),this.digitDecimalLength(e)));return(this._multiply(t,o)-this._multiply(e,o))/o},t.prototype.subtract=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._handle(t,this._subtract)},t.prototype._devide=function(t,e){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];if(r.length>0)return this._devide.apply(this,n([this._devide(t,e),r[0]],r.slice(1)));var o=this.floatToInteger(t)/this.floatToInteger(e),u=Math.pow(10,this.digitDecimalLength(e)-this.digitDecimalLength(t));return this._multiply(o,u)},t.prototype.devide=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._handle(t,this._devide)},t.prototype.round=function(t){void 0===t&&(t=2);var e=Math.pow(10,t);return this.result=Math.round(this.multiply(e).result),this.devide(e)},t}()),o=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i.add.apply(i,t).value()},u=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i.subtract.apply(i,t).value()},l=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i.multiply.apply(i,t).value()},a=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return i.devide.apply(i,t).value()},s=function(t,e){return i.init(t).round(e).value()};e.default=i}])}));
{
"name": "@cdjs/js-math",
"version": "1.0.0",
"version": "1.0.1",
"description": "A simple math calculation library for JavaScript and Node.js",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

+45
-25

@@ -1,37 +0,57 @@

## 构建 Webpack + TypeScript JS 库开发框架
## js-math
### Webpack 相关
A lightweight Javascript math library.
- webpack
- webpack-cli
- webpack-merge
- webpack-dev-server: 启动开发环境,在 webpack.dev.config.js 中配置
- html-webpack-plugin: 输入到页面,在 webpack.base.config.js 中配置
- clean-webpack-plugin: 用于在下一次打包时清除之前打包的文件,3.0.0 注意导入方式和传参
### Installing
### TypeScript 相关
```bash
npm install @cdjs/js-math
// or
yarn add @cdjs/js-math
```
- typescript
- ts-loader: 用于加载 ts 文件
- transpileOnly `true`失去类型检查 `false` 降低编译速度
- fork-ts-checker-webpack-plugin: 在 `transpileOnly: true` 时配置,开启一个独立的进程进行类型检查 [Webpack 文档](https://webpack.docschina.org/guides/build-performance/)
### Usage
### Babel
```javascript
// es6 module
import jsMath, { multiply, add, subtract, devide, round } from '@cdjs/js-math'
// commonjs
const jsMath = require('@cdjs/js-math')
```
### 测试
### Documentation
`npx ts-jest config:init`: 生成 jest 配置文件
| Method | desc | args |
| ------------ | -------------------------------------------------------- | ------------------------------------------------------ |
| multiply | 乘 | ...Array |
| add | 加 | ...Array |
| subtract | 减 | ...Array |
| devide | 除 | ...Array |
| round | 四舍五入 | ratio: Number 精度<br />number?: Number 需要处理的数字 |
| value | 获取最终值 | / |
| setPrecision | 设置浮点数最大保留精度,默认 12 位 | number: Number |
| enableCheck | 是否开启对运算结果是否超出 js 安全数值的提醒,默认 false | check: Boolean |
- `jest`
- `@types/jest`
- `ts-jest`: 测试用例中可以进行类型检查
### How to use
`jest.config.js`中新增`preset: 'ts-jest', testEnvironment: 'node'`
#####Simple use
### eslint
```javascript
// 乘
multiply(3, 2) // 6
add(0,1, 0.2) // 0.3
// 四舍五入
round(0.345, 2) // 0.35
```
- eslint
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
#####Chained use
`"lint": "eslint src --ext .js,.ts"`
```javascript
jsMath
.multiply(0.2, 10, 100)
.add(1, 2, 3, 5, 10, 1000)
.subtract(0.1, 0.3, 0.4)
.devide(2, 5, 5, 20)
.round(2)
.value() // 1.22
```

@@ -25,6 +25,6 @@ import JSMath from './jsMath';

* 四舍五入
* @param float 需要精确的小数
* @param ratio 四舍五入精度
* @param float 需要精确的小数
*/
export declare const round: (ratio: number, float: number) => number;
export declare const round: (float: number, ratio: number) => number;
export default jsMath;