@turf/flip
Advanced tools
Comparing version 4.7.3 to 5.0.4
@@ -1,10 +0,8 @@ | ||
/// <reference types="geojson" /> | ||
import { AllGeoJSON } from '@turf/helpers' | ||
type Feature = GeoJSON.Feature<any>; | ||
type Features = GeoJSON.FeatureCollection<any>; | ||
type Geometry = GeoJSON.GeometryObject; | ||
type Geometries = GeoJSON.GeometryCollection; | ||
declare function flip<T extends Features|Feature|Geometry|Geometries>(geojson: T, mutate?: boolean): T | ||
declare namespace flip { } | ||
export = flip; | ||
export default function flip<T extends AllGeoJSON>( | ||
geojson: T, | ||
options?: { | ||
mutate?: boolean | ||
} | ||
): T |
24
index.js
@@ -1,2 +0,4 @@ | ||
var coordEach = require('@turf/meta').coordEach; | ||
import { coordEach } from '@turf/meta'; | ||
import { isObject } from '@turf/helpers'; | ||
import clone from '@turf/clone'; | ||
@@ -7,5 +9,6 @@ /** | ||
* @name flip | ||
* @param {FeatureCollection|Feature<any>} geojson input features | ||
* @param {boolean} [mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @returns {FeatureCollection|Feature<any>} a feature or set of features of the same type as `input` with flipped coordinates | ||
* @param {GeoJSON} geojson input features | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @returns {GeoJSON} a feature or set of features of the same type as `input` with flipped coordinates | ||
* @example | ||
@@ -19,3 +22,8 @@ * var serbia = turf.point([20.566406, 43.421008]); | ||
*/ | ||
module.exports = function (geojson, mutate) { | ||
function flip(geojson, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var mutate = options.mutate; | ||
if (!geojson) throw new Error('geojson is required'); | ||
@@ -25,3 +33,3 @@ // ensure that we don't modify features in-place and changes to the | ||
// properties. | ||
if (mutate === false || mutate === undefined) geojson = JSON.parse(JSON.stringify(geojson)); | ||
if (mutate === false || mutate === undefined) geojson = clone(geojson); | ||
@@ -35,2 +43,4 @@ coordEach(geojson, function (coord) { | ||
return geojson; | ||
}; | ||
} | ||
export default flip; |
{ | ||
"name": "@turf/flip", | ||
"version": "4.7.3", | ||
"version": "5.0.4", | ||
"description": "turf flip module", | ||
"main": "index.js", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"main.js" | ||
], | ||
"scripts": { | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"bench": "node -r @std/esm bench.js" | ||
}, | ||
@@ -32,11 +36,18 @@ "repository": { | ||
"devDependencies": { | ||
"@turf/helpers": "^4.7.3", | ||
"benchmark": "^2.1.4", | ||
"load-json-file": "^2.0.0", | ||
"tape": "^4.6.3", | ||
"write-json-file": "^2.0.0" | ||
"@std/esm": "*", | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"tape": "*", | ||
"write-json-file": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/meta": "^4.7.3" | ||
"@turf/clone": "^5.0.4", | ||
"@turf/helpers": "^5.0.4", | ||
"@turf/meta": "^5.0.4" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/flip | ||
# flip | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## flip | ||
Takes input features and flips all of their coordinates from `[x, y]` to `[y, x]`. | ||
@@ -9,4 +11,5 @@ | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<any>)** input features | ||
- `mutate` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
- `geojson` **[GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects)** input features | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`) | ||
- `options.mutate` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
@@ -24,3 +27,3 @@ **Examples** | ||
Returns **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<any>)** a feature or set of features of the same type as `input` with flipped coordinates | ||
Returns **[GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects)** a feature or set of features of the same type as `input` with flipped coordinates | ||
@@ -27,0 +30,0 @@ <!-- This file is automatically generated. Please don't edit it directly: |
6955
6
86
52
3
6
+ Added@turf/clone@^5.0.4
+ Added@turf/helpers@^5.0.4
+ Added@turf/clone@5.1.5(transitive)
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/meta@5.2.0(transitive)
- Removed@turf/meta@4.7.4(transitive)
Updated@turf/meta@^5.0.4