You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
"use strict";
|
|
|
|
const matchValue = require("match-value");
|
|
const mapObj = require("map-obj");
|
|
|
|
const normalizeString = require("../../shared/normalize-string");
|
|
const manufacturerMap = require("../manufacturer-map");
|
|
const pickBestOption = require("../../shared/pick-best-option");
|
|
|
|
let normalizedManufacturerMap = mapObj(manufacturerMap, (key, value) => {
|
|
return [ key.toLowerCase(), value ];
|
|
});
|
|
|
|
module.exports = function lcscNormalizeProduct() {
|
|
return async function ({ data, createItem }) {
|
|
let url = normalizeString(data.datasheet.pdf);
|
|
let manufacturer = normalizeString(data.manufacturer.en);
|
|
let model = normalizeString(data.info.number);
|
|
let productID = normalizeString(data.number);
|
|
let description = normalizeString(data.description);
|
|
|
|
let mappedManufacturer = (manufacturer != null)
|
|
? matchValue(manufacturer.toLowerCase(), {
|
|
... normalizedManufacturerMap,
|
|
_: manufacturer
|
|
})
|
|
: null;
|
|
|
|
if (url != null && model != null) {
|
|
createItem({
|
|
id: `datasheet:${manufacturer}:${model}`,
|
|
update: (data) => pickBestOption(data, {
|
|
priority: 0.4,
|
|
manufacturer: mappedManufacturer,
|
|
productID: productID,
|
|
name: model,
|
|
description: description,
|
|
url: url
|
|
})
|
|
});
|
|
}
|
|
};
|
|
};
|