UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

69 lines 2.58 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isBetween = exports.isTypeOf = exports.isInstance = exports.isDefined = exports.isAsyncModuleOptions = exports.TransformBoolean = exports.deepPartialCompare = exports.wipeTimeout = exports.sleep = void 0; const assert_1 = __importDefault(require("assert")); const class_transformer_1 = require("class-transformer"); const sleep = async (ms) => { return await new Promise((resolve) => setTimeout(() => resolve(), ms)); }; exports.sleep = sleep; const wipeTimeout = (timeout) => { if (timeout !== undefined) { clearTimeout(timeout); timeout = undefined; } }; exports.wipeTimeout = wipeTimeout; const deepPartialCompare = (a, b) => { for (const key in a) { // eslint-disable-next-line no-prototype-builtins if (a.hasOwnProperty(key)) { if (typeof a[key] === 'object' && a[key] !== undefined) { // Recursively compare nested objects if (!(0, exports.deepPartialCompare)(a[key], b[key])) { return false; } } else if (a[key] !== b[key]) { // Compare non-object properties return false; } } } return true; }; exports.deepPartialCompare = deepPartialCompare; exports.TransformBoolean = (0, class_transformer_1.Transform)(({ value }) => value === undefined || value === null ? undefined : ['1', 1, 'true', true, 'on'].includes(value), { toClassOnly: true }); const isAsyncModuleOptions = (options) => options !== undefined && ('useFactory' in options || 'useValue' in options || 'useClass' in options || 'useExisting' in options || 'imports' in options); exports.isAsyncModuleOptions = isAsyncModuleOptions; const isDefined = (value) => { (0, assert_1.default)(value !== undefined); (0, assert_1.default)(value !== null); }; exports.isDefined = isDefined; function isInstance(value, type) { return value instanceof type; } exports.isInstance = isInstance; function isTypeOf(value, typeString) { return typeof value === typeString; } exports.isTypeOf = isTypeOf; function isBetween(value, minimum, maximum) { if (isTypeOf(value, 'number')) { return value >= minimum && value <= maximum; } return false; } exports.isBetween = isBetween; //# sourceMappingURL=utils.js.map