diff --git a/src/general.ts b/src/general.ts index a67498f..ec89163 100644 --- a/src/general.ts +++ b/src/general.ts @@ -118,3 +118,7 @@ export function getGlobalThis() { return typeof global !== 'undefined' ? global : self } + +export function isNonEmptyArray(val: unknown): val is Array { + return isArray(val) && !!val.length +} diff --git a/tests/general.spec.ts b/tests/general.spec.ts new file mode 100644 index 0000000..1618159 --- /dev/null +++ b/tests/general.spec.ts @@ -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) +})