add SunCalc definition

This commit is contained in:
Horiuchi_H
2018-06-19 16:19:51 +09:00
parent 085e63ecf0
commit dce93542d0
4 changed files with 120 additions and 0 deletions

49
types/suncalc/index.d.ts vendored Normal file
View File

@@ -0,0 +1,49 @@
// Type definitions for suncalc 1.8
// Project: https://github.com/mourner/suncalc
// Definitions by: horiuchi <https://github.com/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;

View File

@@ -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;

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }