Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/silentcicero/bignumber-to-string
A tiny module to convert BigNumbers to strings that are nested within objects or arrays
https://github.com/silentcicero/bignumber-to-string
Last synced: 5 days ago
JSON representation
A tiny module to convert BigNumbers to strings that are nested within objects or arrays
- Host: GitHub
- URL: https://github.com/silentcicero/bignumber-to-string
- Owner: SilentCicero
- Created: 2016-05-16T17:31:06.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-05-19T15:29:47.000Z (over 8 years ago)
- Last Synced: 2024-12-01T21:17:01.282Z (21 days ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bignumber-to-string
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
A tiny module to convert BigNumbers to strings that are nested within objects or arrays
```
npm install bignumber-to-string
```## Use
BigNumbers are used in various applications, however, most do not want to store
the complex BigNumber object itself in their state or DB. Converting the BigNumber
to a string keeps data precision while being easier to store.## Example
```js
const bigNumberToString = require('bignumber-to-string')const obj = {
data: 100,
somedata: 'sdfsdfsd',
bn: new BigNumber(1000),
something: {
bn: new BigNumber(10000)
}
}console.log(bigNumberToString(obj))
/*
returns:
{
data: 100,
somedata: 'sdfsdfsd',
bn: '1000',
something: {
bn: '10000'
}
}
*/
```## API
### (1) bigNumberToString
Converts any BigNumber objects to a string while bypassing everything else
**Parameters**
- `obj` **Object|Array|String|Boolean|Function** input data
- `base` **Number** base integer for string conversionReturns **Variable** if BigNumber, returns string, else returns what ever input type with BigNumbers converted to strings
## Tests
```
npm test
```## License
```
The MIT License (MIT)Copyright (c) 2016 Nick Dodson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```