diff --git a/types/suncalc/index.d.ts b/types/suncalc/index.d.ts new file mode 100644 index 0000000000..5c9b0bf67e --- /dev/null +++ b/types/suncalc/index.d.ts @@ -0,0 +1,49 @@ +// Type definitions for suncalc 1.8 +// Project: https://github.com/mourner/suncalc +// Definitions by: horiuchi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface GetTimesResult { + dawn: Date; + dusk: Date; + goldenHour: Date; + goldenHourEnd: Date; + nadir: Date; + nauticalDawn: Date; + nauticalDusk: Date; + night: Date; + nightEnd: Date; + solarNoon: Date; + sunrise: Date; + sunriseEnd: Date; + sunset: Date; + sunsetStart: Date; +} +export interface GetSunPositionResult { + altitude: number; + azimuth: number; +} +export interface GetMoonPositionResult { + altitude: number; + azimuth: number; + distance: number; + parallacticAngle: number; +} +export interface GetMoonIlluminationResult { + fraction: number; + phase: number; + angle: number; +} +export interface GetMoonTimes { + rise: Date; + set: Date; + alwaysUp: boolean; + alwaysDown: boolean; +} + +export function getTimes(date: Date, latitude: number, longitude: number): GetTimesResult; +export function addTime(angleInDegrees: number, morningName: string, eveningName: string): void; +export function getPosition(timeAndDate: Date, latitude: number, longitude: number): GetSunPositionResult; +export function getMoonPosition(timeAndDate: Date, latitude: number, longitude: number): GetMoonPositionResult; +export function getMoonIllumination(timeAndDate: Date): GetMoonIlluminationResult; +export function getMoonTimes(date: Date, latitude: number, longitude: number, inUTC?: boolean): GetMoonTimes; diff --git a/types/suncalc/suncalc-tests.ts b/types/suncalc/suncalc-tests.ts new file mode 100644 index 0000000000..0bc8772d04 --- /dev/null +++ b/types/suncalc/suncalc-tests.ts @@ -0,0 +1,48 @@ +import * as SunCalc from 'suncalc'; + +let d: Date; +let x: number; +let b: boolean; + +const date = new Date(); +const latitude = 0.0; +const longitude = 0.0; + +const times = SunCalc.getTimes(date, latitude, longitude); +d = times.dawn; +d = times.dusk; +d = times.goldenHour; +d = times.goldenHourEnd; +d = times.nadir; +d = times.nauticalDawn; +d = times.nauticalDusk; +d = times.night; +d = times.nightEnd; +d = times.solarNoon; +d = times.sunrise; +d = times.sunriseEnd; +d = times.sunset; +d = times.sunsetStart; + +SunCalc.addTime(0.0, 'customTime', 'customTimeEnd'); + +const pos = SunCalc.getPosition(date, latitude, longitude); +x = pos.altitude; +x = pos.azimuth; + +const mp = SunCalc.getMoonPosition(date, latitude, longitude); +x = mp.altitude; +x = mp.azimuth; +x = mp.distance; +x = mp.parallacticAngle; + +const mi = SunCalc.getMoonIllumination(date); +x = mi.fraction; +x = mi.phase; +x = mi.angle; + +const mt = SunCalc.getMoonTimes(date, latitude, longitude, true); +d = mt.rise; +d = mt.set; +b = mt.alwaysUp; +b = mt.alwaysDown; diff --git a/types/suncalc/tsconfig.json b/types/suncalc/tsconfig.json new file mode 100644 index 0000000000..ce875cd1d7 --- /dev/null +++ b/types/suncalc/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "suncalc-tests.ts" + ] +} diff --git a/types/suncalc/tslint.json b/types/suncalc/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/suncalc/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }