@turf/clone 6.5.0 → 7.0.0-alpha.1

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
@@ -5,13 +5,13 @@
5
5
  ## clone
6
6
 
7
7
  Returns a cloned copy of the passed GeoJSON Object, including possible 'Foreign Members'.
8
- ~3-5x faster than the common JSON.parse + JSON.stringify combo method.
8
+ \~3-5x faster than the common JSON.parse + JSON.stringify combo method.
9
9
 
10
- **Parameters**
10
+ ### Parameters
11
11
 
12
- - `geojson` **[GeoJSON][1]** GeoJSON Object
12
+ * `geojson` **[GeoJSON][1]** GeoJSON Object
13
13
 
14
- **Examples**
14
+ ### Examples
15
15
 
16
16
  ```javascript
17
17
  var line = turf.lineString([[-74, 40], [-78, 42], [-82, 35]], {color: 'red'});
package/dist/es/index.js CHANGED
@@ -39,9 +39,9 @@ function clone(geojson) {
39
39
  * @returns {Feature<any>} cloned Feature
40
40
  */
41
41
  function cloneFeature(geojson) {
42
- var cloned = { type: "Feature" };
42
+ const cloned = { type: "Feature" };
43
43
  // Preserve Foreign Members
44
- Object.keys(geojson).forEach(function (key) {
44
+ Object.keys(geojson).forEach((key) => {
45
45
  switch (key) {
46
46
  case "type":
47
47
  case "properties":
@@ -53,7 +53,12 @@ function cloneFeature(geojson) {
53
53
  });
54
54
  // Add properties & geometry last
55
55
  cloned.properties = cloneProperties(geojson.properties);
56
- cloned.geometry = cloneGeometry(geojson.geometry);
56
+ if (geojson.geometry == null) {
57
+ cloned.geometry = null;
58
+ }
59
+ else {
60
+ cloned.geometry = cloneGeometry(geojson.geometry);
61
+ }
57
62
  return cloned;
58
63
  }
59
64
  /**
@@ -64,12 +69,12 @@ function cloneFeature(geojson) {
64
69
  * @returns {Object} cloned Properties
65
70
  */
66
71
  function cloneProperties(properties) {
67
- var cloned = {};
72
+ const cloned = {};
68
73
  if (!properties) {
69
74
  return cloned;
70
75
  }
71
- Object.keys(properties).forEach(function (key) {
72
- var value = properties[key];
76
+ Object.keys(properties).forEach((key) => {
77
+ const value = properties[key];
73
78
  if (typeof value === "object") {
74
79
  if (value === null) {
75
80
  // handle null
@@ -77,7 +82,7 @@ function cloneProperties(properties) {
77
82
  }
78
83
  else if (Array.isArray(value)) {
79
84
  // handle Array
80
- cloned[key] = value.map(function (item) {
85
+ cloned[key] = value.map((item) => {
81
86
  return item;
82
87
  });
83
88
  }
@@ -100,9 +105,9 @@ function cloneProperties(properties) {
100
105
  * @returns {FeatureCollection<any>} cloned Feature Collection
101
106
  */
102
107
  function cloneFeatureCollection(geojson) {
103
- var cloned = { type: "FeatureCollection" };
108
+ const cloned = { type: "FeatureCollection" };
104
109
  // Preserve Foreign Members
105
- Object.keys(geojson).forEach(function (key) {
110
+ Object.keys(geojson).forEach((key) => {
106
111
  switch (key) {
107
112
  case "type":
108
113
  case "features":
@@ -112,7 +117,7 @@ function cloneFeatureCollection(geojson) {
112
117
  }
113
118
  });
114
119
  // Add features
115
- cloned.features = geojson.features.map(function (feature) {
120
+ cloned.features = geojson.features.map((feature) => {
116
121
  return cloneFeature(feature);
117
122
  });
118
123
  return cloned;
@@ -125,12 +130,12 @@ function cloneFeatureCollection(geojson) {
125
130
  * @returns {Geometry<any>} cloned Geometry
126
131
  */
127
132
  function cloneGeometry(geometry) {
128
- var geom = { type: geometry.type };
133
+ const geom = { type: geometry.type };
129
134
  if (geometry.bbox) {
130
135
  geom.bbox = geometry.bbox;
131
136
  }
132
137
  if (geometry.type === "GeometryCollection") {
133
- geom.geometries = geometry.geometries.map(function (g) {
138
+ geom.geometries = geometry.geometries.map((g) => {
134
139
  return cloneGeometry(g);
135
140
  });
136
141
  return geom;
@@ -146,11 +151,11 @@ function cloneGeometry(geometry) {
146
151
  * @returns {Coordinates} all coordinates sliced
147
152
  */
148
153
  function deepSlice(coords) {
149
- var cloned = coords;
154
+ const cloned = coords;
150
155
  if (typeof cloned[0] !== "object") {
151
156
  return cloned.slice();
152
157
  }
153
- return cloned.map(function (coord) {
158
+ return cloned.map((coord) => {
154
159
  return deepSlice(coord);
155
160
  });
156
161
  }
@@ -11,5 +11,5 @@ import { AllGeoJSON } from "@turf/helpers";
11
11
  *
12
12
  * var lineCloned = turf.clone(line);
13
13
  */
14
- declare function clone(geojson: AllGeoJSON): any;
14
+ declare function clone<T extends AllGeoJSON>(geojson: T): T;
15
15
  export default clone;
package/dist/js/index.js CHANGED
@@ -41,9 +41,9 @@ function clone(geojson) {
41
41
  * @returns {Feature<any>} cloned Feature
42
42
  */
43
43
  function cloneFeature(geojson) {
44
- var cloned = { type: "Feature" };
44
+ const cloned = { type: "Feature" };
45
45
  // Preserve Foreign Members
46
- Object.keys(geojson).forEach(function (key) {
46
+ Object.keys(geojson).forEach((key) => {
47
47
  switch (key) {
48
48
  case "type":
49
49
  case "properties":
@@ -55,7 +55,12 @@ function cloneFeature(geojson) {
55
55
  });
56
56
  // Add properties & geometry last
57
57
  cloned.properties = cloneProperties(geojson.properties);
58
- cloned.geometry = cloneGeometry(geojson.geometry);
58
+ if (geojson.geometry == null) {
59
+ cloned.geometry = null;
60
+ }
61
+ else {
62
+ cloned.geometry = cloneGeometry(geojson.geometry);
63
+ }
59
64
  return cloned;
60
65
  }
61
66
  /**
@@ -66,12 +71,12 @@ function cloneFeature(geojson) {
66
71
  * @returns {Object} cloned Properties
67
72
  */
68
73
  function cloneProperties(properties) {
69
- var cloned = {};
74
+ const cloned = {};
70
75
  if (!properties) {
71
76
  return cloned;
72
77
  }
73
- Object.keys(properties).forEach(function (key) {
74
- var value = properties[key];
78
+ Object.keys(properties).forEach((key) => {
79
+ const value = properties[key];
75
80
  if (typeof value === "object") {
76
81
  if (value === null) {
77
82
  // handle null
@@ -79,7 +84,7 @@ function cloneProperties(properties) {
79
84
  }
80
85
  else if (Array.isArray(value)) {
81
86
  // handle Array
82
- cloned[key] = value.map(function (item) {
87
+ cloned[key] = value.map((item) => {
83
88
  return item;
84
89
  });
85
90
  }
@@ -102,9 +107,9 @@ function cloneProperties(properties) {
102
107
  * @returns {FeatureCollection<any>} cloned Feature Collection
103
108
  */
104
109
  function cloneFeatureCollection(geojson) {
105
- var cloned = { type: "FeatureCollection" };
110
+ const cloned = { type: "FeatureCollection" };
106
111
  // Preserve Foreign Members
107
- Object.keys(geojson).forEach(function (key) {
112
+ Object.keys(geojson).forEach((key) => {
108
113
  switch (key) {
109
114
  case "type":
110
115
  case "features":
@@ -114,7 +119,7 @@ function cloneFeatureCollection(geojson) {
114
119
  }
115
120
  });
116
121
  // Add features
117
- cloned.features = geojson.features.map(function (feature) {
122
+ cloned.features = geojson.features.map((feature) => {
118
123
  return cloneFeature(feature);
119
124
  });
120
125
  return cloned;
@@ -127,12 +132,12 @@ function cloneFeatureCollection(geojson) {
127
132
  * @returns {Geometry<any>} cloned Geometry
128
133
  */
129
134
  function cloneGeometry(geometry) {
130
- var geom = { type: geometry.type };
135
+ const geom = { type: geometry.type };
131
136
  if (geometry.bbox) {
132
137
  geom.bbox = geometry.bbox;
133
138
  }
134
139
  if (geometry.type === "GeometryCollection") {
135
- geom.geometries = geometry.geometries.map(function (g) {
140
+ geom.geometries = geometry.geometries.map((g) => {
136
141
  return cloneGeometry(g);
137
142
  });
138
143
  return geom;
@@ -148,11 +153,11 @@ function cloneGeometry(geometry) {
148
153
  * @returns {Coordinates} all coordinates sliced
149
154
  */
150
155
  function deepSlice(coords) {
151
- var cloned = coords;
156
+ const cloned = coords;
152
157
  if (typeof cloned[0] !== "object") {
153
158
  return cloned.slice();
154
159
  }
155
- return cloned.map(function (coord) {
160
+ return cloned.map((coord) => {
156
161
  return deepSlice(coord);
157
162
  });
158
163
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/clone",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.1",
4
4
  "description": "turf clone module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -28,6 +28,7 @@
28
28
  "exports": {
29
29
  "./package.json": "./package.json",
30
30
  ".": {
31
+ "types": "./dist/js/index.d.ts",
31
32
  "import": "./dist/es/index.js",
32
33
  "require": "./dist/js/index.js"
33
34
  }
@@ -38,27 +39,28 @@
38
39
  "dist"
39
40
  ],
40
41
  "scripts": {
41
- "bench": "ts-node bench.js",
42
+ "bench": "tsx bench.js",
42
43
  "build": "npm-run-all build:*",
43
44
  "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
44
45
  "build:js": "tsc",
45
- "docs": "node ../../scripts/generate-readmes",
46
+ "docs": "tsx ../../scripts/generate-readmes",
46
47
  "test": "npm-run-all test:*",
47
- "test:tape": "ts-node -r esm test.js",
48
- "test:types": "tsc --esModuleInterop --noEmit types.ts"
48
+ "test:tape": "tsx test.js",
49
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
49
50
  },
50
51
  "devDependencies": {
51
- "@turf/meta": "^6.5.0",
52
+ "@turf/meta": "^7.0.0-alpha.1",
52
53
  "@types/tape": "*",
53
54
  "benchmark": "*",
54
55
  "npm-run-all": "*",
55
56
  "tape": "*",
56
- "ts-node": "*",
57
57
  "tslint": "*",
58
+ "tsx": "*",
58
59
  "typescript": "*"
59
60
  },
60
61
  "dependencies": {
61
- "@turf/helpers": "^6.5.0"
62
+ "@turf/helpers": "^7.0.0-alpha.1",
63
+ "tslib": "^2.3.0"
62
64
  },
63
- "gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
65
+ "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
64
66
  }