@mirta/basics 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +9 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ declare const isNumber: (value: unknown) => value is number;
|
|
|
28
28
|
declare const isBoolean: (value: unknown) => value is boolean;
|
|
29
29
|
declare const isFunction: (value: unknown) => value is ((...args: unknown[]) => unknown);
|
|
30
30
|
|
|
31
|
+
declare const mqttToBoolean: (value: WbRules.MqttValue) => boolean;
|
|
32
|
+
|
|
31
33
|
type EventHandler = (...args: unknown[]) => void;
|
|
32
34
|
type OnEvent<THandler extends EventHandler> = (handler: THandler) => {
|
|
33
35
|
off: () => void;
|
|
@@ -113,5 +115,5 @@ interface EventRaiser<THandler extends EventHandler> extends Event<THandler> {
|
|
|
113
115
|
*/
|
|
114
116
|
declare function useEvent<THandler extends EventHandler>(): EventRaiser<THandler>;
|
|
115
117
|
|
|
116
|
-
export { debounce, isBoolean, isFunction, isNumber, isString, throttle, useEvent };
|
|
118
|
+
export { debounce, isBoolean, isFunction, isNumber, isString, mqttToBoolean, throttle, useEvent };
|
|
117
119
|
export type { Event, EventHandler, EventRaiser, OnEvent, OnceEvent };
|
package/dist/index.mjs
CHANGED
|
@@ -99,6 +99,14 @@ const isNumber = (value) => typeof value === 'number';
|
|
|
99
99
|
const isBoolean = (value) => typeof value === 'boolean';
|
|
100
100
|
const isFunction = (value) => typeof value === 'function';
|
|
101
101
|
|
|
102
|
+
const mqttToBoolean = (value) => {
|
|
103
|
+
if (isString(value))
|
|
104
|
+
return !['', '0', 'off', 'false'].includes(value);
|
|
105
|
+
if (isNumber(value))
|
|
106
|
+
return value !== 0;
|
|
107
|
+
return value;
|
|
108
|
+
};
|
|
109
|
+
|
|
102
110
|
/**
|
|
103
111
|
* Построитель экземпляра события.
|
|
104
112
|
* @example
|
|
@@ -164,4 +172,4 @@ function useEvent() {
|
|
|
164
172
|
};
|
|
165
173
|
}
|
|
166
174
|
|
|
167
|
-
export { debounce, isBoolean, isFunction, isNumber, isString, throttle, useEvent };
|
|
175
|
+
export { debounce, isBoolean, isFunction, isNumber, isString, mqttToBoolean, throttle, useEvent };
|