Skip to content

Homework 19 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions js-core/homeworks/homework-19/cat.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
<meta charset="UTF-8">
<title>cat</title>
</head>
<body>
<img src='cat.jpg'>
</body>
</html>
11 changes: 11 additions & 0 deletions js-core/homeworks/homework-19/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home work 19</title>
</head>
<body>

<script src="src/main.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions js-core/homeworks/homework-19/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const http = require('http');
const fs = require('fs');
const port = 3000;

http.createServer( (request, response) =>{
let path = request.url;
if(path == '/'){
path = '/index.html';
}
let source = '';
if (fs.existsSync('.' + path)) {
source = fs.readFileSync('.' + path);
}else{
source = 'no such resource';
response.statusCode = 404;
}
response.end(source);
}).listen(port, (err) => {
if (err) {
return console.log('something bad happened', err);
}
console.log(`server is listening on ${port}`)
})
70 changes: 70 additions & 0 deletions js-core/homeworks/homework-19/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* task 0
Даны строки разделенные различным образом,
верните строки разделенные / или _, в нижнем регистре
solution("ActiveModel::Errors") => active_model/errors"
solution("HelloHowAreYou") => "hello_how_are_you"
solution("MyNAMEIsBOND-JamesBond") => my_name_is_bond_james_bond"
solution("MAINCompany::BEST-MAINUser") => "main_company/best_main_user"
*/

let solution = string => {
string = string.replace('::','/');
string = string.replace('-','_');
let lastModifiedLetterPosition = -2;
const splitAndLower = (match, p1,offset, string) => {
const nextLetter = string.charAt(offset + 1);
const prevLetter = string.charAt(offset - 1);
const isNexLetterSmall = nextLetter.toLowerCase() === nextLetter;
const isNexLetterSubSplitter = nextLetter === '_';
const isPrevLetterSplitter = prevLetter === '/';
const isPrevLetterSubSplitter = prevLetter === '_';
const noSplitter = (
offset == 0 ||
offset == lastModifiedLetterPosition + 1 && (!isNexLetterSmall || isNexLetterSubSplitter) ||
isPrevLetterSplitter ||
isPrevLetterSubSplitter
);
const splitter = noSplitter ? '' : '_';
lastModifiedLetterPosition = offset;
return splitter + p1.toLowerCase();
}
string = string.replace(/([A-Z])/gm,splitAndLower);
return string;
}
console.log("ActiveModel::Errors => ",solution("ActiveModel::Errors"));
console.log("HelloHowAreYou => ",solution("HelloHowAreYou"));
console.log("MyNAMEIsBOND-JamesBond => ",solution("MyNAMEIsBOND-JamesBond"));
console.log("MAINCompany::BEST-MAINUser => ",solution("MAINCompany::BEST-MAINUser"));

/* TASK 0.5
ГОТОВО: Добавить кота в ваш КОД в Node.js !!
КОТА ОСТАВИТЬ
Добавить проверку на существование файла
*/


/* TASK 1
По приложению phone-book;
1. Для каждой страницы у вас должен быть класс с одноименным названием
в отдельном файле
2. Каждый класс должен содержать методы render() - который рендерит всю страницу
3. Удалить jquery.js и bootstrap.js с проекта
-> Закончить keypad с прошлого занятия, добавить функционал для удаления номера
Сортировка таблицы!
Визуализировать страницы Edit contact, User, Add User;
TASK 2
1. keypad - сделать чтобы номер можно было набрать с клавиатуры (!)
2. Формат номера должен быть таким (099)-17-38-170
*/

/*
TASK 3
edit-contact,
- сделать данные редактируемыми (атрибут contentEditable) // input
- изменять backgroundColor
add-user при клике:
index.html/contacts.html - в поле search при вводе буквы,
добавить поиск по имени если имя включает хотя бы одну эту букву.
после ввода каждого символа, фильтровать отображаемых пользователей.
При удалении всех символов отобразить снова весь список
*/