https://github.com/ericgio/distance-utils
A set of utilities for converting and formatting distances.
https://github.com/ericgio/distance-utils
distance-calculation
Last synced: 5 months ago
JSON representation
A set of utilities for converting and formatting distances.
- Host: GitHub
- URL: https://github.com/ericgio/distance-utils
- Owner: ericgio
- License: mit
- Created: 2019-10-09T05:44:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T22:22:45.000Z (over 3 years ago)
- Last Synced: 2025-10-08T11:55:18.421Z (8 months ago)
- Topics: distance-calculation
- Language: JavaScript
- Homepage:
- Size: 963 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# distance-utils
A set of utilities for converting and formatting distances.
[](https://www.npmjs.com/package/@ericgio/distance-utils)
[](https://www.npmjs.com/package/@ericgio/distance-utils)
[](https://travis-ci.org/ericgio/distance-utils)
[](https://coveralls.io/github/ericgio/distance-utils)
[](LICENSE.md)
## Installation
```
npm install --save @ericgio/distance-utils
```
or
```
yarn add @ericgio/distance-utils
```
## Functions
#### formatDistance
Formats distance measurements, by stripping trailing zeroes and restricting floats to at most 2 decimal places.
```js
formatDistance(1.3333) // => '1.33'
formatDistance(1.00) // => '1'
```
#### round
Rounds a number to a specified level of precision. Similar to [Lodash's round function](https://lodash.com/docs/4.17.15#round).
```js
round(4.006) // => 4
round(4.006, 2) // => 4.01
round(4060, -2) // => 4100
```
#### milesToKm
Converts miles to kilometers.
```js
milesToKm(6.21) // => 10
milesToKm(6.21, 1) // => 10.0
```
#### metersToMiles
Converts meters to miles.
```js
metersToMiles(10000) // => 6.21
metersToMiles(10000, 1) // => 6.2
```
#### metersToFeet
Converts meters to feet.
```js
metersToFeet(1582) // => 5190
metersToFeet(1, 2) // => 3.28
```
## License
[MIT](https://github.com/ericgio/distance-utils/blob/master/LICENSE.md)