File tree Expand file tree Collapse file tree 8 files changed +130
-0
lines changed Expand file tree Collapse file tree 8 files changed +130
-0
lines changed Original file line number Diff line number Diff line change 1+
Original file line number Diff line number Diff line change 1+
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " skyroc-type-utils" ,
3+ "type" : " module" ,
4+ "version" : " 0.0.1" ,
5+ "private" : true ,
6+ "description" : " UI Primitives Template" ,
7+ "publishConfig" : {
8+ "registry" : " https://registry.npmjs.org/" ,
9+ "main" : " ./dist/index.js" ,
10+ "module" : " ./dist/index.js"
11+ },
12+ "sideEffects" : false ,
13+ "exports" : {
14+ "." : " ./src/index.ts"
15+ },
16+ "main" : " src/index.ts" ,
17+ "module" : " src/index.ts" ,
18+ "types" : " src/index.ts" ,
19+ "files" : [" dist" ],
20+ "scripts" : {
21+ "build" : " tsdown"
22+ },
23+ "devDependencies" : {
24+ "tsdown" : " 0.12.9" ,
25+ "typescript" : " 5.8.2"
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ export type Fn = ( ...args : any [ ] ) => any ;
2+
3+ export type Noop = ( ) => void ;
4+
5+ /**
6+ * - get all the function types in an object
7+ * @example
8+ * interface Foo {
9+ * a: number;
10+ * b?: string;
11+ * c(): void;
12+ * d: (x: number) => string;
13+ * e?: () => void; // optional also can be recognized
14+ * }
15+ * type FooFnTypes = FunctionUnion<Foo>; // (() => void) | ((x:number)=>string) | (()=>void)
16+ */
17+ export type OnlyFunctions < T > = {
18+ [ K in keyof T as NonNullable < T [ K ] > extends Fn ? K : never ] : T [ K ] ;
19+ } ;
20+
21+ /**
22+ * - get all the function keys in an object
23+ * @example
24+ * interface Foo {
25+ * a: number;
26+ * b?: string;
27+ * c(): void;
28+ * d: (x: number) => string;
29+ * e?: () => void; // 可选也能识别
30+ * }
31+ * type FooFnKeys = FunctionKeys<Foo>; // 'c' | 'd' | 'e'
32+ */
33+ export type FunctionKeys < T > = {
34+ [ K in keyof T ] ?: NonNullable < T [ K ] > extends Fn ? K : never ;
35+ } [ keyof T ] ;
36+
37+ /**
38+ * - get all the function types in an object
39+ * @example
40+ * interface Foo {
41+ * a: number;
42+ * b?: string;
43+ * c(): void;
44+ * d: (x: number) => string;
45+ * e?: () => void; // 可选也能识别
46+ * }
47+ * type FooFnTypes = FunctionUnion<Foo>; // (() => void) | ((x:number)=>string) | (()=>void)
48+ */
49+ export type FunctionUnion < T > = {
50+ [ K in keyof T ] : NonNullable < T [ K ] > extends Fn ? T [ K ] : never ;
51+ } [ keyof T ] ;
Original file line number Diff line number Diff line change 1+ export * from './fn' ;
2+
3+ export * from './utils' ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @description
3+ * without changing the type’s semantics, it only prettifies the IDE display—flattening the shape so hints are easier to read.
4+ * @example
5+ * type Raw = { a: number } & { b: string };
6+ * type Pretty = Prettify<Raw>;
7+ * // => { a: number; b: string; }
8+ */
9+ export type Prettify < T > = { [ K in keyof T ] : T [ K ] } & { } ;
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "target" : " ESNext" ,
4+ "jsx" : " preserve" ,
5+ "jsxImportSource" : " vue" ,
6+ "lib" : [" DOM" , " ESNext" ],
7+ "baseUrl" : " ." ,
8+ "module" : " ESNext" ,
9+ "moduleResolution" : " bundler" ,
10+ "resolveJsonModule" : true ,
11+ "types" : [" node" ],
12+ "strict" : true ,
13+ "strictNullChecks" : true ,
14+ "noUnusedLocals" : true ,
15+ "declaration" : true ,
16+ "emitDeclarationOnly" : true ,
17+ "outDir" : " ./dist" ,
18+ "allowSyntheticDefaultImports" : true ,
19+ "esModuleInterop" : true ,
20+ "forceConsistentCasingInFileNames" : true ,
21+ "isolatedModules" : true ,
22+ "verbatimModuleSyntax" : true ,
23+ "skipLibCheck" : true
24+ },
25+ "include" : [" src/**/*" ],
26+ "exclude" : [" node_modules" , " dist" ]
27+ }
Original file line number Diff line number Diff line change 1+ import { defineConfig } from 'tsdown' ;
2+
3+ export default defineConfig ( {
4+ clean : true ,
5+ dts : true ,
6+ entry : [ 'src/index.ts' ] ,
7+ minify : false ,
8+ platform : 'neutral' ,
9+ shims : true ,
10+ sourcemap : false
11+ } ) ;
You can’t perform that action at this time.
0 commit comments