Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
napalmpapalam committed Jul 31, 2023
1 parent 7f7cbbb commit 13d0fe7
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 12 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [1.0.0-rc.4] - 2023-07-31
### Fixed
- `@distributedlab/tools` - `BN` format decimals size of the output value

## [1.0.0-rc.3] - 2023-07-31
### Added
- `@distributedlab/reactity` - `extend` ability to extend multiple parents
Expand Down Expand Up @@ -311,7 +315,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[old repo]: https://github.com/distributed-lab/web-kit-old

[Unreleased]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.3...HEAD
[Unreleased]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.4...HEAD
[1.0.0-rc.4]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.3...1.0.0-rc.4
[1.0.0-rc.3]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.2...1.0.0-rc.3
[1.0.0-rc.2]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.1...1.0.0-rc.2
[1.0.0-rc.1]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.0...1.0.0-rc.1
Expand Down
2 changes: 1 addition & 1 deletion packages/fetcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/fetcher",
"version": "1.0.0-rc.3",
"version": "1.0.0-rc.4",
"description": "Fetch API wrapper with the extended functionality and simple interface",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jac/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/jac",
"version": "1.0.0-rc.3",
"version": "1.0.0-rc.4",
"description": "A library for constructing JSON-API compliant requests and responses",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/reactivity",
"version": "1.0.0-rc.3",
"version": "1.0.0-rc.4",
"description": "Implementation of the reactivity connections to propagate changes between objects",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/tools",
"version": "1.0.0-rc.3",
"version": "1.0.0-rc.4",
"description": "Collection of common utility functions and classes",
"repository": {
"type": "git",
Expand Down
15 changes: 10 additions & 5 deletions packages/tools/src/bn/bn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,11 @@ describe('performs BN unit test', () => {
})

test('formatting should return correct string', () => {
expect(BN.fromRaw(10.223, 6).format({ decimals: 2 })).toBe('10.22')
expect(BN.fromRaw(10.223, 6).format({ decimals: 10 })).toBe(
'10.2230000000',
)

expect(
BN.fromRaw(0, 1).format({
decimals: 2,
Expand Down Expand Up @@ -665,15 +670,15 @@ describe('performs BN unit test', () => {
decimals: 6,
groupSeparator: ',',
}),
).toBe('122,334,444,23.1231231')
).toBe('122,334,444,23.123123')

expect(
BN.fromRaw('12233444423.123123123123123', 18).format({
decimals: 6,
groupSeparator: '.',
decimalSeparator: ',',
}),
).toBe('122.334.444.23,1231231')
).toBe('122.334.444.23,123123')

expect(
BN.fromRaw('12233444423.123123123123123', 18).format({
Expand All @@ -682,7 +687,7 @@ describe('performs BN unit test', () => {
decimalSeparator: '.',
groupSize: 3,
}),
).toBe('122 334 444 23.1231231')
).toBe('122 334 444 23.123123')

expect(
BN.fromRaw('12233444423.123123123123123', 18).format({
Expand All @@ -692,7 +697,7 @@ describe('performs BN unit test', () => {
decimalSeparator: '.',
groupSize: 3,
}),
).toBe('122 334 444 23.12 31 23 1')
).toBe('122 334 444 23.12 31 23')

expect(
BN.fromRaw('12233444423.123123123123123', 18).format({
Expand All @@ -703,7 +708,7 @@ describe('performs BN unit test', () => {
decimalSeparator: '.',
groupSize: 3,
}),
).toBe('122 334 444 23.12_31_23_1')
).toBe('122 334 444 23.12_31_23')
})
})
})
2 changes: 1 addition & 1 deletion packages/tools/src/bn/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const format = (value: string, format: BnFormatConfig) => {
}

if (decimals) {
fraction = fraction.padEnd(decimals, '0').slice(0, decimals + 1)
fraction = fraction.padEnd(decimals, '0').slice(0, decimals)
} else {
fraction = ''
decimalSeparator = ''
Expand Down
2 changes: 1 addition & 1 deletion packages/w3p/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/w3p",
"version": "1.0.0-rc.3",
"version": "1.0.0-rc.4",
"description": "Wrapper for Web3 Providers",
"repository": {
"type": "git",
Expand Down

0 comments on commit 13d0fe7

Please sign in to comment.