File tree Expand file tree Collapse file tree 4 files changed +86
-46
lines changed
Expand file tree Collapse file tree 4 files changed +86
-46
lines changed Original file line number Diff line number Diff line change 1212 "dependencies" : {
1313 "@ant-design/icons" : " ^5.6.1" ,
1414 "@ctrl/tinycolor" : " ^4.1.0" ,
15+ "@types/lodash" : " ^4.17.16" ,
1516 "antd" : " ^5.24.4" ,
1617 "axios" : " ^1.8.3" ,
18+ "lodash" : " ^4.17.21" ,
1719 "react" : " ^19.0.0" ,
1820 "react-dom" : " ^19.0.0" ,
1921 "semver" : " ^7.7.1"
Original file line number Diff line number Diff line change 1313 -moz-osx-font-smoothing : grayscale;
1414}
1515
16- a {
17- font-weight : 500 ;
18- color : # 646cff ;
19- text-decoration : inherit;
20- }
21- a : hover {
22- color : # 535bf2 ;
23- }
24-
2516body {
2617 margin : 0 ;
2718 display : flex;
2819 place-items : center;
2920 min-width : 320px ;
3021 min-height : 100vh ;
3122}
32-
33- h1 {
34- font-size : 3.2em ;
35- line-height : 1.1 ;
36- }
37-
38- button {
39- border-radius : 8px ;
40- border : 1px solid transparent;
41- padding : 0.6em 1.2em ;
42- font-size : 1em ;
43- font-weight : 500 ;
44- font-family : inherit;
45- background-color : # 1a1a1a ;
46- cursor : pointer;
47- transition : border-color 0.25s ;
48- }
49- button : hover {
50- border-color : # 646cff ;
51- }
52- button : focus ,
53- button : focus-visible {
54- outline : 4px auto -webkit-focus-ring-color;
55- }
56-
57- @media (prefers-color-scheme : light) {
58- : root {
59- color : # 213547 ;
60- background-color : # ffffff ;
61- }
62- a : hover {
63- color : # 747bff ;
64- }
65- button {
66- background-color : # f9f9f9 ;
67- }
68- }
Original file line number Diff line number Diff line change 1+ import axios from "axios" ;
2+
3+ export interface NpmPackageSuggestion {
4+ name : string ;
5+ version : string ;
6+ description : string ;
7+ score : {
8+ final : number ;
9+ detail : {
10+ quality : number ;
11+ popularity : number ;
12+ maintenance : number ;
13+ } ;
14+ } ;
15+ }
16+
17+ interface NpmsApiResponse {
18+ package : {
19+ name : string ;
20+ version : string ;
21+ description : string ;
22+ links : {
23+ npm : string ;
24+ homepage ?: string ;
25+ repository ?: string ;
26+ } ;
27+ } ;
28+ score : {
29+ final : number ;
30+ detail : {
31+ quality : number ;
32+ popularity : number ;
33+ maintenance : number ;
34+ } ;
35+ } ;
36+ searchScore : number ;
37+ }
38+
39+ /**
40+ * Fetches package suggestions from npms.io API
41+ * @param query Search query string
42+ * @param size Number of suggestions to return (default: 10)
43+ * @returns Array of package suggestions
44+ */
45+ export const fetchPackageSuggestions = async (
46+ query : string ,
47+ size : number = 10
48+ ) : Promise < NpmPackageSuggestion [ ] > => {
49+ if ( ! query . trim ( ) ) {
50+ return [ ] ;
51+ }
52+
53+ try {
54+ const response = await axios . get < NpmsApiResponse [ ] > (
55+ `https://api.npms.io/v2/search/suggestions` ,
56+ {
57+ params : { q : query , size } ,
58+ }
59+ ) ;
60+
61+ // Transform the response to our desired format
62+ return response . data . map ( ( item : NpmsApiResponse ) => ( {
63+ name : item . package . name ,
64+ version : item . package . version ,
65+ description : item . package . description ,
66+ score : item . score ,
67+ } ) ) ;
68+ } catch ( error ) {
69+ console . error ( "Error fetching package suggestions:" , error ) ;
70+ return [ ] ;
71+ }
72+ } ;
You can’t perform that action at this time.
0 commit comments