Skip to content

Commit

Permalink
feat: add isNonEmptyArray (#2)
Browse files Browse the repository at this point in the history
* feat: add isNonEmptyArray

* test: add isNonEmptyArray test case

* feat: add isNonEmptyArray

* test: update test cases
  • Loading branch information
chouchouji authored Oct 28, 2024
1 parent 4e19ac0 commit 181c488
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@ export function getGlobalThis() {

return typeof global !== 'undefined' ? global : self
}

export function isNonEmptyArray(val: unknown): val is Array<any> {
return isArray(val) && !!val.length
}
7 changes: 7 additions & 0 deletions tests/general.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { it, expect } from 'vitest'
import { isNonEmptyArray } from '../src'

it('isNonEmptyArray', () => {
expect(isNonEmptyArray([])).toBe(false)
expect(isNonEmptyArray([1, 2])).toBe(true)
})

0 comments on commit 181c488

Please sign in to comment.