├── .gitignore ├── LICENSE ├── Lesson01 ├── Activity01 │ └── paste_into_console.js ├── Activity02 │ ├── create_elements.js │ ├── css │ │ ├── semantic.min.css │ │ ├── store_with_header.css │ │ └── themes │ │ │ └── default │ │ │ └── assets │ │ │ └── fonts │ │ │ ├── icons.woff │ │ │ └── icons.woff2 │ ├── data │ │ └── products.js │ ├── dynamic_storefront.html │ ├── filter_and_search.js │ ├── images │ │ ├── brick-wall-1245825_1920.jpg │ │ └── products │ │ │ ├── apples.jpg │ │ │ ├── avocado.jpg │ │ │ ├── blueberry_muffins.jpg │ │ │ ├── butter.jpg │ │ │ ├── cherries.jpg │ │ │ ├── chocolate_chips_cookies.png │ │ │ ├── christmas_cookies.jpg │ │ │ ├── croissant.jpg │ │ │ ├── dark_chocolate.jpg │ │ │ ├── eggs.jpg │ │ │ ├── grapes.jpg │ │ │ ├── milk_chocolate.jpg │ │ │ ├── nachos.jpg │ │ │ ├── parmesan.jpg │ │ │ ├── pear.jpg │ │ │ ├── petit_french_baguette.jpg │ │ │ ├── smiley_cookies.jpg │ │ │ ├── strawberries.jpg │ │ │ ├── swiss_cheese.jpg │ │ │ ├── white_chocolate.jpg │ │ │ └── whole_wheat_bread.jpg │ ├── search_box.js │ └── tags_holder.js ├── Example │ ├── css │ │ ├── semantic.min.css │ │ ├── store.css │ │ ├── store_with_header.css │ │ └── themes │ │ │ └── default │ │ │ └── assets │ │ │ └── fonts │ │ │ ├── icons.woff │ │ │ └── icons.woff2 │ ├── data │ │ ├── generate_data.js │ │ └── products.js │ ├── images │ │ ├── brick-wall-1245825_1920.jpg │ │ └── products │ │ │ ├── apples.jpg │ │ │ ├── avocado.jpg │ │ │ ├── blueberry_muffins.jpg │ │ │ ├── butter.jpg │ │ │ ├── cherries.jpg │ │ │ ├── chocolate_chips_cookies.png │ │ │ ├── christmas_cookies.jpg │ │ │ ├── croissant.jpg │ │ │ ├── dark_chocolate.jpg │ │ │ ├── eggs.jpg │ │ │ ├── grapes.jpg │ │ │ ├── milk_chocolate.jpg │ │ │ ├── nachos.jpg │ │ │ ├── parmesan.jpg │ │ │ ├── pear.jpg │ │ │ ├── petit_french_baguette.jpg │ │ │ ├── smiley_cookies.jpg │ │ │ ├── strawberries.jpg │ │ │ ├── swiss_cheese.jpg │ │ │ ├── white_chocolate.jpg │ │ │ └── whole_wheat_bread.jpg │ ├── sample_001 │ │ └── sample-page.html │ ├── sample_002 │ │ └── sample-store-front.html │ ├── sample_003 │ │ ├── create_elements.html │ │ └── create_elements.js │ ├── sample_counter │ │ ├── counter_component.css │ │ ├── counter_component.js │ │ └── web_components.html │ └── sample_shadow_dom │ │ └── shadow_dom.html ├── Exercise01 │ └── alert_paragraphs.html ├── Exercise04 │ ├── open_close_tree_print.js │ └── prettier_tree_print.js ├── Exercise05 │ ├── first_approach.js │ └── second_approach.js ├── Exercise06 │ ├── create_elements.js │ ├── css │ │ ├── semantic.min.css │ │ ├── store_with_header.css │ │ └── themes │ │ │ └── default │ │ │ └── assets │ │ │ └── fonts │ │ │ ├── icons.woff │ │ │ └── icons.woff2 │ ├── data │ │ └── products.js │ ├── dynamic_storefront.html │ ├── filter_and_search.js │ └── images │ │ ├── brick-wall-1245825_1920.jpg │ │ └── products │ │ ├── apples.jpg │ │ ├── avocado.jpg │ │ ├── blueberry_muffins.jpg │ │ ├── butter.jpg │ │ ├── cherries.jpg │ │ ├── chocolate_chips_cookies.png │ │ ├── christmas_cookies.jpg │ │ ├── croissant.jpg │ │ ├── dark_chocolate.jpg │ │ ├── eggs.jpg │ │ ├── grapes.jpg │ │ ├── milk_chocolate.jpg │ │ ├── nachos.jpg │ │ ├── parmesan.jpg │ │ ├── pear.jpg │ │ ├── petit_french_baguette.jpg │ │ ├── smiley_cookies.jpg │ │ ├── strawberries.jpg │ │ ├── swiss_cheese.jpg │ │ ├── white_chocolate.jpg │ │ └── whole_wheat_bread.jpg └── Exercise07 │ ├── create_elements.js │ ├── css │ ├── semantic.min.css │ ├── store_with_header.css │ └── themes │ │ └── default │ │ └── assets │ │ └── fonts │ │ ├── icons.woff │ │ └── icons.woff2 │ ├── data │ └── products.js │ ├── dynamic_storefront.html │ ├── filter_and_search.js │ ├── images │ ├── brick-wall-1245825_1920.jpg │ └── products │ │ ├── apples.jpg │ │ ├── avocado.jpg │ │ ├── blueberry_muffins.jpg │ │ ├── butter.jpg │ │ ├── cherries.jpg │ │ ├── chocolate_chips_cookies.png │ │ ├── christmas_cookies.jpg │ │ ├── croissant.jpg │ │ ├── dark_chocolate.jpg │ │ ├── eggs.jpg │ │ ├── grapes.jpg │ │ ├── milk_chocolate.jpg │ │ ├── nachos.jpg │ │ ├── parmesan.jpg │ │ ├── pear.jpg │ │ ├── petit_french_baguette.jpg │ │ ├── smiley_cookies.jpg │ │ ├── strawberries.jpg │ │ ├── swiss_cheese.jpg │ │ ├── white_chocolate.jpg │ │ └── whole_wheat_bread.jpg │ └── search_box.js ├── Lesson02 ├── Activity03 │ ├── index.js │ ├── package-lock.json │ └── package.json ├── Example │ ├── sample_event_loop │ │ └── event_loop_sample.js │ ├── sample_npm │ │ ├── index.js │ │ └── package.json │ └── sample_scripts │ │ ├── index.js │ │ └── package.json ├── Exercise08 │ └── event_loop.js ├── Exercise09 │ ├── .nvmrc │ └── url_explorer.js └── Exercise10 │ ├── index.js │ ├── package-lock.json │ └── package.json ├── Lesson03 ├── Activity04 │ ├── .gitignore │ ├── index.js │ ├── package-lock.json │ └── package.json ├── Example │ ├── sample_filesystem │ │ ├── .gitignore │ │ ├── copy_file.js │ │ ├── directories_and_files.js │ │ ├── file_status.js │ │ ├── list_dir.js │ │ ├── read_stream.js │ │ └── write_stream.js │ ├── sample_globals │ │ ├── argv.js │ │ ├── console.js │ │ ├── dir_and_filename.js │ │ ├── read_input.js │ │ ├── setInterval.js │ │ └── setTimeout.js │ ├── sample_http │ │ ├── http_client_get.js │ │ ├── http_client_get_with_headers.js │ │ ├── http_client_post.js │ │ └── http_server.js │ └── sample_scraping │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── print_all_paths.js │ │ └── print_all_texts.js ├── Exercise11 │ ├── index.js │ └── package.json ├── Exercise12 │ ├── index.js │ ├── package-lock.json │ └── package.json ├── Exercise13 │ ├── index.js │ ├── package-lock.json │ └── package.json ├── Exercise14 │ ├── html │ │ └── index.html │ ├── index.js │ ├── package-lock.json │ ├── package.json │ ├── products.json │ └── static │ │ ├── css │ │ ├── semantic.min.css │ │ ├── store.css │ │ └── themes │ │ │ └── default │ │ │ └── assets │ │ │ └── fonts │ │ │ ├── icons.woff │ │ │ └── icons.woff2 │ │ └── images │ │ ├── brick-wall-1245825_1920.jpg │ │ └── products │ │ ├── apples.jpg │ │ ├── avocado.jpg │ │ ├── blueberry_muffins.jpg │ │ ├── butter.jpg │ │ ├── cherries.jpg │ │ ├── chocolate_chips_cookies.png │ │ ├── christmas_cookies.jpg │ │ ├── croissant.jpg │ │ ├── dark_chocolate.jpg │ │ ├── eggs.jpg │ │ ├── grapes.jpg │ │ ├── milk_chocolate.jpg │ │ ├── nachos.jpg │ │ ├── parmesan.jpg │ │ ├── pear.jpg │ │ ├── petit_french_baguette.jpg │ │ ├── smiley_cookies.jpg │ │ ├── strawberries.jpg │ │ ├── swiss_cheese.jpg │ │ ├── white_chocolate.jpg │ │ └── whole_wheat_bread.jpg └── Exercise15 │ ├── index.js │ ├── package-lock.json │ └── package.json ├── Lesson04 ├── Activity05 │ ├── config.js │ ├── package-lock.json │ ├── package.json │ ├── routes │ │ ├── check-in.js │ │ └── lock.js │ └── server.js ├── Example │ ├── Example18b │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── routes │ │ │ ├── devices │ │ │ │ ├── light.js │ │ │ │ └── lightStructure.js │ │ │ └── index.js │ │ └── server.js │ ├── heater │ │ ├── README.md │ │ ├── config.js │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── routes │ │ │ ├── check-in.js │ │ │ ├── devices │ │ │ │ ├── heater.js │ │ │ │ ├── light.js │ │ │ │ └── lightStructure.js │ │ │ └── index.js │ │ └── server.js │ └── mongo_logger_middleware │ │ ├── README.md │ │ ├── config.js │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── routes │ │ ├── check-in.js │ │ ├── devices │ │ │ ├── light.js │ │ │ └── lightStructure.js │ │ └── index.js │ │ └── server.js ├── Exercise16 │ ├── package-lock.json │ ├── package.json │ └── server.js ├── Exercise17 │ ├── package-lock.json │ ├── package.json │ ├── routes │ │ └── index.js │ └── server.js ├── Exercise18 │ ├── package-lock.json │ ├── package.json │ ├── routes │ │ ├── devices │ │ │ └── light.js │ │ └── index.js │ └── server.js ├── Exercise19 │ ├── package-lock.json │ ├── package.json │ ├── routes │ │ ├── devices │ │ │ ├── light.js │ │ │ └── lightStructure.js │ │ └── index.js │ └── server.js ├── Exercise20 │ ├── package-lock.json │ ├── package.json │ ├── routes │ │ ├── devices │ │ │ ├── light.js │ │ │ └── lightStructure.js │ │ └── index.js │ └── server.js └── Exercise21 │ ├── config.js │ ├── package-lock.json │ ├── package.json │ ├── routes │ ├── check-in.js │ ├── devices │ │ ├── light.js │ │ └── lightStructure.js │ └── index.js │ └── server.js ├── Lesson05 ├── Activtiy06 │ ├── .babelrc │ ├── .gitignore │ ├── build │ │ ├── bundle.js │ │ ├── images │ │ │ ├── bulb_off.png │ │ │ └── bulb_on.png │ │ ├── index.html │ │ └── js │ │ │ ├── __extra__ │ │ │ └── changeColor.js │ │ │ ├── colorLight.js │ │ │ ├── flashingLight.js │ │ │ ├── light.js │ │ │ └── viewer.js │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── images │ │ │ ├── bulb_off.png │ │ │ └── bulb_on.png │ │ ├── index.html │ │ └── js │ │ │ ├── __extra__ │ │ │ └── changeColor.js │ │ │ ├── colorLight.js │ │ │ ├── flashingLight.js │ │ │ ├── light.js │ │ │ └── viewer.js │ └── webpack.config.js ├── Exercise22 │ ├── .gitignore │ ├── images │ │ ├── bulb_off.png │ │ └── bulb_on.png │ ├── index.html │ ├── js │ │ ├── __extra__ │ │ │ └── changeColor.js │ │ ├── light.js │ │ └── viewer.js │ ├── package-lock.json │ └── package.json ├── Exercise23 │ └── number.js ├── Exercise24 │ ├── .gitignore │ ├── images │ │ ├── bulb_off.png │ │ └── bulb_on.png │ ├── index.html │ ├── js │ │ ├── __extra__ │ │ │ └── changeColor.js │ │ ├── light.js │ │ └── viewer.js │ ├── package-lock.json │ └── package.json ├── Exercise25 │ ├── .gitignore │ ├── images │ │ ├── bulb_off.png │ │ └── bulb_on.png │ ├── index.html │ ├── js │ │ ├── __extra__ │ │ │ └── changeColor.js │ │ ├── light.js │ │ └── viewer.js │ ├── package-lock.json │ └── package.json ├── Exercise26 │ ├── .gitignore │ ├── images │ │ ├── bulb_off.png │ │ └── bulb_on.png │ ├── index.html │ ├── js │ │ ├── __extra__ │ │ │ └── changeColor.js │ │ ├── colorLight.js │ │ ├── light.js │ │ └── viewer.js │ ├── package-lock.json │ └── package.json ├── Exercise27 │ ├── .gitignore │ ├── images │ │ ├── bulb_off.png │ │ └── bulb_on.png │ ├── index.html │ ├── js │ │ ├── __extra__ │ │ │ └── changeColor.js │ │ ├── colorLight.js │ │ ├── light.js │ │ └── viewer.js │ ├── package-lock.json │ └── package.json ├── Exercise28 │ ├── .babelrc │ ├── .gitignore │ ├── build │ │ ├── bundle.js │ │ ├── images │ │ │ ├── bulb_off.png │ │ │ └── bulb_on.png │ │ ├── index.html │ │ └── js │ │ │ ├── __extra__ │ │ │ └── changeColor.js │ │ │ ├── colorLight.js │ │ │ ├── light.js │ │ │ └── viewer.js │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── images │ │ │ ├── bulb_off.png │ │ │ └── bulb_on.png │ │ ├── index.html │ │ └── js │ │ │ ├── __extra__ │ │ │ └── changeColor.js │ │ │ ├── colorLight.js │ │ │ ├── light.js │ │ │ └── viewer.js │ └── webpack.config.js └── start │ ├── .gitignore │ ├── images │ ├── bulb_off.png │ └── bulb_on.png │ ├── index.html │ ├── js │ └── viewer.js │ ├── package-lock.json │ └── package.json ├── Lesson06 ├── .gitignore ├── Activity07 │ ├── result │ │ ├── .eslintrc │ │ ├── .gitignore │ │ ├── .huskyrc │ │ ├── .prettierignore │ │ ├── __tests__ │ │ │ └── calc.test.js │ │ ├── css │ │ │ └── style.css │ │ ├── images │ │ │ └── screenshot.png │ │ ├── index.html │ │ ├── jest-puppeteer.config.js │ │ ├── js │ │ │ └── index.js │ │ ├── package-lock.json │ │ └── package.json │ └── start │ │ ├── .gitignore │ │ ├── css │ │ └── style.css │ │ ├── images │ │ └── screenshot.png │ │ ├── index.html │ │ ├── js │ │ └── index.js │ │ ├── package-lock.json │ │ └── package.json ├── Exercise29 │ ├── result │ │ ├── .eslintrc │ │ ├── .gitignore │ │ ├── .prettierignore │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ │ └── square.js │ └── start │ │ └── .gitignore ├── Exercise30 │ ├── result │ │ ├── __test__ │ │ │ └── math.test.js │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ │ └── math.js │ └── start │ │ └── src │ │ └── math.js ├── Exercise31 │ ├── result │ │ ├── __test__ │ │ │ └── math.test.js │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ │ └── math.js │ └── start │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ └── math.js ├── Exercise32 │ ├── result │ │ ├── __tests__ │ │ │ └── fib.test.js │ │ ├── fastFib.js │ │ ├── package.json │ │ ├── slowFib.js │ │ └── yarn.lock │ └── start │ │ ├── fastFib.js │ │ ├── package.json │ │ ├── slowFib.js │ │ └── yarn.lock ├── Exercise33 │ ├── .gitignore │ ├── result │ │ ├── .gitignore │ │ ├── __tests__ │ │ │ └── test.test.js │ │ ├── css │ │ │ └── style.css │ │ ├── images │ │ │ └── screenshot.png │ │ ├── index.html │ │ ├── jest-puppeteer.config.js │ │ ├── js │ │ │ └── index.js │ │ ├── package-lock.json │ │ └── package.json │ └── start │ │ ├── .gitignore │ │ ├── css │ │ └── style.css │ │ ├── images │ │ └── screenshot.png │ │ ├── index.html │ │ ├── js │ │ └── index.js │ │ ├── package-lock.json │ │ └── package.json ├── Exercise34 │ ├── result │ │ └── README.md │ └── start │ │ ├── .eslintrc │ │ ├── .gitignore │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ └── js.js ├── Exercise35 │ ├── result │ │ ├── .eslintrc │ │ ├── .gitignore │ │ ├── .huskyrc │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ │ └── js.js │ └── start │ │ ├── .eslintrc │ │ ├── .gitignore │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ └── js.js └── Exercise36 │ ├── .gitignore │ ├── result │ ├── .gitignore │ ├── __test__ │ │ └── quiz.test.js │ ├── index.html │ ├── jest-puppeteer.config.js │ ├── js │ │ ├── main.js │ │ └── questions.js │ ├── package-lock.json │ └── package.json │ └── start │ ├── .gitignore │ ├── index.html │ ├── js │ ├── main.js │ └── questions.js │ └── package.json ├── Lesson07 ├── Activity08 │ └── Activity08.js ├── Activity09 │ └── Activity09.js ├── Activity10 │ ├── Activity10.js │ └── Activity10_Solution.js ├── Exercise37 │ └── Exercise37.js ├── Exercise38 │ └── Exercise38.js ├── Exercise39 │ └── Exercise39.js ├── Exercise40 │ └── Exercise40.js ├── Exercise41 │ └── Exercise41.js ├── Exercise42 │ └── Exercise42.js ├── Exercise43 │ └── Exercise43.js ├── Exercise44 │ └── Exercise44.js ├── Exercise45 │ └── Exercise45.js ├── Exercise46 │ └── Exercise46.js ├── Exercise47 │ └── Exercise47.js ├── Exercise48 │ └── Exercise48.js ├── Exercise49 │ └── Exercise49.js ├── Exercise50 │ └── Exercise50.js ├── Exercise51 │ └── Exercise51.js ├── Exercise52 │ └── Exercise52.js ├── Exercise53 │ └── Exercise53.js ├── Exercise54 │ └── Exercise54.js ├── Exercise55 │ └── Exercise55.js ├── Exercise56 │ └── Exercise56.js ├── Exercise57 │ └── Exercise57.js ├── Exercise58 │ └── Exercise58.js ├── Exercise59 │ └── Exercise59.js └── Exercise60 │ └── Exercise60.js ├── Lesson08 ├── Activity11 │ └── Activity11.js ├── Activity12 │ └── Activity12.js ├── Exercise61 │ └── Exercise61.js ├── Exercise62 │ └── Exercise62.js ├── Exercise63 │ └── Exercise63.js ├── Exercise64 │ └── Exercise64.js ├── Exercise65 │ └── Exercise65.js └── Exercise66 │ └── Exercise66.js ├── Lesson09 ├── Activity13 │ └── events.js ├── Activity14 │ └── filewatcher.js ├── Exercise67 │ └── Exercise67.js ├── Exercise68 │ └── Exercise68.js └── Exercise69 │ └── Exercise69.js ├── Lesson10 ├── .gitignore ├── Activity15 │ ├── activity-on-checkout-prop-start.html │ ├── activity-on-checkout-prop-start.js │ ├── activity-on-checkout-prop.html │ ├── activity-on-checkout-prop.js │ └── package.json ├── Activity16 │ ├── activity-items-selector-test-start.js │ ├── activity-items-selector-test.js │ └── package.json ├── Activity17 │ ├── activity-app-start.html │ ├── activity-app-start.js │ ├── activity-app.html │ ├── activity-app.js │ ├── activity-bff.js │ └── package.json ├── Examples │ ├── 01-first-class │ │ ├── .babelrc │ │ ├── example-1-functions-as-values.js │ │ ├── example-10-this-react-issues.html │ │ ├── example-10-this-react-issues.js │ │ ├── example-2-inversion-of-control.js │ │ ├── example-3-add-event-listener.js │ │ ├── example-4-fs-readdir-callback.js │ │ ├── example-5-fetch-then.js │ │ ├── example-6-fs-readdir-promise.js │ │ ├── example-7-array-first-class.js │ │ ├── example-8-parent-child-react.html │ │ ├── example-8-parent-child-react.js │ │ ├── example-9-child-parent-react.html │ │ ├── example-9-child-parent-react.js │ │ ├── example-render-prop.js │ │ ├── package.json │ │ └── test.js │ ├── 02-pure │ │ ├── example-1-double-test.js │ │ ├── example-redux-counter.js │ │ └── package.json │ ├── 03-higher-order │ │ ├── example-1-react-bind.html │ │ ├── example-1-react-bind.js │ │ ├── example-2-test-parameter-bind.js │ │ ├── example-3-function-prototype-bind-call.js │ │ ├── example-4-array-like-array.js │ │ ├── example-5-sum-curried.js │ │ ├── example-6-partial-sum.js │ │ ├── example-7-generic-curry.js │ │ ├── example-8-revealing-module.js │ │ ├── example-9-function-comp-react.html │ │ ├── example-9-function-comp-react.js │ │ └── package.json │ ├── 04-composition │ │ ├── example-1-sum-simple-compose.js │ │ ├── example-2-micro-hello.js │ │ ├── example-3-request-timer.js │ │ ├── example-4-api-key-auth.js │ │ ├── example-5-express-api-key-auth.js │ │ └── package.json │ └── 05-immutability-side-effects │ │ ├── example-1-redux-action-creator.js │ │ ├── example-2-immutable-map-filter-reduce.js │ │ ├── example-3-immutable-object-rest-spread.js │ │ ├── example-4-immutable-array-rest-spread.js │ │ ├── example-5-immutable-object-freeze.js │ │ ├── example-6-component-did-mount-request.html │ │ ├── example-6-component-did-mount-request.js │ │ ├── example-7-use-effect-request.html │ │ ├── example-7-use-effect-request.js │ │ ├── example-8-thunk-usage.js │ │ ├── example-9-redux-thunk-request.html │ │ ├── example-9-redux-thunk-request.js │ │ ├── package.json │ │ └── schema.graphql ├── Exercise70 │ ├── exercise-re-implement-array-methods-start.js │ ├── exercise-re-implement-array-methods.js │ └── package.json ├── Exercise71 │ ├── exercise-price-of-basket-start.js │ ├── exercise-price-of-basket.js │ └── package.json ├── Exercise72 │ ├── exercise-add-product-start.html │ ├── exercise-add-product-start.js │ ├── exercise-add-product.html │ ├── exercise-add-product.js │ └── package.json ├── Exercise73 │ ├── exercise-render-prop-start.html │ ├── exercise-render-prop-start.js │ ├── exercise-render-prop.html │ ├── exercise-render-prop.js │ └── package.json ├── Exercise74 │ ├── exercise-redux-dispatch-start.html │ ├── exercise-redux-dispatch-start.js │ ├── exercise-redux-dispatch.html │ ├── exercise-redux-dispatch.js │ └── package.json ├── Exercise75 │ ├── exercise-reducer-test-start.js │ ├── exercise-reducer-test.js │ └── package.json ├── Exercise76 │ ├── exercise-items-selector-start.html │ ├── exercise-items-selector-start.js │ ├── exercise-items-selector.html │ ├── exercise-items-selector.js │ └── package.json ├── Exercise77 │ ├── exercise-2-to-n-compose-start.js │ ├── exercise-2-to-n-compose.js │ └── package.json ├── Exercise78 │ ├── exercise-micro-compose-start.js │ ├── exercise-micro-compose.js │ └── package.json ├── Exercise79 │ ├── exercise-refactor-action-creators-start.html │ ├── exercise-refactor-action-creators-start.js │ ├── exercise-refactor-action-creators.html │ ├── exercise-refactor-action-creators.js │ └── package.json ├── Exercise80 │ ├── exercise-map-to-props-start.html │ ├── exercise-map-to-props-start.js │ ├── exercise-map-to-props.html │ ├── exercise-map-to-props.js │ └── package.json ├── Exercise81 │ ├── exercise-graphql-micro-start.js │ ├── exercise-graphql-micro.js │ └── package.json └── package.json └── README.md /Lesson01/Activity01/paste_into_console.js: -------------------------------------------------------------------------------- 1 | var csv = 'name,price,unit\n'; 2 | var elements = Array.from(document.getElementsByClassName('item')); 3 | elements.forEach((el) => { 4 | var priceAndUnitElement = el.getElementsByTagName('span')[0]; 5 | var priceAndUnit = priceAndUnitElement.textContent.split("/"); 6 | var price = priceAndUnit[0].trim(); 7 | var unit = priceAndUnit[1].trim(); 8 | 9 | var name = el.getElementsByTagName('a')[0].textContent; 10 | 11 | csv += `${name},${price},${unit}\n`; 12 | }); 13 | console.log(csv); 14 | -------------------------------------------------------------------------------- /Lesson01/Activity02/css/themes/default/assets/fonts/icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/css/themes/default/assets/fonts/icons.woff -------------------------------------------------------------------------------- /Lesson01/Activity02/css/themes/default/assets/fonts/icons.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/css/themes/default/assets/fonts/icons.woff2 -------------------------------------------------------------------------------- /Lesson01/Activity02/dynamic_storefront.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 |

