From 7f12902b23b166cba0457261d55c8d7d2a912e45 Mon Sep 17 00:00:00 2001 From: Philippe Torrel Date: Thu, 9 Jul 2026 14:33:21 +0200 Subject: [PATCH] --- .../tag19/02_csv-to-html/data/products.csv | 9 +++ .../tag19/02_csv-to-html/index.html | 14 ++++ .../unterricht/tag19/02_csv-to-html/index.js | 66 +++++++++++++++++++ .../tag19/02_csv-to-html/package-lock.json | 28 ++++++++ .../tag19/02_csv-to-html/package.json | 16 +++++ .../tag19/02_csv-to-html/products.html | 46 +++++++++++++ 6 files changed, 179 insertions(+) create mode 100644 02_advanced/unterricht/tag19/02_csv-to-html/data/products.csv create mode 100644 02_advanced/unterricht/tag19/02_csv-to-html/index.html create mode 100644 02_advanced/unterricht/tag19/02_csv-to-html/index.js create mode 100644 02_advanced/unterricht/tag19/02_csv-to-html/package-lock.json create mode 100644 02_advanced/unterricht/tag19/02_csv-to-html/package.json create mode 100644 02_advanced/unterricht/tag19/02_csv-to-html/products.html diff --git a/02_advanced/unterricht/tag19/02_csv-to-html/data/products.csv b/02_advanced/unterricht/tag19/02_csv-to-html/data/products.csv new file mode 100644 index 0000000..5c138dd --- /dev/null +++ b/02_advanced/unterricht/tag19/02_csv-to-html/data/products.csv @@ -0,0 +1,9 @@ +Code,Short Description,Tagline,Quantity,Price +MUG0007,coffee mug with LCD level indicator,never again reach for the empty mug,20,49.90 +MUG0013,coffee mug with bluetooth-connected coffee grounds scanner for automatized fortune telling,put the smart into coffee reading,20,99.90 +OFF3145,pen with pre-warmed ink (tested on the South Pole),the pen is mightier than the cold,50,29.90 +COM1001,ambidextrous computer mouse,end the dictate of left and right,10,19.90 +COM0404,Easter egg themed webcam for your monitor,put an Easter egg on hardware too,20,149.90 +COM0001,Vulcan language vi cheatsheet,learn vi and Vulcan at the same time,3,9.90 +COM1536,Klingon language emacs cheatsheet,learn emacs and Klingon at the same time,50,9.90 +MOB0555,smartphone case with built-in screen,never miss a message,20,39.90 diff --git a/02_advanced/unterricht/tag19/02_csv-to-html/index.html b/02_advanced/unterricht/tag19/02_csv-to-html/index.html new file mode 100644 index 0000000..8d14c6b --- /dev/null +++ b/02_advanced/unterricht/tag19/02_csv-to-html/index.html @@ -0,0 +1,14 @@ + + + + + + Products + + + +
+
+
+ + diff --git a/02_advanced/unterricht/tag19/02_csv-to-html/index.js b/02_advanced/unterricht/tag19/02_csv-to-html/index.js new file mode 100644 index 0000000..7f4a539 --- /dev/null +++ b/02_advanced/unterricht/tag19/02_csv-to-html/index.js @@ -0,0 +1,66 @@ +// const fs = require('node:fs') // commonjs +import fs from 'node:fs'; // module - esm +import color from 'chalk'; + +// VARS ====================== +const STOCK_WARN_AMOUNT = 5; + +const data = fs.readFileSync('data/products.csv', 'utf-8'); + +const products = data.split('\n'); +const headerAr = products.shift().split(/\s*,\s*/); // => [ 'Code', 'Short Description', 'Tagline', 'Quantity', 'Price' ] + +// Funktionen ================ +const recordToHtml = (row) => { + const [code, shortDescription, tagline, quantity, price] = row.split(/\s*,\s*/); //=> ['MUG0007','coffee mug with LCD level indicator','never again reach for the empty mug','20','49.90'] + + const html = `
  • +

    ${shortDescription}

    +

    ${tagline}

    +

    Price: $${Number(price).toFixed(2)}

    + ${quantity < STOCK_WARN_AMOUNT ? '

    Nur noch wenige Exemplare verfügbar!

    ' : ''}
  • `; + + return html; +}; + +const writeHtmlDocument = (content = '') => { + const headerStr = ` + + + + + Products + + + +
    +
    `; + + const footerStr = `
    +
    + + +`; + + const htmlDoc = `${headerStr}${content}${footerStr}`; + + fs.writeFile('products.html', htmlDoc, 'utf-8', (err) => { + if (err) console.log(color.red(err)); + + console.log(color.green('File created!')); + }); +}; + +// logic +const listItems = products + .filter((row) => row !== '') // leere String Einträge rausgefiltert + .map((row) => { + return recordToHtml(row); // => '
  • ...
  • ' + }); + +const list = ``; + +// Output =================== +console.log(list); + +writeHtmlDocument(list); diff --git a/02_advanced/unterricht/tag19/02_csv-to-html/package-lock.json b/02_advanced/unterricht/tag19/02_csv-to-html/package-lock.json new file mode 100644 index 0000000..9b7614c --- /dev/null +++ b/02_advanced/unterricht/tag19/02_csv-to-html/package-lock.json @@ -0,0 +1,28 @@ +{ + "name": "02_csv-to-html", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "02_csv-to-html", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "chalk": "^5.6.2" + } + }, + "node_modules/chalk": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz", + "integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==", + "license": "MIT", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + } + } +} diff --git a/02_advanced/unterricht/tag19/02_csv-to-html/package.json b/02_advanced/unterricht/tag19/02_csv-to-html/package.json new file mode 100644 index 0000000..8130570 --- /dev/null +++ b/02_advanced/unterricht/tag19/02_csv-to-html/package.json @@ -0,0 +1,16 @@ +{ + "name": "02_csv-to-html", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "module", + "dependencies": { + "chalk": "^5.6.2" + } +} diff --git a/02_advanced/unterricht/tag19/02_csv-to-html/products.html b/02_advanced/unterricht/tag19/02_csv-to-html/products.html new file mode 100644 index 0000000..761d899 --- /dev/null +++ b/02_advanced/unterricht/tag19/02_csv-to-html/products.html @@ -0,0 +1,46 @@ + + + + + + Products + + + +
    +
    • +

      coffee mug with LCD level indicator

      +

      never again reach for the empty mug

      +

      Price: $49.90

      +
    • +

      coffee mug with bluetooth-connected coffee grounds scanner for automatized fortune telling

      +

      put the smart into coffee reading

      +

      Price: $99.90

      +
    • +

      pen with pre-warmed ink (tested on the South Pole)

      +

      the pen is mightier than the cold

      +

      Price: $29.90

      +
    • +

      ambidextrous computer mouse

      +

      end the dictate of left and right

      +

      Price: $19.90

      +
    • +

      Easter egg themed webcam for your monitor

      +

      put an Easter egg on hardware too

      +

      Price: $149.90

      +
    • +

      Vulcan language vi cheatsheet

      +

      learn vi and Vulcan at the same time

      +

      Price: $9.90

      +

      Nur noch wenige Exemplare verfügbar!

    • +

      Klingon language emacs cheatsheet

      +

      learn emacs and Klingon at the same time

      +

      Price: $9.90

      +
    • +

      smartphone case with built-in screen

      +

      never miss a message

      +

      Price: $39.90

      +
    +
    + +