Skip to content

Commit

Permalink
feat(fromString): add option to parse string with lat first
Browse files Browse the repository at this point in the history
  • Loading branch information
evansiroky committed Mar 7, 2017
1 parent 8cf7b09 commit feff642
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 64 deletions.
68 changes: 35 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ No one has agreed on a standard way of representing lon/lat. This is a small nor

#### Table of Contents

- [input](#input)
- [InvalidCoordinateException](#invalidcoordinateexception)
- [lonlat.types.input](#lonlattypesinput)
- [lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)
- [conveyal/lonlat](#conveyallonlat)
- [fromCoordinates](#fromcoordinates)
- [fromLatlng](#fromlatlng)
Expand All @@ -34,9 +34,9 @@ No one has agreed on a standard way of representing lon/lat. This is a small nor
- [toLeaflet](#toleaflet)
- [toPoint](#topoint)
- [toString](#tostring)
- [lonlat](#lonlat)
- [lonlat.types.output](#lonlattypesoutput)

### input
### lonlat.types.input

(type)

Expand All @@ -57,7 +57,7 @@ Type: ([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference

- `unknown`

### InvalidCoordinateException
### lonlat.types.InvalidCoordinateException

(exception type)

Expand All @@ -75,7 +75,7 @@ Parse an unknown type of input.

**Parameters**

- `unknown` **[input](#input)**
- `unknown` **[lonlat.types.input](#lonlattypesinput)**

**Examples**

Expand Down Expand Up @@ -104,9 +104,9 @@ position = lonlat({}) // Error: Invalid latitude value: und
position = lonlat(null) // Error: Value must not be null or undefined
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[lonlat](#lonlat)**
Returns **[lonlat.types.output](#lonlattypesoutput)**

#### fromCoordinates

Expand All @@ -127,9 +127,9 @@ var position = lonlat.fromCoordinates([12, 34]) // { lon: 12, lat: 34 }
position = lonlat.fromGeoJSON([12, 34]) // { lon: 12, lat: 34 }
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[lonlat](#lonlat)**
Returns **[lonlat.types.output](#lonlattypesoutput)**

#### fromLatlng

Expand All @@ -150,9 +150,9 @@ var position = lonlat.fromLatlng({ longitude: 12, latitude: 34 }) // { lon: 12
position = lonlat.fromLeaflet({ lng: 12, lat: 34 }) // { lon: 12, lat: 34 }
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[lonlat](#lonlat)**
Returns **[lonlat.types.output](#lonlattypesoutput)**

#### fromPoint

Expand All @@ -171,9 +171,9 @@ var lonlat = require('@conveyal/lonlat')
var position = lonlat.fromPoint({ x: 12, y: 34 }) // { lon: 12, lat: 34 }
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[lonlat](#lonlat)**
Returns **[lonlat.types.output](#lonlattypesoutput)**

#### fromString

Expand All @@ -182,28 +182,30 @@ Tries to parse from a string.
**Parameters**

- `str` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** A string in the format: `longitude,latitude`
- `latIsFrist` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Whether or not the first value is latitude. (optional, default `false`)

**Examples**

```javascript
var lonlat = require('@conveyal/lonlat')

var position = lonlat.fromString('12,34') // { lon: 12, lat: 34 }
var position = lonlat.fromString('12,34') // { lon: 12, lat: 34 }
var position = lonlat.fromString('12,34', true) // { lon: 34, lat: 12 }
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[lonlat](#lonlat)**
Returns **[lonlat.types.output](#lonlattypesoutput)**

#### isEqual

Determine if two inputs are equal to each other

**Parameters**

- `lonlat1` **[input](#input)**
- `lonlat2` **[input](#input)**
- `epsilon` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** The maximum acceptable deviation to be considered equal. Default = 0
- `lonlat1` **input**
- `lonlat2` **input**
- `epsilon` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** The maximum acceptable deviation to be considered equal. (optional, default `0`)

**Examples**

Expand All @@ -213,16 +215,16 @@ var lonlat = require('@conveyal/lonlat')
var isEqual = lonlat.isEqual('12,34', [12, 34]) // true
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**

#### print

**Parameters**

- `input` **[input](#input)**
- `fixed` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** The number of decimal places to round to.
- `input` **input**
- `fixed` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** The number of decimal places to round to. (optional, default `5`)

**Examples**

Expand All @@ -232,7 +234,7 @@ var lonlat = require('@conveyal/lonlat')
var pretty = lonlat.print('12.345678,34') // '12.34568, 34.00000'
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** A string with in the format `longitude,latitude` rounded to
the number of decimal places as specified by `fixed`
Expand All @@ -245,7 +247,7 @@ Translates to a coordinate array.

**Parameters**

- `input` **[input](#input)**
- `input` **[lonlat.types.input](#lonlattypesinput)**

**Examples**

Expand All @@ -255,7 +257,7 @@ var lonlat = require('@conveyal/lonlat')
var coords = lonlat.toCoordinates('12,34') // [12, 34]
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** An array in the format [longitude, latitude]

Expand All @@ -266,7 +268,7 @@ This function requires Leaflet to be installed as a global variable `L` in the w

**Parameters**

- `input` **[input](#input)**
- `input` **[lonlat.types.input](#lonlattypesinput)**

**Examples**

Expand All @@ -276,7 +278,7 @@ var lonlat = require('@conveyal/lonlat')
var position = lonlat.toLeaflet({ lat: 12, long: 34 }) // Leaflet LatLng object
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** A Leaflet LatLng object

Expand All @@ -286,7 +288,7 @@ Translates to point Object.

**Parameters**

- `input` **[input](#input)**
- `input` **[lonlat.types.input](#lonlattypesinput)**

**Examples**

Expand All @@ -296,7 +298,7 @@ var lonlat = require('@conveyal/lonlat')
var point = lonlat.toPoint('12,34') // { x: 12, y: 34 }
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** An object with `x` and `y` attributes representing latitude and longitude respectively

Expand All @@ -306,7 +308,7 @@ Translates to coordinate string.

**Parameters**

- `input` **[input](#input)**
- `input` **[lonlat.types.input](#lonlattypesinput)**

**Examples**

Expand All @@ -316,11 +318,11 @@ var lonlat = require('@conveyal/lonlat')
var str = lonlat.toString({ lat: 12, longitude: 34 }) // '34,12'
```

- Throws **[InvalidCoordinateException](#invalidcoordinateexception)**
- Throws **[lonlat.types.InvalidCoordinateException](#lonlattypesinvalidcoordinateexception)**

Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** A string in the format 'longitude,latitude'

### lonlat
### lonlat.types.output

(type)

Expand Down
Loading

0 comments on commit feff642

Please sign in to comment.