Skip to content

Commit 240ad8e

Browse files
committed
feat: util/func isTruthy
1 parent ae31cb5 commit 240ad8e

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/rollup/gen-pkg.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { InputOption } from "rollup";
22
import { deepTrimStartDir, joinPath, trimStartDir } from "../util/path";
33
import { posix as pp } from "path";
4+
import { isTruthy } from "../util/func";
45

56
export interface GetEntryPointsFormatOptions {
67
baseDir?: string;
@@ -191,7 +192,7 @@ function flatIndexEntryPoints<T>(ep: Record<string, T>): [string, T][] {
191192
e.endsWith("/index") ? [`./${e.slice(0, e.length - 6)}`, file] : null,
192193
];
193194

194-
return entries.filter(<T>(v: T): v is NonNullable<T> => !!v);
195+
return entries.filter(isTruthy);
195196
})
196197
.flat(1);
197198
}

src/rollup/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function rollupOptions({
5959
bundleOptions && rollupBundle(bundleOptions),
6060
nodeOptions && rollupNode(nodeOptions),
6161
dtsOptions && rollupDts(dtsOptions),
62-
].filter((v): v is Promise<RollupOptions> => !!v);
62+
].filter(isTruthy);
6363

6464
return Promise.all(options);
6565
}

src/util/func.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type FalsyValueExceptNaN = false | 0 | 0n | "" | null | undefined;
2+
3+
export const isTruthy = Boolean as unknown as <T>(
4+
v: T,
5+
) => v is Exclude<T, FalsyValueExceptNaN>;

0 commit comments

Comments
 (0)