-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(win32-def): update dependencies
- Loading branch information
1 parent
2fe7310
commit 9fa7a90
Showing
3 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
export type FnCallParam = string | string[] | readonly string[] | ||
export type FnCallParams = FnCallParam[] | readonly FnCallParam[] | never[] | ||
export type FnParamsExpand = string[][] | ||
|
||
export function expandFFIParamArray(input: FnCallParams): FnParamsExpand { | ||
const res: FnParamsExpand = [] | ||
const tmp: string[] = [] | ||
permute(input, 0, tmp, res) | ||
return res | ||
} | ||
|
||
function permute(input: FnCallParams, index: number, current: string[], result: FnParamsExpand): void { | ||
if (index === input.length) { | ||
result.push(current) | ||
return | ||
} | ||
|
||
const item = input[index] | ||
|
||
if (Array.isArray(item)) { | ||
const len = item.length | ||
|
||
for (let i = 0; i < len; i += 1) { | ||
const tmp = item[i] ?? [] | ||
permute(input, index + 1, current.concat(tmp), result) | ||
} | ||
} | ||
else if (typeof item === 'string') { | ||
permute(input, index + 1, current.concat([item]), result) | ||
} | ||
else { | ||
throw new TypeError('invalid input') | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters