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, rejectedParts } from './config';
import { csvConfig } from './config';
const csv = require('csvtojson'); const csv = require('csvtojson');
export async function getBOM(csvBOM: string) { export async function getBOM(csvBOM: string) {
const rawBOM = await csv(csvConfig).fromString(csvBOM); 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; return bom;
} }

20
src/parts.d.ts vendored
View File

@ -1,4 +1,4 @@
enum PartType { enum ComponentType {
R, R,
C, C,
D, D,
@ -7,12 +7,26 @@ enum PartType {
COMPONENT, 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; Part: string;
PartType?: PartType;
Value: string; Value: string;
} }
declare interface Component extends Part {
Designator: string; //A letter like R, C, D etc
ComponentType: ComponentType;
}
declare interface structuredParts { declare interface structuredParts {
C: { C: {
[key: string]: string; [key: string]: string;

View File

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

View File

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