Skip to content

Commit 05fd55d

Browse files
authored
Merge pull request #100 from mapbox/readme_cleanup
Readme cleanup, final API state
2 parents 4146e58 + e5b928e commit 05fd55d

File tree

12 files changed

+90
-61
lines changed

12 files changed

+90
-61
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
shpwrite.js
2+
node_modules
3+
example/*.dbf
4+
example/*.shp
5+
example/*.shx
6+
yarn.lock

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
6+
7+
<a name="0.4.0"></a>
8+
## [0.4.0](https://github.com/mapbox/shp-write/compare/v0.3.2...v0.4.0) (2023-08-20)
9+
10+
* Upgrade JSZip and dbf dependencies
11+
* Added types
12+
* Added options for compression and type output to `zip` and `download`
13+
* Added deprecation warning to `download` (not needed for this library)
14+
*
15+
516
<a name="0.3.2"></a>
617
## [0.3.2](https://github.com/mapbox/shp-write/compare/v0.3.1...v0.3.2) (2016-12-06)
718

README.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,56 @@ Or in a browser
2929
```js
3030
var shpwrite = require("shp-write");
3131

32-
// (minimal) set names for feature types and zipped folder
33-
var options = {
34-
folder: "myshapes",
35-
filename: "mydownload",
36-
outputType: "base64",
32+
// a GeoJSON bridge for features
33+
const zipData = shpwrite.zip(
34+
{
35+
type: "FeatureCollection",
36+
features: [
37+
{
38+
type: "Feature",
39+
geometry: {
40+
type: "Point",
41+
coordinates: [0, 0],
42+
},
43+
properties: {
44+
name: "Foo",
45+
},
46+
},
47+
{
48+
type: "Feature",
49+
geometry: {
50+
type: "Point",
51+
coordinates: [0, 10],
52+
},
53+
properties: {
54+
name: "Bar",
55+
},
56+
},
57+
],
58+
}
59+
);
60+
61+
```
62+
63+
## Options Example
64+
65+
```js
66+
var shpwrite = require("shp-write");
67+
68+
const options = {
69+
folder: "my_internal_shapes_folder",
70+
filename: "my_zip_filename",
71+
outputType: "blob",
3772
compression: "DEFLATE",
3873
types: {
3974
point: "mypoints",
4075
polygon: "mypolygons",
4176
line: "mylines",
4277
},
4378
};
79+
4480
// a GeoJSON bridge for features
45-
shpwrite.download(
81+
const zipData = shpwrite.zip(
4682
{
4783
type: "FeatureCollection",
4884
features: [
@@ -70,7 +106,6 @@ shpwrite.download(
70106
},
71107
options
72108
);
73-
// triggers a download of a zip file with shapefiles contained within.
74109
```
75110

76111
## API

dist/index.d.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ declare module "shp-write" {
1919
export interface DownloadOptions {
2020
folder?: string;
2121
filename?: string;
22-
types: {
22+
types?: {
2323
point?: string;
2424
polygon?: string;
2525
line?: string;
@@ -48,19 +48,9 @@ declare module "shp-write" {
4848
outputType: OutputType
4949
}
5050

51-
DEFAULT_ZIP_OPTIONS = {
52-
compression: 'STORE',
53-
outputType: 'base64',
54-
types: {
55-
point: "mypoints",
56-
polygon: "mypolygons",
57-
line: "mylines",
58-
},
59-
};
60-
6151
export function download(
6252
geojson: GeoJSON.FeatureCollection,
63-
options?: DownloadOptions & ZipOptions = DEFAULT_ZIP_OPTIONS
53+
options?: DownloadOptions & ZipOptions = {}
6454
): void;
6555

6656
export function write(
@@ -79,6 +69,6 @@ declare module "shp-write" {
7969

8070
export function zip<T extends OutputType>(
8171
geojson: GeoJSON.FeatureCollection,
82-
options: DownloadOptions & ZipOptions = DEFAULT_ZIP_OPTIONS,
72+
options: DownloadOptions & ZipOptions = {},
8373
stream = false): Promise<OutputByType[T]>;
8474
}

example/point.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function finish(err, files) {
2626
}
2727

2828
function toBuffer(ab) {
29-
var buffer = new Buffer(ab.byteLength),
29+
var buffer = Buffer.alloc(ab.byteLength),
3030
view = new Uint8Array(ab);
3131
for (var i = 0; i < buffer.length; ++i) { buffer[i] = view[i]; }
3232
return buffer;

example/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function finish(err, files) {
2727
}
2828

2929
function toBuffer(ab) {
30-
var buffer = new Buffer(ab.byteLength),
30+
var buffer = Buffer.alloc(ab.byteLength),
3131
view = new Uint8Array(ab);
3232
for (var i = 0; i < buffer.length; ++i) { buffer[i] = view[i]; }
3333
return buffer;

example/test_linestring.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function finish(err, files) {
2424
}
2525

2626
function toBuffer(ab) {
27-
var buffer = new Buffer(ab.byteLength),
27+
var buffer = Buffer.alloc(ab.byteLength),
2828
view = new Uint8Array(ab);
2929
for (var i = 0; i < buffer.length; ++i) { buffer[i] = view[i]; }
3030
return buffer;

example/test_multiple_poly.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function finish(err, files) {
2222
}
2323

2424
function toBuffer(ab) {
25-
var buffer = new Buffer(ab.byteLength),
25+
var buffer = Buffer.alloc(ab.byteLength),
2626
view = new Uint8Array(ab);
2727
for (var i = 0; i < buffer.length; ++i) { buffer[i] = view[i]; }
2828
return buffer;

example/test_polygon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function finish(err, files) {
2525
}
2626

2727
function toBuffer(ab) {
28-
var buffer = new Buffer(ab.byteLength),
28+
var buffer = Buffer.alloc(ab.byteLength),
2929
view = new Uint8Array(ab);
3030
for (var i = 0; i < buffer.length; ++i) { buffer[i] = view[i]; }
3131
return buffer;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "shp-write",
3-
"version": "0.3.2",
3+
"version": "0.4.0",
44
"description": "write shapefiles from pure javascript",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)