Filter parts using array methods instead of separate function
This commit is contained in:
parent
2584a58df2
commit
70e444d6a3
@ -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
20
src/parts.d.ts
vendored
@ -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;
|
||||
|
@ -2,7 +2,7 @@ export class PartsTable {
|
||||
constructor(
|
||||
public htmlTable: HTMLTableElement,
|
||||
public headers: string[],
|
||||
public jsonBOM: part[],
|
||||
public jsonBOM: Part[],
|
||||
) {}
|
||||
|
||||
//Reset table
|
||||
|
10
src/utils.ts
10
src/utils.ts
@ -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
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user