Convert backend code to ES modules

Bundling code now with Rollup for its flat bundling and tree shaking
support. Front end code still goes through Webpack for browser support.
This commit is contained in:
Zaid Abdulla committed 2019-02-04 23:47:54 -08:00
1 parent 824639976f
commit 1e41c72d60
62 files changed
+718 -898

No files matched your search

+6 -11
View File
@@ -18,9 +18,9 @@
*/
"use strict";
const crypto = require("crypto");
import crypto from "crypto";
const later = require("later");
import later from "later";
function md532(str) {
const digest = crypto
@@ -35,22 +35,22 @@ function md532(str) {
);
}
function variance(deviceId, vrnc) {
export function variance(deviceId, vrnc) {
return (md532(deviceId) >>> 0) % vrnc;
}
function interval(timestamp, intrvl, offset = 0) {
export function interval(timestamp, intrvl, offset = 0) {
return Math.trunc((timestamp + offset) / intrvl) * intrvl - offset;
}
function parseCron(cronExp) {
export function parseCron(cronExp) {
const parts = cronExp.trim().split(/\s+/);
if (parts.length === 5) parts.unshift("*");
return later.schedule(later.parse.cron(parts.join(" "), true));
}
function cron(timestamp, schedule, offset = 0) {
export function cron(timestamp, schedule, offset = 0) {
// TODO later.js doesn't throw erorr if expression is invalid!
const ret = [0, 0];
@@ -62,8 +62,3 @@ function cron(timestamp, schedule, offset = 0) {
return ret;
}
exports.variance = variance;
exports.interval = interval;
exports.parseCron = parseCron;
exports.cron = cron;