Filter parts using array methods instead of separate function

This commit is contained in:
Nick Playfair 2025-06-12 15:35:46 +01:00
parent 2584a58df2
commit 70e444d6a3
4 changed files with 26 additions and 12 deletions

View File

@ -1,9 +1,9 @@
import { isJunk } from './utils';
import { csvConfig } from './config';
import { csvConfig, rejectedParts } from './config';
const csv = require('csvtojson');
export async function getBOM(csvBOM: string) {
const rawBOM = await csv(csvConfig).fromString(csvBOM);
const bom = rawBOM.filter((part: part) => !isJunk(part));
// const bom = rawBOM.filter((part: Part) => !isJunk(part));
const bom = rawBOM.filter((part: Part) => !rejectedParts.includes(part.Part));
return bom;
}

20
src/parts.d.ts vendored
View File

@ -1,4 +1,4 @@
enum PartType {
enum ComponentType {
R,
C,
D,
@ -7,12 +7,26 @@ enum PartType {
COMPONENT,
}
declare interface part {
enum Potentiometers {
VOL = 'VOL',
TONE = 'TONE',
GAIN = 'GAIN',
RES = 'RES',
LEVEL = 'LEVEL',
DIST = 'DIST',
PRESENCE = 'PRESENCE',
}
declare interface Part {
Part: string;
PartType?: PartType;
Value: string;
}
declare interface Component extends Part {
Designator: string; //A letter like R, C, D etc
ComponentType: ComponentType;
}
declare interface structuredParts {
C: {
[key: string]: string;

View File

@ -2,7 +2,7 @@ export class PartsTable {
constructor(
public htmlTable: HTMLTableElement,
public headers: string[],
public jsonBOM: part[],
public jsonBOM: Part[],
) {}
//Reset table

View File

@ -1,9 +1,9 @@
import { rejectedParts } from './config';
export function isJunk(element: part): boolean {
// Returns true if element is in the rejected list
return rejectedParts.includes(element.Part);
}
// no longer needed
// export function isJunk(element: Part): boolean {
// // Returns true if element is in the rejected list
// return rejectedParts.includes(element.Part);
// }
// TODO
/*