From 9a06ebddce44c8c57960c16b46aad72ec8d12e98 Mon Sep 17 00:00:00 2001 From: alalluna Date: Fri, 5 Jul 2024 17:48:06 +0200 Subject: [PATCH 1/3] create branch #5 --- staff/tere-albenca/playground/calculator/calculate.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 staff/tere-albenca/playground/calculator/calculate.ts diff --git a/staff/tere-albenca/playground/calculator/calculate.ts b/staff/tere-albenca/playground/calculator/calculate.ts new file mode 100644 index 0000000..e69de29 From 02714d3e79a14bf19be18c61b1e2b97568c11d12 Mon Sep 17 00:00:00 2001 From: alalluna Date: Mon, 8 Jul 2024 16:41:49 +0200 Subject: [PATCH 2/3] first example #6 --- .../playground/calculator/calculate.ts | 33 +++++++++ .../profesional-calculator/index.css | 73 +++++++++++++++++++ .../profesional-calculator/index.html | 29 ++++++++ 3 files changed, 135 insertions(+) create mode 100644 staff/tere-albenca/playground/calculator/profesional-calculator/index.css create mode 100644 staff/tere-albenca/playground/calculator/profesional-calculator/index.html diff --git a/staff/tere-albenca/playground/calculator/calculate.ts b/staff/tere-albenca/playground/calculator/calculate.ts index e69de29..803b49d 100644 --- a/staff/tere-albenca/playground/calculator/calculate.ts +++ b/staff/tere-albenca/playground/calculator/calculate.ts @@ -0,0 +1,33 @@ +function calculate(op: 'add' | 'sub' | 'mul' | 'div', a: number, b: number) { + switch (op) { + case 'add': + return a + b; + case 'sub': + return a - b; + case 'mul': + return a * b; + case 'div': + if (b! == 0) { + return a / b; + + } else { + throw new Error('Division by zero is not possible') + } + default: + throw new Error("Invalid operation."); + + } + // TODO +} + +console.log(calculate('add', 1, 2)) +// 3 + +console.log(calculate('sub', 1, 2)) +// -1 + +console.log(calculate('mul', 1, 2)) +// 2 + +console.log(calculate('div', 1, 2)) +// 0.5 \ No newline at end of file diff --git a/staff/tere-albenca/playground/calculator/profesional-calculator/index.css b/staff/tere-albenca/playground/calculator/profesional-calculator/index.css new file mode 100644 index 0000000..5615d03 --- /dev/null +++ b/staff/tere-albenca/playground/calculator/profesional-calculator/index.css @@ -0,0 +1,73 @@ +body { + display: flex; + justify-content: center; + align-items: center; + min-height: 100vh; + background-color: #4d8ac8; + box-sizing: border-box; + margin: 0; + padding: 0; + font-family: "Roboto", sans-serif; +} + +.calculator-container { + background-color: #ebf5ff; + padding: 20px; + border-radius: 10px; + width: 240px; +} + +.calculator-result-preview { + background-color: #cce6ff; + width: auto; + border-radius: 5px; + padding: 10px; +} + +#operation { + color: #4F8AC5; + font-size: 10px; +} + +#operation-result { + color: #173C5D; + font-size: 20px; + font-weight: bold; + display: flex; + justify-content: flex-end; +} + +#calculator-buttons { + display: flex; + justify-content: space-between; + margin-top: 10px; + flex-wrap: wrap; +} + +.button { + background-color: #CCE6FF; + padding: 5px; + border-radius: 8px; + width: 18%; + height: 40px; + border: 0; + color: #193C60; + font-weight: bold; + font-size: 12px; + margin-top: 6px; + cursor: pointer; +} + +.dark { + background-color: #A3D0FA; + color: #4F8CCB; +} + +.small { + height: 30px; + font-size: 10px; +} + +.large { + width: 38%; +} \ No newline at end of file diff --git a/staff/tere-albenca/playground/calculator/profesional-calculator/index.html b/staff/tere-albenca/playground/calculator/profesional-calculator/index.html new file mode 100644 index 0000000..2e63a7d --- /dev/null +++ b/staff/tere-albenca/playground/calculator/profesional-calculator/index.html @@ -0,0 +1,29 @@ + + + + + + + + Calculator + + + + + + + + + +
+
+
+
0
+
+
+
+ + + + + \ No newline at end of file From d0c24613ac9ea85f8406808098021406530b53b2 Mon Sep 17 00:00:00 2001 From: alalluna Date: Wed, 17 Jul 2024 12:30:19 +0200 Subject: [PATCH 3/3] create calculator with typescript #5 --- .../playground/calculator/.gitignore | 130 ++++++++++++++++++ .../playground/calculator/LICENSE | 21 +++ .../playground/calculator/README.md | 2 + .../playground/calculator/index.js | 27 ++++ .../playground/calculator/index.test.ts | 19 +++ .../calculator/{calculate.ts => index.ts} | 5 +- .../playground/calculator/package-lock.json | 13 ++ .../playground/calculator/package.json | 16 +++ .../profesional-calculator/index.css | 73 ---------- .../profesional-calculator/index.html | 29 ---- .../playground/calculator/tsconfig.json | 17 +++ 11 files changed, 247 insertions(+), 105 deletions(-) create mode 100644 staff/tere-albenca/playground/calculator/.gitignore create mode 100644 staff/tere-albenca/playground/calculator/LICENSE create mode 100644 staff/tere-albenca/playground/calculator/README.md create mode 100644 staff/tere-albenca/playground/calculator/index.js create mode 100644 staff/tere-albenca/playground/calculator/index.test.ts rename staff/tere-albenca/playground/calculator/{calculate.ts => index.ts} (89%) create mode 100644 staff/tere-albenca/playground/calculator/package-lock.json create mode 100644 staff/tere-albenca/playground/calculator/package.json delete mode 100644 staff/tere-albenca/playground/calculator/profesional-calculator/index.css delete mode 100644 staff/tere-albenca/playground/calculator/profesional-calculator/index.html create mode 100644 staff/tere-albenca/playground/calculator/tsconfig.json diff --git a/staff/tere-albenca/playground/calculator/.gitignore b/staff/tere-albenca/playground/calculator/.gitignore new file mode 100644 index 0000000..c6bba59 --- /dev/null +++ b/staff/tere-albenca/playground/calculator/.gitignore @@ -0,0 +1,130 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* diff --git a/staff/tere-albenca/playground/calculator/LICENSE b/staff/tere-albenca/playground/calculator/LICENSE new file mode 100644 index 0000000..738e917 --- /dev/null +++ b/staff/tere-albenca/playground/calculator/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 manuelbarzi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/staff/tere-albenca/playground/calculator/README.md b/staff/tere-albenca/playground/calculator/README.md new file mode 100644 index 0000000..2695000 --- /dev/null +++ b/staff/tere-albenca/playground/calculator/README.md @@ -0,0 +1,2 @@ +# typescript-boot +TypeScript boot diff --git a/staff/tere-albenca/playground/calculator/index.js b/staff/tere-albenca/playground/calculator/index.js new file mode 100644 index 0000000..7365f27 --- /dev/null +++ b/staff/tere-albenca/playground/calculator/index.js @@ -0,0 +1,27 @@ +"use strict"; +function calculate(op, a, b) { + switch (op) { + case 'add': + return a + b; + case 'sub': + return a - b; + case 'mul': + return a * b; + case 'div': + if (b == 0) { + return a / b; + } + else { + throw new Error('Division by zero is not possible'); + } + } + // TODO +} +console.log(calculate('add', 1, 2)); +// 3 +console.log(calculate('sub', 1, 2)); +// -1 +console.log(calculate('mul', 1, 2)); +// 2 +console.log(calculate('div', 1, 2)); +// 0.5 diff --git a/staff/tere-albenca/playground/calculator/index.test.ts b/staff/tere-albenca/playground/calculator/index.test.ts new file mode 100644 index 0000000..43d2c47 --- /dev/null +++ b/staff/tere-albenca/playground/calculator/index.test.ts @@ -0,0 +1,19 @@ +import calculate from "./index.js"; +console.info("TEST CACULATE"); + +console.info('case 1: add 1 plus 2'); +console.assert(calculate("add", 1, 2) === 3, "add 1 plus 2 results in 3"); +//3 + +console.info('case 2: sub 1 minus 2'); +console.assert(calculate("sub", 1, 2) === -1, "substract 1 minus 2 results in -1"); +//-1 + +console.info('case 3: mul 1 by 2'); +console.assert(calculate("mul", 1, 2) === 2, "multiplicate 1 by 2results in 2"); +//2 + +console.info('case 4: div 1 by 2'); +console.assert(calculate("div", 1, 2) === .5, "divide 1 by 2 results in .5"); +//0.5 + diff --git a/staff/tere-albenca/playground/calculator/calculate.ts b/staff/tere-albenca/playground/calculator/index.ts similarity index 89% rename from staff/tere-albenca/playground/calculator/calculate.ts rename to staff/tere-albenca/playground/calculator/index.ts index 803b49d..3b491d5 100644 --- a/staff/tere-albenca/playground/calculator/calculate.ts +++ b/staff/tere-albenca/playground/calculator/index.ts @@ -13,13 +13,12 @@ function calculate(op: 'add' | 'sub' | 'mul' | 'div', a: number, b: number) { } else { throw new Error('Division by zero is not possible') } - default: - throw new Error("Invalid operation."); - } // TODO } + +export default calculate console.log(calculate('add', 1, 2)) // 3 diff --git a/staff/tere-albenca/playground/calculator/package-lock.json b/staff/tere-albenca/playground/calculator/package-lock.json new file mode 100644 index 0000000..ace56e4 --- /dev/null +++ b/staff/tere-albenca/playground/calculator/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "calculator", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "calculator", + "version": "1.0.0", + "license": "ISC" + } + } +} diff --git a/staff/tere-albenca/playground/calculator/package.json b/staff/tere-albenca/playground/calculator/package.json new file mode 100644 index 0000000..c4eebdf --- /dev/null +++ b/staff/tere-albenca/playground/calculator/package.json @@ -0,0 +1,16 @@ +{ + "name": "calculator", + "version": "1.0.0", + "description": "", + "type": "module", + "main": "index.js", + "scripts": { + "build": "tsc *.ts --target esnext", + "test": "node index.test.js", + "compile-test": "tsc --noEmit index.ts && tsx index.test.ts", + "compile-test-inspect": "tsc --noEmit index.ts && tsx --inspect-brk index.test.ts" + }, + "keywords": [], + "author": "", + "license": "ISC" +} \ No newline at end of file diff --git a/staff/tere-albenca/playground/calculator/profesional-calculator/index.css b/staff/tere-albenca/playground/calculator/profesional-calculator/index.css deleted file mode 100644 index 5615d03..0000000 --- a/staff/tere-albenca/playground/calculator/profesional-calculator/index.css +++ /dev/null @@ -1,73 +0,0 @@ -body { - display: flex; - justify-content: center; - align-items: center; - min-height: 100vh; - background-color: #4d8ac8; - box-sizing: border-box; - margin: 0; - padding: 0; - font-family: "Roboto", sans-serif; -} - -.calculator-container { - background-color: #ebf5ff; - padding: 20px; - border-radius: 10px; - width: 240px; -} - -.calculator-result-preview { - background-color: #cce6ff; - width: auto; - border-radius: 5px; - padding: 10px; -} - -#operation { - color: #4F8AC5; - font-size: 10px; -} - -#operation-result { - color: #173C5D; - font-size: 20px; - font-weight: bold; - display: flex; - justify-content: flex-end; -} - -#calculator-buttons { - display: flex; - justify-content: space-between; - margin-top: 10px; - flex-wrap: wrap; -} - -.button { - background-color: #CCE6FF; - padding: 5px; - border-radius: 8px; - width: 18%; - height: 40px; - border: 0; - color: #193C60; - font-weight: bold; - font-size: 12px; - margin-top: 6px; - cursor: pointer; -} - -.dark { - background-color: #A3D0FA; - color: #4F8CCB; -} - -.small { - height: 30px; - font-size: 10px; -} - -.large { - width: 38%; -} \ No newline at end of file diff --git a/staff/tere-albenca/playground/calculator/profesional-calculator/index.html b/staff/tere-albenca/playground/calculator/profesional-calculator/index.html deleted file mode 100644 index 2e63a7d..0000000 --- a/staff/tere-albenca/playground/calculator/profesional-calculator/index.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - Calculator - - - - - - - - - -
-
-
-
0
-
-
-
- - - - - \ No newline at end of file diff --git a/staff/tere-albenca/playground/calculator/tsconfig.json b/staff/tere-albenca/playground/calculator/tsconfig.json new file mode 100644 index 0000000..6ce184a --- /dev/null +++ b/staff/tere-albenca/playground/calculator/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "outDir": "./dist" + }, + "include": [ + "index.ts" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file