@turf/rewind 7.0.0-alpha.0 → 7.0.0-alpha.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,26 +39,21 @@ Returns **[GeoJSON][4]** rewind Polygon
39
39
 
40
40
  [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
41
41
 
42
- <!-- This file is automatically generated. Please don't edit it directly:
43
- if you find an error, edit the source file (likely index.js), and re-run
44
- ./scripts/generate-readmes in the turf project. -->
42
+ <!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
45
43
 
46
44
  ---
47
45
 
48
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
49
- module collection dedicated to geographic algorithms. It is maintained in the
50
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
51
- PRs and issues.
46
+ This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
52
47
 
53
48
  ### Installation
54
49
 
55
- Install this module individually:
50
+ Install this single module individually:
56
51
 
57
52
  ```sh
58
53
  $ npm install @turf/rewind
59
54
  ```
60
55
 
61
- Or install the Turf module that includes it as a function:
56
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
62
57
 
63
58
  ```sh
64
59
  $ npm install @turf/turf
@@ -0,0 +1,96 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ var _clone = require('@turf/clone');
6
+ var _booleanclockwise = require('@turf/boolean-clockwise');
7
+ var _meta = require('@turf/meta');
8
+ var _invariant = require('@turf/invariant');
9
+ var _helpers = require('@turf/helpers');
10
+ function rewind(geojson, options = {}) {
11
+ var _a, _b;
12
+ options = options || {};
13
+ if (!_helpers.isObject.call(void 0, options))
14
+ throw new Error("options is invalid");
15
+ const mutate = (_a = options.mutate) != null ? _a : false;
16
+ const reverse = (_b = options.reverse) != null ? _b : false;
17
+ if (!geojson)
18
+ throw new Error("<geojson> is required");
19
+ if (typeof reverse !== "boolean")
20
+ throw new Error("<reverse> must be a boolean");
21
+ if (typeof mutate !== "boolean")
22
+ throw new Error("<mutate> must be a boolean");
23
+ if (!mutate && geojson.type !== "Point" && geojson.type !== "MultiPoint") {
24
+ geojson = _clone.clone.call(void 0, geojson);
25
+ }
26
+ const results = [];
27
+ switch (geojson.type) {
28
+ case "GeometryCollection":
29
+ _meta.geomEach.call(void 0, geojson, function(geometry) {
30
+ rewindFeature(geometry, reverse);
31
+ });
32
+ return geojson;
33
+ case "FeatureCollection":
34
+ _meta.featureEach.call(void 0, geojson, function(feature) {
35
+ const rewoundFeature = rewindFeature(feature, reverse);
36
+ _meta.featureEach.call(void 0, rewoundFeature, function(result) {
37
+ results.push(result);
38
+ });
39
+ });
40
+ return _helpers.featureCollection.call(void 0, results);
41
+ }
42
+ return rewindFeature(geojson, reverse);
43
+ }
44
+ __name(rewind, "rewind");
45
+ function rewindFeature(geojson, reverse) {
46
+ const type = geojson.type === "Feature" ? geojson.geometry.type : geojson.type;
47
+ switch (type) {
48
+ case "GeometryCollection":
49
+ _meta.geomEach.call(void 0, geojson, function(geometry) {
50
+ rewindFeature(geometry, reverse);
51
+ });
52
+ return geojson;
53
+ case "LineString":
54
+ rewindLineString(_invariant.getCoords.call(void 0, geojson), reverse);
55
+ return geojson;
56
+ case "Polygon":
57
+ rewindPolygon(_invariant.getCoords.call(void 0, geojson), reverse);
58
+ return geojson;
59
+ case "MultiLineString":
60
+ _invariant.getCoords.call(void 0, geojson).forEach(function(lineCoords) {
61
+ rewindLineString(lineCoords, reverse);
62
+ });
63
+ return geojson;
64
+ case "MultiPolygon":
65
+ _invariant.getCoords.call(void 0, geojson).forEach(function(lineCoords) {
66
+ rewindPolygon(lineCoords, reverse);
67
+ });
68
+ return geojson;
69
+ case "Point":
70
+ case "MultiPoint":
71
+ return geojson;
72
+ }
73
+ }
74
+ __name(rewindFeature, "rewindFeature");
75
+ function rewindLineString(coords, reverse) {
76
+ if (_booleanclockwise.booleanClockwise.call(void 0, coords) === reverse)
77
+ coords.reverse();
78
+ }
79
+ __name(rewindLineString, "rewindLineString");
80
+ function rewindPolygon(coords, reverse) {
81
+ if (_booleanclockwise.booleanClockwise.call(void 0, coords[0]) !== reverse) {
82
+ coords[0].reverse();
83
+ }
84
+ for (let i = 1; i < coords.length; i++) {
85
+ if (_booleanclockwise.booleanClockwise.call(void 0, coords[i]) === reverse) {
86
+ coords[i].reverse();
87
+ }
88
+ }
89
+ }
90
+ __name(rewindPolygon, "rewindPolygon");
91
+ var turf_rewind_default = rewind;
92
+
93
+
94
+
95
+ exports.default = turf_rewind_default; exports.rewind = rewind;
96
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AAWA,SAAS,aAAa;AACtB,SAAS,wBAAwB;AACjC,SAAS,UAAU,mBAAmB;AACtC,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB,gBAAgB;AAoB5C,SAAS,OACP,SACA,UAGI,CAAC,GACmC;AAzC1C;AA2CE,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,UAAS,aAAQ,WAAR,YAAkB;AACjC,QAAM,WAAU,aAAQ,YAAR,YAAmB;AAGnC,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,uBAAuB;AACrD,MAAI,OAAO,YAAY;AACrB,UAAM,IAAI,MAAM,6BAA6B;AAC/C,MAAI,OAAO,WAAW;AACpB,UAAM,IAAI,MAAM,4BAA4B;AAG9C,MAAI,CAAC,UAAU,QAAQ,SAAS,WAAW,QAAQ,SAAS,cAAc;AACxE,cAAU,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MAAI,iBAAiB,OAAO,CAAC,CAAC,MAAM,SAAS;AAC3C,WAAO,CAAC,EAAE,QAAQ;AAAA,EACpB;AAEA,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,QAAI,iBAAiB,OAAO,CAAC,CAAC,MAAM,SAAS;AAC3C,aAAO,CAAC,EAAE,QAAQ;AAAA,IACpB;AAAA,EACF;AACF;AAXS;AAcT,IAAO,sBAAQ","sourcesContent":["import type {\n Feature,\n Position,\n GeometryCollection,\n Geometry,\n LineString,\n MultiLineString,\n MultiPolygon,\n Polygon,\n FeatureCollection,\n} from \"geojson\";\nimport { clone } from \"@turf/clone\";\nimport { booleanClockwise } from \"@turf/boolean-clockwise\";\nimport { geomEach, featureEach } from \"@turf/meta\";\nimport { getCoords } from \"@turf/invariant\";\nimport { featureCollection, isObject } from \"@turf/helpers\";\nimport type { AllGeoJSON } from \"@turf/helpers\";\n\n/**\n * Rewind {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon} outer ring counterclockwise and inner rings clockwise (Uses {@link http://en.wikipedia.org/wiki/Shoelace_formula|Shoelace Formula}).\n *\n * @name rewind\n * @param {GeoJSON} geojson input GeoJSON Polygon\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.reverse=false] enable reverse winding\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} rewind Polygon\n * @example\n * var polygon = turf.polygon([[[121, -29], [138, -29], [138, -18], [121, -18], [121, -29]]]);\n *\n * var rewind = turf.rewind(polygon);\n *\n * //addToMap\n * var addToMap = [rewind];\n */\nfunction rewind<T extends AllGeoJSON>(\n geojson: T,\n options: {\n reverse?: boolean;\n mutate?: boolean;\n } = {}\n): Geometry | Feature | FeatureCollection {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const mutate = options.mutate ?? false;\n const reverse = options.reverse ?? false;\n\n // validation\n if (!geojson) throw new Error(\"<geojson> is required\");\n if (typeof reverse !== \"boolean\")\n throw new Error(\"<reverse> must be a boolean\");\n if (typeof mutate !== \"boolean\")\n throw new Error(\"<mutate> must be a boolean\");\n\n // Prevent input mutation if requested and necessary.\n if (!mutate && geojson.type !== \"Point\" && geojson.type !== \"MultiPoint\") {\n geojson = clone(geojson);\n }\n\n // Support Feature Collection or Geometry Collection\n const results: Feature[] = [];\n switch (geojson.type) {\n case \"GeometryCollection\":\n geomEach(geojson, function (geometry) {\n rewindFeature(geometry, reverse);\n });\n return geojson;\n case \"FeatureCollection\":\n featureEach(geojson, function (feature) {\n const rewoundFeature = rewindFeature(feature, reverse) as Feature;\n featureEach(rewoundFeature, function (result) {\n results.push(result);\n });\n });\n return featureCollection(results);\n }\n // Support Feature or Geometry Objects\n return rewindFeature(geojson, reverse);\n}\n\n/**\n * Rewind\n *\n * @private\n * @param {Geometry|Feature<any>} geojson Geometry or Feature\n * @param {Boolean} [reverse=false] enable reverse winding\n * @returns {Geometry|Feature<any>} rewind Geometry or Feature\n */\nfunction rewindFeature(\n geojson: Geometry | GeometryCollection | Feature,\n reverse: boolean\n) {\n const type =\n geojson.type === \"Feature\" ? geojson.geometry.type : geojson.type;\n\n // Support all GeoJSON Geometry Objects\n switch (type) {\n case \"GeometryCollection\":\n geomEach(geojson, function (geometry) {\n rewindFeature(geometry, reverse);\n });\n return geojson;\n case \"LineString\":\n rewindLineString(getCoords(geojson as LineString), reverse);\n return geojson;\n case \"Polygon\":\n rewindPolygon(getCoords(geojson as Polygon), reverse);\n return geojson;\n case \"MultiLineString\":\n getCoords(geojson as MultiLineString).forEach(function (lineCoords) {\n rewindLineString(lineCoords, reverse);\n });\n return geojson;\n case \"MultiPolygon\":\n getCoords(geojson as MultiPolygon).forEach(function (lineCoords) {\n rewindPolygon(lineCoords, reverse);\n });\n return geojson;\n case \"Point\":\n case \"MultiPoint\":\n // noop\n return geojson;\n }\n}\n\n/**\n * Rewind LineString - outer ring clockwise\n *\n * @private\n * @param {Array<Array<number>>} coords GeoJSON LineString geometry coordinates\n * @param {Boolean} [reverse=false] enable reverse winding\n * @returns {void} mutates coordinates\n */\nfunction rewindLineString(coords: Position[], reverse: boolean) {\n if (booleanClockwise(coords) === reverse) coords.reverse();\n}\n\n/**\n * Rewind Polygon - outer ring counterclockwise and inner rings clockwise.\n *\n * @private\n * @param {Array<Array<Array<number>>>} coords GeoJSON Polygon geometry coordinates\n * @param {Boolean} [reverse=false] enable reverse winding\n * @returns {void} mutates coordinates\n */\nfunction rewindPolygon(coords: Position[][], reverse: boolean) {\n // outer ring\n if (booleanClockwise(coords[0]) !== reverse) {\n coords[0].reverse();\n }\n // inner rings\n for (let i = 1; i < coords.length; i++) {\n if (booleanClockwise(coords[i]) === reverse) {\n coords[i].reverse();\n }\n }\n}\n\nexport { rewind };\nexport default rewind;\n"]}
@@ -0,0 +1,26 @@
1
+ import { Geometry, Feature, FeatureCollection } from 'geojson';
2
+ import { AllGeoJSON } from '@turf/helpers';
3
+
4
+ /**
5
+ * Rewind {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon} outer ring counterclockwise and inner rings clockwise (Uses {@link http://en.wikipedia.org/wiki/Shoelace_formula|Shoelace Formula}).
6
+ *
7
+ * @name rewind
8
+ * @param {GeoJSON} geojson input GeoJSON Polygon
9
+ * @param {Object} [options={}] Optional parameters
10
+ * @param {boolean} [options.reverse=false] enable reverse winding
11
+ * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
12
+ * @returns {GeoJSON} rewind Polygon
13
+ * @example
14
+ * var polygon = turf.polygon([[[121, -29], [138, -29], [138, -18], [121, -18], [121, -29]]]);
15
+ *
16
+ * var rewind = turf.rewind(polygon);
17
+ *
18
+ * //addToMap
19
+ * var addToMap = [rewind];
20
+ */
21
+ declare function rewind<T extends AllGeoJSON>(geojson: T, options?: {
22
+ reverse?: boolean;
23
+ mutate?: boolean;
24
+ }): Geometry | Feature | FeatureCollection;
25
+
26
+ export { rewind as default, rewind };
@@ -0,0 +1,26 @@
1
+ import { Geometry, Feature, FeatureCollection } from 'geojson';
2
+ import { AllGeoJSON } from '@turf/helpers';
3
+
4
+ /**
5
+ * Rewind {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon} outer ring counterclockwise and inner rings clockwise (Uses {@link http://en.wikipedia.org/wiki/Shoelace_formula|Shoelace Formula}).
6
+ *
7
+ * @name rewind
8
+ * @param {GeoJSON} geojson input GeoJSON Polygon
9
+ * @param {Object} [options={}] Optional parameters
10
+ * @param {boolean} [options.reverse=false] enable reverse winding
11
+ * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
12
+ * @returns {GeoJSON} rewind Polygon
13
+ * @example
14
+ * var polygon = turf.polygon([[[121, -29], [138, -29], [138, -18], [121, -18], [121, -29]]]);
15
+ *
16
+ * var rewind = turf.rewind(polygon);
17
+ *
18
+ * //addToMap
19
+ * var addToMap = [rewind];
20
+ */
21
+ declare function rewind<T extends AllGeoJSON>(geojson: T, options?: {
22
+ reverse?: boolean;
23
+ mutate?: boolean;
24
+ }): Geometry | Feature | FeatureCollection;
25
+
26
+ export { rewind as default, rewind };
@@ -0,0 +1,96 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ import { clone } from "@turf/clone";
6
+ import { booleanClockwise } from "@turf/boolean-clockwise";
7
+ import { geomEach, featureEach } from "@turf/meta";
8
+ import { getCoords } from "@turf/invariant";
9
+ import { featureCollection, isObject } from "@turf/helpers";
10
+ function rewind(geojson, options = {}) {
11
+ var _a, _b;
12
+ options = options || {};
13
+ if (!isObject(options))
14
+ throw new Error("options is invalid");
15
+ const mutate = (_a = options.mutate) != null ? _a : false;
16
+ const reverse = (_b = options.reverse) != null ? _b : false;
17
+ if (!geojson)
18
+ throw new Error("<geojson> is required");
19
+ if (typeof reverse !== "boolean")
20
+ throw new Error("<reverse> must be a boolean");
21
+ if (typeof mutate !== "boolean")
22
+ throw new Error("<mutate> must be a boolean");
23
+ if (!mutate && geojson.type !== "Point" && geojson.type !== "MultiPoint") {
24
+ geojson = clone(geojson);
25
+ }
26
+ const results = [];
27
+ switch (geojson.type) {
28
+ case "GeometryCollection":
29
+ geomEach(geojson, function(geometry) {
30
+ rewindFeature(geometry, reverse);
31
+ });
32
+ return geojson;
33
+ case "FeatureCollection":
34
+ featureEach(geojson, function(feature) {
35
+ const rewoundFeature = rewindFeature(feature, reverse);
36
+ featureEach(rewoundFeature, function(result) {
37
+ results.push(result);
38
+ });
39
+ });
40
+ return featureCollection(results);
41
+ }
42
+ return rewindFeature(geojson, reverse);
43
+ }
44
+ __name(rewind, "rewind");
45
+ function rewindFeature(geojson, reverse) {
46
+ const type = geojson.type === "Feature" ? geojson.geometry.type : geojson.type;
47
+ switch (type) {
48
+ case "GeometryCollection":
49
+ geomEach(geojson, function(geometry) {
50
+ rewindFeature(geometry, reverse);
51
+ });
52
+ return geojson;
53
+ case "LineString":
54
+ rewindLineString(getCoords(geojson), reverse);
55
+ return geojson;
56
+ case "Polygon":
57
+ rewindPolygon(getCoords(geojson), reverse);
58
+ return geojson;
59
+ case "MultiLineString":
60
+ getCoords(geojson).forEach(function(lineCoords) {
61
+ rewindLineString(lineCoords, reverse);
62
+ });
63
+ return geojson;
64
+ case "MultiPolygon":
65
+ getCoords(geojson).forEach(function(lineCoords) {
66
+ rewindPolygon(lineCoords, reverse);
67
+ });
68
+ return geojson;
69
+ case "Point":
70
+ case "MultiPoint":
71
+ return geojson;
72
+ }
73
+ }
74
+ __name(rewindFeature, "rewindFeature");
75
+ function rewindLineString(coords, reverse) {
76
+ if (booleanClockwise(coords) === reverse)
77
+ coords.reverse();
78
+ }
79
+ __name(rewindLineString, "rewindLineString");
80
+ function rewindPolygon(coords, reverse) {
81
+ if (booleanClockwise(coords[0]) !== reverse) {
82
+ coords[0].reverse();
83
+ }
84
+ for (let i = 1; i < coords.length; i++) {
85
+ if (booleanClockwise(coords[i]) === reverse) {
86
+ coords[i].reverse();
87
+ }
88
+ }
89
+ }
90
+ __name(rewindPolygon, "rewindPolygon");
91
+ var turf_rewind_default = rewind;
92
+ export {
93
+ turf_rewind_default as default,
94
+ rewind
95
+ };
96
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import type {\n Feature,\n Position,\n GeometryCollection,\n Geometry,\n LineString,\n MultiLineString,\n MultiPolygon,\n Polygon,\n FeatureCollection,\n} from \"geojson\";\nimport { clone } from \"@turf/clone\";\nimport { booleanClockwise } from \"@turf/boolean-clockwise\";\nimport { geomEach, featureEach } from \"@turf/meta\";\nimport { getCoords } from \"@turf/invariant\";\nimport { featureCollection, isObject } from \"@turf/helpers\";\nimport type { AllGeoJSON } from \"@turf/helpers\";\n\n/**\n * Rewind {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon} outer ring counterclockwise and inner rings clockwise (Uses {@link http://en.wikipedia.org/wiki/Shoelace_formula|Shoelace Formula}).\n *\n * @name rewind\n * @param {GeoJSON} geojson input GeoJSON Polygon\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.reverse=false] enable reverse winding\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} rewind Polygon\n * @example\n * var polygon = turf.polygon([[[121, -29], [138, -29], [138, -18], [121, -18], [121, -29]]]);\n *\n * var rewind = turf.rewind(polygon);\n *\n * //addToMap\n * var addToMap = [rewind];\n */\nfunction rewind<T extends AllGeoJSON>(\n geojson: T,\n options: {\n reverse?: boolean;\n mutate?: boolean;\n } = {}\n): Geometry | Feature | FeatureCollection {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const mutate = options.mutate ?? false;\n const reverse = options.reverse ?? false;\n\n // validation\n if (!geojson) throw new Error(\"<geojson> is required\");\n if (typeof reverse !== \"boolean\")\n throw new Error(\"<reverse> must be a boolean\");\n if (typeof mutate !== \"boolean\")\n throw new Error(\"<mutate> must be a boolean\");\n\n // Prevent input mutation if requested and necessary.\n if (!mutate && geojson.type !== \"Point\" && geojson.type !== \"MultiPoint\") {\n geojson = clone(geojson);\n }\n\n // Support Feature Collection or Geometry Collection\n const results: Feature[] = [];\n switch (geojson.type) {\n case \"GeometryCollection\":\n geomEach(geojson, function (geometry) {\n rewindFeature(geometry, reverse);\n });\n return geojson;\n case \"FeatureCollection\":\n featureEach(geojson, function (feature) {\n const rewoundFeature = rewindFeature(feature, reverse) as Feature;\n featureEach(rewoundFeature, function (result) {\n results.push(result);\n });\n });\n return featureCollection(results);\n }\n // Support Feature or Geometry Objects\n return rewindFeature(geojson, reverse);\n}\n\n/**\n * Rewind\n *\n * @private\n * @param {Geometry|Feature<any>} geojson Geometry or Feature\n * @param {Boolean} [reverse=false] enable reverse winding\n * @returns {Geometry|Feature<any>} rewind Geometry or Feature\n */\nfunction rewindFeature(\n geojson: Geometry | GeometryCollection | Feature,\n reverse: boolean\n) {\n const type =\n geojson.type === \"Feature\" ? geojson.geometry.type : geojson.type;\n\n // Support all GeoJSON Geometry Objects\n switch (type) {\n case \"GeometryCollection\":\n geomEach(geojson, function (geometry) {\n rewindFeature(geometry, reverse);\n });\n return geojson;\n case \"LineString\":\n rewindLineString(getCoords(geojson as LineString), reverse);\n return geojson;\n case \"Polygon\":\n rewindPolygon(getCoords(geojson as Polygon), reverse);\n return geojson;\n case \"MultiLineString\":\n getCoords(geojson as MultiLineString).forEach(function (lineCoords) {\n rewindLineString(lineCoords, reverse);\n });\n return geojson;\n case \"MultiPolygon\":\n getCoords(geojson as MultiPolygon).forEach(function (lineCoords) {\n rewindPolygon(lineCoords, reverse);\n });\n return geojson;\n case \"Point\":\n case \"MultiPoint\":\n // noop\n return geojson;\n }\n}\n\n/**\n * Rewind LineString - outer ring clockwise\n *\n * @private\n * @param {Array<Array<number>>} coords GeoJSON LineString geometry coordinates\n * @param {Boolean} [reverse=false] enable reverse winding\n * @returns {void} mutates coordinates\n */\nfunction rewindLineString(coords: Position[], reverse: boolean) {\n if (booleanClockwise(coords) === reverse) coords.reverse();\n}\n\n/**\n * Rewind Polygon - outer ring counterclockwise and inner rings clockwise.\n *\n * @private\n * @param {Array<Array<Array<number>>>} coords GeoJSON Polygon geometry coordinates\n * @param {Boolean} [reverse=false] enable reverse winding\n * @returns {void} mutates coordinates\n */\nfunction rewindPolygon(coords: Position[][], reverse: boolean) {\n // outer ring\n if (booleanClockwise(coords[0]) !== reverse) {\n coords[0].reverse();\n }\n // inner rings\n for (let i = 1; i < coords.length; i++) {\n if (booleanClockwise(coords[i]) === reverse) {\n coords[i].reverse();\n }\n }\n}\n\nexport { rewind };\nexport default rewind;\n"],"mappings":";;;;AAWA,SAAS,aAAa;AACtB,SAAS,wBAAwB;AACjC,SAAS,UAAU,mBAAmB;AACtC,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB,gBAAgB;AAoB5C,SAAS,OACP,SACA,UAGI,CAAC,GACmC;AAzC1C;AA2CE,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,UAAS,aAAQ,WAAR,YAAkB;AACjC,QAAM,WAAU,aAAQ,YAAR,YAAmB;AAGnC,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,uBAAuB;AACrD,MAAI,OAAO,YAAY;AACrB,UAAM,IAAI,MAAM,6BAA6B;AAC/C,MAAI,OAAO,WAAW;AACpB,UAAM,IAAI,MAAM,4BAA4B;AAG9C,MAAI,CAAC,UAAU,QAAQ,SAAS,WAAW,QAAQ,SAAS,cAAc;AACxE,cAAU,MAAM,OAAO;AAAA,EACzB;AAGA,QAAM,UAAqB,CAAC;AAC5B,UAAQ,QAAQ,MAAM;AAAA,IACpB,KAAK;AACH,eAAS,SAAS,SAAU,UAAU;AACpC,sBAAc,UAAU,OAAO;AAAA,MACjC,CAAC;AACD,aAAO;AAAA,IACT,KAAK;AACH,kBA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AAC,EAAE,QAAQ;AAAA,IACpB;AAAA,EACF;AACF;AAXS;AAcT,IAAO,sBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/rewind",
3
- "version": "7.0.0-alpha.0",
3
+ "version": "7.0.0-alpha.110+1411d63a7",
4
4
  "description": "turf rewind module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -28,43 +28,54 @@
28
28
  "polygon",
29
29
  "rewind"
30
30
  ],
31
- "main": "dist/js/index.js",
32
- "module": "dist/es/index.js",
31
+ "type": "commonjs",
32
+ "main": "dist/cjs/index.cjs",
33
+ "module": "dist/esm/index.mjs",
34
+ "types": "dist/cjs/index.d.ts",
33
35
  "exports": {
34
36
  "./package.json": "./package.json",
35
37
  ".": {
36
- "import": "./dist/es/index.js",
37
- "require": "./dist/js/index.js"
38
+ "import": {
39
+ "types": "./dist/esm/index.d.mts",
40
+ "default": "./dist/esm/index.mjs"
41
+ },
42
+ "require": {
43
+ "types": "./dist/cjs/index.d.ts",
44
+ "default": "./dist/cjs/index.cjs"
45
+ }
38
46
  }
39
47
  },
40
- "types": "index.d.ts",
41
48
  "sideEffects": false,
42
49
  "files": [
43
- "dist",
44
- "index.d.ts"
50
+ "dist"
45
51
  ],
46
52
  "scripts": {
47
- "bench": "node -r esm bench.js",
48
- "build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json",
49
- "docs": "node ../../scripts/generate-readmes",
50
- "test": "npm-run-all test:*",
51
- "test:tape": "node -r esm test.js",
53
+ "bench": "tsx bench.ts",
54
+ "build": "tsup --config ../../tsup.config.ts",
55
+ "docs": "tsx ../../scripts/generate-readmes.ts",
56
+ "test": "npm-run-all --npm-path npm test:*",
57
+ "test:tape": "tsx test.ts",
52
58
  "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
53
59
  },
54
60
  "devDependencies": {
55
- "benchmark": "*",
56
- "load-json-file": "*",
57
- "npm-run-all": "*",
58
- "rollup": "*",
59
- "tape": "*",
60
- "write-json-file": "*"
61
+ "@types/benchmark": "^2.1.5",
62
+ "@types/tape": "^4.2.32",
63
+ "benchmark": "^2.1.4",
64
+ "load-json-file": "^7.0.1",
65
+ "npm-run-all": "^4.1.5",
66
+ "tape": "^5.7.2",
67
+ "tsup": "^8.0.1",
68
+ "tsx": "^4.6.2",
69
+ "typescript": "^5.2.2",
70
+ "write-json-file": "^5.0.0"
61
71
  },
62
72
  "dependencies": {
63
- "@turf/boolean-clockwise": "^7.0.0-alpha.0",
64
- "@turf/clone": "^7.0.0-alpha.0",
65
- "@turf/helpers": "^7.0.0-alpha.0",
66
- "@turf/invariant": "^7.0.0-alpha.0",
67
- "@turf/meta": "^7.0.0-alpha.0"
73
+ "@turf/boolean-clockwise": "^7.0.0-alpha.110+1411d63a7",
74
+ "@turf/clone": "^7.0.0-alpha.110+1411d63a7",
75
+ "@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
76
+ "@turf/invariant": "^7.0.0-alpha.110+1411d63a7",
77
+ "@turf/meta": "^7.0.0-alpha.110+1411d63a7",
78
+ "tslib": "^2.6.2"
68
79
  },
69
- "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
80
+ "gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
70
81
  }
package/dist/es/index.js DELETED
@@ -1,134 +0,0 @@
1
- import clone from '@turf/clone';
2
- import booleanClockwise from '@turf/boolean-clockwise';
3
- import { featureEach, geomEach } from '@turf/meta';
4
- import { getCoords } from '@turf/invariant';
5
- import { isObject, featureCollection } from '@turf/helpers';
6
-
7
- /**
8
- * Rewind {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon} outer ring counterclockwise and inner rings clockwise (Uses {@link http://en.wikipedia.org/wiki/Shoelace_formula|Shoelace Formula}).
9
- *
10
- * @name rewind
11
- * @param {GeoJSON} geojson input GeoJSON Polygon
12
- * @param {Object} [options={}] Optional parameters
13
- * @param {boolean} [options.reverse=false] enable reverse winding
14
- * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
15
- * @returns {GeoJSON} rewind Polygon
16
- * @example
17
- * var polygon = turf.polygon([[[121, -29], [138, -29], [138, -18], [121, -18], [121, -29]]]);
18
- *
19
- * var rewind = turf.rewind(polygon);
20
- *
21
- * //addToMap
22
- * var addToMap = [rewind];
23
- */
24
- function rewind(geojson, options) {
25
- // Optional parameters
26
- options = options || {};
27
- if (!isObject(options)) throw new Error("options is invalid");
28
- var reverse = options.reverse || false;
29
- var mutate = options.mutate || false;
30
-
31
- // validation
32
- if (!geojson) throw new Error("<geojson> is required");
33
- if (typeof reverse !== "boolean")
34
- throw new Error("<reverse> must be a boolean");
35
- if (typeof mutate !== "boolean")
36
- throw new Error("<mutate> must be a boolean");
37
-
38
- // prevent input mutation
39
- if (mutate === false) geojson = clone(geojson);
40
-
41
- // Support Feature Collection or Geometry Collection
42
- var results = [];
43
- switch (geojson.type) {
44
- case "GeometryCollection":
45
- geomEach(geojson, function (geometry) {
46
- rewindFeature(geometry, reverse);
47
- });
48
- return geojson;
49
- case "FeatureCollection":
50
- featureEach(geojson, function (feature) {
51
- featureEach(rewindFeature(feature, reverse), function (result) {
52
- results.push(result);
53
- });
54
- });
55
- return featureCollection(results);
56
- }
57
- // Support Feature or Geometry Objects
58
- return rewindFeature(geojson, reverse);
59
- }
60
-
61
- /**
62
- * Rewind
63
- *
64
- * @private
65
- * @param {Geometry|Feature<any>} geojson Geometry or Feature
66
- * @param {Boolean} [reverse=false] enable reverse winding
67
- * @returns {Geometry|Feature<any>} rewind Geometry or Feature
68
- */
69
- function rewindFeature(geojson, reverse) {
70
- var type = geojson.type === "Feature" ? geojson.geometry.type : geojson.type;
71
-
72
- // Support all GeoJSON Geometry Objects
73
- switch (type) {
74
- case "GeometryCollection":
75
- geomEach(geojson, function (geometry) {
76
- rewindFeature(geometry, reverse);
77
- });
78
- return geojson;
79
- case "LineString":
80
- rewindLineString(getCoords(geojson), reverse);
81
- return geojson;
82
- case "Polygon":
83
- rewindPolygon(getCoords(geojson), reverse);
84
- return geojson;
85
- case "MultiLineString":
86
- getCoords(geojson).forEach(function (lineCoords) {
87
- rewindLineString(lineCoords, reverse);
88
- });
89
- return geojson;
90
- case "MultiPolygon":
91
- getCoords(geojson).forEach(function (lineCoords) {
92
- rewindPolygon(lineCoords, reverse);
93
- });
94
- return geojson;
95
- case "Point":
96
- case "MultiPoint":
97
- return geojson;
98
- }
99
- }
100
-
101
- /**
102
- * Rewind LineString - outer ring clockwise
103
- *
104
- * @private
105
- * @param {Array<Array<number>>} coords GeoJSON LineString geometry coordinates
106
- * @param {Boolean} [reverse=false] enable reverse winding
107
- * @returns {void} mutates coordinates
108
- */
109
- function rewindLineString(coords, reverse) {
110
- if (booleanClockwise(coords) === reverse) coords.reverse();
111
- }
112
-
113
- /**
114
- * Rewind Polygon - outer ring counterclockwise and inner rings clockwise.
115
- *
116
- * @private
117
- * @param {Array<Array<Array<number>>>} coords GeoJSON Polygon geometry coordinates
118
- * @param {Boolean} [reverse=false] enable reverse winding
119
- * @returns {void} mutates coordinates
120
- */
121
- function rewindPolygon(coords, reverse) {
122
- // outer ring
123
- if (booleanClockwise(coords[0]) !== reverse) {
124
- coords[0].reverse();
125
- }
126
- // inner rings
127
- for (var i = 1; i < coords.length; i++) {
128
- if (booleanClockwise(coords[i]) === reverse) {
129
- coords[i].reverse();
130
- }
131
- }
132
- }
133
-
134
- export default rewind;
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,142 +0,0 @@
1
- 'use strict';
2
-
3
- var clone = require('@turf/clone');
4
- var booleanClockwise = require('@turf/boolean-clockwise');
5
- var meta = require('@turf/meta');
6
- var invariant = require('@turf/invariant');
7
- var helpers = require('@turf/helpers');
8
-
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
-
11
- var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
12
- var booleanClockwise__default = /*#__PURE__*/_interopDefaultLegacy(booleanClockwise);
13
-
14
- /**
15
- * Rewind {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon} outer ring counterclockwise and inner rings clockwise (Uses {@link http://en.wikipedia.org/wiki/Shoelace_formula|Shoelace Formula}).
16
- *
17
- * @name rewind
18
- * @param {GeoJSON} geojson input GeoJSON Polygon
19
- * @param {Object} [options={}] Optional parameters
20
- * @param {boolean} [options.reverse=false] enable reverse winding
21
- * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
22
- * @returns {GeoJSON} rewind Polygon
23
- * @example
24
- * var polygon = turf.polygon([[[121, -29], [138, -29], [138, -18], [121, -18], [121, -29]]]);
25
- *
26
- * var rewind = turf.rewind(polygon);
27
- *
28
- * //addToMap
29
- * var addToMap = [rewind];
30
- */
31
- function rewind(geojson, options) {
32
- // Optional parameters
33
- options = options || {};
34
- if (!helpers.isObject(options)) throw new Error("options is invalid");
35
- var reverse = options.reverse || false;
36
- var mutate = options.mutate || false;
37
-
38
- // validation
39
- if (!geojson) throw new Error("<geojson> is required");
40
- if (typeof reverse !== "boolean")
41
- throw new Error("<reverse> must be a boolean");
42
- if (typeof mutate !== "boolean")
43
- throw new Error("<mutate> must be a boolean");
44
-
45
- // prevent input mutation
46
- if (mutate === false) geojson = clone__default['default'](geojson);
47
-
48
- // Support Feature Collection or Geometry Collection
49
- var results = [];
50
- switch (geojson.type) {
51
- case "GeometryCollection":
52
- meta.geomEach(geojson, function (geometry) {
53
- rewindFeature(geometry, reverse);
54
- });
55
- return geojson;
56
- case "FeatureCollection":
57
- meta.featureEach(geojson, function (feature) {
58
- meta.featureEach(rewindFeature(feature, reverse), function (result) {
59
- results.push(result);
60
- });
61
- });
62
- return helpers.featureCollection(results);
63
- }
64
- // Support Feature or Geometry Objects
65
- return rewindFeature(geojson, reverse);
66
- }
67
-
68
- /**
69
- * Rewind
70
- *
71
- * @private
72
- * @param {Geometry|Feature<any>} geojson Geometry or Feature
73
- * @param {Boolean} [reverse=false] enable reverse winding
74
- * @returns {Geometry|Feature<any>} rewind Geometry or Feature
75
- */
76
- function rewindFeature(geojson, reverse) {
77
- var type = geojson.type === "Feature" ? geojson.geometry.type : geojson.type;
78
-
79
- // Support all GeoJSON Geometry Objects
80
- switch (type) {
81
- case "GeometryCollection":
82
- meta.geomEach(geojson, function (geometry) {
83
- rewindFeature(geometry, reverse);
84
- });
85
- return geojson;
86
- case "LineString":
87
- rewindLineString(invariant.getCoords(geojson), reverse);
88
- return geojson;
89
- case "Polygon":
90
- rewindPolygon(invariant.getCoords(geojson), reverse);
91
- return geojson;
92
- case "MultiLineString":
93
- invariant.getCoords(geojson).forEach(function (lineCoords) {
94
- rewindLineString(lineCoords, reverse);
95
- });
96
- return geojson;
97
- case "MultiPolygon":
98
- invariant.getCoords(geojson).forEach(function (lineCoords) {
99
- rewindPolygon(lineCoords, reverse);
100
- });
101
- return geojson;
102
- case "Point":
103
- case "MultiPoint":
104
- return geojson;
105
- }
106
- }
107
-
108
- /**
109
- * Rewind LineString - outer ring clockwise
110
- *
111
- * @private
112
- * @param {Array<Array<number>>} coords GeoJSON LineString geometry coordinates
113
- * @param {Boolean} [reverse=false] enable reverse winding
114
- * @returns {void} mutates coordinates
115
- */
116
- function rewindLineString(coords, reverse) {
117
- if (booleanClockwise__default['default'](coords) === reverse) coords.reverse();
118
- }
119
-
120
- /**
121
- * Rewind Polygon - outer ring counterclockwise and inner rings clockwise.
122
- *
123
- * @private
124
- * @param {Array<Array<Array<number>>>} coords GeoJSON Polygon geometry coordinates
125
- * @param {Boolean} [reverse=false] enable reverse winding
126
- * @returns {void} mutates coordinates
127
- */
128
- function rewindPolygon(coords, reverse) {
129
- // outer ring
130
- if (booleanClockwise__default['default'](coords[0]) !== reverse) {
131
- coords[0].reverse();
132
- }
133
- // inner rings
134
- for (var i = 1; i < coords.length; i++) {
135
- if (booleanClockwise__default['default'](coords[i]) === reverse) {
136
- coords[i].reverse();
137
- }
138
- }
139
- }
140
-
141
- module.exports = rewind;
142
- module.exports.default = rewind;
package/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { AllGeoJSON } from "@turf/helpers";
2
-
3
- /**
4
- * http://turfjs.org/docs/#rewind
5
- */
6
- export default function rewind<T extends AllGeoJSON>(
7
- geojson: T,
8
- options?: {
9
- reverse?: boolean;
10
- mutate?: boolean;
11
- }
12
- ): T;