@@ -239,7 +239,7 @@ export function changeSingleVariable(
239239}
240240
241241export function changeGroupsForSingleVariable (
242- variableGroups : VariableGroup [ ] ,
242+ variableGroups : VariableGroup [ ] | VariableGroup ,
243243 variableID : string ,
244244 groups : string [ ] ,
245245) {
@@ -300,13 +300,19 @@ export function changeGroupsForMultipleVariables(
300300}
301301
302302export function renameVariableGroup (
303- duplicateVariableGroups : VariableGroup [ ] ,
303+ duplicateVariableGroups : VariableGroup [ ] | VariableGroup ,
304304 groupID : string ,
305305 newLabel : string ,
306306) {
307- const variableGroupArrayLength : number = duplicateVariableGroups . length ;
308- for ( let i = 0 ; i < variableGroupArrayLength - 1 ; i ++ ) {
309- const currentVariableGroup = duplicateVariableGroups [ i ] ;
307+ const variableGroupArrayLength : number = Array . isArray (
308+ duplicateVariableGroups ,
309+ )
310+ ? duplicateVariableGroups . length
311+ : 1 ;
312+ for ( let i = 0 ; i < variableGroupArrayLength ; i ++ ) {
313+ const currentVariableGroup = Array . isArray ( duplicateVariableGroups )
314+ ? duplicateVariableGroups [ i ]
315+ : duplicateVariableGroups ;
310316 if ( currentVariableGroup [ '@_ID' ] === groupID ) {
311317 currentVariableGroup . labl = newLabel ;
312318 break ;
@@ -316,32 +322,49 @@ export function renameVariableGroup(
316322}
317323
318324export function deleteVariableGroup (
319- duplicateVariableGroups : VariableGroup [ ] ,
325+ duplicateVariableGroups : VariableGroup [ ] | VariableGroup ,
320326 groupID : string ,
321327) {
322- const variableGroupArrayLength : number = duplicateVariableGroups . length ;
328+ const variableGroupArrayLength : number = Array . isArray (
329+ duplicateVariableGroups ,
330+ )
331+ ? duplicateVariableGroups . length
332+ : 1 ;
323333 let index = - 1 ;
324334 for ( let i = 0 ; i < variableGroupArrayLength ; i ++ ) {
325- const currentVariableGroup = duplicateVariableGroups [ i ] ;
335+ const currentVariableGroup = Array . isArray ( duplicateVariableGroups )
336+ ? duplicateVariableGroups [ i ]
337+ : duplicateVariableGroups ;
326338 if ( currentVariableGroup [ '@_ID' ] === groupID ) {
327339 index = i ;
328340 break ;
329341 }
330342 }
331343 if ( index > - 1 ) {
332- duplicateVariableGroups . splice ( index , 1 ) ;
344+ if ( Array . isArray ( duplicateVariableGroups ) ) {
345+ duplicateVariableGroups . splice ( index , 1 ) ;
346+ } else {
347+ return [ ] ;
348+ }
333349 }
334350 return duplicateVariableGroups ;
335351}
336352
337353export function removeVariablesFromGroups (
338354 groupID : string ,
339355 variableIDs : string [ ] ,
340- duplicateVariableGroups : VariableGroup [ ] ,
356+ duplicateVariableGroups : VariableGroup [ ] | VariableGroup ,
341357) {
342- const variableGroupArrayLength : number = duplicateVariableGroups . length ;
358+ // If the variable groups are not an array (when there is only one variable group), we need to make it an array
359+ const variableGroupArrayLength : number = Array . isArray (
360+ duplicateVariableGroups ,
361+ )
362+ ? duplicateVariableGroups . length
363+ : 1 ;
343364 for ( let i = 0 ; i < variableGroupArrayLength ; i ++ ) {
344- const currentVariableGroup = duplicateVariableGroups [ i ] ;
365+ const currentVariableGroup = Array . isArray ( duplicateVariableGroups )
366+ ? duplicateVariableGroups [ i ]
367+ : duplicateVariableGroups ;
345368 if ( currentVariableGroup [ '@_ID' ] === groupID ) {
346369 const variableListAsArray : string [ ] =
347370 currentVariableGroup [ '@_var' ] ?. split ( ' ' ) || [ ] ;
0 commit comments