diff --git a/Esempi/Autenticazione/autenticazione.html b/Esempi/Autenticazione/autenticazione.html new file mode 100644 index 0000000..c679461 --- /dev/null +++ b/Esempi/Autenticazione/autenticazione.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Esempi/Autenticazione/handling-exception.js b/Esempi/Autenticazione/handling-exception.js new file mode 100644 index 0000000..98325cb --- /dev/null +++ b/Esempi/Autenticazione/handling-exception.js @@ -0,0 +1,63 @@ +var Messaggio = /** @class */ (function () { + function Messaggio() { + this.elemento = this.Crea(); + } + Messaggio.prototype.Crea = function () { + var div = document.createElement('div'); + var p = document.createElement('p'); + div.appendChild(p); + return div; + }; + Messaggio.prototype.InserisciMessaggio = function (stringa) { + var p = this.elemento.querySelector('p'); + if (p) { + p.textContent = stringa; + } + }; + Messaggio.prototype.Mostra = function () { + document.body.appendChild(this.elemento); + }; + Messaggio.prototype.Distruggi = function () { + var _this = this; + setTimeout(function () { + if (_this.elemento.parentNode) { + _this.elemento.parentNode.removeChild(_this.elemento); + } + }, 5000); + }; + return Messaggio; +}()); +var ProgrammaAutorizzazione = /** @class */ (function () { + function ProgrammaAutorizzazione() { + } + ProgrammaAutorizzazione.Esegui = function () { + var autorizzazioneUtente = true; + var messaggioAutorizzazione = new Messaggio(); + try { + var accessoUtente = this.VerificaAutorizzazione(autorizzazioneUtente); + messaggioAutorizzazione.InserisciMessaggio(accessoUtente); + messaggioAutorizzazione.Mostra(); + } + catch (error) { + console.log(error); + messaggioAutorizzazione.InserisciMessaggio(error); + messaggioAutorizzazione.Mostra(); + //ritorno messaggio + } + finally { + if (messaggioAutorizzazione) { + messaggioAutorizzazione.Distruggi(); + } + } + }; + ProgrammaAutorizzazione.VerificaAutorizzazione = function (autorizzazione) { + if (autorizzazione) { + return 'Utente Autorizzato'; + } + else { + throw new Error("Utente non autorizzato"); + } + }; + return ProgrammaAutorizzazione; +}()); +ProgrammaAutorizzazione.Esegui(); diff --git a/Esempi/Autenticazione/handling-exception.ts b/Esempi/Autenticazione/handling-exception.ts new file mode 100644 index 0000000..1309eea --- /dev/null +++ b/Esempi/Autenticazione/handling-exception.ts @@ -0,0 +1,72 @@ +class Messaggio { + + private elemento: HTMLDivElement + + constructor() { + this.elemento = this.Crea() + } + + private Crea(): HTMLDivElement { + const div = document.createElement('div') as HTMLDivElement + const p = document.createElement('p') as HTMLParagraphElement + div.appendChild(p) + + return div + } + + public InserisciMessaggio(stringa:string) { + const p = this.elemento.querySelector('p') + if (p) { + p.textContent = stringa + } + } + + public Mostra():void { + document.body.appendChild(this.elemento) + } + + public Distruggi():void { + setTimeout(() => { + if (this.elemento.parentNode) { + this.elemento.parentNode.removeChild(this.elemento) + } + }, 5000); + } +} + + + +class ProgrammaAutorizzazione { + + static Esegui() { + let autorizzazioneUtente:boolean = false + + let messaggioAutorizzazione: Messaggio = new Messaggio() + try { + let accessoUtente = this.VerificaAutorizzazione(autorizzazioneUtente) + messaggioAutorizzazione.InserisciMessaggio(accessoUtente) + messaggioAutorizzazione.Mostra() + } catch (error) { + console.log(error); + messaggioAutorizzazione.InserisciMessaggio(error) + messaggioAutorizzazione.Mostra() + //ritorno messaggio + } finally { + if (messaggioAutorizzazione) { + messaggioAutorizzazione.Distruggi() + } + } + + } + static VerificaAutorizzazione(autorizzazione: boolean):string { + if (autorizzazione) { + return 'Utente Autorizzato' + } else { + throw new Error("Utente non autorizzato"); + } + } + +} + +ProgrammaAutorizzazione.Esegui() + diff --git a/Esempi/Autenticazione/prova1.mts b/Esempi/Autenticazione/prova1.mts new file mode 100644 index 0000000..33a1cdc --- /dev/null +++ b/Esempi/Autenticazione/prova1.mts @@ -0,0 +1,5 @@ +export class Prova1 { + constructor(parameters) { + + } +} \ No newline at end of file diff --git a/parte2-css/pagine/blog.html b/parte2-css/pagine/blog.html new file mode 100644 index 0000000..e2a522e --- /dev/null +++ b/parte2-css/pagine/blog.html @@ -0,0 +1,76 @@ + + +
+
+ +
+
+
+

Titolo blog

+
+
+

Inserisci introduzione

+

Inserisci introduzione

+

Inserisci introduzione

+

Sottotitolo

+

Paragrafo

+

Paragrafo

+

Paragrafo

+

Paragrafo

+
+
+

Informazioni articolo

+
    +
  • + Nome autore: +
  • +
  • + Data: +
  • +
  • + Categoria: +
  • +
  • + Tag: +
  • +
+
+
+
+
+
diff --git a/parte5-webcomponents/componenti/components.mjs b/parte5-webcomponents/componenti/components.mjs new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/parte5-webcomponents/componenti/components.mjs @@ -0,0 +1 @@ +export {}; diff --git a/parte5-webcomponents/componenti/components.mts b/parte5-webcomponents/componenti/components.mts new file mode 100644 index 0000000..d750a71 --- /dev/null +++ b/parte5-webcomponents/componenti/components.mts @@ -0,0 +1 @@ +import { container } from "./container/container.mjs"; diff --git a/parte5-webcomponents/componenti/container/container.html b/parte5-webcomponents/componenti/container/container.html new file mode 100644 index 0000000..fd39f76 --- /dev/null +++ b/parte5-webcomponents/componenti/container/container.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/parte5-webcomponents/componenti/container/container.mjs b/parte5-webcomponents/componenti/container/container.mjs new file mode 100644 index 0000000..c4518d3 --- /dev/null +++ b/parte5-webcomponents/componenti/container/container.mjs @@ -0,0 +1,9 @@ +import { AttaccaShadow, OttieniContentDaTemplate, OttieniTemplate } from "../function.mjs"; +export const container = customElements.define('container', class Container extends HTMLDivElement { + constructor() { + super(); + const shadow = AttaccaShadow(this); + const templateContent = OttieniContentDaTemplate(OttieniTemplate('container-template')); + shadow.appendChild(templateContent); + } +}); diff --git a/parte5-webcomponents/componenti/container/container.mts b/parte5-webcomponents/componenti/container/container.mts new file mode 100644 index 0000000..839de81 --- /dev/null +++ b/parte5-webcomponents/componenti/container/container.mts @@ -0,0 +1,14 @@ +import { AttaccaShadow, OttieniContentDaTemplate, OttieniTemplate } from "../function.mjs" + +export const container = customElements.define('container', + class Container extends HTMLDivElement { + constructor() { + super() + + const shadow = AttaccaShadow(this) + const templateContent = OttieniContentDaTemplate(OttieniTemplate('container-template')) + + shadow.appendChild(templateContent) + } + } +) diff --git a/parte5-webcomponents/componenti/container/template.css b/parte5-webcomponents/componenti/container/template.css new file mode 100644 index 0000000..e69de29 diff --git a/parte5-webcomponents/componenti/form/form.html b/parte5-webcomponents/componenti/form/form.html new file mode 100644 index 0000000..8cf14b9 --- /dev/null +++ b/parte5-webcomponents/componenti/form/form.html @@ -0,0 +1,43 @@ + + + + + + + + \ No newline at end of file diff --git a/parte5-webcomponents/componenti/form/form.mjs b/parte5-webcomponents/componenti/form/form.mjs new file mode 100644 index 0000000..004d85a --- /dev/null +++ b/parte5-webcomponents/componenti/form/form.mjs @@ -0,0 +1,12 @@ +import { InserisciTemplateNelloShadowDOM } from "../function.mjs"; +const formInfodit = customElements.define('form-infodit', class FormInfodit extends HTMLElement { + constructor() { + super(); + //Creazione dello shadow Dom + const shadow = this.attachShadow({ mode: 'closed' }); + //Prendiamo il contenuto del template e lo copiamo su una variabile + //const template = OttieniTemplateDaHTML('form.html','form-template') as Promise + //Attacchiamo la copia del template sullo shadow DOM + InserisciTemplateNelloShadowDOM(shadow, 'form.html', 'form-template'); + } +}); diff --git a/parte5-webcomponents/componenti/form/form.mts b/parte5-webcomponents/componenti/form/form.mts new file mode 100644 index 0000000..0f2779b --- /dev/null +++ b/parte5-webcomponents/componenti/form/form.mts @@ -0,0 +1,17 @@ +import { InserisciTemplateNelloShadowDOM } from "../function.mjs" + +const formInfodit = customElements.define('form-infodit', + class FormInfodit extends HTMLElement { + constructor() { + super() + //Creazione dello shadow Dom + const shadow = this.attachShadow({ mode: 'closed' }) + + //Prendiamo il contenuto del template e lo copiamo su una variabile + //const template = OttieniTemplateDaHTML('form.html','form-template') as Promise + + //Attacchiamo la copia del template sullo shadow DOM + InserisciTemplateNelloShadowDOM(shadow,'form.html','form-template') + } + } +) \ No newline at end of file diff --git a/parte5-webcomponents/componenti/form/prova.html b/parte5-webcomponents/componenti/form/prova.html new file mode 100644 index 0000000..393ed49 --- /dev/null +++ b/parte5-webcomponents/componenti/form/prova.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/parte5-webcomponents/componenti/function.mjs b/parte5-webcomponents/componenti/function.mjs new file mode 100644 index 0000000..424e800 --- /dev/null +++ b/parte5-webcomponents/componenti/function.mjs @@ -0,0 +1,69 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +/** + * + * @param elemento Per i custom Elements usa this + * @param aperto Predefinito = false + * @returns + */ +export function AttaccaShadow(elemento, aperto = false) { + if (!aperto) { + return elemento.attachShadow({ mode: 'closed' }); + } + else { + return elemento.attachShadow({ mode: 'open' }); + } +} +export function OttieniTemplate(id) { + return document.getElementById(id); +} +export function OttieniContentDaTemplate(template) { + return template.content; +} +// export function OttieniTemplateDaHTML(percorso: string, id_template:string): Node { +// fetch(percorso) +// .then(risposta => risposta.text()) +// .then(html => { +// document.body.insertAdjacentHTML('beforeend',html) +// const template = document.getElementById(id_template) as HTMLTemplateElement +// const clone = template.cloneNode(true) as Node +// return clone +// }) +// } +export function InserisciTemplateNelloShadowDOM(shadowRoot, percorso, id_template) { + return __awaiter(this, void 0, void 0, function* () { + try { + const risposta = yield fetch(percorso); + if (!risposta.ok) { + throw new Error(`Errore durante il caricamento del template: ${risposta.statusText}`); + } + const html = yield risposta.text(); + // Verifica se il template è già presente nel DOM + if (!document.getElementById(id_template)) { + // Inserisci temporaneamente il template nel DOM per accedervi + document.body.insertAdjacentHTML('beforeend', html); + } + // Ottieni il template dal DOM + const template = document.getElementById(id_template); + if (!template) { + throw new Error(`Template con id "${id_template}" non trovato.`); + } + // Clona il contenuto del template + const clone = template.content.cloneNode(true); + // Appendi il clone allo shadowRoot + shadowRoot.appendChild(clone); + // Rimuovi il template temporaneamente inserito + template.remove(); + } + catch (errore) { + console.error('Errore durante l\'inserimento del template nello shadow DOM:', errore); + } + }); +} diff --git a/parte5-webcomponents/componenti/function.mts b/parte5-webcomponents/componenti/function.mts new file mode 100644 index 0000000..8c82537 --- /dev/null +++ b/parte5-webcomponents/componenti/function.mts @@ -0,0 +1,68 @@ + +/** + * + * @param elemento Per i custom Elements usa this + * @param aperto Predefinito = false + * @returns + */ +export function AttaccaShadow(elemento: Element, aperto = false) { + if (!aperto) { + return elemento.attachShadow({ mode: 'closed' }) + } else { + return elemento.attachShadow({ mode: 'open' }) + } +} + +export function OttieniTemplate(id:string): HTMLTemplateElement { + return document.getElementById(id) as HTMLTemplateElement +} + +export function OttieniContentDaTemplate(template: HTMLTemplateElement) { + return template.content +} + +// export function OttieniTemplateDaHTML(percorso: string, id_template:string): Node { +// fetch(percorso) +// .then(risposta => risposta.text()) +// .then(html => { +// document.body.insertAdjacentHTML('beforeend',html) +// const template = document.getElementById(id_template) as HTMLTemplateElement +// const clone = template.cloneNode(true) as Node + +// return clone +// }) +// } + +export async function InserisciTemplateNelloShadowDOM(shadowRoot: ShadowRoot, percorso: string, id_template: string): Promise { + try { + const risposta = await fetch(percorso); + if (!risposta.ok) { + throw new Error(`Errore durante il caricamento del template: ${risposta.statusText}`); + } + const html = await risposta.text(); + + // Verifica se il template è già presente nel DOM + if (!document.getElementById(id_template)) { + // Inserisci temporaneamente il template nel DOM per accedervi + document.body.insertAdjacentHTML('beforeend', html); + } + + // Ottieni il template dal DOM + const template = document.getElementById(id_template) as HTMLTemplateElement; + if (!template) { + throw new Error(`Template con id "${id_template}" non trovato.`); + } + + // Clona il contenuto del template + const clone = template.content.cloneNode(true); + + // Appendi il clone allo shadowRoot + shadowRoot.appendChild(clone); + + // Rimuovi il template temporaneamente inserito + template.remove(); + + } catch (errore) { + console.error('Errore durante l\'inserimento del template nello shadow DOM:', errore); + } +} diff --git a/parte5-webcomponents/componenti/prodotti-casa/esempio.html b/parte5-webcomponents/componenti/prodotti-casa/esempio.html new file mode 100644 index 0000000..7778819 --- /dev/null +++ b/parte5-webcomponents/componenti/prodotti-casa/esempio.html @@ -0,0 +1,10 @@ + + Detersivo + $10.00 + + + Sapone Mani + $5.00 + + + \ No newline at end of file diff --git a/parte5-webcomponents/componenti/prodotti-casa/prodotti-casa.html b/parte5-webcomponents/componenti/prodotti-casa/prodotti-casa.html new file mode 100644 index 0000000..7bacdf1 --- /dev/null +++ b/parte5-webcomponents/componenti/prodotti-casa/prodotti-casa.html @@ -0,0 +1,34 @@ + + diff --git a/parte5-webcomponents/componenti/prodotti-casa/prodotti-casa.mjs b/parte5-webcomponents/componenti/prodotti-casa/prodotti-casa.mjs new file mode 100644 index 0000000..bf9f64f --- /dev/null +++ b/parte5-webcomponents/componenti/prodotti-casa/prodotti-casa.mjs @@ -0,0 +1,11 @@ +import { InserisciTemplateNelloShadowDOM } from "../function.mjs" + +customElements.define('prodotto-casa', + class ProdottoCasa extends HTMLElement { + constructor() { + super() + + InserisciTemplateNelloShadowDOM(this.attachShadow({mode:'closed'}),'prodotti-casa.html','prodotto-casa-template') + } + } +) \ No newline at end of file diff --git a/parte5-webcomponents/componenti/pulsante/pulsante.css b/parte5-webcomponents/componenti/pulsante/pulsante.css new file mode 100644 index 0000000..42ca695 --- /dev/null +++ b/parte5-webcomponents/componenti/pulsante/pulsante.css @@ -0,0 +1,11 @@ +div { + width: max-content; + border: 1px solid; + border-radius: 5px; + margin: 10px; + padding: 5px 10px; + cursor: pointer; +} +.giallo { + background-color: yellow; +} \ No newline at end of file diff --git a/parte5-webcomponents/componenti/pulsante/pulsante.html b/parte5-webcomponents/componenti/pulsante/pulsante.html index 0464721..97ea431 100644 --- a/parte5-webcomponents/componenti/pulsante/pulsante.html +++ b/parte5-webcomponents/componenti/pulsante/pulsante.html @@ -1,15 +1,41 @@ \ No newline at end of file + + + } + + customElements.define('mio-pulsante', Pulsante) + \ No newline at end of file diff --git a/parte5-webcomponents/componenti/pulsante/pulsante.mjs b/parte5-webcomponents/componenti/pulsante/pulsante.mjs new file mode 100644 index 0000000..c50785b --- /dev/null +++ b/parte5-webcomponents/componenti/pulsante/pulsante.mjs @@ -0,0 +1,29 @@ +"use strict"; +class ElementoPersonalizzato { + /** + * + * @param nomeSelettore Dai un nome specifico per l'elemento + * @param css Crea una cartella per ogni componente e usa come percorso il nome della cartella e il file CSS + */ + constructor(nomeSelettore, css) { + this.selettori = OttientiSelettori(nomeSelettore); + this.selettori.forEach(elemento => { + AggiungiEvento(elemento, 'click', () => elemento.classList.add('giallo')); + }); + OttieniCSS(css); + } +} +const pulsante = new ElementoPersonalizzato('pulsante', 'pulsante/pulsante.css'); +function OttientiSelettori(nome) { + return document.querySelectorAll(nome); +} +function AggiungiEvento(element, type, funzione) { + element.addEventListener(type, funzione); +} +function OttieniCSS(href) { + let head = document.getElementsByTagName('HEAD')[0]; + let link = document.createElement('link'); + link.rel = 'stylesheet'; + link.href = './componenti/' + href; + head.appendChild(link); +} diff --git a/parte5-webcomponents/componenti/pulsante/pulsante.mts b/parte5-webcomponents/componenti/pulsante/pulsante.mts new file mode 100644 index 0000000..f77252e --- /dev/null +++ b/parte5-webcomponents/componenti/pulsante/pulsante.mts @@ -0,0 +1,37 @@ +class ElementoPersonalizzato { + selettori: NodeListOf; + + /** + * + * @param nomeSelettore Dai un nome specifico per l'elemento + * @param css Crea una cartella per ogni componente e usa come percorso il nome della cartella e il file CSS + */ + constructor( + nomeSelettore: string, css: string + ) { + this.selettori = OttientiSelettori(nomeSelettore) + this.selettori.forEach(elemento => { + AggiungiEvento(elemento, 'click', () => elemento.classList.add('giallo')) + }); + OttieniCSS(css) + } +} + +const pulsante = new ElementoPersonalizzato('pulsante', 'pulsante/pulsante.css') + +function OttientiSelettori(nome:string): NodeListOf { + return document.querySelectorAll(nome) +} + +function AggiungiEvento(element: Element, type: keyof HTMLElementEventMap, funzione: (this: HTMLElement, ev: Event) => any) { + element.addEventListener(type, funzione); +} + +function OttieniCSS(href: string) { + let head = document.getElementsByTagName('HEAD')[0]; + let link = document.createElement('link'); + link.rel = 'stylesheet'; + link.href = './componenti/' + href; + head.appendChild(link); +} + diff --git a/parte5-webcomponents/componenti/pulsante/pulsante.ts b/parte5-webcomponents/componenti/pulsante/pulsante.ts index d012a29..e69de29 100644 --- a/parte5-webcomponents/componenti/pulsante/pulsante.ts +++ b/parte5-webcomponents/componenti/pulsante/pulsante.ts @@ -1,17 +0,0 @@ -class Pulsante extends HTMLElement { - constructor() { - super(); - - const shadow = this.attachShadow({mode: 'closed'}) - const template = document.getElementById('pulsante-template') as HTMLTemplateElement - - const templateClonato = template.content.cloneNode(true) - shadow.appendChild(templateClonato) - - this.addEventListener('click', () => { - this.classList.toggle('giallo') - }) - } -} - -customElements.define('mio-pulsante', Pulsante) \ No newline at end of file diff --git a/parte5-webcomponents/web-components.html b/parte5-webcomponents/web-components.html index e537f10..9ad9fd6 100644 --- a/parte5-webcomponents/web-components.html +++ b/parte5-webcomponents/web-components.html @@ -8,41 +8,12 @@ - - - - Ciao + Clicca - - + + \ No newline at end of file diff --git a/parte6-JavaScript/oop.js b/parte6-JavaScript/oop.js new file mode 100644 index 0000000..cfa4b45 --- /dev/null +++ b/parte6-JavaScript/oop.js @@ -0,0 +1,43 @@ + //Classe per creare un oggetto + class Box { + + constructor(lunghezza, altezza) { + //I parametri vengono applicate alle proprietà del box + this.lunghezza = lunghezza; + this.altezza = altezza; + + } + + //Funzione generica per tutti i box + apri() { + console.log('Box aperto'); + } + } + + //Possiamo creare tutti i box che vogliamo + box_normale = new Box(20,20) + console.log(box_normale); + box_normale.apri() + + //Classe SpecialBox che estende Box + class SpecialBox extends Box { + + contenuto //Proprietà specifica + + constructor(lunghezza, altezza, contenuto) { + //Chiama il costruttore della classe base + super(lunghezza, altezza) + //Parametri specifici di questa classe + this.contenuto = contenuto + } + + //Riscriviamo la funzione per questa classe + apri() { + console.log('Trovato ' + this.contenuto); + } + } + + + boxFungo = new SpecialBox(10, 20, 'Fungo') + console.log(boxFungo); + boxFungo.apri() diff --git a/parte6-JavaScript/oop.ts b/parte6-JavaScript/oop.ts new file mode 100644 index 0000000..47c5e0b --- /dev/null +++ b/parte6-JavaScript/oop.ts @@ -0,0 +1,41 @@ +class Utente { + + constructor( + private _username : string, + private _password : string + ) { + + } + + public get username() : string { + return this._username; + } + public set username(v : string) { + this._username = v; + } + + public get password() : string { + return this._password; + } + public set password(v : string) { + this._password = v; + } + + + private _metodi_pagamento : []; + public get metodi_pagamento() : [] { + return this._metodi_pagamento; + } + public set metodi_pagamento(v : []) { + this._metodi_pagamento = v; + } + +} + +const utente1 = new Utente('Marco','12345') + +class Carrello { + constructor(parameters) { + + } +} \ No newline at end of file diff --git a/parte6-JavaScript/pratica.js b/parte6-JavaScript/pratica.js new file mode 100644 index 0000000..5a9963a --- /dev/null +++ b/parte6-JavaScript/pratica.js @@ -0,0 +1,39 @@ +//Box + //Lunghezza, altezza + //Apri +//SpecialBox + //Box + //Contenuto + //Apri + +class Box { + constructor(lunghezza, altezza) { + this.lunghezza = lunghezza + this.altezza = altezza + } + + Apri() { + console.log(`Box aperto. Non c'è nulla`); + } +} + +class SpecialBox extends Box { + + constructor(contenuto) { + super(20,20) + this.contenuto = contenuto + } + + Apri() { + console.log(`Box aperto. Trovato ` + this.contenuto); + } +} + +box1 = new Box(20,20) +console.log(box1); + +boxSpada = new SpecialBox('Spada') +console.log(boxSpada); + +box1.Apri() +boxSpada.Apri() diff --git a/parte6-JavaScript/prova.html b/parte6-JavaScript/prova.html new file mode 100644 index 0000000..63a3ed7 --- /dev/null +++ b/parte6-JavaScript/prova.html @@ -0,0 +1,18 @@ + + + + + + + Document + + + + + + + \ No newline at end of file diff --git a/parte6-JavaScript/stringhe.js b/parte6-JavaScript/stringhe.js new file mode 100644 index 0000000..9d8641f --- /dev/null +++ b/parte6-JavaScript/stringhe.js @@ -0,0 +1,46 @@ + + str = ` Questo è un corso di sviluppo web ` + + console.log(str); + + //Puliamo la stringa dagli spazi vuoti all'inizio e alla fine del testo + + str_pulito = str.trim() + + console.log(str_pulito); + + + str_programmazione = str_pulito.replace('sviluppo web', 'programmazione') + + //Creiamo stringhe da potere concatenare + + str_intro = `Questo è un corso di` + str_intro_clean = str_intro.trim() + + str_sviluppo_web = 'sviluppo web' + str_programmazione = 'programmazione' + + str_full_web = Unisci_Stringhe(str_intro,str_sviluppo_web) + str_full_programmazione = Unisci_Stringhe(str_intro,str_programmazione) + + console.log(str_full_web); + console.log(str_full_programmazione); + + str = 'Questa è una stringa di testo' + + lunghezza_testo = str.length + + str.toUpperCase() //QUESTA È UNA STRINGA DI TESTO + + str.toLowerCase() //questa è una stringa di testo + + /** + * Inseriamo le stringhe da unire, il programma le prenderà una alla volta le pulirà con trim e le unirà con join + * @param {...string} stringhe Possiamo inserire più stringhe separate da virgole + * @returns Riporta l'unione di tutte le stringhe come una frase o paragrafo unico + */ + function Unisci_Stringhe(...stringhe) { + return stringhe.map(s => s.trim()).join(' ') + } + + Unisci_Stringhe() \ No newline at end of file diff --git a/parte6-JavaScript/stringhe.ts b/parte6-JavaScript/stringhe.ts new file mode 100644 index 0000000..0c71f15 --- /dev/null +++ b/parte6-JavaScript/stringhe.ts @@ -0,0 +1,3 @@ +let str:string = 'Ciao' + +str.trim() \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..b895388 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "ES6", + "lib": ["DOM", "ES6"], + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true + } +}