Welcome to Fresh Products Store!

10 | 11 | 17 |
18 | 19 |
20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Lesson01/Activity02/images/brick-wall-1245825_1920.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/brick-wall-1245825_1920.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/apples.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/apples.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/avocado.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/avocado.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/blueberry_muffins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/blueberry_muffins.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/butter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/butter.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/cherries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/cherries.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/chocolate_chips_cookies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/chocolate_chips_cookies.png -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/christmas_cookies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/christmas_cookies.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/croissant.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/croissant.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/dark_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/dark_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/eggs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/eggs.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/grapes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/grapes.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/milk_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/milk_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/nachos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/nachos.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/parmesan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/parmesan.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/pear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/pear.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/petit_french_baguette.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/petit_french_baguette.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/smiley_cookies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/smiley_cookies.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/strawberries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/strawberries.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/swiss_cheese.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/swiss_cheese.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/white_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/white_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Activity02/images/products/whole_wheat_bread.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Activity02/images/products/whole_wheat_bread.jpg -------------------------------------------------------------------------------- /Lesson01/Example/css/store.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-attachment: fixed; 3 | background-image: url('../images/brick-wall-1245825_1920.jpg'); 4 | } 5 | 6 | body > section { 7 | background: rgba(200, 200, 200, 0.4); 8 | height: 100%; 9 | margin: 0 auto; 10 | overflow-y: scroll; 11 | padding: 10px 20px; 12 | width: 1024px; 13 | } 14 | 15 | h1.title { 16 | color: #6b2a13; 17 | font-size: 3em; 18 | } 19 | 20 | .ui.items .item { 21 | background: rgba(250, 250, 250, 0.8); 22 | border-radius: 5px; 23 | box-shadow: #444 2px 2px 5px; 24 | padding: 10px; 25 | } 26 | 27 | .ui.items .item img { 28 | max-height: 150px; 29 | } 30 | -------------------------------------------------------------------------------- /Lesson01/Example/css/themes/default/assets/fonts/icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/css/themes/default/assets/fonts/icons.woff -------------------------------------------------------------------------------- /Lesson01/Example/css/themes/default/assets/fonts/icons.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/css/themes/default/assets/fonts/icons.woff2 -------------------------------------------------------------------------------- /Lesson01/Example/data/generate_data.js: -------------------------------------------------------------------------------- 1 | // Use this script to generate the products.js content from the storefront HTML 2 | const productsString = JSON.stringify(Array.from(document.querySelectorAll('.item')) 3 | .map(pEl => { 4 | const priceWithUnit = pEl.querySelector('.meta span').innerHTML.split(' / '); 5 | 6 | let o = {}; 7 | o.price = parseFloat(priceWithUnit[0].substr(1)); 8 | o.unit = priceWithUnit[1]; 9 | o.name = pEl.querySelector('a').innerHTML; 10 | o.description = pEl.querySelector('.description').innerHTML; 11 | o.image = pEl.querySelector('img').getAttribute('src'); 12 | o.tags = []; 13 | Array.from(pEl.querySelectorAll('.label')) 14 | .forEach(l => o.tags.push(l.innerHTML)); 15 | 16 | return o; 17 | }), null, 2); 18 | 19 | console.log(`const products = ${productsString};\n`); 20 | -------------------------------------------------------------------------------- /Lesson01/Example/images/brick-wall-1245825_1920.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/brick-wall-1245825_1920.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/apples.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/apples.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/avocado.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/avocado.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/blueberry_muffins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/blueberry_muffins.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/butter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/butter.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/cherries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/cherries.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/chocolate_chips_cookies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/chocolate_chips_cookies.png -------------------------------------------------------------------------------- /Lesson01/Example/images/products/christmas_cookies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/christmas_cookies.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/croissant.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/croissant.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/dark_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/dark_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/eggs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/eggs.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/grapes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/grapes.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/milk_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/milk_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/nachos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/nachos.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/parmesan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/parmesan.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/pear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/pear.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/petit_french_baguette.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/petit_french_baguette.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/smiley_cookies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/smiley_cookies.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/strawberries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/strawberries.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/swiss_cheese.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/swiss_cheese.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/white_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/white_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Example/images/products/whole_wheat_bread.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Example/images/products/whole_wheat_bread.jpg -------------------------------------------------------------------------------- /Lesson01/Example/sample_001/sample-page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Sample Page 4 | 5 | 6 |

This is a paragraph.

7 |
8 |

This is a paragraph inside a div.

9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Lesson01/Example/sample_003/create_elements.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |

Welcome to Fresh Products Store!

9 | 10 |
11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Lesson01/Example/sample_counter/counter_component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | display: inline-block; 3 | font-family: sans-serif; 4 | font-size: 0.9em; 5 | margin: 5px 10px; 6 | } 7 | 8 | span { 9 | display: inline-block; 10 | padding: 0 5px; 11 | } 12 | -------------------------------------------------------------------------------- /Lesson01/Example/sample_counter/web_components.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Web Components Example 4 | 5 | 6 | 7 | 8 |
9 |
10 | 11 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Lesson01/Example/sample_shadow_dom/shadow_dom.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Shadow DOM Sample Code 4 | 10 | 11 | 12 |

This is a normal paragraph.

13 | 14 |

I'm in a Shadow DOM tree.

15 | 16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Lesson01/Exercise01/alert_paragraphs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Sample Page 4 | 5 | 6 |

This is a paragraph.

7 |
8 |

This is a paragraph inside a div.

