78 lines
2.3 KiB
JavaScript
78 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// experimental script to demonstrate jq processing capabilities. playground
|
|
// not rellevent to PoC itself just practice with jq
|
|
// --- IGNORE ---
|
|
import jq from "node-jq";
|
|
|
|
const mockOdmdbResponse = {
|
|
data: [
|
|
{
|
|
email: "john.doe@example.com",
|
|
seekworkingyear: 5,
|
|
dt_create: "2025-01-10T10:30:00Z",
|
|
skills: ["JavaScript", "Node.js", "React"],
|
|
},
|
|
{
|
|
email: "jane.smith@example.com",
|
|
seekworkingyear: 3,
|
|
dt_create: "2025-01-11T14:20:00Z",
|
|
skills: ["Python", "Django", "PostgreSQL"],
|
|
},
|
|
{
|
|
email: "bob.wilson@example.com",
|
|
seekworkingyear: 8,
|
|
dt_create: "2025-01-12T09:15:00Z",
|
|
skills: ["Java", "Spring", "AWS"],
|
|
},
|
|
],
|
|
};
|
|
|
|
async function testJqProcessing() {
|
|
console.log("🧪 Testing jq processing capabilities...\n");
|
|
|
|
// Test 1: Basic filtering
|
|
console.log("📋 Test 1: Basic data formatting");
|
|
const basicFormat = await jq.run(
|
|
".[] | {email, experience: .seekworkingyear}",
|
|
mockOdmdbResponse.data,
|
|
{ input: "json" }
|
|
);
|
|
console.log(basicFormat);
|
|
console.log("\n" + "=".repeat(50) + "\n");
|
|
|
|
// Test 2: CSV conversion
|
|
console.log("📊 Test 2: CSV conversion");
|
|
const csvData = await jq.run(
|
|
'map([.email, .seekworkingyear] | @csv) | join("\n")',
|
|
mockOdmdbResponse.data,
|
|
{ input: "json" }
|
|
);
|
|
console.log("email,experience");
|
|
console.log(csvData);
|
|
console.log("\n" + "=".repeat(50) + "\n");
|
|
|
|
// Test 3: Advanced filtering
|
|
console.log("🔍 Test 3: Advanced filtering (experience > 4 years)");
|
|
const filtered = await jq.run(
|
|
"map(select(.seekworkingyear > 4)) | .[] | {email, years: .seekworkingyear, skills}",
|
|
mockOdmdbResponse.data,
|
|
{ input: "json" }
|
|
);
|
|
console.log(filtered);
|
|
console.log("\n" + "=".repeat(50) + "\n");
|
|
|
|
// Test 4: Statistical summary
|
|
console.log("📈 Test 4: Statistical summary");
|
|
const stats = await jq.run(
|
|
"{ total_seekers: length, avg_experience: (map(.seekworkingyear) | add / length), skill_count: (map(.skills[]) | group_by(.) | map({skill: .[0], count: length})) }",
|
|
mockOdmdbResponse.data,
|
|
{ input: "json" }
|
|
);
|
|
console.log(JSON.stringify(JSON.parse(stats), null, 2));
|
|
|
|
console.log("\n✅ All jq tests completed successfully!");
|
|
}
|
|
|
|
testJqProcessing().catch(console.error);
|