From 5465f09f627cbc5e273b27c0c2042ce089faadb6 Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Sat, 19 Jul 2025 16:05:33 -0300 Subject: [PATCH] :wrench: chore(scripts/utils): support common arrays on `variableToBoolean()`, fix `omitObjectKeys()` changing the provided object instead of creating a new one --- ags/scripts/utils.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ags/scripts/utils.ts b/ags/scripts/utils.ts index 375f6bd..32c1875 100644 --- a/ags/scripts/utils.ts +++ b/ags/scripts/utils.ts @@ -1,14 +1,14 @@ import { createPoll } from "ags/time"; import { exec, execAsync } from "ags/process"; +import { Accessor, For, With } from "ags"; +import { Astal, Gtk } from "ags/gtk4"; + import GLib from "gi://GLib?version=2.0"; import Gio from "gi://Gio?version=2.0"; -import { Accessor, For, With } from "ags"; -import GObject from "gi://GObject?version=2.0"; -import { Astal, Gtk } from "ags/gtk4"; /** gnim doesn't export this, so we need to do it again */ -export type WidgetNodeType = Array | GObject.Object | number | string | boolean | null | undefined; +export type WidgetNodeType = Array | JSX.Element | number | string | boolean | null | undefined; export const decoder = new TextDecoder("utf-8"), encoder = new TextEncoder(); @@ -25,9 +25,9 @@ export function getHyprlandVersion(): string { } export function omitObjectKeys(obj: ObjT, keys: keyof ObjT|Array): ObjT { - const finalObject = obj; + const finalObject = { ...obj }; - for(const objKey of Object.keys(obj as object)) { + for(const objKey of Object.keys(finalObject as object)) { if(!Array.isArray(keys)) { if(objKey === keys) { delete finalObject[keys as keyof typeof finalObject]; @@ -47,11 +47,13 @@ export function omitObjectKeys(obj: ObjT, keys: keyof ObjT|Array< return finalObject; } -export function variableToBoolean(variable: any|Accessor|Accessor>): boolean|Accessor { +export function variableToBoolean(variable: any|Array|Accessor|any>): boolean|Accessor { return (variable instanceof Accessor) ? variable.as(v => Array.isArray(v) ? (v as Array).length > 0 : Boolean(v)) + : Array.isArray(variable) ? + variable.length > 0 : Boolean(variable); }