From b4b84d8d6b46d31fd81e19cbdae44b242cc55122 Mon Sep 17 00:00:00 2001 From: Basile Bruneau Date: Wed, 6 May 2020 23:05:24 +0200 Subject: [PATCH] chore: add type definition --- index.d.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ index.js | 3 +-- package.json | 5 +++-- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..21e7ae6 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,43 @@ +namespace DottedMapLib { + interface Settings { + height?: number; + width?: number; + countries?: string[]; + region?: { lat: { min: number; max: number }; lng: { min: number; max: number } }; + grid?: 'vertical' | 'diagonal'; + } + + interface SvgOptions { + color?: string; + radius?: number; + } + + interface Pin { + lat: number; + lng: number; + data?: any; + svgOptions?: SvgOptions; + } + + interface SvgSettings { + shape?: 'circle' | 'hexagon'; + color?: string; + backgroundColor?: string; + radius?: number; + } + + type Point = { + x: number; + y: number; + data?: any; + svgOptions?: SvgOptions; + }; +} + +export default class DottedMap { + constructor(settings: DottedMapLib.Settings); + + addPin(pin: DottedMapLib.Pin): void; + getPoints(): DottedMapLib.Point[]; + getSVG(settings: DottedMapLib.SvgSettings): string; +} diff --git a/index.js b/index.js index ea5734e..4c81ded 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,7 @@ -const fs = require('fs'); const proj4 = require('proj4'); const inside = require('point-in-geopolygon'); +const geojsonWorld = require('./countries.geo.json'); -const geojsonWorld = JSON.parse(fs.readFileSync(__dirname + '/countries.geo.json', { encoding: 'utf8' })); const geojsonByCountry = geojsonWorld.features.reduce((countries, feature) => { countries[feature.id] = feature; return countries; diff --git a/package.json b/package.json index 07f8364..4b6ff36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dotted-map", - "version": "1.0.0", + "version": "1.0.4", "description": "", "main": "index.js", "scripts": { @@ -15,5 +15,6 @@ }, "devDependencies": { "prettier": "^2.0.5" - } + }, + "sideEffects": false }