@@ -131,23 +131,52 @@ export function paths(o: Record<string, any>, path?: string): string[] {
131131}
132132
133133export function updateRecordValue < T > (
134- obj : Record < string , T > | undefined ,
134+ o : Record < string , T > | undefined ,
135135 key : string ,
136136 value : T | undefined ,
137137) : Record < string , T > {
138- if ( obj == null ) {
139- obj = Object . create ( null ) as Record < string , T > ;
138+ if ( o == null ) {
139+ o = Object . create ( null ) as Record < string , T > ;
140140 }
141141
142142 if ( value != null && ( typeof value !== 'boolean' || value ) ) {
143143 if ( typeof value === 'object' ) {
144- obj [ key ] = { ...value } ;
144+ o [ key ] = { ...value } ;
145145 } else {
146- obj [ key ] = value ;
146+ o [ key ] = value ;
147147 }
148148 } else {
149- const { [ key ] : _ , ...rest } = obj ;
150- obj = rest ;
149+ const { [ key ] : _ , ...rest } = o ;
150+ o = rest ;
151151 }
152- return obj ;
152+ return o ;
153+ }
154+
155+ /**
156+ * Efficiently checks if an object has at least one own enumerable property
157+ * @param o - The object to check
158+ * @returns true if the object has at least one own enumerable property, false otherwise
159+ */
160+ export function hasKeys ( o : Record < string , any > | null | undefined ) : boolean {
161+ for ( const k in o ) {
162+ if ( Object . hasOwn ( o , k ) ) return true ;
163+ }
164+ return false ;
165+ }
166+
167+ /**
168+ * Efficiently checks if an object has at least the specified number of truthy values (or at least one if not specified)
169+ * @param o - The object to check (typically a Record<string, boolean>)
170+ * @param required - The minimum number of truthy values required (default: 1)
171+ * @returns true if the object has at least the required number of properties with truthy values
172+ */
173+ export function hasTruthyKeys ( o : Record < string , any > | null | undefined , required : number = 1 ) : boolean {
174+ let count = 0 ;
175+ for ( const k in o ) {
176+ if ( Object . hasOwn ( o , k ) && o [ k ] ) {
177+ count ++ ;
178+ if ( count >= required ) return true ; // Early exit once we know we have enough
179+ }
180+ }
181+ return count >= required ;
153182}
0 commit comments