Use ES6 modules

This commit is contained in:
Matthew Oslan
2019-05-12 01:38:27 -04:00
parent f0c32a32ba
commit 31af9d3320
4 changed files with 42 additions and 39 deletions

View File

@@ -1,8 +1,9 @@
import * as express from "express";
import { CronJob } from "cron";
const CronJob = require( "cron" ).CronJob,
server = require( "../server.js" ),
count = { temp: 0, humidity: 0 };
import * as server from "../server";
const count = { temp: 0, humidity: 0 };
let today: PWSStatus = {},
yesterday: PWSStatus = {},
@@ -15,7 +16,7 @@ function sameDay(d1: Date, d2: Date): boolean {
d1.getDate() === d2.getDate();
}
exports.captureWUStream = function( req: express.Request, res: express.Response ) {
export const captureWUStream = function( req: express.Request, res: express.Response ) {
let prev: number, curr: number;
if ( !( "dateutc" in req.query ) || !sameDay( current_date, new Date( req.query.dateutc + "Z") )) {
@@ -43,11 +44,11 @@ exports.captureWUStream = function( req: express.Request, res: express.Response
res.send( "success\n" );
};
exports.useLocalWeather = function(): boolean {
export const useLocalWeather = function(): boolean {
return server.pws !== "none" ? true : false;
};
exports.getLocalWeather = function(): LocalWeather {
export const getLocalWeather = function(): LocalWeather {
const result: LocalWeather = {};
// Use today's weather if we dont have information for yesterday yet (i.e. on startup)

View File

@@ -1,21 +1,21 @@
import * as express from "express";
import * as express from "express";
import * as http from "http";
import * as https from "https";
import * as SunCalc from "suncalc";
import * as moment from "moment-timezone";
import * as geoTZ from "geo-tz";
import * as local from "./local";
import { AdjustmentOptions, GeoCoordinates, TimeData, WateringData, WeatherData } from "../types";
const http = require( "http" ),
https = require ( "https" ),
local = require( "./local"),
SunCalc = require( "suncalc" ),
moment = require( "moment-timezone" ),
geoTZ = require( "geo-tz" ),
// Define regex filters to match against location
filters = {
gps: /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/,
pws: /^(?:pws|icao|zmw):/,
url: /^https?:\/\/([\w\.-]+)(:\d+)?(\/.*)?$/,
time: /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})([+-])(\d{2})(\d{2})/,
timezone: /^()()()()()()([+-])(\d{2})(\d{2})/
};
// Define regex filters to match against location
const filters = {
gps: /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/,
pws: /^(?:pws|icao|zmw):/,
url: /^https?:\/\/([\w\.-]+)(:\d+)?(\/.*)?$/,
time: /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})([+-])(\d{2})(\d{2})/,
timezone: /^()()()()()()([+-])(\d{2})(\d{2})/
};
/**
* Resolves a location description to geographic coordinates.
@@ -174,7 +174,8 @@ async function getOWMWeatherData( coordinates: GeoCoordinates ): Promise< Weathe
* @return A Promise that will be resolved with WateringData.
*/
async function getLocalWateringData( coordinates: GeoCoordinates ): Promise< WateringData > {
return local.getLocalWeather();
// TODO is this type assertion safe?
return local.getLocalWeather() as WateringData;
}
/**
@@ -279,7 +280,7 @@ function checkWeatherRestriction( adjustmentValue: number, weather: WateringData
return false;
}
exports.getWeatherData = async function( req: express.Request, res: express.Response ) {
export const getWeatherData = async function( req: express.Request, res: express.Response ) {
const location: string = getParameter(req.query.loc);
if ( !location ) {
@@ -309,7 +310,7 @@ exports.getWeatherData = async function( req: express.Request, res: express.Resp
// API Handler when using the weatherX.py where X represents the
// adjustment method which is encoded to also carry the watering
// restriction and therefore must be decoded
exports.getWateringData = async function( req: express.Request, res: express.Response ) {
export const getWateringData = async function( req: express.Request, res: express.Response ) {
// The adjustment method is encoded by the OpenSprinkler firmware and must be
// parsed. This allows the adjustment method and the restriction type to both