From 181c48888429c67ddca968782093be1d253ef826 Mon Sep 17 00:00:00 2001 From: chouchouji <70570907+chouchouji@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:31:53 +0800 Subject: [PATCH] feat: add isNonEmptyArray (#2) * feat: add isNonEmptyArray * test: add isNonEmptyArray test case * feat: add isNonEmptyArray * test: update test cases --- src/general.ts | 4 ++++ tests/general.spec.ts | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/general.spec.ts 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) +})