From f071c53a0173077be667579793842184032f429f Mon Sep 17 00:00:00 2001 From: Mariia Shuryha Date: Fri, 27 Sep 2024 16:40:29 +0300 Subject: [PATCH 01/12] added HW-2 --- .vscode/settings.json | 3 +++ HomeWork/HW_Lesson_2/Task_2.html | 19 +++++++++++++++++++ HomeWork/HW_Lesson_2/Task_3.html | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 HomeWork/HW_Lesson_2/Task_2.html create mode 100644 HomeWork/HW_Lesson_2/Task_3.html diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6f3a2913e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/HomeWork/HW_Lesson_2/Task_2.html b/HomeWork/HW_Lesson_2/Task_2.html new file mode 100644 index 000000000..6f8ff4ad6 --- /dev/null +++ b/HomeWork/HW_Lesson_2/Task_2.html @@ -0,0 +1,19 @@ + + + + + + Document + + +

Hello, Mariia!

+ + + + \ No newline at end of file diff --git a/HomeWork/HW_Lesson_2/Task_3.html b/HomeWork/HW_Lesson_2/Task_3.html new file mode 100644 index 000000000..6557b995f --- /dev/null +++ b/HomeWork/HW_Lesson_2/Task_3.html @@ -0,0 +1,16 @@ + + + + + + Document + + + + + + \ No newline at end of file From 4ca4a833291822ff525c055076b0103d02659fd2 Mon Sep 17 00:00:00 2001 From: Mariia Shuryha Date: Fri, 27 Sep 2024 16:48:02 +0300 Subject: [PATCH 02/12] added new name to folder --- HomeWork/{HW_Lesson_2 => HomeWorkAnswers}/Task_2.html | 0 HomeWork/{HW_Lesson_2 => HomeWorkAnswers}/Task_3.html | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename HomeWork/{HW_Lesson_2 => HomeWorkAnswers}/Task_2.html (100%) rename HomeWork/{HW_Lesson_2 => HomeWorkAnswers}/Task_3.html (100%) diff --git a/HomeWork/HW_Lesson_2/Task_2.html b/HomeWork/HomeWorkAnswers/Task_2.html similarity index 100% rename from HomeWork/HW_Lesson_2/Task_2.html rename to HomeWork/HomeWorkAnswers/Task_2.html diff --git a/HomeWork/HW_Lesson_2/Task_3.html b/HomeWork/HomeWorkAnswers/Task_3.html similarity index 100% rename from HomeWork/HW_Lesson_2/Task_3.html rename to HomeWork/HomeWorkAnswers/Task_3.html From 191ffc62bc2fa5d7bc3068f4ab475cc4a4205c96 Mon Sep 17 00:00:00 2001 From: Mariia Shuryha Date: Tue, 1 Oct 2024 15:34:57 +0300 Subject: [PATCH 03/12] added HW-3 --- ClassWork/Lesson 3/task3.html | 2 +- .../{ => Lesson-2}/Task_2.html | 0 .../{ => Lesson-2}/Task_3.html | 0 .../Lesson-3/HW-Task-1/index.html | 35 ++++++++++++++++++ .../Lesson-3/HW-Task-1/task_1.js | 18 ++++++++++ .../Lesson-3/HW-Task-2/index.html | 31 ++++++++++++++++ .../Lesson-3/HW-Task-2/style.css | 18 ++++++++++ .../Lesson-3/HW-Task-2/task_2.js | 23 ++++++++++++ .../Lesson-3/HW-Task-3/index.html | 36 +++++++++++++++++++ .../Lesson-3/HW-Task-3/task_3.js | 17 +++++++++ 10 files changed, 179 insertions(+), 1 deletion(-) rename HomeWork/HomeWorkAnswers/{ => Lesson-2}/Task_2.html (100%) rename HomeWork/HomeWorkAnswers/{ => Lesson-2}/Task_3.html (100%) create mode 100644 HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-1/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-1/task_1.js create mode 100644 HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/style.css create mode 100644 HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/task_2.js create mode 100644 HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-3/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-3/task_3.js diff --git a/ClassWork/Lesson 3/task3.html b/ClassWork/Lesson 3/task3.html index 88b0c0b16..179240aca 100644 --- a/ClassWork/Lesson 3/task3.html +++ b/ClassWork/Lesson 3/task3.html @@ -23,7 +23,7 @@ + + + + + + + diff --git a/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-1/task_1.js b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-1/task_1.js new file mode 100644 index 000000000..1446f1f70 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-1/task_1.js @@ -0,0 +1,18 @@ +while (true) { + let userInput = prompt("Enter a number"); + + if (Number.isInteger(Number(userInput))) { + ifEven(userInput) + } else { + alert("Будь ласка, введіть ціле число."); + } + + function ifEven(number) { + if (number % 2 == 0) { + alert("this number is even"); + } else { + alert("this number is odd"); + } + } +} + diff --git a/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/index.html b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/index.html new file mode 100644 index 000000000..ff27a3dd1 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/index.html @@ -0,0 +1,31 @@ + + + + + + Document + + + +
+ + + + + + + \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/style.css b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/style.css new file mode 100644 index 000000000..44cf737b9 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/style.css @@ -0,0 +1,18 @@ +html, body { + height: 100%; /* Забезпечує 100% висоту для body */ + margin: 0; +} + +.centered-block { + width: 300px; /* Ширина блоку */ + padding: 20px; /* Відступи всередині блоку */ + margin: auto; /* Центрування по горизонталі */ + position: absolute; /* Абсолютне позиціонування для центрування по вертикалі */ + top: 50%; /* Центрування по вертикалі */ + left: 50%; /* Центрування по горизонталі */ + transform: translate(-50%, -50%); /* Рівномірне зміщення на 50% по осям */ + border: 3px solid black; /* Рамка блоку */ + font-size: 24px; /* Великий шрифт */ + text-align: center; /* Вирівнювання тексту по центру */ + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Тінь для більшої видимості */ +} \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/task_2.js b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/task_2.js new file mode 100644 index 000000000..b3ac81179 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-2/task_2.js @@ -0,0 +1,23 @@ +let currentDate = new Date(); + +let dayOfWeek = currentDate.getDay(); + +console.log(dayOfWeek); + +let output = document.querySelector('#output'); + +if (dayOfWeek == 0){ + output.innerHTML = "Today is Sunday"; +} else if (dayOfWeek == 1){ + output.innerHTML = "Today is Monday"; +} else if (dayOfWeek == 2){ + output.innerHTML = "Today is Tuesday"; +} else if (dayOfWeek == 3){ + output.innerHTML = "Today is Wednesday"; +} else if (dayOfWeek == 4){ + output.innerHTML = "Today is Thursday"; +} else if (dayOfWeek == 5){ + output.innerHTML = "Today is Friday"; +} else if (dayOfWeek == 6){ + output.innerHTML = "Today is Saturday"; +} \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-3/index.html b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-3/index.html new file mode 100644 index 000000000..8b6353f6e --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-3/index.html @@ -0,0 +1,36 @@ + + + + + + Document + + + + + + + + + + + \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-3/task_3.js b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-3/task_3.js new file mode 100644 index 000000000..04aa0dd1b --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-3/HW-Task-3/task_3.js @@ -0,0 +1,17 @@ +while (true) { + let userYear = prompt("Enter a year:"); + + if (Number.isInteger(Number(userYear))) { + ifLeapYear(userYear); + } else { + alert("Будь ласка, введіть ціле число."); + } + + function ifLeapYear(year) { + if ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)) { + alert(`${year} leap year`); + } else { + alert(`${year} not a leap year`); + } + } +} \ No newline at end of file From 5df315e353fb1ac41bb7730e1461f6f119bdd98f Mon Sep 17 00:00:00 2001 From: Mariia Shuryha Date: Wed, 2 Oct 2024 20:01:47 +0300 Subject: [PATCH 04/12] added HW-4 --- .vscode/settings.json | 2 +- .../Lesson-4/HW-Task-1/index.html | 43 ++++++++++++ .../Lesson-4/HW-Task-1/task_1.js | 55 +++++++++++++++ .../Lesson-4/HW-Task-2/index.html | 42 +++++++++++ .../Lesson-4/HW-Task-2/task_2.js | 69 +++++++++++++++++++ 5 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-1/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-1/task_1.js create mode 100644 HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-2/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-2/task_2.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 6f3a2913e..f673a71b7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "liveServer.settings.port": 5501 + "liveServer.settings.port": 5502 } \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-1/index.html b/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-1/index.html new file mode 100644 index 000000000..98696a06e --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-1/index.html @@ -0,0 +1,43 @@ + + + + + + + Document + + + + + + + + + + + \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-1/task_1.js b/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-1/task_1.js new file mode 100644 index 000000000..40520ebbc --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-1/task_1.js @@ -0,0 +1,55 @@ +function getRandomChoice() { + let randomNuber = Math.floor(Math.random() * 3); + switch (randomNuber) { + case 0: + return "камінь"; + case 1: + return "ножиці"; + case 2: + return "папір"; + } +} + +function getUserChoice() { + while (true) { + let userChoice = prompt("Ваш хід (камінь/ножиці/папір)").toLowerCase(); + let isValid = userChoice == "камінь" || userChoice == "ножиці" || userChoice == "папір"; + if (isValid) return userChoice; + } + +} + +let userChoice = getUserChoice() +let computerChoice = getRandomChoice(); + +console.log(userChoice); +console.log(computerChoice); + +function getWinner(userChoice, computerChoice) { + if (userChoice == computerChoice) { + return "Нічия!"; + } + + if (userChoice == "камінь") { + if (computerChoice == "ножиці") { + return "Гравець перемагає! Камінь б'є ножиці."; + } else { + return "Комп'ютер перемагає! Папір б'є камінь."; + } + } else if (userChoice == "ножиці") { + if (computerChoice == "папір") { + return "Гравець перемагає! Ножиці б'ють папір."; + } else { + return "Комп'ютер перемагає! Камінь б'є ножиці."; + } + } else if (userChoice == "папір") { + if (computerChoice == "камінь") { + return "Гравець перемагає! Папір б'є камінь."; + } else { + return "Комп'ютер перемагає! Ножиці б'ють папір."; + } + } +} + +let result = getWinner(userChoice, computerChoice); +alert (result); \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-2/index.html b/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-2/index.html new file mode 100644 index 000000000..f1bafc713 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-2/index.html @@ -0,0 +1,42 @@ + + + + + + + Document + + + + + + + + + \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-2/task_2.js b/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-2/task_2.js new file mode 100644 index 000000000..9bf55542c --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-4/HW-Task-2/task_2.js @@ -0,0 +1,69 @@ +function getRandomOperator() { + let operators = ['+', '-', '*', '/']; + let randomIndex = Math.floor(Math.random() * operators.length); // Випадковий індекс від 0 до 3 + return operators[randomIndex]; +} + +function getRandomNumber() { + return Math.floor(Math.random() * 100) + 1; +} + + + +function calculateResult(num1, num2, operator) { + let result; + switch (operator) { + case '+': + result = num1 + num2; + break; + case '-': + result = num1 - num2; + break; + case '*': + result = num1 * num2; + break; + case '/': + if (num2 !== 0) { + result = num1 / num2; + } else { + result = null; // Уникання ділення на нуль + } + break; + } + return result; +} + + + +function playMathQuiz() { + let attempts = 5; + let correctAnswers = 0; + let incorrectAnswers = 0; + + for (let i = 0; i < attempts; i++) { + let num1 = getRandomNumber(); + let num2 = getRandomNumber(); + let operator = getRandomOperator(); + + let correctResult = calculateResult(num1, num2, operator); + + if (correctResult === null) { + i-- // Повторити спробу + continue; + } + + let userAnswer = parseFloat(prompt(`Вирішіть вираз: ${num1} ${operator} ${num2}`)); + + if (userAnswer === correctResult) { + alert("Правильно!"); + correctAnswers++; + } else { + alert(`Неправильно. Правильна відповідь: ${correctResult}`); + incorrectAnswers++; + } + } + + alert(`Гра завершена! Правильні відповіді: ${correctAnswers}, Неправильні відповіді: ${incorrectAnswers}`); +} + +playMathQuiz(); \ No newline at end of file From 590ec979f65fe43ffe8b6a7c0f59d7b11edc977c Mon Sep 17 00:00:00 2001 From: Mariia Shuryha Date: Fri, 4 Oct 2024 19:16:21 +0300 Subject: [PATCH 05/12] added HW-5 --- .../Lesson-5/HW-Task-1/index.html | 42 ++++++++++ .../Lesson-5/HW-Task-1/task_1.js | 30 +++++++ .../Lesson-5/HW-Task-2/index.html | 38 +++++++++ .../Lesson-5/HW-Task-2/task_2.js | 78 +++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-1/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-1/task_1.js create mode 100644 HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-2/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-2/task_2.js diff --git a/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-1/index.html b/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-1/index.html new file mode 100644 index 000000000..ef7dac8f0 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-1/index.html @@ -0,0 +1,42 @@ + + + + + + + Document + + + + + + + + + + \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-1/task_1.js b/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-1/task_1.js new file mode 100644 index 000000000..0e0762f56 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-1/task_1.js @@ -0,0 +1,30 @@ +function getNumericValue(message) { + while (true) { + let value = prompt(message); + let isValid = !isNaN(value) && value !== "" && value !== null; + if (isValid) return Number(value); + } +} + +let getIndex = (weight, height) => weight / (height * height); + +let getCategoty = index =>{ + if (index < 18.5) { + return "Недостатня вага"; + } else if (index >= 18.5 && index < 24.9){ + return "Нормальна вага"; + } else if (index >= 25 && index < 29.9){ + return "Надмірна вага"; + } else{ + return "Ожиріння"; + } +} + +const userWeight = getNumericValue("Введіть вагу (в кг)"); +const userHeight = getNumericValue("Введіть зріст (в см)")/100; + +let userIndex = getIndex(userWeight, userHeight); +let userCategory = getCategoty(userIndex); + +alert(`Ваш Індекс маси тіла (ІМТ): ${userIndex.toFixed(2)}. Категорія: ${userCategory}.`); + diff --git a/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-2/index.html b/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-2/index.html new file mode 100644 index 000000000..fe65251f4 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-2/index.html @@ -0,0 +1,38 @@ + + + + + + + Document + + + + + + + + + \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-2/task_2.js b/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-2/task_2.js new file mode 100644 index 000000000..bf25a8b8d --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-5/HW-Task-2/task_2.js @@ -0,0 +1,78 @@ +let circleAreaPerimeter = radius => { + const area = Math.PI * Math.pow(radius, 2); + const perimeter = 2 * Math.PI * radius; + return { area, perimeter }; +} + +let rectangleAreaPerimeter = (length, width) => { + const area = length * width; + const perimeter = 2 * (length + width); + return { area, perimeter }; +} + +let triangleAreaPerimeter = (a, b, c) => { + const perimeter = a + b + c; + const semiPerimeter = perimeter / 2; + const area = Math.sqrt(semiPerimeter * (semiPerimeter - a) * (semiPerimeter - b) * (semiPerimeter - c)); + return { area, perimeter }; +} + +let getUserChoiceOfFigure = () => { + while (true) { + let userChoice = prompt("Оберіть тип фігури (коло/прямокутник/трикутник)").toLowerCase(); + let isValid = userChoice == "коло" || userChoice == "прямокутник" || userChoice == "трикутник"; + if (isValid) return userChoice; + } + +} + +let validateInput = (...values) => { + for (let value of values) { + if (isNaN(value) || value <= 0) { + return false; + } + } + return true; +} + +function showResult(figure, area, perimeter) { + alert(`Фігура: ${figure}\nПлоща: ${area.toFixed(2)}\nПериметр: ${perimeter.toFixed(2)}`); +} + +let figure = getUserChoiceOfFigure(); +let result; + +switch (figure) { + case "коло": + const radius = parseFloat(prompt("Введіть радіус кола:")); + if (validateInput(radius)) { + result = circleAreaPerimeter(radius); + showResult("Коло", result.area, result.perimeter); + } else { + alert("Будь ласка, введіть коректний радіус."); + } + break; + + case "прямокутник": + const length = parseFloat(prompt("Введіть довжину прямокутника:")); + const width = parseFloat(prompt("Введіть ширину прямокутника:")); + if (validateInput(length, width)) { + result = rectangleAreaPerimeter(length, width); + showResult("Прямокутник", result.area, result.perimeter); + } else { + alert("Будь ласка, введіть коректні значення для довжини та ширини."); + } + break; + + case "трикутник": + const a = parseFloat(prompt("Введіть довжину першої сторони трикутника:")); + const b = parseFloat(prompt("Введіть довжину другої сторони трикутника:")); + const c = parseFloat(prompt("Введіть довжину третьої сторони трикутника:")); + if (validateInput(a, b, c)) { + result = triangleAreaPerimeter(a, b, c); + showResult("Трикутник", result.area, result.perimeter); + } else { + alert("Будь ласка, введіть коректні значення для сторін трикутника."); + } + break; +} From d670afd2d785bb054b68e69d9f0dffac14cd8c76 Mon Sep 17 00:00:00 2001 From: Mariia Shuryha Date: Sat, 5 Oct 2024 23:42:41 +0300 Subject: [PATCH 06/12] added HW-6 --- .../Lesson-6/HW-Task-1/index.html | 39 ++++++++ .../Lesson-6/HW-Task-1/task_1.js | 45 +++++++++ .../Lesson-6/HW-Task-2/index.html | 97 +++++++++++++++++++ .../Lesson-6/HW-Task-2/task_2.js | 0 4 files changed, 181 insertions(+) create mode 100644 HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-1/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-1/task_1.js create mode 100644 HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/task_2.js diff --git a/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-1/index.html b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-1/index.html new file mode 100644 index 000000000..39b20a08c --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-1/index.html @@ -0,0 +1,39 @@ + + + + + + + Document + + + + + + + + + \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-1/task_1.js b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-1/task_1.js new file mode 100644 index 000000000..1b273ae72 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-1/task_1.js @@ -0,0 +1,45 @@ +let mark = []; + + let arrayAvg = array => { + let sum = 0; + + for (const value of array) { + sum += value; + } + + let avg = Math.round(sum / array.length); + return avg; + } + + let arrayMax = array => { + return Math.max(...array); + } + + let arrayMin = array => { + return Math.min(...array); + } + + let getNumericValue = message => { + while (true) { + let value = prompt(message); + let isValid = !isNaN(value) && value !== "" && value !== null && value >= 0 && value <= 100; + if (isValid) { + return Number(value); + } else { + alert("Невірне значення, повторіть спробу."); + } + } + } + + let attempts = 5; + + for (let i = 1; i <= attempts; i++) { + let value = getNumericValue(`Введіть оцінку для учня ${[i]}`); + mark.push(value); + } + + let min = arrayMin(mark); + let max = arrayMax(mark); + let avg = arrayAvg(mark); + + alert(` Найвищий бал: ${max}\n Найнижчий бал: ${min}\n Середній бал: ${avg}`); \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/index.html b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/index.html new file mode 100644 index 000000000..00522f990 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/index.html @@ -0,0 +1,97 @@ + + + + + + + Document + + + + + + + + + + \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/task_2.js b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/task_2.js new file mode 100644 index 000000000..e69de29bb From 39c806a67bf17d8da685b6010107a9157f851531 Mon Sep 17 00:00:00 2001 From: Mariia Shuryha Date: Sat, 5 Oct 2024 23:44:46 +0300 Subject: [PATCH 07/12] added .js file to HW-6 --- .../Lesson-6/HW-Task-2/index.html | 59 +------------------ .../Lesson-6/HW-Task-2/task_2.js | 55 +++++++++++++++++ 2 files changed, 56 insertions(+), 58 deletions(-) diff --git a/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/index.html b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/index.html index 00522f990..5d03315dd 100644 --- a/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/index.html +++ b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/index.html @@ -8,64 +8,7 @@ - + diff --git a/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/task_2.js b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/task_2.js index e69de29bb..94c6741fd 100644 --- a/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/task_2.js +++ b/HomeWork/HomeWorkAnswers/Lesson-6/HW-Task-2/task_2.js @@ -0,0 +1,55 @@ +let shoppingList = []; + + let addItemToList = item => { + shoppingList.push(item); + alert(`${item} додано до списку товарів.`); + } + + let removeItem = item => { + let index = shoppingList.indexOf(item); + if (index !== -1) { + shoppingList.splice(index, 1); + alert(`${item} видалено зі списку.`); + } else { + alert(`Товар "${item}" не знайдено у списку.`); + } + } + + let showList = () => { + if (shoppingList.length === 0) { + alert("Список покупок порожній."); + } else { + alert("Поточний список покупок:\n" + shoppingList.join(", ")); + } + } + + let shoppingApp =() =>{ + while (true) { + let action = prompt("Оберіть дію: додати (add), видалити (remove), показати список (show) або завершити (exit)").toLowerCase(); + + if (action === "add") { + let itemToAdd = prompt("Введіть назву товару для додавання у список"); + if (itemToAdd) { + addItemToList(itemToAdd) + } else { + alert("Некоректна назва товару."); + } + } else if (action === "remove") { + let itemToRemove = prompt("Введіть назву товару для видалення зі списку"); + if (itemToRemove) { + removeItem(itemToRemove) + } else { + alert("Некоректна назва товару."); + } + } else if (action === "show") { + showList(); + } else if (action === "exit") { + alert("Дякуємо за користування додатком."); + break; + } else { + alert("Некоректна дія. Будь ласка, оберіть: add, remove, show або exit."); + } + } + } + + shoppingApp(); \ No newline at end of file From 5557fb3e9e1c17207866e9c9a9515e47c1438ab8 Mon Sep 17 00:00:00 2001 From: Mariia Shuryha Date: Mon, 7 Oct 2024 23:03:18 +0300 Subject: [PATCH 08/12] added HW-7 --- .../Lesson-7/HW-Task-1/index.html | 38 +++++++ .../Lesson-7/HW-Task-1/task_1.js | 98 +++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 HomeWork/HomeWorkAnswers/Lesson-7/HW-Task-1/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-7/HW-Task-1/task_1.js diff --git a/HomeWork/HomeWorkAnswers/Lesson-7/HW-Task-1/index.html b/HomeWork/HomeWorkAnswers/Lesson-7/HW-Task-1/index.html new file mode 100644 index 000000000..29c60e2e7 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-7/HW-Task-1/index.html @@ -0,0 +1,38 @@ + + + + + + + Document + + + + + + + + + \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-7/HW-Task-1/task_1.js b/HomeWork/HomeWorkAnswers/Lesson-7/HW-Task-1/task_1.js new file mode 100644 index 000000000..dede50d1e --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-7/HW-Task-1/task_1.js @@ -0,0 +1,98 @@ +const studentGroup = { + students: [], + + addStudent: function (firstName, lastName, age, id, averageGrade) { + let newStudent = new Student(firstName, lastName, age, id, averageGrade); + this.students.push(newStudent); + alert("Студент успішно доданий!"); + }, + + removeStudent: function (id) { + const index = this.students.findIndex(student => student.id === id); + + if (index !== -1) { + this.students.splice(index, 1); + alert(`Студент з ID ${id} успішно видалений!`); + } else { + alert(`Студента з ID ${id} не знайдено.`); + } + }, + + listStudents: function () { + if (this.students.length === 0) { + alert("Список студентів порожній."); + return; + } + + let studentList = "Список студентів:\n"; + this.students.forEach(student => { + studentList += `ID: ${student.id}, Ім'я: ${student.firstName}, Прізвище: ${student.lastName}, Вік: ${student.age}, Середній бал: ${student.averageGrade}\n`; + }); + + alert(studentList); + }, + + findStudentById: function (id) { + const student = this.students.find(student => student.id === id); + + if (student) { + alert(`Інформація про студента з ID ${id}:\nІм'я: ${student.firstName}\nПрізвище: ${student.lastName}\nВік: ${student.age}\nСередній бал: ${student.averageGrade}`); + } else { + alert(`Студента з ID ${id} не знайдено.`); + } + } +}; + + +function studentManagementApp() { + + const actions = { + + add: function () { + let firstName = prompt("Введіть ім'я студента:"); + let lastName = prompt("Введіть прізвище студента:"); + let age = Number(prompt("Введіть вік студента:")); + let id = prompt("Введіть ID студента:"); + let averageGrade = Number(prompt("Введіть середній бал студента:")); + studentGroup.addStudent(firstName, lastName, age, id, averageGrade); + }, + remove: function () { + let id = prompt("Введіть ID студента для видалення:"); + studentGroup.removeStudent(id); + }, + list: function () { + studentGroup.listStudents(); + }, + find: function () { + let id = prompt("Введіть ID студента для пошуку:"); + studentGroup.findStudentById(id); + }, + exit: function () { + alert("Завершення програми."); + return false; + } + }; + + while (true) { + let action = prompt("Оберіть дію: додати (add), видалити (remove), показати список (list), знайти студента (find), завершити (exit)").toLowerCase(); + + // Виклик методу на основі дії + if (actions[action]) { + const result = actions[action](); + if (result === false) break; // Вихід з циклу, якщо action - exit + } else { + alert("Некоректна дія. Будь ласка, оберіть: add, remove, list, find або exit."); + } + } +} + +let Student = function (firstName, lastName, age, id, averageGrade) { + this.firstName = firstName; + this.lastName = lastName; + this.age = age; + this.id = id; + this.averageGrade = averageGrade; +}; + + +studentManagementApp(); From c111384a24e608bbd7c54660346ed39fa6a1bde4 Mon Sep 17 00:00:00 2001 From: Mariia Shuryha Date: Tue, 8 Oct 2024 20:11:52 +0300 Subject: [PATCH 09/12] added HW-8 --- .../Lesson-8/HW-Task-1/index.html | 55 ++ .../Lesson-8/HW-Task-1/js/controller.js | 4 + .../Lesson-8/HW-Task-1/js/model.js | 8 + .../Lesson-8/HW-Task-1/js/view.js | 9 + .../Lesson-8/HW-Task-1/style.css | 9 + node_modules/.bin/mustache | 16 + node_modules/.bin/mustache.cmd | 17 + node_modules/.bin/mustache.ps1 | 28 + node_modules/.package-lock.json | 15 + node_modules/mustache/CHANGELOG.md | 618 ++++++++++++++ node_modules/mustache/LICENSE | 11 + node_modules/mustache/README.md | 621 ++++++++++++++ node_modules/mustache/bin/mustache | 150 ++++ node_modules/mustache/mustache.js | 772 ++++++++++++++++++ node_modules/mustache/mustache.min.js | 1 + node_modules/mustache/mustache.mjs | 764 +++++++++++++++++ node_modules/mustache/package.json | 67 ++ .../mustache/wrappers/dojo/mustache.js.post | 4 + .../mustache/wrappers/dojo/mustache.js.pre | 9 + .../mustache/wrappers/jquery/mustache.js.post | 13 + .../mustache/wrappers/jquery/mustache.js.pre | 9 + .../wrappers/mootools/mustache.js.post | 5 + .../wrappers/mootools/mustache.js.pre | 2 + .../wrappers/qooxdoo/mustache.js.post | 9 + .../mustache/wrappers/qooxdoo/mustache.js.pre | 172 ++++ .../mustache/wrappers/yui3/mustache.js.post | 4 + .../mustache/wrappers/yui3/mustache.js.pre | 1 + package-lock.json | 20 + package.json | 5 + 29 files changed, 3418 insertions(+) create mode 100644 HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/index.html create mode 100644 HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/controller.js create mode 100644 HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/model.js create mode 100644 HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/view.js create mode 100644 HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/style.css create mode 100644 node_modules/.bin/mustache create mode 100644 node_modules/.bin/mustache.cmd create mode 100644 node_modules/.bin/mustache.ps1 create mode 100644 node_modules/.package-lock.json create mode 100644 node_modules/mustache/CHANGELOG.md create mode 100644 node_modules/mustache/LICENSE create mode 100644 node_modules/mustache/README.md create mode 100644 node_modules/mustache/bin/mustache create mode 100644 node_modules/mustache/mustache.js create mode 100644 node_modules/mustache/mustache.min.js create mode 100644 node_modules/mustache/mustache.mjs create mode 100644 node_modules/mustache/package.json create mode 100644 node_modules/mustache/wrappers/dojo/mustache.js.post create mode 100644 node_modules/mustache/wrappers/dojo/mustache.js.pre create mode 100644 node_modules/mustache/wrappers/jquery/mustache.js.post create mode 100644 node_modules/mustache/wrappers/jquery/mustache.js.pre create mode 100644 node_modules/mustache/wrappers/mootools/mustache.js.post create mode 100644 node_modules/mustache/wrappers/mootools/mustache.js.pre create mode 100644 node_modules/mustache/wrappers/qooxdoo/mustache.js.post create mode 100644 node_modules/mustache/wrappers/qooxdoo/mustache.js.pre create mode 100644 node_modules/mustache/wrappers/yui3/mustache.js.post create mode 100644 node_modules/mustache/wrappers/yui3/mustache.js.pre create mode 100644 package-lock.json create mode 100644 package.json diff --git a/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/index.html b/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/index.html new file mode 100644 index 000000000..0f507d162 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/index.html @@ -0,0 +1,55 @@ + + + + + + Document + + + + + + +

Список книг у бібліотеці

+
+ + + + + + + + + + + \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/controller.js b/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/controller.js new file mode 100644 index 000000000..c72b401e1 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/controller.js @@ -0,0 +1,4 @@ +let html = document.querySelector("#bookList"); +let template = document.querySelector("#template").innerHTML; + +bookList.renderWithTemplate(books, html, template); \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/model.js b/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/model.js new file mode 100644 index 000000000..30b305774 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/model.js @@ -0,0 +1,8 @@ +const books = [ + { title: "1984", author: "Джордж Орвелл", year: 1949, genre: "Антиутопія" }, + { title: "Гаррі Поттер і філософський камінь", author: "Дж. К. Роулінг", year: 1997, genre: "Фентезі" }, + { title: "Гра престолів", author: "Джордж Р. Р. Мартін", year: 1996, genre: "Фентезі" }, + { title: "Старий і море", author: "Ернест Хемінгуей", year: 1952, genre: "Пригодницький роман" }, + { title: "Майстер і Маргарита", author: "Михайло Булгаков", year: 1967, genre: "Фантастика" }, +]; + diff --git a/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/view.js b/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/view.js new file mode 100644 index 000000000..ff64b09ba --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/js/view.js @@ -0,0 +1,9 @@ +const bookList = { + renderWithTemplate(books, element, template){ + let html = ""; + books.forEach(book => { + html += Mustache.render(template, book); + }); + element.innerHTML = html; + } +} \ No newline at end of file diff --git a/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/style.css b/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/style.css new file mode 100644 index 000000000..c2690a904 --- /dev/null +++ b/HomeWork/HomeWorkAnswers/Lesson-8/HW-Task-1/style.css @@ -0,0 +1,9 @@ +.book { + border: 1px solid #ddd; + padding: 10px; + margin: 10px 0; + border-radius: 5px; +} +.book h3 { + margin: 0 0 5px 0; +} \ No newline at end of file diff --git a/node_modules/.bin/mustache b/node_modules/.bin/mustache new file mode 100644 index 000000000..10e4e5aa0 --- /dev/null +++ b/node_modules/.bin/mustache @@ -0,0 +1,16 @@ +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") + +case `uname` in + *CYGWIN*|*MINGW*|*MSYS*) + if command -v cygpath > /dev/null 2>&1; then + basedir=`cygpath -w "$basedir"` + fi + ;; +esac + +if [ -x "$basedir/node" ]; then + exec "$basedir/node" "$basedir/../mustache/bin/mustache" "$@" +else + exec node "$basedir/../mustache/bin/mustache" "$@" +fi diff --git a/node_modules/.bin/mustache.cmd b/node_modules/.bin/mustache.cmd new file mode 100644 index 000000000..92cf68dc4 --- /dev/null +++ b/node_modules/.bin/mustache.cmd @@ -0,0 +1,17 @@ +@ECHO off +GOTO start +:find_dp0 +SET dp0=%~dp0 +EXIT /b +:start +SETLOCAL +CALL :find_dp0 + +IF EXIST "%dp0%\node.exe" ( + SET "_prog=%dp0%\node.exe" +) ELSE ( + SET "_prog=node" + SET PATHEXT=%PATHEXT:;.JS;=;% +) + +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\mustache\bin\mustache" %* diff --git a/node_modules/.bin/mustache.ps1 b/node_modules/.bin/mustache.ps1 new file mode 100644 index 000000000..ec52dfec4 --- /dev/null +++ b/node_modules/.bin/mustache.ps1 @@ -0,0 +1,28 @@ +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +$ret=0 +if (Test-Path "$basedir/node$exe") { + # Support pipeline input + if ($MyInvocation.ExpectingInput) { + $input | & "$basedir/node$exe" "$basedir/../mustache/bin/mustache" $args + } else { + & "$basedir/node$exe" "$basedir/../mustache/bin/mustache" $args + } + $ret=$LASTEXITCODE +} else { + # Support pipeline input + if ($MyInvocation.ExpectingInput) { + $input | & "node$exe" "$basedir/../mustache/bin/mustache" $args + } else { + & "node$exe" "$basedir/../mustache/bin/mustache" $args + } + $ret=$LASTEXITCODE +} +exit $ret diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json new file mode 100644 index 000000000..780cd6366 --- /dev/null +++ b/node_modules/.package-lock.json @@ -0,0 +1,15 @@ +{ + "name": "JavaScript-course-2024", + "lockfileVersion": 3, + "requires": true, + "packages": { + "node_modules/mustache": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", + "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==", + "bin": { + "mustache": "bin/mustache" + } + } + } +} diff --git a/node_modules/mustache/CHANGELOG.md b/node_modules/mustache/CHANGELOG.md new file mode 100644 index 000000000..b1f72d0a3 --- /dev/null +++ b/node_modules/mustache/CHANGELOG.md @@ -0,0 +1,618 @@ +# Change Log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +## [4.2.0] / 28 March 2021 + +### Added + +* [#773]: Add package.json `exports` field, by [@manzt]. + +## [4.1.0] / 6 December 2020 + +### Added + +* [#764]: `render()` now recognizes a config object argument, by [@pineapplemachine]. + +### Fixed + +* [#764]: Ask custom `escape` functions to escape all types of values (including `number`s), by [@pineapplemachine]. + +## [4.0.1] / 15 March 2020 + +### Fixed + + * [#739]: Fix custom delimiters in nested partials, by [@aielo]. + +## [4.0.0] / 16 January 2020 + +Majority of using projects don't have to worry by this being a new major version. + +**TLDR;** if your project manipulates `Writer.prototype.parse | Writer.cache` directly or uses `.to_html()`, you probably have to change that code. + +This release allows the internal template cache to be customised, either by disabling it completely +or provide a custom strategy deciding how the cache should behave when mustache.js parses templates. + +```js +const mustache = require('mustache'); + +// disable caching +Mustache.templateCache = undefined; + +// or use a built-in Map in modern environments +Mustache.templateCache = new Map(); +``` + +Projects that wanted to customise the caching behaviour in earlier versions of mustache.js were forced to +override internal method responsible for parsing templates; `Writer.prototype.parse`. In short, that was unfortunate +because there is more than caching happening in that method. + +We've improved that now by introducing a first class API that only affects template caching. + +The default template cache behaves as before and is still compatible with older JavaScript environments. +For those who wants to provide a custom more sopisiticated caching strategy, one can do that with an object that adheres to the following requirements: + +```ts +{ + set(cacheKey: string, value: string): void + get(cacheKey: string): string | undefined + clear(): void +} +``` + +### Added + +* [#731]: Allow template caching to be customised, by [@AndrewLeedham]. + +### Removed + +* [#735]: Remove `.to_html()`, by [@phillipj]. + +## [3.2.1] / 30 December 2019 + +### Fixed + + * [#733]: Allow the CLI to use JavaScript views when the project has ES6 modules enabled, by [@eobrain]. + +## [3.2.0] / 18 December 2019 + +### Added + +* [#728]: Expose ECMAScript Module in addition to UMD (CommonJS, AMD & global scope), by [@phillipj] and [@zekth]. + +### Using mustache.js as an ES module + +To stay backwards compatible with already using projects, the default exposed module format is still UMD. +That means projects using mustache.js as an CommonJS, AMD or global scope module, from npm or directly from github.com +can keep on doing that for now. + +For those projects who would rather want to use mustache.js as an ES module, the `mustache/mustache.mjs` file has to +be `import`ed directly. + +Below are some usage scenarios for different runtimes. + +#### Modern browser with ES module support + +```html + + +``` + +#### [Node.js](https://nodejs.org) (>= v13.2.0 or using --experimental-modules flag) + +```js +// index.mjs +import mustache from 'mustache/mustache.mjs' + +console.log(mustache.render('Hello {{name}}!', { name: 'Santa' })) +// Hello Santa! +``` + +ES Module support for Node.js will be improved in the future when [Conditional Exports](https://nodejs.org/api/esm.html#esm_conditional_exports) +is enabled by default rather than being behind an experimental flag. + +More info in [Node.js ECMAScript Modules docs](https://nodejs.org/api/esm.html). + +#### [Deno](https://deno.land/) + +```js +// index.ts +import mustache from 'https://unpkg.com/mustache@3.2.0/mustache.mjs' + +console.log(mustache.render('Hello {{name}}!', { name: 'Santa' })) +// Hello Santa! +``` + +## [3.1.0] / 13 September 2019 + +### Added + + * [#717]: Added support .js files as views in command line tool, by [@JEStaubach]. + +### Fixed + + * [#716]: Bugfix for indentation of inline partials, by [@yotammadem]. + +## [3.0.3] / 27 August 2019 + +### Added + + * [#713]: Add test cases for custom functions in partials, by [@wol-soft]. + +### Fixed + + * [#714]: Bugfix for wrong function output in partials with indentation, by [@phillipj]. + +## [3.0.2] / 21 August 2019 + +### Fixed + + * [#705]: Fix indentation of partials, by [@kevindew] and [@yotammadem]. + +### Dev + + * [#701]: Fix test failure for Node 10 and above, by [@andersk]. + * [#704]: Lint all test files just like the source files, by [@phillipj]. + * Start experimenting & comparing GitHub Actions vs Travis CI, by [@phillipj]. + +## [3.0.1] / 11 November 2018 + + * [#679]: Fix partials not rendering tokens when using custom tags, by [@stackchain]. + +## [3.0.0] / 16 September 2018 + +We are very happy to announce a new major version of mustache.js. We want to be very careful not to break projects +out in the wild, and adhering to [Semantic Versioning](http://semver.org/) we have therefore cut this new major version. + +The changes introduced will likely not require any actions for most using projects. The things to look out for that +might cause unexpected rendering results are described in the migration guide below. + +A big shout out and thanks to [@raymond-lam] for this release! Without his contributions with code and issue triaging, +this release would never have happened. + +### Major + +* [#618]: Allow rendering properties of primitive types that are not objects, by [@raymond-lam]. +* [#643]: `Writer.prototype.parse` to cache by tags in addition to template string, by [@raymond-lam]. +* [#664]: Fix `Writer.prototype.parse` cache, by [@seminaoki]. + +### Minor + +* [#673]: Add `tags` parameter to `Mustache.render()`, by [@raymond-lam]. + +### Migrating from mustache.js v2.x to v3.x + +#### Rendering properties of primitive types + +We have ensured properties of primitive types can be rendered at all times. That means `Array.length`, `String.length` +and similar. A corner case where this could cause unexpected output follows: + +View: +``` +{ + stooges: [ + { name: "Moe" }, + { name: "Larry" }, + { name: "Curly" } + ] +} +``` + +Template: +``` +{{#stooges}} + {{name}}: {{name.length}} characters +{{/stooges}} +``` + +Output with v3.0: +``` + Moe: 3 characters + Larry: 5 characters + Curly: 5 characters +``` + +Output with v2.x: +``` + Moe: characters + Larry: characters + Curly: characters +``` + +#### Caching for templates with custom delimiters + +We have improved the templates cache to ensure custom delimiters are taken into consideration for the cache. +This improvement might cause unexpected rendering behaviour for using projects actively using the custom delimiters functionality. + +Previously it was possible to use `Mustache.parse()` as a means to set global custom delimiters. If custom +delimiters were provided as an argument, it would affect all following calls to `Mustache.render()`. +Consider the following: + +```js +const template = "[[item.title]] [[item.value]]"; +mustache.parse(template, ["[[", "]]"]); + +console.log( + mustache.render(template, { + item: { + title: "TEST", + value: 1 + } + }) +); + +>> TEST 1 +``` + +The above illustrates the fact that `Mustache.parse()` made mustache.js cache the template without considering +the custom delimiters provided. This is no longer true. + +We no longer encourage using `Mustache.parse()` for this purpose, but have rather added a fourth argument to +`Mustache.render()` letting you provide custom delimiters when rendering. + +If you still need the pre-parse the template and use custom delimiters at the same time, ensure to provide +the custom delimiters as argument to `Mustache.render()` as well. + +## [2.3.2] / 17 August 2018 + +This release is made to revert changes introduced in [2.3.1] that caused unexpected behaviour for several users. + +### Minor + + * [#670]: Rollback template cache causing unexpected behaviour, by [@raymond-lam]. + +## [2.3.1] / 7 August 2018 + +### Minor + + * [#643]: `Writer.prototype.parse` to cache by tags in addition to template string, by [@raymond-lam]. + * [#664]: Fix `Writer.prototype.parse` cache, by [@seminaoki]. + +### Dev + + * [#666]: Install release tools with npm rather than pre-commit hook & `Rakefile`, by [@phillipj]. + * [#667], [#668]: Stabilize browser test suite, by [@phillipj]. + +### Docs + + * [#644]: Document global Mustache.escape overriding capacity, by [@paultopia]. + * [#657]: Correct `Mustache.parse()` return type documentation, by [@bbrooks]. + +## [2.3.0] / 8 November 2016 + +### Minor + + * [#540]: Add optional `output` argument to mustache CLI, by [@wizawu]. + * [#597]: Add compatibility with amdclean, by [@mightyplow]. + +### Dev + + * [#553]: Assert `null` lookup when rendering an unescaped value, by [@dasilvacontin]. + * [#580], [#610]: Ignore eslint for greenkeeper updates, by [@phillipj]. + * [#560]: Fix CLI tests for Windows, by [@kookookchoozeus]. + * Run browser tests w/node v4, by [@phillipj]. + +### Docs + + * [#542]: Add API documentation to README, by [@tomekwi]. + * [#546]: Add missing syntax highlighting to README code blocks, by [@pra85]. + * [#569]: Update Ctemplate links in README, by [@mortonfox]. + * [#592]: Change "loadUser" to "loadUser()" in README, by [@Flaque]. + * [#593]: Adding doctype to HTML code example in README, by [@calvinf]. + +### Dependencies + + * eslint -> 2.2.0. Breaking changes fix by [@phillipj]. [#548] + * eslint -> 2.5.1. + * mocha -> 3.0.2. + * zuul -> 3.11.0. + +## [2.2.1] / 13 December 2015 + +### Fixes + + * Improve HTML escaping, by [@phillipj]. + * Fix inconsistency in defining global mustache object, by [@simast]. + * Fix switch-case indent error, by [@norfish]. + * Unpin chai and eslint versions, by [@dasilvacontin]. + * Update README.md with proper grammar, by [@EvanLovely]. + * Update mjackson username in README, by [@mjackson]. + * Remove syntax highlighting in README code sample, by [@imagentleman]. + * Fix typo in README, by [@Xcrucifier]. + * Fix link typo in README, by [@keirog]. + +## [2.2.0] / 15 October 2015 + +### Added + + * Add Partials support to CLI, by [@palkan]. + +### Changed + + * Move install instructions to README's top, by [@mateusortiz] + * Improved devhook install output, by [@ShashankaNataraj]. + * Clarifies and improves language in documentation, by [@jfmercer]. + * Linting CLI tool, by [@phillipj]. + * npm 2.x and node v4 on Travis, by [@phillipj]. + +### Fixes + + * Fix README spelling error to "aforementioned", by [@djchie]. + * Equal error message test in .render() for server and browser, by [@phillipj]. + +### Dependencies + + * chai -> 3.3.0 + * eslint -> 1.6.0 + +## [2.1.3] / 23 July 2015 + +### Added + + * Throw error when providing .render() with invalid template type, by [@phillipj]. + * Documents use of string literals containing double quotes, by [@jfmercer]. + +### Changed + + * Move mustache gif to githubusercontent, by [@Andersos]. + +### Fixed + + * Update UMD Shim to be resilient to HTMLElement global pollution, by [@mikesherov]. + +## [2.1.2] / 17 June 2015 + +### Added + + * Mustache global definition ([#466]) by [@yousefcisco]. + +## [2.1.1] / 11 June 2015 + +### Added + + * State that we use semver on the change log, by [@dasilvacontin]. + * Added version links to change log, by [@dasilvacontin]. + +### Fixed + + * Bugfix for using values from view's context prototype, by [@phillipj]. + * Improve test with undefined/null lookup hit using dot notation, by [@dasilvacontin]. + * Bugfix for null/undefined lookup hit when using dot notation, by [@phillipj]. + * Remove moot `version` property from bower.json, by [@kkirsche]. + * bower.json doesn't require a version bump via hook, by [@dasilvacontin]. + + +## [2.1.0] / 5 June 2015 + + * Added license attribute to package.json, by [@pgilad]. + * Minor changes to make mustache.js compatible with both WSH and ASP, by [@nagaozen]. + * Improve CLI view parsing error, by [@phillipj]. + * Bugfix for view context cache, by [@phillipj]. + +## [2.0.0] / 27 Mar 2015 + + * Fixed lookup not stopping upon finding `undefined` or `null` values, by [@dasilvacontin]. + * Refactored pre-commit hook, by [@dasilvacontin]. + +## [1.2.0] / 24 Mar 2015 + + * Added -v option to CLI, by [@phillipj]. + * Bugfix for rendering Number when it serves as the Context, by [@phillipj]. + * Specified files in package.json for a cleaner install, by [@phillipj]. + +## [1.1.0] / 18 Feb 2015 + + * Refactor Writer.renderTokens() for better readability, by [@phillipj]. + * Cleanup tests section in readme, by [@phillipj]. + * Added JSHint to tests/CI, by [@phillipj]. + * Added node v0.12 on travis, by [@phillipj]. + * Created command line tool, by [@phillipj]. + * Added *falsy* to Inverted Sections description in README, by [@kristijanmatic]. + +## [1.0.0] / 20 Dec 2014 + + * Inline tag compilation, by [@mjackson]. + * Fixed AMD registration, volo package.json entry, by [@jrburke]. + * Added spm support, by [@afc163]. + * Only access properties of objects on Context.lookup, by [@cmbuckley]. + +## [0.8.2] / 17 Mar 2014 + + * Supporting Bower through a bower.json file. + +## [0.8.1] / 3 Jan 2014 + + * Fix usage of partial templates. + +## [0.8.0] / 2 Dec 2013 + + * Remove compile* writer functions, use mustache.parse instead. Smaller API. + * Throw an error when rendering a template that contains higher-order sections and + the original template is not provided. + * Remove low-level Context.make function. + * Better code readability and inline documentation. + * Stop caching templates by name. + +## [0.7.3] / 5 Nov 2013 + + * Don't require the original template to be passed to the rendering function + when using compiled templates. This is still required when using higher-order + functions in order to be able to extract the portion of the template + that was contained by that section. Fixes [#262]. + * Performance improvements. + +## [0.7.2] / 27 Dec 2012 + + * Fixed a rendering bug ([#274]) when using nested higher-order sections. + * Better error reporting on failed parse. + * Converted tests to use mocha instead of vows. + +## [0.7.1] / 6 Dec 2012 + + * Handle empty templates gracefully. Fixes [#265], [#267], and [#270]. + * Cache partials by template, not by name. Fixes [#257]. + * Added Mustache.compileTokens to compile the output of Mustache.parse. Fixes + [#258]. + +## [0.7.0] / 10 Sep 2012 + + * Rename Renderer => Writer. + * Allow partials to be loaded dynamically using a callback (thanks + [@TiddoLangerak] for the suggestion). + * Fixed a bug with higher-order sections that prevented them from being + passed the raw text of the section from the original template. + * More concise token format. Tokens also include start/end indices in the + original template. + * High-level API is consistent with the Writer API. + * Allow partials to be passed to the pre-compiled function (thanks + [@fallenice]). + * Don't use eval (thanks [@cweider]). + +## [0.6.0] / 31 Aug 2012 + + * Use JavaScript's definition of falsy when determining whether to render an + inverted section or not. Issue [#186]. + * Use Mustache.escape to escape values inside {{}}. This function may be + reassigned to alter the default escaping behavior. Issue [#244]. + * Fixed a bug that clashed with QUnit (thanks [@kannix]). + * Added volo support (thanks [@guybedford]). + +[4.1.0]: https://github.com/janl/mustache.js/compare/v4.0.1...v4.1.0 +[4.0.1]: https://github.com/janl/mustache.js/compare/v4.0.0...v4.0.1 +[4.0.0]: https://github.com/janl/mustache.js/compare/v3.2.1...v4.0.0 +[3.2.1]: https://github.com/janl/mustache.js/compare/v3.2.0...v3.2.1 +[3.2.0]: https://github.com/janl/mustache.js/compare/v3.1.0...v3.2.0 +[3.1.0]: https://github.com/janl/mustache.js/compare/v3.0.3...v3.1.0 +[3.0.3]: https://github.com/janl/mustache.js/compare/v3.0.2...v3.0.3 +[3.0.2]: https://github.com/janl/mustache.js/compare/v3.0.1...v3.0.2 +[3.0.1]: https://github.com/janl/mustache.js/compare/v3.0.0...v3.0.1 +[3.0.0]: https://github.com/janl/mustache.js/compare/v2.3.2...v3.0.0 +[2.3.2]: https://github.com/janl/mustache.js/compare/v2.3.1...v2.3.2 +[2.3.1]: https://github.com/janl/mustache.js/compare/v2.3.0...v2.3.1 +[2.3.0]: https://github.com/janl/mustache.js/compare/v2.2.1...v2.3.0 +[2.2.1]: https://github.com/janl/mustache.js/compare/v2.2.0...v2.2.1 +[2.2.0]: https://github.com/janl/mustache.js/compare/v2.1.3...v2.2.0 +[2.1.3]: https://github.com/janl/mustache.js/compare/v2.1.2...v2.1.3 +[2.1.2]: https://github.com/janl/mustache.js/compare/v2.1.1...v2.1.2 +[2.1.1]: https://github.com/janl/mustache.js/compare/v2.1.0...v2.1.1 +[2.1.0]: https://github.com/janl/mustache.js/compare/v2.0.0...v2.1.0 +[2.0.0]: https://github.com/janl/mustache.js/compare/v1.2.0...v2.0.0 +[1.2.0]: https://github.com/janl/mustache.js/compare/v1.1.0...v1.2.0 +[1.1.0]: https://github.com/janl/mustache.js/compare/v1.0.0...v1.1.0 +[1.0.0]: https://github.com/janl/mustache.js/compare/0.8.2...v1.0.0 +[0.8.2]: https://github.com/janl/mustache.js/compare/0.8.1...0.8.2 +[0.8.1]: https://github.com/janl/mustache.js/compare/0.8.0...0.8.1 +[0.8.0]: https://github.com/janl/mustache.js/compare/0.7.3...0.8.0 +[0.7.3]: https://github.com/janl/mustache.js/compare/0.7.2...0.7.3 +[0.7.2]: https://github.com/janl/mustache.js/compare/0.7.1...0.7.2 +[0.7.1]: https://github.com/janl/mustache.js/compare/0.7.0...0.7.1 +[0.7.0]: https://github.com/janl/mustache.js/compare/0.6.0...0.7.0 +[0.6.0]: https://github.com/janl/mustache.js/compare/0.5.2...0.6.0 + +[#186]: https://github.com/janl/mustache.js/issues/186 +[#244]: https://github.com/janl/mustache.js/issues/244 +[#257]: https://github.com/janl/mustache.js/issues/257 +[#258]: https://github.com/janl/mustache.js/issues/258 +[#262]: https://github.com/janl/mustache.js/issues/262 +[#265]: https://github.com/janl/mustache.js/issues/265 +[#267]: https://github.com/janl/mustache.js/issues/267 +[#270]: https://github.com/janl/mustache.js/issues/270 +[#274]: https://github.com/janl/mustache.js/issues/274 +[#466]: https://github.com/janl/mustache.js/issues/466 +[#540]: https://github.com/janl/mustache.js/issues/540 +[#542]: https://github.com/janl/mustache.js/issues/542 +[#546]: https://github.com/janl/mustache.js/issues/546 +[#548]: https://github.com/janl/mustache.js/issues/548 +[#553]: https://github.com/janl/mustache.js/issues/553 +[#560]: https://github.com/janl/mustache.js/issues/560 +[#569]: https://github.com/janl/mustache.js/issues/569 +[#580]: https://github.com/janl/mustache.js/issues/580 +[#592]: https://github.com/janl/mustache.js/issues/592 +[#593]: https://github.com/janl/mustache.js/issues/593 +[#597]: https://github.com/janl/mustache.js/issues/597 +[#610]: https://github.com/janl/mustache.js/issues/610 +[#643]: https://github.com/janl/mustache.js/issues/643 +[#644]: https://github.com/janl/mustache.js/issues/644 +[#657]: https://github.com/janl/mustache.js/issues/657 +[#664]: https://github.com/janl/mustache.js/issues/664 +[#666]: https://github.com/janl/mustache.js/issues/666 +[#667]: https://github.com/janl/mustache.js/issues/667 +[#668]: https://github.com/janl/mustache.js/issues/668 +[#670]: https://github.com/janl/mustache.js/issues/670 +[#618]: https://github.com/janl/mustache.js/issues/618 +[#673]: https://github.com/janl/mustache.js/issues/673 +[#679]: https://github.com/janl/mustache.js/issues/679 +[#701]: https://github.com/janl/mustache.js/issues/701 +[#704]: https://github.com/janl/mustache.js/issues/704 +[#705]: https://github.com/janl/mustache.js/issues/705 +[#713]: https://github.com/janl/mustache.js/issues/713 +[#714]: https://github.com/janl/mustache.js/issues/714 +[#716]: https://github.com/janl/mustache.js/issues/716 +[#717]: https://github.com/janl/mustache.js/issues/717 +[#728]: https://github.com/janl/mustache.js/issues/728 +[#733]: https://github.com/janl/mustache.js/issues/733 +[#731]: https://github.com/janl/mustache.js/issues/731 +[#735]: https://github.com/janl/mustache.js/issues/735 +[#739]: https://github.com/janl/mustache.js/issues/739 +[#764]: https://github.com/janl/mustache.js/issues/764 +[#773]: https://github.com/janl/mustache.js/issues/773 + +[@afc163]: https://github.com/afc163 +[@aielo]: https://github.com/aielo +[@andersk]: https://github.com/andersk +[@Andersos]: https://github.com/Andersos +[@AndrewLeedham]: https://github.com/AndrewLeedham +[@bbrooks]: https://github.com/bbrooks +[@calvinf]: https://github.com/calvinf +[@cmbuckley]: https://github.com/cmbuckley +[@cweider]: https://github.com/cweider +[@dasilvacontin]: https://github.com/dasilvacontin +[@djchie]: https://github.com/djchie +[@eobrain]: https://github.com/eobrain +[@EvanLovely]: https://github.com/EvanLovely +[@fallenice]: https://github.com/fallenice +[@Flaque]: https://github.com/Flaque +[@guybedford]: https://github.com/guybedford +[@imagentleman]: https://github.com/imagentleman +[@JEStaubach]: https://github.com/JEStaubach +[@jfmercer]: https://github.com/jfmercer +[@jrburke]: https://github.com/jrburke +[@kannix]: https://github.com/kannix +[@keirog]: https://github.com/keirog +[@kkirsche]: https://github.com/kkirsche +[@kookookchoozeus]: https://github.com/kookookchoozeus +[@kristijanmatic]: https://github.com/kristijanmatic +[@kevindew]: https://github.com/kevindew +[@manzt]: https://github.com/manzt +[@mateusortiz]: https://github.com/mateusortiz +[@mightyplow]: https://github.com/mightyplow +[@mikesherov]: https://github.com/mikesherov +[@mjackson]: https://github.com/mjackson +[@mortonfox]: https://github.com/mortonfox +[@nagaozen]: https://github.com/nagaozen +[@norfish]: https://github.com/norfish +[@palkan]: https://github.com/palkan +[@paultopia]: https://github.com/paultopia +[@pgilad]: https://github.com/pgilad +[@phillipj]: https://github.com/phillipj +[@pineapplemachine]: https://github.com/pineapplemachine +[@pra85]: https://github.com/pra85 +[@raymond-lam]: https://github.com/raymond-lam +[@seminaoki]: https://github.com/seminaoki +[@ShashankaNataraj]: https://github.com/ShashankaNataraj +[@simast]: https://github.com/simast +[@stackchain]: https://github.com/stackchain +[@TiddoLangerak]: https://github.com/TiddoLangerak +[@tomekwi]: https://github.com/tomekwi +[@wizawu]: https://github.com/wizawu +[@wol-soft]: https://github.com/wol-soft +[@Xcrucifier]: https://github.com/Xcrucifier +[@yotammadem]: https://github.com/yotammadem +[@yousefcisco]: https://github.com/yousefcisco +[@zekth]: https://github.com/zekth diff --git a/node_modules/mustache/LICENSE b/node_modules/mustache/LICENSE new file mode 100644 index 000000000..4df7d1aae --- /dev/null +++ b/node_modules/mustache/LICENSE @@ -0,0 +1,11 @@ +The MIT License + +Copyright (c) 2009 Chris Wanstrath (Ruby) +Copyright (c) 2010-2014 Jan Lehnardt (JavaScript) +Copyright (c) 2010-2015 The mustache.js community + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mustache/README.md b/node_modules/mustache/README.md new file mode 100644 index 000000000..127dfe106 --- /dev/null +++ b/node_modules/mustache/README.md @@ -0,0 +1,621 @@ +# mustache.js - Logic-less {{mustache}} templates with JavaScript + +> What could be more logical awesome than no logic at all? + +[![Build Status](https://travis-ci.org/janl/mustache.js.svg?branch=master)](https://travis-ci.org/janl/mustache.js) + +[mustache.js](http://github.com/janl/mustache.js) is a zero-dependency implementation of the [mustache](http://mustache.github.com/) template system in JavaScript. + +[Mustache](http://mustache.github.com/) is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object. + +We call it "logic-less" because there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values. + +For a language-agnostic overview of mustache's template syntax, see the `mustache(5)` [manpage](http://mustache.github.com/mustache.5.html). + +## Where to use mustache.js? + +You can use mustache.js to render mustache templates anywhere you can use JavaScript. This includes web browsers, server-side environments such as [Node.js](http://nodejs.org/), and [CouchDB](http://couchdb.apache.org/) views. + +mustache.js ships with support for the [CommonJS](http://www.commonjs.org/) module API, the [Asynchronous Module Definition](https://github.com/amdjs/amdjs-api/wiki/AMD) API (AMD) and [ECMAScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). + +In addition to being a package to be used programmatically, you can use it as a [command line tool](#command-line-tool). + +And this will be your templates after you use Mustache: + +!['stache](https://cloud.githubusercontent.com/assets/288977/8779228/a3cf700e-2f02-11e5-869a-300312fb7a00.gif) + +## Install + +You can get Mustache via [npm](http://npmjs.com). + +```bash +$ npm install mustache --save +``` + +## Usage + +Below is a quick example how to use mustache.js: + +```js +var view = { + title: "Joe", + calc: function () { + return 2 + 4; + } +}; + +var output = Mustache.render("{{title}} spends {{calc}}", view); +``` + +In this example, the `Mustache.render` function takes two parameters: 1) the [mustache](http://mustache.github.com/) template and 2) a `view` object that contains the data and code needed to render the template. + +## Templates + +A [mustache](http://mustache.github.com/) template is a string that contains any number of mustache tags. Tags are indicated by the double mustaches that surround them. `{{person}}` is a tag, as is `{{#person}}`. In both examples we refer to `person` as the tag's key. There are several types of tags available in mustache.js, described below. + +There are several techniques that can be used to load templates and hand them to mustache.js, here are two of them: + +#### Include Templates + +If you need a template for a dynamic part in a static website, you can consider including the template in the static HTML file to avoid loading templates separately. Here's a small example: + +```js +// file: render.js + +function renderHello() { + var template = document.getElementById('template').innerHTML; + var rendered = Mustache.render(template, { name: 'Luke' }); + document.getElementById('target').innerHTML = rendered; +} +``` + +```html + + +
Loading...
+ + + + + + +``` + +#### Load External Templates + +If your templates reside in individual files, you can load them asynchronously and render them when they arrive. Another example using [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch): + +```js +function renderHello() { + fetch('template.mustache') + .then((response) => response.text()) + .then((template) => { + var rendered = Mustache.render(template, { name: 'Luke' }); + document.getElementById('target').innerHTML = rendered; + }); +} +``` + +### Variables + +The most basic tag type is a simple variable. A `{{name}}` tag renders the value of the `name` key in the current context. If there is no such key, nothing is rendered. + +All variables are HTML-escaped by default. If you want to render unescaped HTML, use the triple mustache: `{{{name}}}`. You can also use `&` to unescape a variable. + +If you'd like to change HTML-escaping behavior globally (for example, to template non-HTML formats), you can override Mustache's escape function. For example, to disable all escaping: `Mustache.escape = function(text) {return text;};`. + +If you want `{{name}}` _not_ to be interpreted as a mustache tag, but rather to appear exactly as `{{name}}` in the output, you must change and then restore the default delimiter. See the [Custom Delimiters](#custom-delimiters) section for more information. + +View: + +```json +{ + "name": "Chris", + "company": "GitHub" +} +``` + +Template: + +``` +* {{name}} +* {{age}} +* {{company}} +* {{{company}}} +* {{&company}} +{{=<% %>=}} +* {{company}} +<%={{ }}=%> +``` + +Output: + +```html +* Chris +* +* <b>GitHub</b> +* GitHub +* GitHub +* {{company}} +``` + +JavaScript's dot notation may be used to access keys that are properties of objects in a view. + +View: + +```json +{ + "name": { + "first": "Michael", + "last": "Jackson" + }, + "age": "RIP" +} +``` + +Template: + +```html +* {{name.first}} {{name.last}} +* {{age}} +``` + +Output: + +```html +* Michael Jackson +* RIP +``` + +### Sections + +Sections render blocks of text zero or more times, depending on the value of the key in the current context. + +A section begins with a pound and ends with a slash. That is, `{{#person}}` begins a `person` section, while `{{/person}}` ends it. The text between the two tags is referred to as that section's "block". + +The behavior of the section is determined by the value of the key. + +#### False Values or Empty Lists + +If the `person` key does not exist, or exists and has a value of `null`, `undefined`, `false`, `0`, or `NaN`, or is an empty string or an empty list, the block will not be rendered. + +View: + +```json +{ + "person": false +} +``` + +Template: + +```html +Shown. +{{#person}} +Never shown! +{{/person}} +``` + +Output: + +```html +Shown. +``` + +#### Non-Empty Lists + +If the `person` key exists and is not `null`, `undefined`, or `false`, and is not an empty list the block will be rendered one or more times. + +When the value is a list, the block is rendered once for each item in the list. The context of the block is set to the current item in the list for each iteration. In this way we can loop over collections. + +View: + +```json +{ + "stooges": [ + { "name": "Moe" }, + { "name": "Larry" }, + { "name": "Curly" } + ] +} +``` + +Template: + +```html +{{#stooges}} +{{name}} +{{/stooges}} +``` + +Output: + +```html +Moe +Larry +Curly +``` + +When looping over an array of strings, a `.` can be used to refer to the current item in the list. + +View: + +```json +{ + "musketeers": ["Athos", "Aramis", "Porthos", "D'Artagnan"] +} +``` + +Template: + +```html +{{#musketeers}} +* {{.}} +{{/musketeers}} +``` + +Output: + +```html +* Athos +* Aramis +* Porthos +* D'Artagnan +``` + +If the value of a section variable is a function, it will be called in the context of the current item in the list on each iteration. + +View: + +```js +{ + "beatles": [ + { "firstName": "John", "lastName": "Lennon" }, + { "firstName": "Paul", "lastName": "McCartney" }, + { "firstName": "George", "lastName": "Harrison" }, + { "firstName": "Ringo", "lastName": "Starr" } + ], + "name": function () { + return this.firstName + " " + this.lastName; + } +} +``` + +Template: + +```html +{{#beatles}} +* {{name}} +{{/beatles}} +``` + +Output: + +```html +* John Lennon +* Paul McCartney +* George Harrison +* Ringo Starr +``` + +#### Functions + +If the value of a section key is a function, it is called with the section's literal block of text, un-rendered, as its first argument. The second argument is a special rendering function that uses the current view as its view argument. It is called in the context of the current view object. + +View: + +```js +{ + "name": "Tater", + "bold": function () { + return function (text, render) { + return "" + render(text) + ""; + } + } +} +``` + +Template: + +```html +{{#bold}}Hi {{name}}.{{/bold}} +``` + +Output: + +```html +Hi Tater. +``` + +### Inverted Sections + +An inverted section opens with `{{^section}}` instead of `{{#section}}`. The block of an inverted section is rendered only if the value of that section's tag is `null`, `undefined`, `false`, *falsy* or an empty list. + +View: + +```json +{ + "repos": [] +} +``` + +Template: + +```html +{{#repos}}{{name}}{{/repos}} +{{^repos}}No repos :({{/repos}} +``` + +Output: + +```html +No repos :( +``` + +### Comments + +Comments begin with a bang and are ignored. The following template: + +```html +

Today{{! ignore me }}.

+``` + +Will render as follows: + +```html +

Today.

+``` + +Comments may contain newlines. + +### Partials + +Partials begin with a greater than sign, like {{> box}}. + +Partials are rendered at runtime (as opposed to compile time), so recursive partials are possible. Just avoid infinite loops. + +They also inherit the calling context. Whereas in ERB you may have this: + +```html+erb +<%= partial :next_more, :start => start, :size => size %> +``` + +Mustache requires only this: + +```html +{{> next_more}} +``` + +Why? Because the `next_more.mustache` file will inherit the `size` and `start` variables from the calling context. In this way you may want to think of partials as includes, imports, template expansion, nested templates, or subtemplates, even though those aren't literally the case here. + + +For example, this template and partial: + + base.mustache: +

Names

+ {{#names}} + {{> user}} + {{/names}} + + user.mustache: + {{name}} + +Can be thought of as a single, expanded template: + +```html +

Names

+{{#names}} + {{name}} +{{/names}} +``` + +In mustache.js an object of partials may be passed as the third argument to `Mustache.render`. The object should be keyed by the name of the partial, and its value should be the partial text. + +```js +Mustache.render(template, view, { + user: userTemplate +}); +``` + +### Custom Delimiters + +Custom delimiters can be used in place of `{{` and `}}` by setting the new values in JavaScript or in templates. + +#### Setting in JavaScript + +The `Mustache.tags` property holds an array consisting of the opening and closing tag values. Set custom values by passing a new array of tags to `render()`, which gets honored over the default values, or by overriding the `Mustache.tags` property itself: + +```js +var customTags = [ '<%', '%>' ]; +``` + +##### Pass Value into Render Method +```js +Mustache.render(template, view, {}, customTags); +``` + +##### Override Tags Property +```js +Mustache.tags = customTags; +// Subsequent parse() and render() calls will use customTags +``` + +#### Setting in Templates + +Set Delimiter tags start with an equals sign and change the tag delimiters from `{{` and `}}` to custom strings. + +Consider the following contrived example: + +```html+erb +* {{ default_tags }} +{{=<% %>=}} +* <% erb_style_tags %> +<%={{ }}=%> +* {{ default_tags_again }} +``` + +Here we have a list with three items. The first item uses the default tag style, the second uses ERB style as defined by the Set Delimiter tag, and the third returns to the default style after yet another Set Delimiter declaration. + +According to [ctemplates](https://htmlpreview.github.io/?https://raw.githubusercontent.com/OlafvdSpek/ctemplate/master/doc/howto.html), this "is useful for languages like TeX, where double-braces may occur in the text and are awkward to use for markup." + +Custom delimiters may not contain whitespace or the equals sign. + +## Pre-parsing and Caching Templates + +By default, when mustache.js first parses a template it keeps the full parsed token tree in a cache. The next time it sees that same template it skips the parsing step and renders the template much more quickly. If you'd like, you can do this ahead of time using `mustache.parse`. + +```js +Mustache.parse(template); + +// Then, sometime later. +Mustache.render(template, view); +``` + +## Command line tool + +mustache.js is shipped with a Node.js based command line tool. It might be installed as a global tool on your computer to render a mustache template of some kind + +```bash +$ npm install -g mustache + +$ mustache dataView.json myTemplate.mustache > output.html +``` + +also supports stdin. + +```bash +$ cat dataView.json | mustache - myTemplate.mustache > output.html +``` + +or as a package.json `devDependency` in a build process maybe? + +```bash +$ npm install mustache --save-dev +``` + +```json +{ + "scripts": { + "build": "mustache dataView.json myTemplate.mustache > public/output.html" + } +} +``` +```bash +$ npm run build +``` + +The command line tool is basically a wrapper around `Mustache.render` so you get all the features. + +If your templates use partials you should pass paths to partials using `-p` flag: + +```bash +$ mustache -p path/to/partial1.mustache -p path/to/partial2.mustache dataView.json myTemplate.mustache +``` + +## Plugins for JavaScript Libraries + +mustache.js may be built specifically for several different client libraries, including the following: + + - [jQuery](http://jquery.com/) + - [MooTools](http://mootools.net/) + - [Dojo](http://www.dojotoolkit.org/) + - [YUI](http://developer.yahoo.com/yui/) + - [qooxdoo](http://qooxdoo.org/) + +These may be built using [Rake](http://rake.rubyforge.org/) and one of the following commands: +```bash +$ rake jquery +$ rake mootools +$ rake dojo +$ rake yui3 +$ rake qooxdoo +``` + +## TypeScript + +Since the source code of this package is written in JavaScript, we follow the [TypeScript publishing docs](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html) preferred approach +by having type definitions available via [@types/mustache](https://www.npmjs.com/package/@types/mustache). + +## Testing + +In order to run the tests you'll need to install [Node.js](http://nodejs.org/). + +You also need to install the sub module containing [Mustache specifications](http://github.com/mustache/spec) in the project root. +```bash +$ git submodule init +$ git submodule update +``` +Install dependencies. +```bash +$ npm install +``` +Then run the tests. +```bash +$ npm test +``` +The test suite consists of both unit and integration tests. If a template isn't rendering correctly for you, you can make a test for it by doing the following: + + 1. Create a template file named `mytest.mustache` in the `test/_files` + directory. Replace `mytest` with the name of your test. + 2. Create a corresponding view file named `mytest.js` in the same directory. + This file should contain a JavaScript object literal enclosed in + parentheses. See any of the other view files for an example. + 3. Create a file with the expected output in `mytest.txt` in the same + directory. + +Then, you can run the test with: +```bash +$ TEST=mytest npm run test-render +``` + +### Browser tests + +Browser tests are not included in `npm test` as they run for too long, although they are ran automatically on Travis when merged into master. Run browser tests locally in any browser: +```bash +$ npm run test-browser-local +``` +then point your browser to `http://localhost:8080/__zuul` + +## Who uses mustache.js? + +An updated list of mustache.js users is kept [on the Github wiki](https://github.com/janl/mustache.js/wiki/Beard-Competition). Add yourself or your company if you use mustache.js! + +## Contributing + +mustache.js is a mature project, but it continues to actively invite maintainers. You can help out a high-profile project that is used in a lot of places on the web. No big commitment required, if all you do is review a single [Pull Request](https://github.com/janl/mustache.js/pulls), you are a maintainer. And a hero. + +### Your First Contribution + +- review a [Pull Request](https://github.com/janl/mustache.js/pulls) +- fix an [Issue](https://github.com/janl/mustache.js/issues) +- update the [documentation](https://github.com/janl/mustache.js#usage) +- make a website +- write a tutorial + +## Thanks + +mustache.js wouldn't kick ass if it weren't for these fine souls: + + * Chris Wanstrath / defunkt + * Alexander Lang / langalex + * Sebastian Cohnen / tisba + * J Chris Anderson / jchris + * Tom Robinson / tlrobinson + * Aaron Quint / quirkey + * Douglas Crockford + * Nikita Vasilyev / NV + * Elise Wood / glytch + * Damien Mathieu / dmathieu + * Jakub Kuźma / qoobaa + * Will Leinweber / will + * dpree + * Jason Smith / jhs + * Aaron Gibralter / agibralter + * Ross Boucher / boucher + * Matt Sanford / mzsanford + * Ben Cherry / bcherry + * Michael Jackson / mjackson + * Phillip Johnsen / phillipj + * David da Silva Contín / dasilvacontin diff --git a/node_modules/mustache/bin/mustache b/node_modules/mustache/bin/mustache new file mode 100644 index 000000000..6db073f5d --- /dev/null +++ b/node_modules/mustache/bin/mustache @@ -0,0 +1,150 @@ +#!/usr/bin/env node + +var fs = require('fs'), + path = require('path'); + +var Mustache = require('..'); +var pkg = require('../package'); +var partials = {}; + +var partialsPaths = []; +var partialArgIndex = -1; + +while ((partialArgIndex = process.argv.indexOf('-p')) > -1) { + partialsPaths.push(process.argv.splice(partialArgIndex, 2)[1]); +} + +var viewArg = process.argv[2]; +var templateArg = process.argv[3]; +var outputArg = process.argv[4]; + +if (hasVersionArg()) { + return console.log(pkg.version); +} + +if (!templateArg || !viewArg) { + console.error('Syntax: mustache