From 71515402150b312d281b1234ede8cf1cde033e1c Mon Sep 17 00:00:00 2001 From: NastyaKatyushkina Date: Thu, 15 Apr 2021 21:01:32 +0500 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9A=D0=B0=D1=82=D1=8E=D1=88=D0=BA=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/task_2/index.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/task_2/index.ts b/src/task_2/index.ts index 06535aa..1c5f0bf 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -5,10 +5,28 @@ * Когда присваивается некорректный e-mail возбуждается ошибка. */ -class Example { +function check_mail(target: object, propertyKey: string | symbol): any{ + let email: string + let discriptor: PropertyDescriptor = { + get: function(){ + return email + }, + set: function(newmail: string){ + if (newmail.match(/[A-Za-z0-9]+@[A-Za-z0-9]+.[A-Za-z]{2,4}/)){ + email = newmail; + console.log("email valid") + } + throw "Invalid email" + } + + } +} + +class Example{ + @check_mail public email: string = ""; } let exampleInstance = new Example(); exampleInstance.email = "fkkldfjg"; // генерирует эксепшен -exampleInstance.email = "misha@mail.ru"; // выводит в консоль e-mail valid +exampleInstance.email = "misha@mail.ru"; // выводит в консоль e-mail valid \ No newline at end of file From 635266ec148c7dadeed430c78a685371f248a306 Mon Sep 17 00:00:00 2001 From: NastyaKatyushkina Date: Thu, 15 Apr 2021 21:02:37 +0500 Subject: [PATCH 2/4] =?UTF-8?q?=D0=9A=D0=B0=D1=82=D1=8E=D1=88=D0=BA=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/task_1/index.ts | 16 ++++++++++++++++ src/task_2/index.ts | 8 -------- src/task_4/index.ts | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/task_1/index.ts b/src/task_1/index.ts index 53a04d7..9a135c4 100644 --- a/src/task_1/index.ts +++ b/src/task_1/index.ts @@ -26,3 +26,19 @@ class Calculator { return (this.a + this.b).toString(); } } + +class DecorateRu extends Calculator +{ + public exec(): string + { + return 'Результат сложения ${this.a} + ${this.b} = ${super.exec()}' + } +} + +class DecorateEn extends Calculator +{ + public exec(): string + { + return 'Result of the addition operation ${this.a} + ${this.b} = ${super.exec()}' + } +} \ No newline at end of file diff --git a/src/task_2/index.ts b/src/task_2/index.ts index 1c5f0bf..b0dce98 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -22,11 +22,3 @@ function check_mail(target: object, propertyKey: string | symbol): any{ } } -class Example{ - @check_mail - public email: string = ""; -} - -let exampleInstance = new Example(); -exampleInstance.email = "fkkldfjg"; // генерирует эксепшен -exampleInstance.email = "misha@mail.ru"; // выводит в консоль e-mail valid \ No newline at end of file diff --git a/src/task_4/index.ts b/src/task_4/index.ts index dc0e179..01aec59 100644 --- a/src/task_4/index.ts +++ b/src/task_4/index.ts @@ -6,6 +6,6 @@ function getProperty(obj: T, key: K): T[K] { return obj[key]; } -const x = undefined; +const x = {m: 7}; console.log(getProperty(x, "m")); \ No newline at end of file From 7ebc684c21d72e99013a6ec471da2bdae4185a3d Mon Sep 17 00:00:00 2001 From: NastyaKatyushkina Date: Thu, 15 Apr 2021 22:49:07 +0500 Subject: [PATCH 3/4] =?UTF-8?q?=D0=9A=D0=B0=D1=82=D1=8E=D1=88=D0=BA=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/task_1/index.ts | 1 + src/task_2/index.ts | 1 - src/task_4/index.ts | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/task_1/index.ts b/src/task_1/index.ts index 9a135c4..97ceee6 100644 --- a/src/task_1/index.ts +++ b/src/task_1/index.ts @@ -27,6 +27,7 @@ class Calculator { } } + class DecorateRu extends Calculator { public exec(): string diff --git a/src/task_2/index.ts b/src/task_2/index.ts index b0dce98..4be4bfc 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -21,4 +21,3 @@ function check_mail(target: object, propertyKey: string | symbol): any{ } } - diff --git a/src/task_4/index.ts b/src/task_4/index.ts index 01aec59..b8c02cc 100644 --- a/src/task_4/index.ts +++ b/src/task_4/index.ts @@ -8,4 +8,4 @@ function getProperty(obj: T, key: K): T[K] { const x = {m: 7}; -console.log(getProperty(x, "m")); \ No newline at end of file +console.log(getProperty(x, "m")); From 0229377246091422c8bc54fdecd4b09af04c468e Mon Sep 17 00:00:00 2001 From: NastyaKatyushkina Date: Sun, 25 Apr 2021 19:55:53 +0500 Subject: [PATCH 4/4] =?UTF-8?q?=D0=9A=D0=B0=D1=82=D1=8E=D1=88=D0=BA=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/task_1/index.ts | 17 +++++++++++++---- src/task_2/index.ts | 29 +++++++++++++++++++---------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/task_1/index.ts b/src/task_1/index.ts index 97ceee6..a8f8b78 100644 --- a/src/task_1/index.ts +++ b/src/task_1/index.ts @@ -27,19 +27,28 @@ class Calculator { } } +class Decor extends Calculator +{ + protected calculators: Calculator; + constructor(a: number, b: number) + { + super(a, b) + this.calculators = new Calculator(a, b) + } +} -class DecorateRu extends Calculator +class DecorateRu extends Decor { public exec(): string { - return 'Результат сложения ${this.a} + ${this.b} = ${super.exec()}' + return 'Результат сложения ${this.a} + ${this.b} = ${this.calculators.exec()}' } } -class DecorateEn extends Calculator +class DecorateEn extends Decor { public exec(): string { - return 'Result of the addition operation ${this.a} + ${this.b} = ${super.exec()}' + return 'Result of the addition operation ${this.a} + ${this.b} = ${this.calculators.exec()}' } } \ No newline at end of file diff --git a/src/task_2/index.ts b/src/task_2/index.ts index 4be4bfc..010a14a 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -5,19 +5,28 @@ * Когда присваивается некорректный e-mail возбуждается ошибка. */ -function check_mail(target: object, propertyKey: string | symbol): any{ - let email: string +function check_mail(target: Object, propertyKey: string): any{ + let email = ""; let discriptor: PropertyDescriptor = { - get: function(){ - return email + get: function() + { + return email; }, - set: function(newmail: string){ - if (newmail.match(/[A-Za-z0-9]+@[A-Za-z0-9]+.[A-Za-z]{2,4}/)){ - email = newmail; - console.log("email valid") + set: function(newmail: string) + { + let mail_write = /[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-zA-Z0-9]+/ + if (mail_write.test(newmail)) + { + email = newmail; + console.log('email valid') + } - throw "Invalid email" + else + { + throw "Invalid email" + } } - } + return discriptor; } +