MCPcopy Create free account
hub / github.com/PartPilotLab/PartPilot / extractPartInfoFromLCSCResponse

Function extractPartInfoFromLCSCResponse

lib/helper/lcsc_api.ts:4–51  ·  view source on GitHub ↗
(lcsc_response: any)

Source from the content-addressed store, hash-verified

2import { PartState } from "./part_state";
3
4export function extractPartInfoFromLCSCResponse(lcsc_response: any): PartState {
5 const result = lcsc_response.result;
6
7 const productLink = `https://www.lcsc.com/product-detail/${result.catalogName.replace(/\s/g, '-').replace(/-\(/g, '_').replace(/\)-/g, '_').replace(/-{2,}/g, '-').replace(/\//g, '_')}_${result.title.replace(/\s/g, '-').replace(/-\(/g, '_').replace(/\)-/g, '_').replace(/-{2,}/g, '-').replace(/\//g, '_')}_${result.productCode}.html`;
8 let paramVOList = [];
9 if(result.paramVOList) {
10 paramVOList = result.paramVOList.reduce((acc: any, curr: any) => {
11 let value = curr.paramValueEnForSearch;
12 if(curr.paramNameEn == "Tolerance"){
13 value = curr.paramValueEn
14 }
15 acc[curr.paramNameEn] = value;
16 return acc;
17 }, {});
18 }
19 console.log(paramVOList);
20
21 return {
22 id: result.productId.toString(),
23 title: result.title,
24 quantity: result.stockNumber,
25 productId: result.productId,
26 productCode: result.productCode,
27 productModel: result.productModel,
28 productDescription: result.productIntroEn,
29 parentCatalogName: result.parentCatalogName,
30 catalogName: result.catalogName,
31 brandName: result.brandNameEn,
32 encapStandard: result.encapStandard,
33 productImages: result.productImages,
34 pdfLink: result.pdfUrl,
35 productLink: productLink,
36 prices: result.productPriceList.map((price: any) => ({
37 ladder: price.ladder.toString(),
38 price: parseFloat(price.productPrice),
39 })),
40 voltage: paramVOList["Voltage Rated"] ?? undefined,
41 resistance: paramVOList["Resistance"] ?? undefined,
42 power: paramVOList["Power(Watts)"] ?? undefined,
43 current: paramVOList["Rated Current"] ?? undefined,
44 tolerance: paramVOList["Tolerance"] ?? undefined,
45 frequency: paramVOList["Frequency"] ?? undefined,
46 capacitance: paramVOList["Capacitance"] ?? undefined, //in pF (pico Farad)
47 inductance: paramVOList["Inductance"] ?? undefined, //in uH (micro Henry)
48 createdAt: new Date(),
49 updatedAt: new Date(),
50 };
51 }

Callers 2

POSTFunction · 0.90
POSTFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected