🔧 chore(scripts/utils): support common arrays on variableToBoolean(), fix omitObjectKeys() changing the provided object instead of creating a new one

This commit is contained in:
retrozinndev
2025-07-19 16:05:33 -03:00
parent a06fb5f9e7
commit 5465f09f62
+9 -7
View File
@@ -1,14 +1,14 @@
import { createPoll } from "ags/time"; import { createPoll } from "ags/time";
import { exec, execAsync } from "ags/process"; 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 GLib from "gi://GLib?version=2.0";
import Gio from "gi://Gio?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 */ /** gnim doesn't export this, so we need to do it again */
export type WidgetNodeType = Array<GObject.Object> | GObject.Object | number | string | boolean | null | undefined; export type WidgetNodeType = Array<JSX.Element> | JSX.Element | number | string | boolean | null | undefined;
export const decoder = new TextDecoder("utf-8"), export const decoder = new TextDecoder("utf-8"),
encoder = new TextEncoder(); encoder = new TextEncoder();
@@ -25,9 +25,9 @@ export function getHyprlandVersion(): string {
} }
export function omitObjectKeys<ObjT = object>(obj: ObjT, keys: keyof ObjT|Array<keyof ObjT>): ObjT { export function omitObjectKeys<ObjT = object>(obj: ObjT, keys: keyof ObjT|Array<keyof ObjT>): 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(!Array.isArray(keys)) {
if(objKey === keys) { if(objKey === keys) {
delete finalObject[keys as keyof typeof finalObject]; delete finalObject[keys as keyof typeof finalObject];
@@ -47,11 +47,13 @@ export function omitObjectKeys<ObjT = object>(obj: ObjT, keys: keyof ObjT|Array<
return finalObject; return finalObject;
} }
export function variableToBoolean(variable: any|Accessor<any>|Accessor<Array<any>>): boolean|Accessor<boolean> { export function variableToBoolean(variable: any|Array<any>|Accessor<Array<any>|any>): boolean|Accessor<boolean> {
return (variable instanceof Accessor) ? return (variable instanceof Accessor) ?
variable.as(v => Array.isArray(v) ? variable.as(v => Array.isArray(v) ?
(v as Array<any>).length > 0 (v as Array<any>).length > 0
: Boolean(v)) : Boolean(v))
: Array.isArray(variable) ?
variable.length > 0
: Boolean(variable); : Boolean(variable);
} }