Skip to content

Commit

Permalink
added typing
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Aug 29, 2022
1 parent 2d524a9 commit 4c9e9df
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 2,550 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ dist
*.tif
*.tiff
test/data/*.json
pnpm-lock.yaml
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ npm install geotiff-palette
# usage
## downloaded GeoTIFF
```
const { readFileSync } = require('fs');
const { fromArrayBuffer } = require('geotiff');
const { getPalette } = require('geotiff-palette');
import { readFileSync } from 'fs';
import { fromArrayBuffer } from 'geotiff';
import { getPalette } from 'geotiff-palette';
const data = readFileSync('image.tif');
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function getPalette (image: any, options ?: { debug?: boolean }): Readonly<[number, number, number, number][]>;
20 changes: 9 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
const getPalette = (image, { debug = false } = { debug: false }) => {
function getPalette (image, { debug = false } = { debug: false }) {
if (debug) console.log("starting getPalette with image", image);
const { fileDirectory } = image;
const {
BitsPerSample,
ColorMap,
ImageLength,
ImageWidth,
PhotometricInterpretation,
SampleFormat,
SamplesPerPixel
} = fileDirectory;
const { BitsPerSample, ColorMap } = fileDirectory;

if (!ColorMap) {
throw new Error("[geotiff-palette]: the image does not contain a color map, so we can't make a palette.");
Expand Down Expand Up @@ -43,4 +35,10 @@ const getPalette = (image, { debug = false } = { debug: false }) => {
return result;
}

module.exports = { getPalette };
if (typeof define === "function" && define.amd) {
define(function() { return { getPalette } });
}

if (typeof module === "object") {
module.exports = { getPalette };
}
Loading

0 comments on commit 4c9e9df

Please sign in to comment.