Update ESLint and Prettier
This commit is contained in:
1 parent
5a9e03db2c
commit
ac980116bd
110 files changed
+2993
-2794
No files matched your search
+15
-10
@@ -21,10 +21,7 @@ import * as crypto from "crypto";
|
||||
import * as later from "later";
|
||||
|
||||
function md532(str): number {
|
||||
const digest = crypto
|
||||
.createHash("md5")
|
||||
.update(str)
|
||||
.digest();
|
||||
const digest = crypto.createHash("md5").update(str).digest();
|
||||
return (
|
||||
digest.readUInt32LE(0) ^
|
||||
digest.readUInt32LE(4) ^
|
||||
@@ -33,29 +30,37 @@ function md532(str): number {
|
||||
);
|
||||
}
|
||||
|
||||
export function variance(deviceId, vrnc): number {
|
||||
export function variance(deviceId: string, vrnc: number): number {
|
||||
return (md532(deviceId) >>> 0) % vrnc;
|
||||
}
|
||||
|
||||
export function interval(timestamp, intrvl, offset = 0): number {
|
||||
export function interval(
|
||||
timestamp: number,
|
||||
intrvl: number,
|
||||
offset = 0
|
||||
): number {
|
||||
return Math.trunc((timestamp + offset) / intrvl) * intrvl - offset;
|
||||
}
|
||||
|
||||
export function parseCron(cronExp): any {
|
||||
export function parseCron(cronExp: string): any {
|
||||
const parts = cronExp.trim().split(/\s+/);
|
||||
if (parts.length === 5) parts.unshift("*");
|
||||
|
||||
return later.schedule(later.parse.cron(parts.join(" "), true));
|
||||
}
|
||||
|
||||
export function cron(timestamp, schedule, offset = 0): number[] {
|
||||
export function cron(
|
||||
timestamp: number,
|
||||
schedule: unknown,
|
||||
offset = 0
|
||||
): number[] {
|
||||
// TODO later.js doesn't throw erorr if expression is invalid!
|
||||
const ret = [0, 0];
|
||||
|
||||
const prev = schedule.prev(1, new Date(timestamp + offset));
|
||||
const prev = (schedule as any).prev(1, new Date(timestamp + offset));
|
||||
if (prev) ret[0] = prev.setMilliseconds(0) - offset;
|
||||
|
||||
const next = schedule.next(1, new Date(timestamp + offset + 1000));
|
||||
const next = (schedule as any).next(1, new Date(timestamp + offset + 1000));
|
||||
if (next) ret[1] = next.setMilliseconds(0) - offset;
|
||||
|
||||
return ret;
|
||||
|
||||
Reference in new issue
Block a user