Skip to content

Commit

Permalink
feat: let tree opts be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Apr 6, 2024
1 parent 048db11 commit 7e25163
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webpod/ps",
"version": "0.0.0-beta.2",
"version": "0.0.0-beta.3",
"description": "A process lookup utility",
"publishConfig": {
"access": "public"
Expand Down
7 changes: 5 additions & 2 deletions src/main/ts/ps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,17 @@ export const pickTree = (list: TPsLookupEntry[], pid: string | number, recursive
]
}

export const tree = async (opts: string | number | TPsTreeOpts, cb: TPsLookupCallback = noop): Promise<TPsLookupEntry[]> => {
export const tree = async (opts?: string | number | TPsTreeOpts | undefined, cb: TPsLookupCallback = noop): Promise<TPsLookupEntry[]> => {
if (typeof opts === 'string' || typeof opts === 'number') {
return tree({ pid: opts }, cb)
}

try {
const all = await lookup()
if (opts === undefined) return all

const {pid, recursive = false} = opts
const list = pickTree(await lookup(), pid, recursive)
const list = pickTree(all, pid, recursive)

cb(null, list)
return list
Expand Down
5 changes: 5 additions & 0 deletions src/test/ts/ps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ describe('tree()', () => {

assert.equal((await lookup({ arguments: marker })).length, 0)
})

it('returns all ps list if no opts provided', async () => {
const list = await tree()
assert.ok(list.length > 0)
})
})

0 comments on commit 7e25163

Please sign in to comment.