Skip to content

Commit 9d92123

Browse files
Merge pull request #253 from ahocevar/types
Auto-generate types
2 parents a934701 + fc32770 commit 9d92123

File tree

7 files changed

+179
-71
lines changed

7 files changed

+179
-71
lines changed

.jsdoc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"plugins": ["plugins/markdown"]
2+
"plugins": ["plugins/markdown", "jsdoc-plugin-typescript"],
3+
"typescript": {
4+
"moduleRoot": "src"
5+
}
36
}

package-lock.json

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"fs-extra": "^7.0.1",
5858
"isomorphic-fetch": "^2.2.1",
5959
"jsdoc": "^3.6.4",
60+
"jsdoc-plugin-typescript": "^2.0.6",
6061
"jshint-stylish": "^2.2.1",
6162
"mocha": "^7.1.0",
6263
"node-abort-controller": "^1.1.0",
@@ -72,11 +73,15 @@
7273
},
7374
"scripts": {
7475
"prebuild": "npm run build:clean && npm run build:module",
75-
"build": "run-p build:browser build:node",
76+
"build": "run-p build:browser build:node build:types",
7677
"build:clean": "rimraf dist-node/ dist-browser/ dist-module/",
7778
"build:node": "parcel build dist-module/geotiff.js --target node --out-dir dist-node/",
7879
"build:browser": "parcel build dist-module/geotiff.js --target browser --out-dir dist-browser/ --global GeoTIFF --public-url .",
7980
"build:module": "shx mkdir -p dist-module && shx cp -rf src/* dist-module/ && node scripts/serialize-workers.cjs",
81+
"build:types": "run-p build:types:*",
82+
"build:types:node": "npx [email protected] -y -- tsc --outdir dist-node/",
83+
"build:types:browser": "npx [email protected] -y -- tsc --outdir dist-browser/",
84+
"build:types:module": "npx [email protected] -y -- tsc --outdir dist-module/",
8085
"watch:browser": "run-p watch:module watch:browser:parcel",
8186
"watch:browser:parcel": "parcel watch dist-module/geotiff.js --target browser --out-dir dist-browser/ --global GeoTIFF --public-url .",
8287
"watch:module": "chokidar \"src/*.js\" -c \"npm run build:module\"",

src/geotiff.js

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @module geotiff */
12
import GeoTIFFImage from './geotiffimage.js';
23
import DataView64 from './dataview64.js';
34
import DataSlice from './dataslice.js';
@@ -20,6 +21,11 @@ export { rgb };
2021
export { getDecoder, addDecoder };
2122
export { setLogger };
2223

24+
/**
25+
* @typedef {Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array}
26+
* TypedArray
27+
*/
28+
2329
function getFieldTypeLength(fieldType) {
2430
switch (fieldType) {
2531
case fieldTypes.BYTE: case fieldTypes.ASCII: case fieldTypes.SBYTE: case fieldTypes.UNDEFINED:
@@ -174,26 +180,7 @@ class GeoTIFFBase {
174180
* Then, the [readRasters]{@link GeoTIFFImage#readRasters} method of the selected
175181
* image is called and the result returned.
176182
* @see GeoTIFFImage.readRasters
177-
* @param {Object} [options={}] optional parameters
178-
* @param {Array} [options.window=whole image] the subset to read data from.
179-
* @param {Array} [options.bbox=whole image] the subset to read data from in
180-
* geographical coordinates.
181-
* @param {Array} [options.samples=all samples] the selection of samples to read from.
182-
* @param {Boolean} [options.interleave=false] whether the data shall be read
183-
* in one single array or separate
184-
* arrays.
185-
* @param {Number} [options.pool=null] The optional decoder pool to use.
186-
* @param {Number} [options.width] The desired width of the output. When the width is not the
187-
* same as the images, resampling will be performed.
188-
* @param {Number} [options.height] The desired height of the output. When the width is not the
189-
* same as the images, resampling will be performed.
190-
* @param {String} [options.resampleMethod='nearest'] The desired resampling method.
191-
* @param {AbortSignal} [options.signal] An AbortSignal that may be signalled if the request is
192-
* to be aborted
193-
* @param {Number|Number[]} [options.fillValue] The value to use for parts of the image
194-
* outside of the images extent. When multiple
195-
* samples are requested, an array of fill values
196-
* can be passed.
183+
* @param {import('./geotiffimage').ReadRasterOptions} [options={}] optional parameters
197184
* @returns {Promise.<(TypedArray|TypedArray[])>} the decoded arrays as a promise
198185
*/
199186
async readRasters(options = {}) {
@@ -290,20 +277,24 @@ class GeoTIFFBase {
290277
}
291278
}
292279

280+
/**
281+
* @typedef {Object} GeoTIFFOptions
282+
* @property {boolean} [cache=false] whether or not decoded tiles shall be cached.
283+
*/
284+
293285
/**
294286
* The abstraction for a whole GeoTIFF file.
295287
* @augments GeoTIFFBase
296288
*/
297289
class GeoTIFF extends GeoTIFFBase {
298290
/**
299291
* @constructor
300-
* @param {Source} source The datasource to read from.
301-
* @param {Boolean} littleEndian Whether the image uses little endian.
302-
* @param {Boolean} bigTiff Whether the image uses bigTIFF conventions.
303-
* @param {Number} firstIFDOffset The numeric byte-offset from the start of the image
292+
* @param {*} source The datasource to read from.
293+
* @param {boolean} littleEndian Whether the image uses little endian.
294+
* @param {boolean} bigTiff Whether the image uses bigTIFF conventions.
295+
* @param {number} firstIFDOffset The numeric byte-offset from the start of the image
304296
* to the first IFD.
305-
* @param {Object} [options] further options.
306-
* @param {Boolean} [options.cache=false] whether or not decoded tiles shall be cached.
297+
* @param {GeoTIFFOptions} [options] further options.
307298
*/
308299
constructor(source, littleEndian, bigTiff, firstIFDOffset, options = {}) {
309300
super();
@@ -450,7 +441,7 @@ class GeoTIFF extends GeoTIFFBase {
450441
/**
451442
* Get the n-th internal subfile of an image. By default, the first is returned.
452443
*
453-
* @param {Number} [index=0] the index of the image to return.
444+
* @param {number} [index=0] the index of the image to return.
454445
* @returns {Promise<GeoTIFFImage>} the image at the given index
455446
*/
456447
async getImage(index = 0) {
@@ -464,7 +455,7 @@ class GeoTIFF extends GeoTIFFBase {
464455
/**
465456
* Returns the count of the internal subfiles.
466457
*
467-
* @returns {Number} the number of internal subfile images
458+
* @returns {number} the number of internal subfile images
468459
*/
469460
async getImageCount() {
470461
let index = 0;
@@ -521,8 +512,8 @@ class GeoTIFF extends GeoTIFFBase {
521512
/**
522513
* Parse a (Geo)TIFF file from the given source.
523514
*
524-
* @param {source~Source} source The source of data to parse from.
525-
* @param {object} options Additional options.
515+
* @param {*} source The source of data to parse from.
516+
* @param {GeoTIFFOptions} [options] Additional options.
526517
* @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
527518
* to be aborted
528519
*/
@@ -608,7 +599,7 @@ class MultiGeoTIFF extends GeoTIFFBase {
608599
/**
609600
* Get the n-th internal subfile of an image. By default, the first is returned.
610601
*
611-
* @param {Number} [index=0] the index of the image to return.
602+
* @param {number} [index=0] the index of the image to return.
612603
* @returns {GeoTIFFImage} the image at the given index
613604
*/
614605
async getImage(index = 0) {
@@ -638,7 +629,7 @@ class MultiGeoTIFF extends GeoTIFFBase {
638629
/**
639630
* Returns the count of the internal subfiles.
640631
*
641-
* @returns {Number} the number of internal subfile images
632+
* @returns {number} the number of internal subfile images
642633
*/
643634
async getImageCount() {
644635
if (this.imageCount !== null) {
@@ -673,7 +664,7 @@ export async function fromUrl(url, options = {}, signal) {
673664
* @param {ArrayBuffer} arrayBuffer The data to read the file from.
674665
* @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
675666
* to be aborted
676-
* @returns {Promise.<GeoTIFF>} The resulting GeoTIFF file.
667+
* @returns {Promise<GeoTIFF>} The resulting GeoTIFF file.
677668
*/
678669
export async function fromArrayBuffer(arrayBuffer, signal) {
679670
return GeoTIFF.fromSource(makeBufferSource(arrayBuffer), signal);
@@ -703,7 +694,7 @@ export async function fromFile(path, signal) {
703694
* @param {Blob|File} blob The Blob or File object to read from.
704695
* @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
705696
* to be aborted
706-
* @returns {Promise.<GeoTIFF>} The resulting GeoTIFF file.
697+
* @returns {Promise<GeoTIFF>} The resulting GeoTIFF file.
707698
*/
708699
export async function fromBlob(blob, signal) {
709700
return GeoTIFF.fromSource(makeFileReaderSource(blob), signal);
@@ -713,12 +704,12 @@ export async function fromBlob(blob, signal) {
713704
* Construct a MultiGeoTIFF from the given URLs.
714705
* @param {string} mainUrl The URL for the main file.
715706
* @param {string[]} overviewUrls An array of URLs for the overview images.
716-
* @param {object} [options] Additional options to pass to the source.
707+
* @param {Object} [options] Additional options to pass to the source.
717708
* See [makeRemoteSource]{@link module:source.makeRemoteSource}
718709
* for details.
719710
* @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
720711
* to be aborted
721-
* @returns {Promise.<MultiGeoTIFF>} The resulting MultiGeoTIFF file.
712+
* @returns {Promise<MultiGeoTIFF>} The resulting MultiGeoTIFF file.
722713
*/
723714
export async function fromUrls(mainUrl, overviewUrls = [], options = {}, signal) {
724715
const mainFile = await GeoTIFF.fromSource(makeRemoteSource(mainUrl, options), signal);

0 commit comments

Comments
 (0)