mourner / suncalc

A tiny JavaScript library for calculating sun/moon positions and phases.
BSD 2-Clause "Simplified" License
3.07k stars 412 forks source link

Would you be willing to contribute a TypeScript Definition for Suncalc? #73

Open akessner opened 8 years ago

akessner commented 8 years ago

Hi, I've made a suncalc TypeScript definition based on your latest version. I was wondering if you would like to add it to the official Typings repository? https://github.com/typings/registry

Details on the process: https://github.com/typings/typings/issues/322

dislick commented 7 years ago

I like this proposal, because I was missing typings for this repository and had to write them myself. Please consider this, @mourner.

sebastianovide commented 7 years ago

Hi @akessner. Do you still have that TypeScript definition ? Thanks

dislick commented 7 years ago

Not @akessner, but this may be helpful for you. It is not complete though.


/// <reference path="../node/node.d.ts" />

interface SunlightTimes {
  sunrise: Date;
  sunriseEnd: Date;
  goldenHourEnd: Date;
  solarNoon: Date;
  goldenHour: Date;
  sunsetStart: Date;
  sunset: Date;
  dusk: Date;
  nauticalDusk: Date;
  night: Date;
  nadir: Date;
  nightEnd: Date;
  nauticalDawn: Date;
  dawn: Date;
}

interface SunPosition {
  altitude: number;
  azimuth: number;
}

interface MoonPosition {
  altitude: number;
  azimuth: number;
  distance: number;
  parallacticAngle: number;
}

interface MoonIllumination {
  fraction: number;
  phase: number;
  angle: number;
}

interface MoonTimes {
  rise: Date;
  set: Date;
  alwaysUp: boolean;
  alwaysDown: boolean;
}

declare module 'suncalc' {
  function getTimes(date: Date, latitude: number, longitude: number): SunlightTimes;
  function getPosition(timeAndDate: Date, latitude: number, longitude: number): SunPosition;
  function getMoonPosition(timeAndDate: Date, latitude: number, longitude: number): MoonPosition;
  function getMoonIllumination(timeAndDate: Date): MoonIllumination;
  function getMoonTimes(date: Date, latitude: number, longitude: number, inUTC?: boolean): MoonTimes;
}
BigglesZX commented 2 years ago

Looks like some kind soul has published these: https://www.npmjs.com/package/@types/suncalc

However, it looks like it might not be up-to-date with the most recent API, e.g. it seems to be missing the recently-added altitude argument to getTimes (https://github.com/mourner/suncalc/issues/104).