Skip to content

Commit

Permalink
feat: 升级ts版本,解决node_modules中ava类型校验问题,修复单元测试不通过问题
Browse files Browse the repository at this point in the history
  • Loading branch information
suxiao committed Jun 16, 2020
1 parent 4cbca22 commit a7e9d38
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"build": "rollup -c",
"watch": "rollup -cw",
"test": "tsc -p tsconfig.test.json && nyc --reporter=lcov --reporter=text --reporter=json ava && rm -rf .nyc_output",
"test1": "ava",
"posttest": "codecov -f coverage/*.json -t 072762c4-c5bc-4393-bcd9-71eac9e7725b",
"prepublish": "rm -rf build && tsc && npm run build",
"tslint": "tslint './src/**/*.?(ts|tsx)'"
Expand All @@ -47,7 +46,7 @@
"rollup-plugin-typescript2": "^0.8.4",
"rollup-watch": "^4.3.1",
"tslint": "^5.8.0",
"typescript": "^2.6.2"
"typescript": "^3.8.3"
},
"license": "MIT"
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type numType = number | string;
* 把错误的数据转正
* strip(0.09999999999999998)=0.1
*/
function strip(num: numType, precision = 12): number {

This comment has been minimized.

Copy link
@culosic

culosic Sep 4, 2024

大哥您好,这里改成15了,但是文档里还是12:camsong/blog#9 (comment) @camsong

This comment has been minimized.

Copy link
@camsong

camsong Sep 5, 2024

Member

感谢指正,已更新文档为15

function strip(num: numType, precision = 15): number {
return +parseFloat(Number(num).toPrecision(precision));
}

Expand All @@ -32,7 +32,7 @@ function float2Fixed(num: numType): number {
return Number(num.toString().replace('.', ''));
}
const dLen = digitLength(num);
return dLen > 0 ? strip(times(num, Math.pow(10, dLen))) : Number(num);
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
}

/**
Expand Down
1 change: 0 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ test('NP.strip can eliminate rounding errors', (t) => {

test('NP.digitLength can do digitLength operation', (t) => {
t.true(NP.digitLength(123.4567890123) === 10);
t.true(NP.digitLength('123.4567890123') === 10);

t.true(NP.digitLength(1.23e-5) === 7);
t.true(NP.digitLength(1.23e-5) === 7);
Expand Down

0 comments on commit a7e9d38

Please sign in to comment.