52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
export function extractNumber(str) {
|
|
if (typeof str !== "string") return null;
|
|
|
|
const cleaned = str.replace(/,/g, "");
|
|
const match = cleaned.match(/\d+(\.\d+)?/);
|
|
return match ? parseFloat(match[0]) : null;
|
|
}
|
|
|
|
export function extractModelId(url) {
|
|
try {
|
|
switch (extractDomain(url)) {
|
|
case "https://www.grays.com": {
|
|
const match = url.match(/\/lot\/([\d-]+)\//);
|
|
return match ? match[1] : null;
|
|
}
|
|
case "https://www.langtons.com.au": {
|
|
const match = url.match(/auc-var-\d+/);
|
|
return match[0];
|
|
}
|
|
case "https://www.lawsons.com.au": {
|
|
const match = url.split("_");
|
|
return match ? match[1] : null;
|
|
}
|
|
case "https://www.pickles.com.au": {
|
|
const model = url.split("/").pop();
|
|
return model ? model : null;
|
|
}
|
|
case "https://www.allbids.com.au": {
|
|
const match = url.match(/-(\d+)(?:[\?#]|$)/);
|
|
return match ? match[1] : null;
|
|
}
|
|
case "https://www.gumtree.com.au": {
|
|
const match = url.match(/\/(\d+)(?:\/)?$/);
|
|
return match ? match[1] : null;
|
|
}
|
|
default:
|
|
return null;
|
|
}
|
|
} catch (error) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function extractDomain(url) {
|
|
try {
|
|
const parsedUrl = new URL(url);
|
|
return parsedUrl.origin;
|
|
} catch (error) {
|
|
return null;
|
|
}
|
|
}
|