9 |
10 | 11 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Lesson01/Exercise04/open_close_tree_print.js: -------------------------------------------------------------------------------- 1 | function printNodes(node, level) { 2 | let message = `${"-".repeat(4 * level)}Node: ${node.nodeName}`; 3 | if (node.nodeValue) { 4 | message += `, content: '${node.nodeValue.trim()}'`; 5 | } 6 | 7 | console.log(message); 8 | var children = node.childNodes || []; 9 | for (var i = 0; i < children.length; i++) { 10 | printNodes(children[i], level + 1); 11 | } 12 | if (children.length > 0) { 13 | console.log(`${"-".repeat(4 * level)}End of: ${node.nodeName}`); 14 | } 15 | } 16 | printNodes(document, 0); 17 | -------------------------------------------------------------------------------- /Lesson01/Exercise04/prettier_tree_print.js: -------------------------------------------------------------------------------- 1 | function printNodes(node, indent) { 2 | if (node.parentNode === null) { 3 | console.log(node.nodeName); 4 | } else { 5 | console.log(`${indent}+---${node.nodeName}`); 6 | indent += node.nextSibling === null ? " " : "| "; 7 | } 8 | 9 | var children = node.childNodes || []; 10 | for (var i = 0; i < children.length; i++) { 11 | printNodes(children[i], indent); 12 | } 13 | } 14 | 15 | printNodes(document, ""); 16 | -------------------------------------------------------------------------------- /Lesson01/Exercise05/first_approach.js: -------------------------------------------------------------------------------- 1 | function containLabels(element, ...labelsToCheck) { 2 | // Query for all label elements in the specified element 3 | const intersection = Array.from(element.querySelectorAll('.label')) 4 | 5 | // map to the label text 6 | .map(e => e.innerHTML) 7 | 8 | // check if the label is in the passed in array 9 | .filter(l => labelsToCheck.includes(l)); 10 | 11 | // If the intersection is equal to the passed in array, we have a match 12 | return intersection.length == labelsToCheck.length; 13 | } 14 | 15 | // 1 - Start from the product root element 16 | Array.from(document.querySelectorAll('.item')) 17 | 18 | // 2 - Filter the list to only include the ones with both labels 19 | .filter(e => containLabels(e, 'organic', 'fruit')) 20 | 21 | // 3 - Find the product name 22 | .map(p => p.querySelector('.content a.header')) 23 | .map(a => a.innerHTML) 24 | 25 | // 4 - Print to the console 26 | .forEach(console.log); 27 | -------------------------------------------------------------------------------- /Lesson01/Exercise06/css/themes/default/assets/fonts/icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/css/themes/default/assets/fonts/icons.woff -------------------------------------------------------------------------------- /Lesson01/Exercise06/css/themes/default/assets/fonts/icons.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/css/themes/default/assets/fonts/icons.woff2 -------------------------------------------------------------------------------- /Lesson01/Exercise06/dynamic_storefront.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 |

Welcome to Fresh Products Store!

10 | 11 | 22 |
23 | 24 |
25 |
26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/brick-wall-1245825_1920.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/brick-wall-1245825_1920.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/apples.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/apples.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/avocado.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/avocado.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/blueberry_muffins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/blueberry_muffins.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/butter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/butter.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/cherries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/cherries.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/chocolate_chips_cookies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/chocolate_chips_cookies.png -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/christmas_cookies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/christmas_cookies.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/croissant.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/croissant.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/dark_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/dark_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/eggs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/eggs.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/grapes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/grapes.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/milk_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/milk_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/nachos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/nachos.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/parmesan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/parmesan.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/pear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/pear.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/petit_french_baguette.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/petit_french_baguette.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/smiley_cookies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/smiley_cookies.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/strawberries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/strawberries.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/swiss_cheese.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/swiss_cheese.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/white_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/white_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise06/images/products/whole_wheat_bread.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise06/images/products/whole_wheat_bread.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/css/themes/default/assets/fonts/icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/css/themes/default/assets/fonts/icons.woff -------------------------------------------------------------------------------- /Lesson01/Exercise07/css/themes/default/assets/fonts/icons.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/css/themes/default/assets/fonts/icons.woff2 -------------------------------------------------------------------------------- /Lesson01/Exercise07/dynamic_storefront.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 |

Welcome to Fresh Products Store!

10 | 11 | 19 |
20 | 21 |
22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/brick-wall-1245825_1920.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/brick-wall-1245825_1920.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/apples.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/apples.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/avocado.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/avocado.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/blueberry_muffins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/blueberry_muffins.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/butter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/butter.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/cherries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/cherries.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/chocolate_chips_cookies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/chocolate_chips_cookies.png -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/christmas_cookies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/christmas_cookies.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/croissant.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/croissant.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/dark_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/dark_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/eggs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/eggs.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/grapes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/grapes.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/milk_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/milk_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/nachos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/nachos.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/parmesan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/parmesan.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/pear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/pear.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/petit_french_baguette.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/petit_french_baguette.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/smiley_cookies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/smiley_cookies.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/strawberries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/strawberries.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/swiss_cheese.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/swiss_cheese.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/white_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/white_chocolate.jpg -------------------------------------------------------------------------------- /Lesson01/Exercise07/images/products/whole_wheat_bread.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson01/Exercise07/images/products/whole_wheat_bread.jpg -------------------------------------------------------------------------------- /Lesson02/Activity03/index.js: -------------------------------------------------------------------------------- 1 | const cheerio = require('cheerio'); 2 | 3 | const html = ` 4 | 5 | 6 | Sample Page 7 | 8 | 9 |

This is a paragraph.

10 |
11 |

This is a paragraph inside a div.

12 |
13 | 14 | 15 | 16 | `; 17 | 18 | const $ = cheerio.load(html); 19 | 20 | $('div').append('

This is another paragraph.

'); 21 | 22 | $('p').each((index, p) => { 23 | console.log(`${index} - ${p.firstChild.data}`); 24 | }); 25 | 26 | console.log($.html()); 27 | -------------------------------------------------------------------------------- /Lesson02/Activity03/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Activity03", 3 | "version": "1.0.0", 4 | "description": "Solution for activity in lesson 2", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/TrainingByPackt/Professional-JavaScript.git", 9 | "directory": "Lesson02/Activity03" 10 | }, 11 | "author": "", 12 | "license": "MIT", 13 | "dependencies": { 14 | "cheerio": "^1.0.0-rc.3" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson02/Example/sample_event_loop/event_loop_sample.js: -------------------------------------------------------------------------------- 1 | console.log('First'); 2 | 3 | setTimeout(() => { 4 | console.log('Last'); 5 | }, 100); 6 | 7 | console.log('Second'); 8 | -------------------------------------------------------------------------------- /Lesson02/Example/sample_npm/index.js: -------------------------------------------------------------------------------- 1 | console.log("I'm an npm package running from sample_npm"); 2 | -------------------------------------------------------------------------------- /Lesson02/Example/sample_npm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sample_npm", 3 | "version": "1.0.0", 4 | "description": "Sample project for the Professional Javascript courseware.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/TrainingByPackt/Professional-JavaScript.git" 12 | }, 13 | "author": "", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/TrainingByPackt/Professional-JavaScript/issues" 17 | }, 18 | "homepage": "https://github.com/TrainingByPackt/Professional-JavaScript#readme" 19 | } 20 | -------------------------------------------------------------------------------- /Lesson02/Example/sample_scripts/index.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const name = ('' + fs.readFileSync('name.txt')).trim(); 3 | console.log(`Hello ${name}!`); 4 | -------------------------------------------------------------------------------- /Lesson02/Example/sample_scripts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sample_scripts", 3 | "version": "1.0.0", 4 | "description": "Sample code to demonstrate npm scripts", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | 9 | "myscript": "echo 'Hello World!'", 10 | 11 | "preexec": "echo 'John Doe' > name.txt", 12 | "exec": "node index.js", 13 | "postexec": "rm -v name.txt", 14 | 15 | "prestart": "echo 'John Doe' > name.txt", 16 | "start": "node index.js", 17 | "poststart": "rm -v name.txt" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git+https://github.com/TrainingByPackt/Professional-JavaScript.git", 22 | "directory": "Lesson02/Example/sample_scripts" 23 | }, 24 | "author": "", 25 | "license": "MIT" 26 | } 27 | -------------------------------------------------------------------------------- /Lesson02/Exercise08/event_loop.js: -------------------------------------------------------------------------------- 1 | console.log('First'); 2 | 3 | const start = Date.now(); 4 | setTimeout(() => { 5 | console.log(`Last, after: ${Date.now() - start}ms`); 6 | }, 100); 7 | 8 | console.log('Second'); 9 | -------------------------------------------------------------------------------- /Lesson02/Exercise09/.nvmrc: -------------------------------------------------------------------------------- 1 | 12.7.0 2 | -------------------------------------------------------------------------------- /Lesson02/Exercise09/url_explorer.js: -------------------------------------------------------------------------------- 1 | const url = new URL('https://www.someserver.com/not/a/path?param1=value1¶m2=value2'); 2 | console.log(`URL is: ${url.href}`); 3 | console.log(`Hostname: ${url.hostname}`); 4 | console.log(`Path: ${url.pathname}`); 5 | 6 | console.log(`Query string is: ${url.search}`); 7 | console.log('Query parameters:') 8 | Array.from(url.searchParams.entries()) 9 | .forEach((entry) => console.log(`\t- ${entry[0]} = ${entry[1]}`)); 10 | -------------------------------------------------------------------------------- /Lesson02/Exercise10/index.js: -------------------------------------------------------------------------------- 1 | const program = require('commander'); 2 | 3 | program.version('0.1.0') 4 | .option('-b, --add-bootstrap', 'Add Bootstrap 4 to the page.') 5 | .option('-c, --add-container', 'Adds a div with container id in the body.') 6 | .option('-t, --title [title]', 'Add a title to the page.') 7 | .parse(process.argv); 8 | 9 | let html = ''; 10 | 11 | if (program.title) { 12 | html += `${program.title}`; 13 | } 14 | 15 | if (program.addBootstrap) { 16 | html += ' { 6 | if (error == null) { 7 | console.log('File exists and is readable'); 8 | } else { 9 | console.log(error.message); 10 | } 11 | }); 12 | 13 | fs.lstat(filename, (statError, stat) => { 14 | if (statError != null) { 15 | console.error('Error while file status.', statError); 16 | return; 17 | } 18 | 19 | console.log(`Is file: ${stat.isFile()}`); 20 | console.log(`Is directory: ${stat.isDirectory()}`); 21 | console.log(`Created at: ${stat.birthtime}`); 22 | console.log(`Last modified at: ${stat.mtime}`); 23 | }); 24 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_filesystem/list_dir.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | fs.readdir('./', (error, files) => { 4 | if (error != null) { 5 | console.error('Error while reading directory.', error); 6 | return; 7 | } 8 | 9 | console.log('-- File names --'); 10 | console.log(files.join('\n')); 11 | }); 12 | 13 | fs.readdir('./', { withFileTypes: true }, (error, files) => { 14 | if (error != null) { 15 | console.error('Error while reading directory.', error); 16 | return; 17 | } 18 | 19 | console.log('-- File infos --'); 20 | console.log(files.map(d => `(${d.isDirectory() ? 'D': 'F'}) ${d.name}`) 21 | .sort() 22 | .join('\n')); 23 | }); 24 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_filesystem/read_stream.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | const readStream = fs.createReadStream(__filename); 4 | 5 | readStream.on('data', (data) => console.log(`--data--\n${data}`)); 6 | readStream.on('ready', () => console.log(`--ready--`)); 7 | readStream.on('close', () => console.log(`--close--`)); 8 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_filesystem/write_stream.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const writable = fs.createWriteStream('todo.txt'); 3 | 4 | writable.on('finish', () => console.log("-- finish --")); 5 | writable.on('close', () => console.log("-- close --")); 6 | 7 | writable.write('- Buy milk\n'); 8 | writable.write('- Buy eggs\n'); 9 | writable.write('- Buy cheese\n'); 10 | 11 | writable.end(); 12 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_globals/argv.js: -------------------------------------------------------------------------------- 1 | console.log(`Arguments are:\n${process.argv.join('\n')}`); 2 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_globals/dir_and_filename.js: -------------------------------------------------------------------------------- 1 | console.log(`This script is in: ${__dirname}`); 2 | console.log(`The full path for this file is: ${__filename}`); 3 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_globals/read_input.js: -------------------------------------------------------------------------------- 1 | process.stdout.write('Type something then press [ENTER]\n'); 2 | process.stdout.write('> '); 3 | 4 | process.stdin.addListener('data', (data) => { 5 | const text = data.toString().trim(); 6 | process.stdout.write(`You typed: '${text}'\n`); 7 | if (text == 'exit') { 8 | process.stderr.write('Exiting your application now.\n'); 9 | process.exit(0); 10 | } else { 11 | process.stdout.write('> '); 12 | } 13 | }); 14 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_globals/setInterval.js: -------------------------------------------------------------------------------- 1 | let counter = 0; 2 | const MAX = 5; 3 | const start = Date.now(); 4 | const timeout = setInterval(() => { 5 | console.log(`Executing ${Date.now() - start}ms in the future.`); 6 | counter++ 7 | if (counter >= MAX) { 8 | console.log(`Ran for too long, cancelling it at ${Date.now() - start}ms`); 9 | clearInterval(timeout); 10 | } 11 | }, 1000); -------------------------------------------------------------------------------- /Lesson03/Example/sample_globals/setTimeout.js: -------------------------------------------------------------------------------- 1 | const start = Date.now(); 2 | setTimeout(() => { 3 | console.log(`I'm ${Date.now() - start}ms late.`); 4 | }, 1000); 5 | 6 | const secondTimer = setTimeout(() => { 7 | console.log(`I am ${Date.now() - start}ms late.`); 8 | }, 3000); 9 | 10 | setTimeout(() => { 11 | console.log(`Refreshing second timer at ${Date.now() - start}ms`); 12 | secondTimer.refresh(); 13 | }, 2000); 14 | 15 | const thirdTimer = setTimeout(() => { 16 | console.log('I am never going to be executed.'); 17 | }, 5000); 18 | 19 | setTimeout(() => { 20 | console.log(`Cancelling third timer at ${Date.now() - start}ms`); 21 | clearTimeout(thirdTimer); 22 | }, 2000); 23 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_http/http_client_get.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | const request = http.get('http://httpbin.org/get', (response) => { 4 | response.on('data', (data) => { 5 | console.log(data.toString()); 6 | }); 7 | }); 8 | 9 | request.end(); 10 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_http/http_client_get_with_headers.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | const url = 'http://httpbin.org/get'; 4 | const options = { 5 | auth: 'myuser:mypass', 6 | headers: { 7 | Test: 'Some Value' 8 | } 9 | }; 10 | 11 | const request = http.get(url, options, (response) => { 12 | response.on('data', (data) => { 13 | console.log(data.toString()); 14 | }); 15 | }); 16 | 17 | request.end(); 18 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_http/http_client_post.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | const url = 'http://httpbin.org/post'; 4 | const options = { 5 | method: 'POST', 6 | }; 7 | 8 | const request = http.request(url, options, (response) => { 9 | response.on('data', (data) => { 10 | console.log(data.toString()); 11 | }); 12 | }); 13 | 14 | request.write('Hello world.'); 15 | request.end(); 16 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_http/http_server.js: -------------------------------------------------------------------------------- 1 | const http = require('http'); 2 | 3 | const server = http.createServer(); 4 | 5 | server.on('request', (request, response) => { 6 | console.log('Request received.', request.url); 7 | response.writeHead(200, { 'Content-type': 'text/plain' }); 8 | response.write('Hello world!'); 9 | response.end(); 10 | }); 11 | 12 | const port = 3000; 13 | console.log('Starting server on port %d.', port); 14 | console.log('Go to: http://localhost:%d', port); 15 | server.listen(port); 16 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_scraping/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sample_scraping", 3 | "version": "1.0.0", 4 | "description": "Web scraping application used as sample.", 5 | "main": "print_all_texts.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/TrainingByPackt/Professional-JavaScript.git", 9 | "directory": "Lesson03/Example/sample_scraping" 10 | }, 11 | "author": "", 12 | "license": "MIT", 13 | "dependencies": { 14 | "jsdom": "^15.1.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_scraping/print_all_paths.js: -------------------------------------------------------------------------------- 1 | const http = require('https'); 2 | const JSDOM = require('jsdom').JSDOM; 3 | const url = require('url'); 4 | 5 | function downloadPage(urlToDownload, callback) { 6 | const request = http.get(urlToDownload, (response) => { 7 | if (response.statusCode != 200) { 8 | console.error('Error while downloading page %s.', urlToDownload); 9 | console.error('Response was: %s %s', response.statusCode, response.statusMessage); 10 | return; 11 | } 12 | 13 | let content = ''; 14 | response.on('data', (chunk) => content += chunk.toString()); 15 | response.on('close', () => callback(content)); 16 | }); 17 | request.end(); 18 | } 19 | 20 | downloadPage('https://medium.com/topic/javascript', (content) => { 21 | const document = new JSDOM(content).window.document; 22 | 23 | Array.from(document.querySelectorAll('a')) 24 | .map((el) => url.parse(el.href).pathname) 25 | .forEach((u) => console.log(u)); 26 | }); 27 | -------------------------------------------------------------------------------- /Lesson03/Example/sample_scraping/print_all_texts.js: -------------------------------------------------------------------------------- 1 | const http = require('https'); 2 | const JSDOM = require('jsdom').JSDOM; 3 | const url = require('url'); 4 | 5 | function downloadPage(urlToDownload, callback) { 6 | const request = http.get(urlToDownload, (response) => { 7 | if (response.statusCode != 200) { 8 | console.error('Error while downloading page %s.', urlToDownload); 9 | console.error('Response was: %s %s', response.statusCode, response.statusMessage); 10 | return; 11 | } 12 | 13 | let content = ''; 14 | response.on('data', (chunk) => content += chunk.toString()); 15 | response.on('close', () => callback(content)); 16 | }); 17 | request.end(); 18 | } 19 | 20 | downloadPage('https://medium.com/topic/javascript', (content) => { 21 | const document = new JSDOM(content).window.document; 22 | 23 | Array.from(document.querySelectorAll('a')) 24 | .map((el) => el.text) 25 | .filter(s => s.trim() != '') 26 | .forEach((s) => console.log(s)); 27 | }); 28 | -------------------------------------------------------------------------------- /Lesson03/Exercise11/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Exercise11", 3 | "version": "1.0.0", 4 | "description": "First exercise for lesson 3.", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/TrainingByPackt/Professional-JavaScript.git", 9 | "directory": "Lesson03/Exercise11" 10 | }, 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /Lesson03/Exercise12/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_002", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "commander": { 8 | "version": "3.0.0", 9 | "resolved": "https://registry.npmjs.org/commander/-/commander-3.0.0.tgz", 10 | "integrity": "sha512-pl3QrGOBa9RZaslQiqnnKX2J068wcQw7j9AIaBQ9/JEp5RY6je4jKTImg0Bd+rpoONSe7GUFSgkxLeo17m3Pow==" 11 | }, 12 | "glob-to-regexp": { 13 | "version": "0.4.1", 14 | "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", 15 | "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Lesson03/Exercise12/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_002", 3 | "version": "1.0.0", 4 | "description": "Application to search for files using globs", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/TrainingByPackt/Professional-JavaScript.git", 9 | "directory": "Lesson03/Exercise12" 10 | }, 11 | "license": "MIT", 12 | "dependencies": { 13 | "commander": "^3.0.0", 14 | "glob-to-regexp": "^0.4.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson03/Exercise13/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Exercise13", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "mime": { 8 | "version": "2.4.4", 9 | "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", 10 | "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lesson03/Exercise13/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Exercise13", 3 | "version": "1.0.0", 4 | "description": "Static HTTP server.", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/TrainingByPackt/Professional-JavaScript.git", 9 | "directory": "Lesson03/Exercise13" 10 | }, 11 | "license": "MIT", 12 | "dependencies": { 13 | "mime": "^2.4.4" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lesson03/Exercise14/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |

Welcome to Fresh Products Store!

9 |
10 | {{#products}} 11 |
12 |
13 |
14 | {{name}} 15 |
16 | {{currency price}} / {{unit}} 17 |
18 |
{{description}}
19 |
20 | {{#tags}} 21 |
{{this}}
22 | {{/tags}} 23 |
24 |
25 |
26 | {{/products}} 27 |
28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /Lesson03/Exercise14/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Exercise14", 3 | "version": "1.0.0", 4 | "description": "Exercise that demonstrate how to create a dynamic web server", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/TrainingByPackt/Professional-JavaScript.git", 9 | "directory": "Lesson03/Exercise14" 10 | }, 11 | "license": "MIT", 12 | "dependencies": { 13 | "handlebars": "^4.4.2", 14 | "mime": "^2.4.4" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/css/store.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-attachment: fixed; 3 | background-image: url('../images/brick-wall-1245825_1920.jpg'); 4 | } 5 | 6 | body > section { 7 | background: rgba(200, 200, 200, 0.4); 8 | height: 100%; 9 | margin: 0 auto; 10 | overflow-y: scroll; 11 | padding: 10px 20px; 12 | width: 1024px; 13 | } 14 | 15 | h1.title { 16 | color: #6b2a13; 17 | font-size: 3em; 18 | } 19 | 20 | .ui.items .item { 21 | background: rgba(250, 250, 250, 0.8); 22 | border-radius: 5px; 23 | box-shadow: #444 2px 2px 5px; 24 | padding: 10px; 25 | } 26 | 27 | .ui.items .item img { 28 | max-height: 150px; 29 | } 30 | -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/css/themes/default/assets/fonts/icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/css/themes/default/assets/fonts/icons.woff -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/css/themes/default/assets/fonts/icons.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/css/themes/default/assets/fonts/icons.woff2 -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/brick-wall-1245825_1920.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/brick-wall-1245825_1920.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/apples.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/apples.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/avocado.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/avocado.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/blueberry_muffins.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/blueberry_muffins.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/butter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/butter.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/cherries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/cherries.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/chocolate_chips_cookies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/chocolate_chips_cookies.png -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/christmas_cookies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/christmas_cookies.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/croissant.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/croissant.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/dark_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/dark_chocolate.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/eggs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/eggs.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/grapes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/grapes.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/milk_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/milk_chocolate.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/nachos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/nachos.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/parmesan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/parmesan.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/pear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/pear.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/petit_french_baguette.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/petit_french_baguette.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/smiley_cookies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/smiley_cookies.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/strawberries.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/strawberries.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/swiss_cheese.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/swiss_cheese.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/white_chocolate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/white_chocolate.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise14/static/images/products/whole_wheat_bread.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson03/Exercise14/static/images/products/whole_wheat_bread.jpg -------------------------------------------------------------------------------- /Lesson03/Exercise15/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Exercise15", 3 | "version": "1.0.0", 4 | "description": "Application to fetch Medium topic pages and print article information to console.", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/TrainingByPackt/Professional-JavaScript.git", 9 | "directory": "Lesson03/Exercise15" 10 | }, 11 | "author": "", 12 | "license": "MIT", 13 | "dependencies": { 14 | "jsdom": "^15.1.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson04/Activity05/config.js: -------------------------------------------------------------------------------- 1 | let config = {}; 2 | // random value below generated with command: openssl rand -base64 32 3 | config.secret = "cSmdV7Nh4e3gIFTO0ljJlH1f/F0ROKZR/hZfRYTSO0A="; 4 | module.exports = config; 5 | -------------------------------------------------------------------------------- /Lesson04/Activity05/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "assignment_solution", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Philip Kirkbride", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.17.1", 13 | "express-validator": "^6.1.1", 14 | "jwt-simple": "^0.5.6" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson04/Activity05/routes/check-in.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const jwt = require('jwt-simple'); 3 | const { check, validationResult } = require('express-validator/check'); 4 | const router = express.Router(); 5 | 6 | // import our config file and get the secret value 7 | const config = require('../config'); 8 | const secret = config.secret; 9 | 10 | router.post('/', [ 11 | check('name').isString() 12 | ], 13 | (req, res) => { 14 | 15 | // If errors return 422, client didn't provide required values 16 | const errors = validationResult(req); 17 | if (!errors.isEmpty()) { 18 | return res.status(422).json({ errors: errors.array() }); 19 | } 20 | 21 | // Otherwise use the server secret to encode the user's request as a JWT 22 | let info = {}; 23 | info.token = jwt.encode(req.body, secret); 24 | res.json(info); 25 | }); 26 | 27 | // Export route so it is available to import 28 | module.exports = router; 29 | -------------------------------------------------------------------------------- /Lesson04/Activity05/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | // Import path and file system libraries for importing our route files 5 | const path = require('path'); 6 | const fs = require('fs'); 7 | 8 | // Import library for handling HTTP errors 9 | const createError = require('http-errors'); 10 | 11 | 12 | // Tell express to enable url encoding 13 | app.use(express.urlencoded({extended: true})); 14 | app.use(express.json()); 15 | 16 | // Import our index route 17 | let lock = require('./routes/lock'); 18 | let checkIn = require('./routes/check-in'); 19 | 20 | app.use('/check-in', checkIn); 21 | app.use('/lock', lock); 22 | 23 | // catch 404 and forward to error handler 24 | app.use(function(req, res, next) { 25 | res.status(404); 26 | res.json(createError(404)); 27 | }); 28 | 29 | // Start our application on port 3000 30 | app.listen(3000, () => console.log('API running on port 3000')); 31 | 32 | -------------------------------------------------------------------------------- /Lesson04/Example/Example18b/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.16.4" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lesson04/Example/Example18b/routes/devices/light.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | // Light structure is imported at the top of the file 5 | const lightStructure = require('./lightStructure.js'); 6 | 7 | // Create four routes each displaying a different aspect of the JSON object 8 | router.get('/', function(req, res, next) { 9 | let info = lightStructure; 10 | res.json(info); 11 | }); 12 | 13 | router.get('/properties', function(req, res, next) { 14 | let info = lightStructure.properties; 15 | res.json(info); 16 | }); 17 | 18 | router.get('/model', function(req, res, next) { 19 | let info = lightStructure.model; 20 | res.json(info); 21 | }); 22 | 23 | router.get('/actions', function(req, res, next) { 24 | let info = lightStructure.actions; 25 | res.json(info); 26 | }); 27 | 28 | // Export route so it is available to import 29 | module.exports = router; 30 | -------------------------------------------------------------------------------- /Lesson04/Example/Example18b/routes/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | router.get('/', function(req, res, next) { 5 | let info = {}; 6 | info.message = "Welcome home! Our first endpoint."; 7 | res.json(info); 8 | }); 9 | 10 | // Export route so it is available to import 11 | module.exports = router; 12 | -------------------------------------------------------------------------------- /Lesson04/Example/Example18b/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | // Import path and file system libraries for importing our route files 5 | const path = require('path'); 6 | const fs = require('fs'); 7 | 8 | // Import library for handling HTTP errors 9 | const createError = require('http-errors'); 10 | 11 | 12 | // Tell express to enable url encoding 13 | app.use(express.urlencoded({extended: true})); 14 | app.use(express.json()); 15 | 16 | // Import our index route 17 | let index = require('./routes/index'); 18 | let light = require('./routes/devices/light'); 19 | 20 | // Tell Express to use our index module for root URL 21 | app.use('/', index); 22 | app.use('/devices/light', light); 23 | 24 | // catch 404 and forward to error handler 25 | app.use(function(req, res, next) { 26 | res.status(404); 27 | res.json(createError(404)); 28 | }); 29 | 30 | // Start our application on port 3000 31 | app.listen(3000, () => console.log('API running on port 3000')); 32 | -------------------------------------------------------------------------------- /Lesson04/Example/heater/config.js: -------------------------------------------------------------------------------- 1 | let config = {}; 2 | config.secret = "LfL0qpg91/ugndUKLWvS6ENutE5Q82ixpRe9MSkX58E="; 3 | module.exports = config; 4 | -------------------------------------------------------------------------------- /Lesson04/Example/heater/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Philip Kirkbride", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.16.4", 13 | "express-validator": "^5.3.1", 14 | "jwt-simple": "^0.5.6" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson04/Example/heater/routes/check-in.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const jwt = require('jwt-simple'); 3 | const { check, validationResult } = require('express-validator/check'); 4 | const router = express.Router(); 5 | 6 | // import our config file and get the secret value 7 | const config = require('../config'); 8 | const secret = config.secret; 9 | 10 | router.post('/', [ 11 | check('name').isString() 12 | ], 13 | (req, res) => { 14 | 15 | // If errors return 422, client didn't provide required values 16 | const errors = validationResult(req); 17 | if (!errors.isEmpty()) { 18 | return res.status(422).json({ errors: errors.array() }); 19 | } 20 | 21 | // Otherwise use the server secret to encode the user's request as a JWT 22 | let info = {}; 23 | info.token = jwt.encode(req.body, secret); 24 | res.json(info); 25 | }); 26 | 27 | // Export route so it is available to import 28 | module.exports = router; 29 | -------------------------------------------------------------------------------- /Lesson04/Example/heater/routes/devices/heater.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const { check, validationResult } = require('express-validator/check'); 3 | const router = express.Router(); 4 | 5 | // Function to run if user sends a PUT request 6 | router.put(['/', '/actions/fade'], [ 7 | check('mode').isNumeric().isLength({ min: 0, max: 1 }), 8 | check('temperature').isNumeric() 9 | ], 10 | (req, res) => { 11 | const errors = validationResult(req); 12 | if (!errors.isEmpty()) { 13 | return res.status(422).json({ errors: errors.array() }); 14 | } 15 | let temperature = req.body.temperature; 16 | let mode = req.body.mode; 17 | 18 | let message = `success: temperature set to ${temperature} mode is ${mode}`; 19 | res.json({"message": message}); 20 | }); 21 | 22 | // Export route so it is available to import 23 | module.exports = router; 24 | -------------------------------------------------------------------------------- /Lesson04/Example/heater/routes/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | router.get('/', function(req, res, next) { 5 | let info = {}; 6 | info.message = "Welcome home! Our first endpoint."; 7 | res.json(info); 8 | }); 9 | 10 | // Export route so it is available to import 11 | module.exports = router; 12 | -------------------------------------------------------------------------------- /Lesson04/Example/mongo_logger_middleware/config.js: -------------------------------------------------------------------------------- 1 | let config = {}; 2 | config.secret = "LfL0qpg91/ugndUKLWvS6ENutE5Q82ixpRe9MSkX58E="; 3 | module.exports = config; 4 | -------------------------------------------------------------------------------- /Lesson04/Example/mongo_logger_middleware/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Philip Kirkbride", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.16.4", 13 | "express-validator": "^5.3.1", 14 | "jwt-simple": "^0.5.6", 15 | "mongodb": "^3.2.3" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lesson04/Example/mongo_logger_middleware/routes/check-in.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const jwt = require('jwt-simple'); 3 | const { check, validationResult } = require('express-validator/check'); 4 | const router = express.Router(); 5 | 6 | // import our config file and get the secret value 7 | const config = require('../config'); 8 | const secret = config.secret; 9 | 10 | router.post('/', [ 11 | check('name').isString() 12 | ], 13 | (req, res) => { 14 | 15 | // If errors return 422, client didn't provide required values 16 | const errors = validationResult(req); 17 | if (!errors.isEmpty()) { 18 | return res.status(422).json({ errors: errors.array() }); 19 | } 20 | 21 | // Otherwise use the server secret to encode the user's request as a JWT 22 | let info = {}; 23 | info.token = jwt.encode(req.body, secret); 24 | res.json(info); 25 | }); 26 | 27 | // Export route so it is available to import 28 | module.exports = router; 29 | -------------------------------------------------------------------------------- /Lesson04/Example/mongo_logger_middleware/routes/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | router.get('/', function(req, res, next) { 5 | let info = {}; 6 | info.message = "Welcome home! Our first endpoint."; 7 | res.json(info); 8 | }); 9 | 10 | // Export route so it is available to import 11 | module.exports = router; 12 | -------------------------------------------------------------------------------- /Lesson04/Exercise16/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Philip Kirkbride", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.16.4" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lesson04/Exercise16/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | app.get('/', (req, res) => { 5 | let info = {}; 6 | info.message = "Welcome home! Our first endpoint."; 7 | res.json(info); 8 | }); 9 | 10 | // Start our application on port 3000 11 | app.listen(3000, () => console.log('API running on port 3000')); 12 | -------------------------------------------------------------------------------- /Lesson04/Exercise17/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Philip Kirkbride", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.16.4" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lesson04/Exercise17/routes/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | router.get('/', function(req, res, next) { 5 | let info = {}; 6 | info.message = "Welcome home! Our first endpoint."; 7 | res.json(info); 8 | }); 9 | 10 | // Export route so it is available to import 11 | module.exports = router; 12 | -------------------------------------------------------------------------------- /Lesson04/Exercise17/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | // Import path and file system libraries for importing our route files 5 | const path = require('path'); 6 | const fs = require('fs'); 7 | 8 | // Import library for handling HTTP errors 9 | const createError = require('http-errors'); 10 | 11 | 12 | // Tell express to enable url encoding 13 | app.use(express.urlencoded({extended: true})); 14 | app.use(express.json()); 15 | 16 | // Import our index route 17 | let index = require('./routes/index'); 18 | 19 | // Tell Express to use our index module for root URL 20 | app.use('/', index); 21 | 22 | // catch 404 and forward to error handler 23 | app.use(function(req, res, next) { 24 | res.status(404); 25 | res.json(createError(404)); 26 | }); 27 | 28 | // Start our application on port 3000 29 | app.listen(3000, () => console.log('API running on port 3000')); 30 | -------------------------------------------------------------------------------- /Lesson04/Exercise18/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Philip Kirkbride", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.16.4" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lesson04/Exercise18/routes/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | router.get('/', function(req, res, next) { 5 | let info = {}; 6 | info.message = "Welcome home! Our first endpoint."; 7 | res.json(info); 8 | }); 9 | 10 | // Export route so it is available to import 11 | module.exports = router; 12 | -------------------------------------------------------------------------------- /Lesson04/Exercise18/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | // Import path and file system libraries for importing our route files 5 | const path = require('path'); 6 | const fs = require('fs'); 7 | 8 | // Import library for handling HTTP errors 9 | const createError = require('http-errors'); 10 | 11 | 12 | // Tell express to enable url encoding 13 | app.use(express.urlencoded({extended: true})); 14 | app.use(express.json()); 15 | 16 | // Import our index route 17 | let index = require('./routes/index'); 18 | let light = require('./routes/devices/light'); 19 | 20 | // Tell Express to use our index module for root URL 21 | app.use('/', index); 22 | app.use('/devices/light', light); 23 | 24 | // catch 404 and forward to error handler 25 | app.use(function(req, res, next) { 26 | res.status(404); 27 | res.json(createError(404)); 28 | }); 29 | 30 | // Start our application on port 3000 31 | app.listen(3000, () => console.log('API running on port 3000')); 32 | -------------------------------------------------------------------------------- /Lesson04/Exercise19/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Philip Kirkbride", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.16.4", 13 | "express-validator": "^5.3.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lesson04/Exercise19/routes/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | router.get('/', function(req, res, next) { 5 | let info = {}; 6 | info.message = "Welcome home! Our first endpoint."; 7 | res.json(info); 8 | }); 9 | 10 | // Export route so it is available to import 11 | module.exports = router; 12 | -------------------------------------------------------------------------------- /Lesson04/Exercise19/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | // Import path and file system libraries for importing our route files 5 | const path = require('path'); 6 | const fs = require('fs'); 7 | 8 | // Import library for handling HTTP errors 9 | const createError = require('http-errors'); 10 | 11 | 12 | // Tell express to enable url encoding 13 | app.use(express.urlencoded({extended: true})); 14 | app.use(express.json()); 15 | 16 | // Import our index route 17 | let index = require('./routes/index'); 18 | let light = require('./routes/devices/light'); 19 | 20 | // Tell Express to use our index module for root URL 21 | app.use('/', index); 22 | app.use('/devices/light', light); 23 | 24 | // catch 404 and forward to error handler 25 | app.use(function(req, res, next) { 26 | res.status(404); 27 | res.json(createError(404)); 28 | }); 29 | 30 | // Start our application on port 3000 31 | app.listen(3000, () => console.log('API running on port 3000')); 32 | -------------------------------------------------------------------------------- /Lesson04/Exercise20/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Philip Kirkbride", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.16.4", 13 | "express-validator": "^5.3.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lesson04/Exercise20/routes/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | router.get('/', function(req, res, next) { 5 | let info = {}; 6 | info.message = "Welcome home! Our first endpoint."; 7 | res.json(info); 8 | }); 9 | 10 | // Export route so it is available to import 11 | module.exports = router; 12 | -------------------------------------------------------------------------------- /Lesson04/Exercise20/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app = express(); 3 | 4 | // Import path and file system libraries for importing our route files 5 | const path = require('path'); 6 | const fs = require('fs'); 7 | 8 | // Import library for handling HTTP errors 9 | const createError = require('http-errors'); 10 | 11 | 12 | // Tell express to enable url encoding 13 | app.use(express.urlencoded({extended: true})); 14 | app.use(express.json()); 15 | 16 | // Import our index route 17 | let index = require('./routes/index'); 18 | let light = require('./routes/devices/light'); 19 | 20 | // Tell Express to use our index module for root URL 21 | app.use('/', index); 22 | app.use('/devices/light', light); 23 | 24 | // catch 404 and forward to error handler 25 | app.use(function(req, res, next) { 26 | res.status(404); 27 | res.json(createError(404)); 28 | }); 29 | 30 | // Start our application on port 3000 31 | app.listen(3000, () => console.log('API running on port 3000')); 32 | -------------------------------------------------------------------------------- /Lesson04/Exercise21/config.js: -------------------------------------------------------------------------------- 1 | let config = {}; 2 | config.secret = "LfL0qpg91/ugndUKLWvS6ENutE5Q82ixpRe9MSkX58E="; 3 | module.exports = config; 4 | -------------------------------------------------------------------------------- /Lesson04/Exercise21/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise_1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Philip Kirkbride", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.16.4", 13 | "express-validator": "^5.3.1", 14 | "jwt-simple": "^0.5.6" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson04/Exercise21/routes/check-in.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const jwt = require('jwt-simple'); 3 | const { check, validationResult } = require('express-validator/check'); 4 | const router = express.Router(); 5 | 6 | // import our config file and get the secret value 7 | const config = require('../config'); 8 | const secret = config.secret; 9 | 10 | router.post('/', [ 11 | check('name').isString() 12 | ], 13 | (req, res) => { 14 | 15 | // If errors return 422, client didn't provide required values 16 | const errors = validationResult(req); 17 | if (!errors.isEmpty()) { 18 | return res.status(422).json({ errors: errors.array() }); 19 | } 20 | 21 | // Otherwise use the server secret to encode the user's request as a JWT 22 | let info = {}; 23 | info.token = jwt.encode(req.body, secret); 24 | res.json(info); 25 | }); 26 | 27 | // Export route so it is available to import 28 | module.exports = router; 29 | -------------------------------------------------------------------------------- /Lesson04/Exercise21/routes/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const router = express.Router(); 3 | 4 | router.get('/', function(req, res, next) { 5 | let info = {}; 6 | info.message = "Welcome home! Our first endpoint."; 7 | res.json(info); 8 | }); 9 | 10 | // Export route so it is available to import 11 | module.exports = router; 12 | -------------------------------------------------------------------------------- /Lesson05/Activtiy06/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /Lesson05/Activtiy06/build/images/bulb_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Activtiy06/build/images/bulb_off.png -------------------------------------------------------------------------------- /Lesson05/Activtiy06/build/images/bulb_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Activtiy06/build/images/bulb_on.png -------------------------------------------------------------------------------- /Lesson05/Activtiy06/build/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Light Viewer 7 | 8 | 9 |
10 | 11 | 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Lesson05/Activtiy06/build/js/viewer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _flashingLight = _interopRequireDefault(require("./flashingLight.js")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | var slider = document.getElementById("brightnessSlider"); 8 | var color = document.getElementById("color"); 9 | var button = document.getElementById("build"); 10 | 11 | button.onclick = function () { 12 | new _flashingLight["default"](true, slider.value, true); 13 | }; -------------------------------------------------------------------------------- /Lesson05/Activtiy06/src/images/bulb_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Activtiy06/src/images/bulb_off.png -------------------------------------------------------------------------------- /Lesson05/Activtiy06/src/images/bulb_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Activtiy06/src/images/bulb_on.png -------------------------------------------------------------------------------- /Lesson05/Activtiy06/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Light Viewer 7 | 8 | 9 |
10 | 11 | 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Lesson05/Activtiy06/src/js/viewer.js: -------------------------------------------------------------------------------- 1 | import FlashingLight from './flashingLight.js'; 2 | 3 | let slider = document.getElementById("brightnessSlider"); 4 | let color = document.getElementById("color"); 5 | let button = document.getElementById("build"); 6 | 7 | button.onclick = function () { 8 | new FlashingLight(true, slider.value, true); 9 | } 10 | -------------------------------------------------------------------------------- /Lesson05/Activtiy06/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | module.exports = { 4 | mode: 'development', 5 | entry: "./build/js/viewer.js", 6 | output: { 7 | path: path.resolve(__dirname, "build"), 8 | filename: "bundle.js" 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /Lesson05/Exercise22/images/bulb_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise22/images/bulb_off.png -------------------------------------------------------------------------------- /Lesson05/Exercise22/images/bulb_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise22/images/bulb_on.png -------------------------------------------------------------------------------- /Lesson05/Exercise22/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Light Viewer 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lesson05/Exercise22/js/light.js: -------------------------------------------------------------------------------- 1 | let light = {}; 2 | light.state = true; 3 | light.level = 0.5; 4 | 5 | var log = function () { 6 | console.log(light); 7 | }; 8 | 9 | export default log; 10 | -------------------------------------------------------------------------------- /Lesson05/Exercise22/js/viewer.js: -------------------------------------------------------------------------------- 1 | import Light from './light.js'; 2 | 3 | // Page elements and variables 4 | let bulb = document.getElementById("bulb"); 5 | let slider = document.getElementById("brightnessSlider"); 6 | let onImage = "images/bulb_on.png"; 7 | let offImage = "images/bulb_off.png"; 8 | 9 | light(); 10 | -------------------------------------------------------------------------------- /Lesson05/Exercise22/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "projs-l5", 3 | "version": "1.0.0", 4 | "description": "Sample code for Lesson 05 in Professional JavaScript.", 5 | "keywords": [ 6 | "Packt", 7 | "JavaScript", 8 | "modules" 9 | ], 10 | "homepage": "https://github.com/TrainingByPackt/Professional-JavaScript", 11 | "bugs": { 12 | "url": "https://github.com/TrainingByPackt/Professional-JavaScript/issues", 13 | "email": "kirkins@gmail.com" 14 | }, 15 | "license": "MIT", 16 | "author": "Philip Kirkbride", 17 | "repository": "https://github.com/TrainingByPackt/Professional-JavaScript", 18 | "scripts": { 19 | "start": "ws" 20 | }, 21 | "devDependencies": { 22 | "local-web-server": "^2.6.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Lesson05/Exercise23/number.js: -------------------------------------------------------------------------------- 1 | Number.prototype.double = function () { 2 | return this.valueOf()*2; 3 | } 4 | 5 | Number.prototype.square = function () { 6 | return this.valueOf()*this.valueOf(); 7 | } 8 | 9 | Number.prototype.fibonacci = function () { 10 | function iterator(a, b, n) { 11 | return n == 0n ? b : iterator((a+b), a, (n-1n)) 12 | } 13 | function fibonacci(n) { 14 | n = BigInt(n); 15 | return iterator(1n, 0n, n); 16 | } 17 | return fibonacci(this.valueOf()); 18 | } 19 | 20 | Number.prototype.factorial = function () { 21 | factorial = (n) => { 22 | n = BigInt(n); 23 | return (n>1) ? n * factorial(n-1n) : n; 24 | } 25 | return factorial(this.valueOf()); 26 | } 27 | 28 | let n = 100; 29 | 30 | console.log( 31 | "for number " + n +"\n", 32 | "double is " + n.double() + "\n", 33 | "square is " + n.square() + "\n", 34 | "fibonacci is " + n.fibonacci() + "\n", 35 | "factorial is " + n.factorial() + "\n" 36 | ); 37 | -------------------------------------------------------------------------------- /Lesson05/Exercise24/images/bulb_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise24/images/bulb_off.png -------------------------------------------------------------------------------- /Lesson05/Exercise24/images/bulb_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise24/images/bulb_on.png -------------------------------------------------------------------------------- /Lesson05/Exercise24/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Light Viewer 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lesson05/Exercise24/js/light.js: -------------------------------------------------------------------------------- 1 | class Light { 2 | constructor(state, brightness) { 3 | // Check that inputs are the right types 4 | this.state = this.checkStateFormat(state); 5 | this.brightness = this.checkBrightnessFormat(brightness); 6 | this.createdAt = Date.now(); 7 | } 8 | 9 | checkStateFormat(state) { 10 | // state must be true or false 11 | if(state) { 12 | return true; 13 | } else { 14 | return false; 15 | } 16 | } 17 | 18 | checkBrightnessFormat(brightness) { 19 | // brightness must be a number between 0.01 and 1 20 | if(isNaN(brightness)) { 21 | brightness = 1; 22 | } else if(brightness > 1) { 23 | brightness = 1; 24 | } else if(brightness < 0.01) { 25 | brightness = 0.01; 26 | } 27 | return brightness; 28 | } 29 | 30 | toggle() { 31 | this.state = !this.state; 32 | } 33 | 34 | test() { 35 | alert("state is " + this.state); 36 | } 37 | } 38 | 39 | export default Light; 40 | -------------------------------------------------------------------------------- /Lesson05/Exercise24/js/viewer.js: -------------------------------------------------------------------------------- 1 | import Light from './light.js'; 2 | 3 | // Page elements and variables 4 | let bulb = document.getElementById("bulb"); 5 | let slider = document.getElementById("brightnessSlider"); 6 | let onImage = "images/bulb_on.png"; 7 | let offImage = "images/bulb_off.png"; 8 | 9 | let light = new Light(true, 0.5); 10 | 11 | // Set image based on light state 12 | bulb.src = light.state ? onImage : offImage; 13 | 14 | // Set opacity based on brightness 15 | bulb.style.opacity = light.brightness; 16 | 17 | // Set slider value to brightness 18 | slider.value = light.brightness; 19 | 20 | bulb.onclick = function () { 21 | light.toggle(); 22 | bulb.src = light.state ? onImage : offImage; 23 | } 24 | 25 | slider.onchange = function () { 26 | light.brightness = this.value; 27 | bulb.style.opacity = light.brightness; 28 | } 29 | -------------------------------------------------------------------------------- /Lesson05/Exercise24/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "projs-l5", 3 | "version": "1.0.0", 4 | "description": "Sample code for Lesson 05 in Professional JavaScript.", 5 | "keywords": [ 6 | "Packt", 7 | "JavaScript", 8 | "modules" 9 | ], 10 | "homepage": "https://github.com/TrainingByPackt/Professional-JavaScript", 11 | "bugs": { 12 | "url": "https://github.com/TrainingByPackt/Professional-JavaScript/issues", 13 | "email": "kirkins@gmail.com" 14 | }, 15 | "license": "MIT", 16 | "author": "Philip Kirkbride", 17 | "repository": "https://github.com/TrainingByPackt/Professional-JavaScript", 18 | "scripts": { 19 | "start": "ws" 20 | }, 21 | "devDependencies": { 22 | "local-web-server": "^2.6.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Lesson05/Exercise25/images/bulb_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise25/images/bulb_off.png -------------------------------------------------------------------------------- /Lesson05/Exercise25/images/bulb_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise25/images/bulb_on.png -------------------------------------------------------------------------------- /Lesson05/Exercise25/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Light Viewer 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lesson05/Exercise25/js/viewer.js: -------------------------------------------------------------------------------- 1 | import Light from './light.js'; 2 | 3 | // Page elements and variables 4 | let bulb = document.getElementById("bulb"); 5 | let slider = document.getElementById("brightnessSlider"); 6 | let onImage = "images/bulb_on.png"; 7 | let offImage = "images/bulb_off.png"; 8 | 9 | let light = new Light(true, 0.5); 10 | 11 | // Set image based on light state 12 | bulb.src = light.getState() ? onImage : offImage; 13 | 14 | // Set opacity based on brightness 15 | bulb.style.opacity = light.getBrightness(); 16 | 17 | // Set slider value to brightness 18 | slider.value = light.getBrightness(); 19 | 20 | bulb.onclick = function () { 21 | light.toggle(); 22 | bulb.src = light.getState() ? onImage : offImage; 23 | } 24 | 25 | slider.onchange = function () { 26 | light.setBrightness(this.value); 27 | bulb.style.opacity = light.getBrightness(); 28 | } 29 | -------------------------------------------------------------------------------- /Lesson05/Exercise25/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "projs-l5", 3 | "version": "1.0.0", 4 | "description": "Sample code for Lesson 05 in Professional JavaScript.", 5 | "keywords": [ 6 | "Packt", 7 | "JavaScript", 8 | "modules" 9 | ], 10 | "homepage": "https://github.com/TrainingByPackt/Professional-JavaScript", 11 | "bugs": { 12 | "url": "https://github.com/TrainingByPackt/Professional-JavaScript/issues", 13 | "email": "kirkins@gmail.com" 14 | }, 15 | "license": "MIT", 16 | "author": "Philip Kirkbride", 17 | "repository": "https://github.com/TrainingByPackt/Professional-JavaScript", 18 | "scripts": { 19 | "start": "ws" 20 | }, 21 | "devDependencies": { 22 | "local-web-server": "^2.6.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Lesson05/Exercise26/images/bulb_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise26/images/bulb_off.png -------------------------------------------------------------------------------- /Lesson05/Exercise26/images/bulb_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise26/images/bulb_on.png -------------------------------------------------------------------------------- /Lesson05/Exercise26/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Light Viewer 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lesson05/Exercise26/js/colorLight.js: -------------------------------------------------------------------------------- 1 | import Light from './light.js'; 2 | 3 | let privateVars = new WeakMap(); 4 | 5 | class ColorLight extends Light { 6 | 7 | constructor(state=false, brightness=100, color="ffffff") { 8 | super(state, brightness); 9 | 10 | // Create info object 11 | let info = {"color": this.checkColorFormat(color)}; 12 | 13 | // Save info into privateVars 14 | privateVars.set(this, info); 15 | } 16 | 17 | checkColorFormat(color) { 18 | // color must be a valid hex color 19 | var isHexColor = /^#[0-9A-F]{6}$/i.test('#'+color); 20 | if(!isHexColor) { 21 | // if invalid make white 22 | color = "ffffff"; 23 | } 24 | return color; 25 | } 26 | 27 | getColor() { 28 | let info = privateVars.get(this); 29 | return info.color; 30 | } 31 | 32 | setColor(color) { 33 | let info = privateVars.get(this); 34 | info.color = this.checkColorFormat(color); 35 | privateVars.set(this, info); 36 | } 37 | 38 | } 39 | 40 | export default ColorLight; 41 | -------------------------------------------------------------------------------- /Lesson05/Exercise26/js/viewer.js: -------------------------------------------------------------------------------- 1 | import ColorLight from './colorLight.js'; 2 | import changeColor from './__extra__/changeColor.js'; 3 | 4 | // Page elements and variables 5 | let bulb = document.getElementById("bulb"); 6 | let slider = document.getElementById("brightnessSlider"); 7 | let onImage = "images/bulb_on.png"; 8 | let offImage = "images/bulb_off.png"; 9 | 10 | let light = new ColorLight(true, 1, "61AD85"); 11 | 12 | // Set image based on light state 13 | bulb.src = light.getState() ? onImage : offImage; 14 | 15 | // Set opacity based on brightness 16 | bulb.style.opacity = light.getBrightness(); 17 | 18 | // Set slider value to brightness 19 | slider.value = light.getBrightness(); 20 | 21 | bulb.onclick = function () { 22 | light.toggle(); 23 | bulb.src = light.getState() ? onImage : offImage; 24 | } 25 | 26 | slider.onchange = function () { 27 | light.setBrightness(this.value); 28 | bulb.style.opacity = light.getBrightness(); 29 | } 30 | 31 | // Update image color 32 | changeColor(light.getColor()); 33 | -------------------------------------------------------------------------------- /Lesson05/Exercise26/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "projs-l5", 3 | "version": "1.0.0", 4 | "description": "Sample code for Lesson 05 in Professional JavaScript.", 5 | "keywords": [ 6 | "Packt", 7 | "JavaScript", 8 | "modules" 9 | ], 10 | "homepage": "https://github.com/TrainingByPackt/Professional-JavaScript", 11 | "bugs": { 12 | "url": "https://github.com/TrainingByPackt/Professional-JavaScript/issues", 13 | "email": "kirkins@gmail.com" 14 | }, 15 | "license": "MIT", 16 | "author": "Philip Kirkbride", 17 | "repository": "https://github.com/TrainingByPackt/Professional-JavaScript", 18 | "scripts": { 19 | "start": "ws" 20 | }, 21 | "devDependencies": { 22 | "local-web-server": "^2.6.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Lesson05/Exercise27/images/bulb_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise27/images/bulb_off.png -------------------------------------------------------------------------------- /Lesson05/Exercise27/images/bulb_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise27/images/bulb_on.png -------------------------------------------------------------------------------- /Lesson05/Exercise27/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Light Viewer 7 | 8 | 9 |
10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Lesson05/Exercise27/js/viewer.js: -------------------------------------------------------------------------------- 1 | import ColorLight from './colorLight.js'; 2 | 3 | let slider = document.getElementById("brightnessSlider"); 4 | let color = document.getElementById("color"); 5 | let button = document.getElementById("build"); 6 | 7 | button.onclick = function () { 8 | new ColorLight(true, slider.value, color.value); 9 | } 10 | -------------------------------------------------------------------------------- /Lesson05/Exercise27/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "projs-l5", 3 | "version": "1.0.0", 4 | "description": "Sample code for Lesson 05 in Professional JavaScript.", 5 | "keywords": [ 6 | "Packt", 7 | "JavaScript", 8 | "modules" 9 | ], 10 | "homepage": "https://github.com/TrainingByPackt/Professional-JavaScript", 11 | "bugs": { 12 | "url": "https://github.com/TrainingByPackt/Professional-JavaScript/issues", 13 | "email": "kirkins@gmail.com" 14 | }, 15 | "license": "MIT", 16 | "author": "Philip Kirkbride", 17 | "repository": "https://github.com/TrainingByPackt/Professional-JavaScript", 18 | "scripts": { 19 | "start": "ws" 20 | }, 21 | "devDependencies": { 22 | "local-web-server": "^2.6.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Lesson05/Exercise28/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /Lesson05/Exercise28/build/images/bulb_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise28/build/images/bulb_off.png -------------------------------------------------------------------------------- /Lesson05/Exercise28/build/images/bulb_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise28/build/images/bulb_on.png -------------------------------------------------------------------------------- /Lesson05/Exercise28/build/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Light Viewer 7 | 8 | 9 |
10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Lesson05/Exercise28/build/js/viewer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var _colorLight = _interopRequireDefault(require("./colorLight.js")); 4 | 5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } 6 | 7 | var slider = document.getElementById("brightnessSlider"); 8 | var color = document.getElementById("color"); 9 | var button = document.getElementById("build"); 10 | 11 | button.onclick = function () { 12 | new _colorLight["default"](true, slider.value, color.value); 13 | }; -------------------------------------------------------------------------------- /Lesson05/Exercise28/src/images/bulb_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise28/src/images/bulb_off.png -------------------------------------------------------------------------------- /Lesson05/Exercise28/src/images/bulb_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/Exercise28/src/images/bulb_on.png -------------------------------------------------------------------------------- /Lesson05/Exercise28/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Light Viewer 7 | 8 | 9 |
10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Lesson05/Exercise28/src/js/viewer.js: -------------------------------------------------------------------------------- 1 | import ColorLight from './colorLight.js'; 2 | 3 | let slider = document.getElementById("brightnessSlider"); 4 | let color = document.getElementById("color"); 5 | let button = document.getElementById("build"); 6 | 7 | button.onclick = function () { 8 | new ColorLight(true, slider.value, color.value); 9 | } 10 | -------------------------------------------------------------------------------- /Lesson05/Exercise28/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | module.exports = { 4 | mode: 'development', 5 | entry: "./build/js/viewer.js", 6 | output: { 7 | path: path.resolve(__dirname, "build"), 8 | filename: "bundle.js" 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /Lesson05/start/images/bulb_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/start/images/bulb_off.png -------------------------------------------------------------------------------- /Lesson05/start/images/bulb_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson05/start/images/bulb_on.png -------------------------------------------------------------------------------- /Lesson05/start/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Light Viewer 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lesson05/start/js/viewer.js: -------------------------------------------------------------------------------- 1 | // Page elements and variables 2 | let bulb = document.getElementById("bulb"); 3 | let slider = document.getElementById("brightnessSlider"); 4 | let onImage = "images/bulb_on.png"; 5 | let offImage = "images/bulb_off.png"; 6 | -------------------------------------------------------------------------------- /Lesson05/start/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "projs-l5", 3 | "version": "1.0.0", 4 | "description": "Sample code for Lesson 05 in Professional JavaScript.", 5 | "keywords": [ 6 | "Packt", 7 | "JavaScript", 8 | "modules" 9 | ], 10 | "homepage": "https://github.com/TrainingByPackt/Professional-JavaScript", 11 | "bugs": { 12 | "url": "https://github.com/TrainingByPackt/Professional-JavaScript/issues", 13 | "email": "kirkins@gmail.com" 14 | }, 15 | "license": "MIT", 16 | "author": "Philip Kirkbride", 17 | "repository": "https://github.com/TrainingByPackt/Professional-JavaScript", 18 | "scripts": { 19 | "start": "ws" 20 | }, 21 | "devDependencies": { 22 | "local-web-server": "^2.6.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Lesson06/Activity07/result/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["airbnb-base", "prettier"], 3 | "parserOptions": { 4 | "ecmaVersion": 2018, 5 | "sourceType": "module" 6 | }, 7 | "env": { 8 | "browser": true, 9 | "node": true, 10 | "es6": true, 11 | "mocha": true, 12 | "jest": true 13 | }, 14 | "plugins": [], 15 | "rules": { 16 | "no-unused-vars": [ 17 | "error", 18 | { 19 | "vars": "local", 20 | "args": "none" 21 | } 22 | ], 23 | "no-plusplus": "off", 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Lesson06/Activity07/result/.huskyrc: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "pre-commit": "npm run lint && npm test" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Lesson06/Activity07/result/.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | -------------------------------------------------------------------------------- /Lesson06/Activity07/result/images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson06/Activity07/result/images/screenshot.png -------------------------------------------------------------------------------- /Lesson06/Activity07/result/jest-puppeteer.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | server: { 3 | command: 'npm start', 4 | port: 8080, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /Lesson06/Activity07/result/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "before", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "http-server": "^0.11.1" 8 | }, 9 | "devDependencies": { 10 | "eslint": "^5.16.0", 11 | "eslint-config-airbnb-base": "^13.1.0", 12 | "eslint-config-prettier": "^4.3.0", 13 | "eslint-plugin-import": "^2.17.3", 14 | "eslint-plugin-jest": "^22.6.4", 15 | "husky": "^2.4.0", 16 | "jest": "^24.8.0", 17 | "jest-puppeteer": "^4.2.0", 18 | "prettier": "^1.18.1", 19 | "puppeteer": "^1.17.0" 20 | }, 21 | "scripts": { 22 | "start": "http-server", 23 | "lint": "prettier --write js/*.js && eslint js/*.js", 24 | "test": "jest" 25 | }, 26 | "jest": { 27 | "preset": "jest-puppeteer" 28 | }, 29 | "author": "", 30 | "license": "ISC" 31 | } 32 | -------------------------------------------------------------------------------- /Lesson06/Activity07/start/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | .idea -------------------------------------------------------------------------------- /Lesson06/Activity07/start/images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson06/Activity07/start/images/screenshot.png -------------------------------------------------------------------------------- /Lesson06/Activity07/start/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "before", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "http-server": "^0.11.1" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "start": "http-server" 12 | }, 13 | "author": "Philip Kirkbride", 14 | "license": "ISC" 15 | } 16 | -------------------------------------------------------------------------------- /Lesson06/Exercise29/result/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["airbnb-base", "prettier"], 3 | "parserOptions": { 4 | "ecmaVersion": 2018, 5 | "sourceType": "module" 6 | }, 7 | "env": { 8 | "browser": true, 9 | "node": true, 10 | "es6": true, 11 | "mocha": true, 12 | "jest": true, 13 | }, 14 | "plugins": [], 15 | "rules": { 16 | "no-unused-vars": [ 17 | "error", 18 | { 19 | "vars": "local", 20 | "args": "none" 21 | } 22 | ], 23 | "no-plusplus": "off", 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Lesson06/Exercise29/result/.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | -------------------------------------------------------------------------------- /Lesson06/Exercise29/result/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lint", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "lint": "prettier --write src/**/*.js && eslint src/*.js" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "eslint": "^5.16.0", 15 | "eslint-config-airbnb-base": "^13.1.0", 16 | "eslint-config-prettier": "^4.3.0", 17 | "eslint-plugin-import": "^2.17.3", 18 | "eslint-plugin-jest": "^22.6.4", 19 | "prettier": "^1.17.1" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Lesson06/Exercise29/result/src/square.js: -------------------------------------------------------------------------------- 1 | const square = x => x * x; 2 | console.log(square(5)); 3 | -------------------------------------------------------------------------------- /Lesson06/Exercise30/result/__test__/math.test.js: -------------------------------------------------------------------------------- 1 | const math = require('./../src/math.js'); 2 | 3 | test('Check that square of 5 is 25', () => { 4 | expect(math.square(5)).toBe(25); 5 | }); 6 | -------------------------------------------------------------------------------- /Lesson06/Exercise30/result/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jest1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "jest": "^24.8.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lesson06/Exercise30/result/src/math.js: -------------------------------------------------------------------------------- 1 | const square = (x) => x * x; 2 | const cube = (x) => x * x * x; 3 | const add = (x, y) => x + y; 4 | const subtract = (x, y) => x - y; 5 | const multiply = (x, y) => x * y; 6 | 7 | const math = { 8 | square, 9 | cube, 10 | add, 11 | subtract, 12 | multiply 13 | } 14 | 15 | module.exports = math; 16 | -------------------------------------------------------------------------------- /Lesson06/Exercise30/start/src/math.js: -------------------------------------------------------------------------------- 1 | const square = (x) => x + x; 2 | const cube = (x) => x * x * x; 3 | const add = (x, y) => x + y; 4 | const subtract = (x, y) => x - y; 5 | const multiply = (x, y) => x * y; 6 | 7 | const math = { 8 | square, 9 | cube, 10 | add, 11 | subtract, 12 | multiply 13 | } 14 | 15 | module.exports = math; 16 | -------------------------------------------------------------------------------- /Lesson06/Exercise31/result/__test__/math.test.js: -------------------------------------------------------------------------------- 1 | const math = require('./../src/math.js'); 2 | 3 | test('Check that square of 5 is 25', () => { 4 | expect(math.square(5)).toBe(25); 5 | }); 6 | 7 | test('check that square of result from 1 + 1 is 4', () => { 8 | const start = new Date(); 9 | expect(math.square(math.add(1,1))).toBe(4); 10 | expect(new Date() - start).toBeLessThan(5000); 11 | }); 12 | 13 | test('check that square of result from 1 - 1 is 0', () => { 14 | expect(math.square(math.subtract(1,1))).toBe(0); 15 | }); 16 | 17 | test('check that square of result from 1 + 1 is 4', () => { 18 | expect(math.subtract(math.cube(5), 5)).toBe(120); 19 | }); 20 | -------------------------------------------------------------------------------- /Lesson06/Exercise31/result/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jest1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "jest": "^24.8.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lesson06/Exercise31/result/src/math.js: -------------------------------------------------------------------------------- 1 | const square = (x) => x * x; 2 | const cube = (x) => x * x * x; 3 | const add = (x, y) => x + y; 4 | const subtract = (x, y) => x - y; 5 | const multiply = (x, y) => x * y; 6 | 7 | const math = { 8 | square, 9 | cube, 10 | add, 11 | subtract, 12 | multiply 13 | } 14 | 15 | module.exports = math; 16 | -------------------------------------------------------------------------------- /Lesson06/Exercise31/start/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jest1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "jest": "^24.8.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lesson06/Exercise31/start/src/math.js: -------------------------------------------------------------------------------- 1 | const square = (x) => x * x; 2 | const cube = (x) => x * x * x; 3 | const add = (x, y) => x + y; 4 | const subtract = (x, y) => x - y; 5 | const multiply = (x, y) => x * y; 6 | 7 | const math = { 8 | square, 9 | cube, 10 | add, 11 | subtract, 12 | multiply 13 | } 14 | 15 | module.exports = math; 16 | -------------------------------------------------------------------------------- /Lesson06/Exercise32/result/__tests__/fib.test.js: -------------------------------------------------------------------------------- 1 | const fastFib = require('./../fastFib'); 2 | const slowFib = require('./../slowFib'); 3 | 4 | test('Fast way of getting Fibonacci of 44', () => { 5 | const start = new Date(); 6 | expect(fastFib(44)).toBe(701408733); 7 | expect(new Date() - start).toBeLessThan(5000); 8 | }); 9 | 10 | test('Timer - Slow way of getting Fibonacci of 44', () => { 11 | const start = new Date(); 12 | expect(slowFib(44)).toBe(701408733); 13 | expect(new Date() - start).toBeLessThan(5000); 14 | }); 15 | -------------------------------------------------------------------------------- /Lesson06/Exercise32/result/fastFib.js: -------------------------------------------------------------------------------- 1 | function fibonacciIterator(a, b, n) { 2 | return n == 0 ? b : fibonacciIterator((a+b), a, (n-1)); 3 | } 4 | 5 | function fibonacci(n) { 6 | return fibonacciIterator(1, 0, n); 7 | } 8 | 9 | module.exports = fibonacci; 10 | -------------------------------------------------------------------------------- /Lesson06/Exercise32/result/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tmp", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "jest": "^24.8.0" 8 | }, 9 | "scripts": { 10 | "test": "jest" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lesson06/Exercise32/result/slowFib.js: -------------------------------------------------------------------------------- 1 | function fib(n) { 2 | return (n<=1) ? n : fib(n - 1) + fib(n - 2); 3 | } 4 | 5 | module.exports = fib; 6 | -------------------------------------------------------------------------------- /Lesson06/Exercise32/start/fastFib.js: -------------------------------------------------------------------------------- 1 | function fibonacciIterator(a, b, n) { 2 | return n == 0 ? b : fibonacciIterator((a+b), a, (n-1)); 3 | } 4 | 5 | function fibonacci(n) { 6 | return fibonacciIterator(1, 0, n); 7 | } 8 | 9 | module.exports = fibonacci; 10 | -------------------------------------------------------------------------------- /Lesson06/Exercise32/start/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tmp", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "dependencies": { 7 | "jest": "^24.8.0" 8 | }, 9 | "scripts": { 10 | "test": "jest" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lesson06/Exercise32/start/slowFib.js: -------------------------------------------------------------------------------- 1 | function fib(n) { 2 | return (n<=1) ? n : fib(n - 1) + fib(n - 2); 3 | } 4 | 5 | module.exports = fib; 6 | -------------------------------------------------------------------------------- /Lesson06/Exercise33/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | .idea -------------------------------------------------------------------------------- /Lesson06/Exercise33/result/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | .idea -------------------------------------------------------------------------------- /Lesson06/Exercise33/result/__tests__/test.test.js: -------------------------------------------------------------------------------- 1 | describe('Calculator', () => { 2 | beforeAll(async () => { 3 | await page.goto('http://localhost:8080/index.html') 4 | }) 5 | 6 | it('Check that 5 times 5 is 25', async () => { 7 | const five = await page.$("#five"); 8 | const multiply = await page.$("#multiply"); 9 | const equals = await page.$("#equals"); 10 | await five.click(); 11 | await multiply.click(); 12 | await five.click(); 13 | await equals.click(); 14 | const result = await page.$eval('#screen', e => e.innerText); 15 | expect(result).toMatch('25'); 16 | }) 17 | }) 18 | -------------------------------------------------------------------------------- /Lesson06/Exercise33/result/images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson06/Exercise33/result/images/screenshot.png -------------------------------------------------------------------------------- /Lesson06/Exercise33/result/jest-puppeteer.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | server: { 3 | command: 'npm start', 4 | port: 8080, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /Lesson06/Exercise33/result/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "after", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "jest-puppeteer.config.js", 6 | "dependencies": { 7 | "http-server": "^0.11.1" 8 | }, 9 | "devDependencies": { 10 | "jest": "^24.8.0", 11 | "jest-puppeteer": "^4.2.0", 12 | "puppeteer": "^1.17.0" 13 | }, 14 | "scripts": { 15 | "test": "jest", 16 | "start": "http-server" 17 | }, 18 | "jest": { 19 | "preset": "jest-puppeteer" 20 | }, 21 | "author": "Philip Kirkbride", 22 | "license": "ISC" 23 | } 24 | -------------------------------------------------------------------------------- /Lesson06/Exercise33/start/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | .idea -------------------------------------------------------------------------------- /Lesson06/Exercise33/start/images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-JavaScript/58c2f50e3764b8d1aae52fca6dd2a7313461cd68/Lesson06/Exercise33/start/images/screenshot.png -------------------------------------------------------------------------------- /Lesson06/Exercise33/start/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "before", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "http-server": "^0.11.1" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "start": "http-server" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC" 16 | } 17 | -------------------------------------------------------------------------------- /Lesson06/Exercise34/result/README.md: -------------------------------------------------------------------------------- 1 | Due to this exercise using a feature of git itself, the result cannot be saved to a repository. 2 | -------------------------------------------------------------------------------- /Lesson06/Exercise34/start/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["airbnb-base", "prettier"], 3 | "parserOptions": { 4 | "ecmaVersion": 2018, 5 | "sourceType": "module" 6 | }, 7 | "env": { 8 | "browser": true, 9 | "node": true, 10 | "es6": true, 11 | "mocha": true, 12 | "jest": true, 13 | }, 14 | "plugins": [], 15 | "rules": { 16 | "no-unused-vars": [ 17 | "error", 18 | { 19 | "vars": "local", 20 | "args": "none" 21 | } 22 | ], 23 | "no-plusplus": "off", 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Lesson06/Exercise34/start/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lint", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "lint": "prettier --write src/**/*.js && eslint src/*.js", 9 | "prettier": "prettier --write src/**/*.js" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "eslint": "^5.16.0", 16 | "eslint-config-airbnb-base": "^13.1.0", 17 | "eslint-config-prettier": "^4.3.0", 18 | "eslint-plugin-import": "^2.17.3", 19 | "eslint-plugin-jest": "^22.6.4", 20 | "prettier": "^1.17.1" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lesson06/Exercise34/start/src/js.js: -------------------------------------------------------------------------------- 1 | const square = x => x * x; 2 | console.log(square(5)); 3 | -------------------------------------------------------------------------------- /Lesson06/Exercise35/result/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["airbnb-base", "prettier"], 3 | "parserOptions": { 4 | "ecmaVersion": 2018, 5 | "sourceType": "module" 6 | }, 7 | "env": { 8 | "browser": true, 9 | "node": true, 10 | "es6": true, 11 | "mocha": true, 12 | "jest": true, 13 | }, 14 | "plugins": [], 15 | "rules": { 16 | "no-unused-vars": [ 17 | "error", 18 | { 19 | "vars": "local", 20 | "args": "none" 21 | } 22 | ], 23 | "no-plusplus": "off", 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Lesson06/Exercise35/result/.huskyrc: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "pre-commit": "npm run lint" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Lesson06/Exercise35/result/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lint", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "lint": "prettier --write src/**/*.js && eslint src/*.js", 9 | "prettier": "prettier --write src/**/*.js" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "eslint": "^5.16.0", 16 | "eslint-config-airbnb-base": "^13.1.0", 17 | "eslint-config-prettier": "^4.3.0", 18 | "eslint-plugin-import": "^2.17.3", 19 | "eslint-plugin-jest": "^22.6.4", 20 | "husky": "^2.3.0", 21 | "prettier": "^1.17.1" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Lesson06/Exercise35/result/src/js.js: -------------------------------------------------------------------------------- 1 | const square = x => x * x; 2 | console.log(square(5)); 3 | -------------------------------------------------------------------------------- /Lesson06/Exercise35/start/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["airbnb-base", "prettier"], 3 | "parserOptions": { 4 | "ecmaVersion": 2018, 5 | "sourceType": "module" 6 | }, 7 | "env": { 8 | "browser": true, 9 | "node": true, 10 | "es6": true, 11 | "mocha": true, 12 | "jest": true, 13 | }, 14 | "plugins": [], 15 | "rules": { 16 | "no-unused-vars": [ 17 | "error", 18 | { 19 | "vars": "local", 20 | "args": "none" 21 | } 22 | ], 23 | "no-plusplus": "off", 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Lesson06/Exercise35/start/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lint", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "lint": "prettier --write src/**/*.js && eslint src/*.js", 9 | "prettier": "prettier --write src/**/*.js" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "eslint": "^5.16.0", 16 | "eslint-config-airbnb-base": "^13.1.0", 17 | "eslint-config-prettier": "^4.3.0", 18 | "eslint-plugin-import": "^2.17.3", 19 | "eslint-plugin-jest": "^22.6.4", 20 | "prettier": "^1.17.1" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lesson06/Exercise35/start/src/js.js: -------------------------------------------------------------------------------- 1 | const square = x => x * x; 2 | console.log(square(5)); 3 | -------------------------------------------------------------------------------- /Lesson06/Exercise36/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | .idea -------------------------------------------------------------------------------- /Lesson06/Exercise36/result/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | .idea -------------------------------------------------------------------------------- /Lesson06/Exercise36/result/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Example quiz 7 | 8 | 9 | 10 |
Score: 0
11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Lesson06/Exercise36/result/jest-puppeteer.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | server: { 3 | command: 'npm start', 4 | port: 8080, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /Lesson06/Exercise36/result/js/questions.js: -------------------------------------------------------------------------------- 1 | export let questions = { 2 | "1": { 3 | "text": "5+5", 4 | "wrong": ["5", "15", "20"], 5 | "right": "10" 6 | }, 7 | "2": { 8 | "text": "100-64", 9 | "wrong": ["77", "50", "20"], 10 | "right": "36" 11 | }, 12 | "3": { 13 | "text": "3*3", 14 | "wrong": ["20", "23", "11"], 15 | "right": "9" 16 | }, 17 | "4": { 18 | "text": "33*3", 19 | "wrong": ["111", "112", "119"], 20 | "right": "99" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lesson06/Exercise36/result/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "before", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "http-server": "^0.11.1" 8 | }, 9 | "devDependencies": { 10 | "jest": "^24.9.0", 11 | "jest-puppeteer": "^4.3.0", 12 | "puppeteer": "^1.19.0" 13 | }, 14 | "scripts": { 15 | "start": "http-server", 16 | "test": "jest" 17 | }, 18 | "jest": { 19 | "preset": "jest-puppeteer" 20 | }, 21 | "keywords": [], 22 | "author": "", 23 | "license": "ISC" 24 | } 25 | -------------------------------------------------------------------------------- /Lesson06/Exercise36/start/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | .idea -------------------------------------------------------------------------------- /Lesson06/Exercise36/start/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Example quiz 7 | 8 | 9 | 10 |
Score: 0
11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Lesson06/Exercise36/start/js/questions.js: -------------------------------------------------------------------------------- 1 | export let questions = { 2 | "1": { 3 | "text": "5+5", 4 | "wrong": ["5", "15", "20"], 5 | "right": "10" 6 | }, 7 | "2": { 8 | "text": "100-64", 9 | "wrong": ["77", "50", "20"], 10 | "right": "36" 11 | }, 12 | "3": { 13 | "text": "3*3", 14 | "wrong": ["20", "23", "11"], 15 | "right": "9" 16 | }, 17 | "4": { 18 | "text": "33*3", 19 | "wrong": ["111", "112", "119"], 20 | "right": "99" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lesson06/Exercise36/start/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "before", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "dependencies": { 7 | "http-server": "^0.11.1" 8 | }, 9 | "scripts": { 10 | "start": "http-server" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC" 15 | } 16 | -------------------------------------------------------------------------------- /Lesson07/Exercise37/Exercise37.js: -------------------------------------------------------------------------------- 1 | let exampleArray1 = []; 2 | Array.isArray(exampleArray1); 3 | 4 | // Or 5 | let exampleArray2 = new Array(); 6 | Array.isArray(exampleArray2); 7 | 8 | // Or 9 | let exampleArray3 = []; 10 | typeof exampleArray3 11 | 12 | // Or 13 | let exampleArray4 = new Array(6); 14 | console.log(exampleArray4); 15 | 16 | // Or 17 | let singers = new Array(6).fill('miku'); 18 | 19 | singers[0] = 'miku'; 20 | console.log(singers); 21 | 22 | singers[3] = 'luka'; 23 | console.log(singers[1]); 24 | 25 | singers[singers.length - 1] = 'rin'; 26 | console.log(singers); 27 | -------------------------------------------------------------------------------- /Lesson07/Exercise38/Exercise38.js: -------------------------------------------------------------------------------- 1 | let singers = []; 2 | singers.push('miku'); 3 | console.log(singers); 4 | 5 | let food = new Array(3) 6 | food.push('burger'); 7 | console.log(food); 8 | 9 | singers.push('me'); 10 | console.log(singers); 11 | 12 | singers.pop(); 13 | console.log(singers); 14 | 15 | singers.unshift('rin') 16 | 17 | console.log(singers); 18 | -------------------------------------------------------------------------------- /Lesson07/Exercise39/Exercise39.js: -------------------------------------------------------------------------------- 1 | let foods = []; 2 | 3 | foods.push('burger'); 4 | foods.push('fries'); 5 | foods.push('wings'); 6 | 7 | console.log(foods.indexOf('burger')); 8 | 9 | console.log(foods.length); 10 | 11 | let position = foods.indexOf('burger'); 12 | foods.splice(position, 1); 13 | 14 | console.log(foods); 15 | -------------------------------------------------------------------------------- /Lesson07/Exercise40/Exercise40.js: -------------------------------------------------------------------------------- 1 | // 1 2 | let singers = []; 3 | // 2 4 | singers.push({ name: 'miku', age: 16 }); 5 | // 3 6 | singers[0].name = 'Hatsune Miku' 7 | console.log(singers); 8 | // 4 9 | singers[0].birthday = 'August 31'; 10 | console.log(singers); 11 | // 5 12 | console.log(singers[0].name); 13 | const propertyName = 'name'; 14 | console.log(singers[0][propertyName]); 15 | // 6 16 | let myConsole = { name: 'PS4', color: 'black', price: 499, library: []}; 17 | // 7 18 | console.log(Object.keys(myConsole)); 19 | // 8 20 | if (myConsole.ramSize) { 21 | console.log('ram size is defined.'); 22 | } 23 | -------------------------------------------------------------------------------- /Lesson07/Exercise41/Exercise41.js: -------------------------------------------------------------------------------- 1 | function betterStringify(item, propertyMap) { 2 | let output = {}; 3 | // Cherry pick all the property we want and store it in the output 4 | propertyMap.forEach((key) => { 5 | if (item[key]) { 6 | output[key] = item[key]; 7 | } 8 | }); 9 | return JSON.stringify(output); 10 | } 11 | 12 | const singer = { 13 | name: 'Hatsune Miku', 14 | age: 16, 15 | birthday: 'August 31', 16 | birthplace: 'Sapporo, Japan', 17 | songList: [ 18 | 'World is mine', 19 | 'Tell your world', 20 | 'Melt' 21 | ] 22 | } 23 | 24 | console.log(betterStringify(singer, ['name', 'birthday'])); 25 | -------------------------------------------------------------------------------- /Lesson07/Exercise42/Exercise42.js: -------------------------------------------------------------------------------- 1 | // 1 2 | const userInfo = ['John', 'chef', 34]; 3 | // 2 4 | let name, age, job; 5 | // 3 6 | [name, job, age] = userInfo; 7 | // 4 8 | console.log(name); 9 | console.log(job); 10 | console.log(age); 11 | // 5 12 | [name, ,age] = userInfo 13 | -------------------------------------------------------------------------------- /Lesson07/Exercise43/Exercise43.js: -------------------------------------------------------------------------------- 1 | // 1 2 | const userInfo = { name: 'John', job: 'chef', age: 34 }; 3 | // 2 4 | let name, job; 5 | // 3 6 | ({ name, job } = userInfo); 7 | // 4 8 | console.log(name); 9 | console.log(job); 10 | // 5 11 | const userInfo = ['John', 'chef', 34]; 12 | let [ name, , age] = userInfo; 13 | console.log(name); 14 | console.log(age); 15 | // 6 16 | const userInfoObj = { name: 'John', job: 'chef', age: 34 }; 17 | let { job } userInfoObj; 18 | console.log(job); 19 | -------------------------------------------------------------------------------- /Lesson07/Exercise44/Exercise44.js: -------------------------------------------------------------------------------- 1 | // 1 2 | const userInfo = ['John', 'chef', 34]; 3 | 4 | // 2 5 | function printUser(name, job, age) { 6 | console.log(name + ' is working as ' + job + ' and is ' + age + ' years old'); 7 | } 8 | 9 | // 3 10 | printUser(...userInfo) 11 | 12 | // 4 13 | const detailedInfo = ['male', ...userInfo, 'July 5'] 14 | console.log(detailedInfo) 15 | 16 | // 5 17 | let detailedInfoCopy = [ ...detailedInfo ]; 18 | console.log(detailedInfoCopy) 19 | 20 | // 6 21 | const userRequest = { name: 'username', type: 'update', data: 'newname'} 22 | 23 | //7 24 | const newObj = { ...userRequest } 25 | console.log(newObj) 26 | 27 | //8 28 | const detailedRequestObj = { data: new Date(), new: true, ...userRequest} 29 | console.log(detailedRequestObj) 30 | 31 | -------------------------------------------------------------------------------- /Lesson07/Exercise45/Exercise45.js: -------------------------------------------------------------------------------- 1 | function Food(name, calories, cost) { 2 | this.name = name; 3 | this.calories = calories; 4 | this.cost = cost; 5 | } 6 | Food.prototype.description = function () { 7 | return this.name + ' calories: ' + this.calories; 8 | } 9 | let burger = new Food('burger', 1000, 9); 10 | console.log(burger.description()); -------------------------------------------------------------------------------- /Lesson07/Exercise46/Exercise46.js: -------------------------------------------------------------------------------- 1 | class Food { 2 | constructor(name, calories, cost) { 3 | this.name = name; 4 | this.calories = calories; 5 | this.cost = cost; 6 | } 7 | static getCalories(food) { 8 | return food.calories 9 | } 10 | description() { 11 | return this.name + ' calories: ' + this.calories; 12 | } 13 | } 14 | 15 | // Food('burger', 1000, 9); 16 | // TypeError: Class constructor Food2 cannot be invoked without 'new' 17 | let friedChicken = new Food('fried chicken', 520, 5); 18 | console.log(friedChicken.description()); 19 | 20 | console.log(Food.getCalories(friedChicken)); /// 520 21 | -------------------------------------------------------------------------------- /Lesson07/Exercise50/Exercise50.js: -------------------------------------------------------------------------------- 1 | const foods = ['sushi', 'tofu', 'fried chicken']; 2 | foods.join(', '); 3 | 4 | function eat_food(food) { 5 | console.log('I am eating ' + food); 6 | } 7 | 8 | function eat_food(food) { 9 | console.log('I am eating ' + food); 10 | } 11 | 12 | for(let i = 0; i < foods.length; i++) { 13 | eat_food(foods[i]); 14 | } 15 | 16 | foods.forEach(eat_food); 17 | 18 | const nutrition = [100, 50, 400]; 19 | const foodInfo = foods.map((food, index) => { 20 | return { 21 | name: food, 22 | calories: nutrition[index] 23 | }; 24 | }); 25 | console.log(foodInfo); -------------------------------------------------------------------------------- /Lesson07/Exercise51/Exercise51.js: -------------------------------------------------------------------------------- 1 | let profiles = [ 2 | 'Michael Scott', 3 | 'Jim Halpert', 4 | 'Dwight Shrute', 5 | 'Random User', 6 | 'Hatsune Miku', 7 | 'Rin Kagamine' 8 | ]; 9 | let hasJim = profiles.includes('Jim Halpert'); 10 | console.log(hasJim); 11 | 12 | profiles = [ 13 | { name: 'Michael Scott', age: 42 }, 14 | { name: 'Jim Halpert', age: 27}, 15 | { name: 'Dwight Shrute', age: 37 }, 16 | { name: 'Random User', age: 10 }, 17 | { name: 'Hatsune Miku', age: 16 }, 18 | { name: 'Rin Kagamine', age: 14 } 19 | ]; 20 | 21 | hasJim = profiles.includes({ name: 'Jim Halpert', age: 27}); 22 | console.log(hasJim); 23 | 24 | hasJim = !!profiles.find((profile) => { 25 | return profile.name === 'Jim Halpert'; 26 | }).length; 27 | console.log(hasJim); 28 | 29 | const adults = profiles.filter((profile) => { 30 | return profile.age > 18; 31 | }); 32 | console.log(adults); 33 | -------------------------------------------------------------------------------- /Lesson07/Exercise52/Exercise52.js: -------------------------------------------------------------------------------- 1 | const numbers = [ 20, 1, 3, 55, 100, 2]; 2 | numbers.sort(); 3 | console.log(numbers); 4 | 5 | function compareNumber(a, b) { 6 | return a - b; 7 | } 8 | numbers.sort(compareNumber); 9 | console.log(numbers); 10 | 11 | const profiles = [ 12 | { name: 'Michael Scott', age: 42 }, 13 | { name: 'Jim Halpert', age: 27}, 14 | { name: 'Dwight Shrute', age: 37 }, 15 | { name: 'Random User', age: 10 }, 16 | { name: 'Hatsune Miku', age: 16 }, 17 | { name: 'Rin Kagamine', age: 14 } 18 | ]; 19 | profiles.sort(); 20 | console.log(profiles); 21 | 22 | function compareAge(a, b) { 23 | return a.age - b.age; 24 | } 25 | 26 | profiles.sort(compareAge); 27 | console.log(profiles); 28 | -------------------------------------------------------------------------------- /Lesson07/Exercise53/Exercise53.js: -------------------------------------------------------------------------------- 1 | const cart = []; 2 | 3 | cart.push({ name: 'CD', price: 12.00, amount: 2 }); 4 | cart.push({ name: 'Book', price: 45.90, amount: 1 }); 5 | cart.push({ name: 'Headphones', price: 5.99, amount: 3 }); 6 | cart.push({ name: 'Coffee', price: 12.00, amount: 2 }); 7 | cart.push({ name: 'Mug', price: 15.45, amount: 1 }); 8 | cart.push({ name: 'Sugar', price: 5.00, amount: 1 }); 9 | 10 | let total = 0; 11 | cart.forEach((item) => { 12 | total += item.price * item.amount; 13 | }); 14 | console.log('Total amount: ' + total); 15 | 16 | function priceReducer (accumulator, currentValue) { 17 | return accumulator += currentValue.price * currentValue.amount; 18 | } 19 | 20 | total = cart.reduce(priceReducer, 0); 21 | console.log('Total amount: ' + total); 22 | -------------------------------------------------------------------------------- /Lesson07/Exercise54/Exercise54.js: -------------------------------------------------------------------------------- 1 | const map = new Map(); 2 | const key1 = 'key1'; 3 | const key2 = { name: 'John', age: 18 }; 4 | const key3 = Map; 5 | map.set(key1, 'value for key1'); 6 | map.set(key2, 'value for key2'); 7 | map.set(key3, 'value for key3'); 8 | console.log(map.get(key1)); 9 | console.log(map.get(key2)); 10 | console.log(map.get(key3)); 11 | 12 | console.log(map.get({ name: 'John', age: 18 })); 13 | 14 | map.forEach((value, key) => { 15 | console.log('the value for key: ' + key + ' is ' + value); 16 | }); 17 | console.log(map.keys()); 18 | console.log(map.values()); 19 | console.log(map.has('non exist')); // false -------------------------------------------------------------------------------- /Lesson07/Exercise55/Exercise55.js: -------------------------------------------------------------------------------- 1 | const planets = [ 2 | 'Mercury', 3 | 'Uranus', 4 | 'Mars', 5 | 'Venus', 6 | 'Neptune', 7 | 'Saturn', 8 | 'Mars', 9 | 'Jupiter', 10 | 'Earth', 11 | 'Saturn' 12 | ]; 13 | const planetSet = new Set(planets); 14 | console.log(planetSet.values()); 15 | 16 | planetSet.add('Venus'); 17 | planetSet.add('Kepler-440b'); 18 | console.log(planetSet.size); 19 | 20 | planetSet.clear(); 21 | console.log(planetSet); 22 | -------------------------------------------------------------------------------- /Lesson07/Exercise56/Exercise56.js: -------------------------------------------------------------------------------- 1 | let planet = 'Earth'; 2 | let sentence = `We are on the planet ${planet}`; 3 | console.log(sentence); 4 | 5 | console.log(sentence.split(' ')); 6 | 7 | sentence = sentence.replace('Earth', 'Venus'); 8 | console.log(sentence); 9 | console.log(sentence.includes('Mars')); 10 | sentence.toUpperCase(); 11 | sentence.toLowerCase(); 12 | sentence.charAt(0); // returns W 13 | console.log(sentence.length); 14 | -------------------------------------------------------------------------------- /Lesson07/Exercise57/Exercise57.js: -------------------------------------------------------------------------------- 1 | function generateRandomString(length) { 2 | const characters = []; 3 | const characterSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 4 | for (let i = 0; i < length; i++) { 5 | characters.push(characterSet.charAt(generateRandomNumber(0, characterSet.length))); 6 | } 7 | return characters.join(''); 8 | } 9 | 10 | function generateRandomNumber(min, max) { 11 | return Math.floor(Math.random() * (max - min + 1)) + min; 12 | } 13 | 14 | console.log(generateRandomString(16)); 15 | 16 | console.log(Math.PI); 17 | 18 | function circleArea(radius) { 19 | return Math.pow(radius, 2) * Math.PI; 20 | } 21 | 22 | const now = new Date(); 23 | console.log(now); 24 | 25 | const past = new Date('August 31, 2007 00:00:00'); 26 | console.log(past); 27 | 28 | console.log(past.getFullYear()); 29 | console.log(past.getMonth()); 30 | console.log(past.getDate()); 31 | 32 | console.log(past.toString()); 33 | 34 | console.log(Math.floor(Date.now() / 1000)); -------------------------------------------------------------------------------- /Lesson07/Exercise58/Exercise58.js: -------------------------------------------------------------------------------- 1 | let symbol1 = Symbol(); 2 | let symbol2 = Symbol('symbol'); 3 | console.log(symbol1 === symbol2); 4 | console.log(symbol1 === Symbol('symbol')); 5 | const testObj = {}; 6 | testObj.name = 'test object'; 7 | testObj.included = 'this will be included'; 8 | const symbolKey = Symbol(); 9 | testObj[symbolKey] = 'this will be hidden'; 10 | 11 | console.log(Object.keys(testObj)); 12 | console.log(testObj[Symbol()]); // Will return undefined 13 | console.log(testObj[symbolKey]); // Will return our hidden property 14 | 15 | const anotherSymbolKey = Symbol.for('key'); 16 | const copyOfAnotherSymbol = Symbol.for('key'); 17 | testObj[anotherSymbolKey] = 'another key'; 18 | console.log(testObj[copyOfAnotherSymbol]); 19 | -------------------------------------------------------------------------------- /Lesson07/Exercise59/Exercise59.js: -------------------------------------------------------------------------------- 1 | function range(max) { 2 | return { 3 | *[Symbol.iterator]() { 4 | for (let i = 0; i < max; i++) { 5 | yield i; 6 | } 7 | } 8 | }; 9 | } 10 | 11 | for (let value of range(10)) { 12 | console.log(value); 13 | } 14 | 15 | function* gen() { 16 | yield 1; 17 | } 18 | 19 | const generator = gen(); 20 | 21 | console.log(generator.next()); 22 | console.log(generator.next()); 23 | console.log(generator.next()); -------------------------------------------------------------------------------- /Lesson07/Exercise60/Exercise60.js: -------------------------------------------------------------------------------- 1 | const simpleObject = {}; 2 | 3 | const handlers = { 4 | get: (object, prop) => { 5 | return 'values are private'; 6 | }, 7 | set: (object, prop, value) => { 8 | if (prop === 'id') { 9 | if (!Number.isNaN(value)) { 10 | throw new TypeError('The id needs to be a number'); 11 | } 12 | } 13 | } 14 | } 15 | 16 | const proxiedValue = new Proxy(simpleObject, handlers); 17 | 18 | proxiedValue.key1 = 'value1'; 19 | 20 | console.log(proxiedValue.key1); 21 | console.log(proxiedValue.keyDoesntExist); 22 | 23 | proxiedValue.id = 'not an id' -------------------------------------------------------------------------------- /Lesson08/Exercise62/Exercise62.js: -------------------------------------------------------------------------------- 1 | const myPromise = new Promise((resolve) => { 2 | resolve(12); 3 | }).then((value) => { 4 | console.log(value); 5 | }); 6 | const myPromiseValue = Promise.resolve(12); 7 | 8 | const myRejectedPromise = Promise.reject(new Error('rejected')); 9 | 10 | myRejectedPromise.catch((error) => { 11 | console.log(error); 12 | }); 13 | 14 | function wait(seconds) { 15 | return new Promise((resolve) => { 16 | setTimeout(() => { 17 | resolve(seconds); 18 | }, seconds * 1000); 19 | }) 20 | } 21 | function waitCallback(seconds, callback) { 22 | setTimeout(callback, seconds * 1000); 23 | } 24 | 25 | wait(2).then((seconds) => { 26 | console.log('i waited ' + seconds + ' seconds'); 27 | }); 28 | wait(2) 29 | .then(() => wait(2)) 30 | .then(() => { 31 | console.log('i waited 4 seconds'); 32 | }); 33 | -------------------------------------------------------------------------------- /Lesson08/Exercise65/Exercise65.js: -------------------------------------------------------------------------------- 1 | function getConcertList() { 2 | return Promise.resolve([ 3 | 'Magical Mirai 2018', 4 | 'Magical Mirai 2019' 5 | ]); 6 | } 7 | 8 | function getPrice(i) { 9 | const prices = [9900, 9000]; 10 | return Promise.resolve(prices[i]); 11 | } 12 | 13 | function buggyCode() { 14 | return Promise.reject(new Error('computer: dont feel like working today')); 15 | } 16 | 17 | async function printList() { 18 | const concerts = await getConcertList(); 19 | const prices = await Promise.all(concerts.map((c, i) => getPrice(i))); 20 | try { 21 | await buggyCode(); 22 | } catch (error) { 23 | console.log('computer produced error'); 24 | console.log(error); 25 | } 26 | return { 27 | concerts, 28 | prices 29 | }; 30 | } 31 | 32 | printList().then(() => { 33 | console.log('I am going to both of them.') 34 | }); 35 | -------------------------------------------------------------------------------- /Lesson09/Exercise67/Exercise67.js: -------------------------------------------------------------------------------- 1 | const EventEmitter = require('events'); 2 | 3 | const emitter = new EventEmitter(); 4 | 5 | emitter.emit('my-event', { value: 'event value' }); 6 | 7 | emitter.on('my-event', (value) => { 8 | console.log(value); 9 | }); 10 | 11 | emitter.emit('my-event', { value: 'another value' }); 12 | 13 | emitter.on('my-event', (value) => { 14 | console.log('i am handling it again'); 15 | }); 16 | emitter.emit('my-event', { value: 'new value' }); 17 | 18 | function handleEvent(event) { 19 | console.log('i am handling event type: ', event.type); 20 | } 21 | 22 | emitter.on('event-with-type', handleEvent); 23 | 24 | emitter.emit('event-with-type', { type: 'sync' }); 25 | emitter.removeListener('event-with-type', handleEvent); 26 | emitter.emit('event-with-type', { type: 'sync2' }); -------------------------------------------------------------------------------- /Lesson10/Activity15/activity-on-checkout-prop-start.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | -------------------------------------------------------------------------------- /Lesson10/Examples/03-higher-order/example-9-function-comp-react.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | 4 | function Hello({who}) { 5 | return

Hello {who}

; 6 | } 7 | 8 | const App = () => ( 9 | <> 10 | 11 | 12 | ); 13 | 14 | ReactDOM.render(, document.querySelector('#app')); 15 | -------------------------------------------------------------------------------- /Lesson10/Examples/03-higher-order/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "03-higher-order", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "serve": "parcel serve" 6 | }, 7 | "author": "Hugo Di Francesco", 8 | "license": "MIT", 9 | "dependencies": { 10 | "parcel-bundler": "^1.12.3", 11 | "react": "^16.9.0", 12 | "react-dom": "^16.9.0", 13 | "react-redux": "^7.1.1", 14 | "redux": "^4.0.4" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson10/Examples/04-composition/example-1-sum-simple-compose.js: -------------------------------------------------------------------------------- 1 | const sum = x => y => x + y; 2 | const multiply = x => y => x * y; 3 | 4 | const compose = (f, g) => x => f(g(x)); 5 | 6 | const add1 = sum(1); 7 | const add2 = sum(2); 8 | const double = multiply(2); 9 | 10 | console.assert( 11 | compose( 12 | add1, 13 | double 14 | )(2) === 5, 15 | 'double -> add1' 16 | ); 17 | console.assert( 18 | compose( 19 | double, 20 | add1 21 | )(2) === 6, 22 | 'add1 -> double' 23 | ); 24 | console.assert( 25 | compose( 26 | double, 27 | add2 28 | )(2) === 8, 29 | 'add2 -> double' 30 | ); 31 | console.assert( 32 | compose( 33 | add2, 34 | double 35 | )(2) === 6, 36 | 'double -> add2' 37 | ); 38 | -------------------------------------------------------------------------------- /Lesson10/Examples/04-composition/example-2-micro-hello.js: -------------------------------------------------------------------------------- 1 | const micro = require('micro'); 2 | 3 | const server = micro(async () => { 4 | return '

Hello micro!

Run this with node example-2-micro-hello.js'; 5 | }); 6 | 7 | server.listen(3000, () => { 8 | console.log('Listening on http://localhost:3000'); 9 | }); 10 | -------------------------------------------------------------------------------- /Lesson10/Examples/04-composition/example-3-request-timer.js: -------------------------------------------------------------------------------- 1 | const micro = require('micro'); 2 | 3 | const hello = () => 4 | '

Hello micro!

Run this with node example-3-request-timer.js'; 5 | 6 | const timer = fn => async (req, res) => { 7 | console.time('request'); 8 | const value = await fn(req, res); 9 | console.timeEnd('request'); 10 | return value; 11 | }; 12 | 13 | const server = micro(timer(hello)); 14 | 15 | server.listen(3000, () => { 16 | console.log('Listening on http://localhost:3000'); 17 | }); 18 | -------------------------------------------------------------------------------- /Lesson10/Examples/04-composition/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "04-composition", 3 | "version": "1.0.0", 4 | "author": "Hugo Di Francesco", 5 | "license": "MIT", 6 | "dependencies": { 7 | "express": "^4.17.1", 8 | "micro": "^9.3.4" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/example-1-redux-action-creator.js: -------------------------------------------------------------------------------- 1 | const ADD_PRODUCT = 'ADD_PRODUCT'; 2 | 3 | function addProduct(newProduct) { 4 | return { 5 | type: ADD_PRODUCT, 6 | newProduct 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/example-2-immutable-map-filter-reduce.js: -------------------------------------------------------------------------------- 1 | // Node.js built-in 2 | const assert = require('assert').strict; 3 | 4 | const initial = [ 5 | { 6 | count: 1, 7 | name: 'Shampoo' 8 | }, 9 | { 10 | count: 2, 11 | name: 'Soap' 12 | } 13 | ]; 14 | 15 | function checkNoMutation() { 16 | assert.deepStrictEqual(initial, [ 17 | { 18 | count: 1, 19 | name: 'Shampoo' 20 | }, 21 | { 22 | count: 2, 23 | name: 'Soap' 24 | } 25 | ]); 26 | } 27 | 28 | checkNoMutation(); 29 | 30 | assert.deepStrictEqual( 31 | initial.map(item => item.name), 32 | ['Shampoo', 'Soap'], 33 | 'demo map' 34 | ); 35 | checkNoMutation(); 36 | 37 | assert( 38 | initial.map(item => item.count).reduce((acc, curr) => acc + curr) === 3, 39 | 'demo map reduce' 40 | ); 41 | checkNoMutation(); 42 | 43 | assert.deepStrictEqual( 44 | initial.filter(item => item.count > 1), 45 | [{count: 2, name: 'Soap'}], 46 | 'demo filter' 47 | ); 48 | checkNoMutation(); 49 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/example-5-immutable-object-freeze.js: -------------------------------------------------------------------------------- 1 | // Node.js built-in 2 | const assert = require('assert').strict; 3 | 4 | const myProduct = Object.freeze({ 5 | name: 'Special Sauce', 6 | price: 1999 7 | }); 8 | 9 | console.assert(myProduct.name === 'Special Sauce', 'no change to properties'); 10 | console.assert(myProduct.price === 1999, 'no change to properties'); 11 | 12 | assert.throws(() => { 13 | 'use strict'; 14 | myProduct.category = 'condiments'; 15 | }, 'writing to an existing property is an error in strict mode'); 16 | 17 | assert.doesNotThrow(() => { 18 | myProduct.category = 'condiments'; 19 | }, 'writing to an existing property is fine in non strict mode'); 20 | 21 | assert.throws(() => { 22 | 'use strict'; 23 | myProduct.name = 'Super Special Sauce'; 24 | }, 'writing a new property is an error in strict mode'); 25 | 26 | assert.doesNotThrow(() => { 27 | myProduct.name = 'Super Special Sauce'; 28 | }, 'writing a new property is fine in non strict mode'); 29 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/example-6-component-did-mount-request.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/example-6-component-did-mount-request.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | 4 | class App extends React.Component { 5 | constructor() { 6 | super(); 7 | this.state = {}; 8 | } 9 | 10 | componentDidMount() { 11 | fetch('https://hello-world-micro.glitch.me') 12 | .then(response => { 13 | if (response.ok) { 14 | return response.text(); 15 | } 16 | }) 17 | .then(data => { 18 | this.setState({ 19 | message: data 20 | }); 21 | }); 22 | } 23 | 24 | render() { 25 | return ( 26 |
27 |

Message: {this.state.message}

28 |
29 | ); 30 | } 31 | } 32 | 33 | ReactDOM.render(, document.querySelector('#app')); 34 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/example-7-use-effect-request.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/example-7-use-effect-request.js: -------------------------------------------------------------------------------- 1 | import React, {useEffect, useState} from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | 4 | const App = () => { 5 | const [message, setMessage] = useState(null); 6 | useEffect(() => { 7 | if (!message) { 8 | fetch('https://hello-world-micro.glitch.me') 9 | .then(response => { 10 | if (response.ok) { 11 | return response.text(); 12 | } 13 | }) 14 | .then(data => { 15 | setMessage(data); 16 | }); 17 | } 18 | }); 19 | return ( 20 |
21 |

Message: {message}

22 |
23 | ); 24 | }; 25 | 26 | ReactDOM.render(, document.querySelector('#app')); 27 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/example-8-thunk-usage.js: -------------------------------------------------------------------------------- 1 | let globalState; 2 | 3 | function thunk() { 4 | return () => { 5 | globalState = 'updated'; 6 | }; 7 | } 8 | 9 | const lazy = thunk(); 10 | console.assert(!globalState, 'executing the thunk does nothing'); 11 | lazy(); 12 | console.assert( 13 | globalState === 'updated', 14 | 'executing the output of the thunk runs the update' 15 | ); 16 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/example-9-redux-thunk-request.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "05-immutability-side-effects", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "serve": "parcel serve" 9 | }, 10 | "keywords": [], 11 | "author": "Hugo Di Francesco", 12 | "license": "MIT", 13 | "dependencies": { 14 | "express-graphql": "^0.9.0", 15 | "graphql": "^14.5.4", 16 | "micro": "^9.3.4", 17 | "react-redux": "^7.1.1", 18 | "redux": "^4.0.4", 19 | "redux-thunk": "^2.3.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Lesson10/Examples/05-immutability-side-effects/schema.graphql: -------------------------------------------------------------------------------- 1 | type basket { 2 | items: [basketItem] 3 | } 4 | 5 | """BasketItem""" 6 | type basketItem { 7 | name: String 8 | price: Int 9 | quantity: Int 10 | id: String 11 | } 12 | 13 | type Mutation { 14 | LineItemCost(id: String): Int 15 | } 16 | 17 | """Root query""" 18 | type Query { 19 | basket: basket 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Lesson10/Exercise70/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "activities", 3 | "version": "1.0.0", 4 | "description": "Lesson 10 Activities", 5 | "main": "index.js", 6 | "scripts": { 7 | "Exercise70": "node exercise-re-implement-array-methods-start.js", 8 | "Exercise70:solution": "node exercise-re-implement-array-methods.js" 9 | }, 10 | "author": "Hugo Di Francesco", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /Lesson10/Exercise71/exercise-price-of-basket-start.js: -------------------------------------------------------------------------------- 1 | const basket1 = [ 2 | { 3 | quantity: 1, 4 | price: 199, 5 | name: 'Soda bottle' 6 | }, 7 | { 8 | quantity: 2, 9 | price: 2499, 10 | name: 'Kitchenware kits' 11 | } 12 | ]; 13 | 14 | const basket2 = [ 15 | { 16 | quantity: 2, 17 | price: 199, 18 | name: 'Soda bottle' 19 | }, 20 | { 21 | quantity: 1, 22 | price: 499, 23 | name: 'Biscuits' 24 | } 25 | ]; 26 | 27 | function totalBasket(basket) { 28 | return basket; 29 | } 30 | 31 | console.assert( 32 | totalBasket(basket1) === 5197, 33 | 'basket1 should tally up to 5197' 34 | ); 35 | console.assert(totalBasket(basket2) === 897, 'basket2 should tally up to 897'); 36 | -------------------------------------------------------------------------------- /Lesson10/Exercise71/exercise-price-of-basket.js: -------------------------------------------------------------------------------- 1 | const basket1 = [ 2 | { 3 | quantity: 1, 4 | price: 199, 5 | name: 'Soda bottle' 6 | }, 7 | { 8 | quantity: 2, 9 | price: 2499, 10 | name: 'Kitchenware kits' 11 | } 12 | ]; 13 | 14 | const basket2 = [ 15 | { 16 | quantity: 2, 17 | price: 199, 18 | name: 'Soda bottle' 19 | }, 20 | { 21 | quantity: 1, 22 | price: 499, 23 | name: 'Biscuits' 24 | } 25 | ]; 26 | 27 | function totalBasket(basket) { 28 | return basket 29 | .map(item => item.price * item.quantity) 30 | .reduce((acc, curr) => acc + curr); 31 | } 32 | 33 | console.assert( 34 | totalBasket(basket1) === 5197, 35 | 'basket1 should tally up to 5197' 36 | ); 37 | console.assert(totalBasket(basket2) === 897, 'basket2 should tally up to 897'); 38 | -------------------------------------------------------------------------------- /Lesson10/Exercise71/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "activities", 3 | "version": "1.0.0", 4 | "description": "Lesson 10 Activities", 5 | "main": "index.js", 6 | "scripts": { 7 | "Exercise71": "node exercise-price-of-basket-start.js", 8 | "Exercise71:solution": "node exercise-price-of-basket.js" 9 | }, 10 | "author": "Hugo Di Francesco", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /Lesson10/Exercise72/exercise-add-product-start.html: -------------------------------------------------------------------------------- 1 |
2 |