Skip to content

Commit 9cdf5b0

Browse files
inizio traduzione
1 parent 132edde commit 9cdf5b0

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

5-network/07-url/article.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11

22
# URL objects
33

4-
The built-in [URL](https://url.spec.whatwg.org/#api) class provides a convenient interface for creating and parsing URLs.
4+
La classe built-in [URL](https://url.spec.whatwg.org/#api) fornisce una comoda interfaccia per la creazione ed il parsing degli URL.
55

6-
There are no networking methods that require exactly a `URL` object, strings are good enough. So technically we don't have to use `URL`. But sometimes it can be really helpful.
6+
Non esistono metodi netowrking che richiedono esattamente un oggetto `URL` object, perché le stringhe sono già abbastanza adatte allo scopo. Quindi tecnicamente non dobbiamo usare `URL`. Talvolta però può essere davvero utile.
77

8-
## Creating a URL
8+
## Creare un URL
99

10-
The syntax to create a new `URL` object:
10+
La sintassi per creare un nuovo oggetto `URL`:
1111

1212
```js
1313
new URL(url, [base])
1414
```
1515

16-
- **`url`** -- the full URL or only path (if base is set, see below),
17-
- **`base`** -- an optional base URL: if set and `url` argument has only path, then the URL is generated relative to `base`.
16+
- **`url`** -- l'URL completo o solo il path (se base è stato impostato, gaurda sotto),
17+
- **`base`** -- un base URL opzionale: se impostato ed l'argomento `url` contiene solo il path, URL viene generato relativamente a `base`.
1818

19-
For example:
19+
Ad esempio:
2020

2121
```js
2222
let url = new URL('https://javascript.info/profile/admin');
2323
```
2424

25-
These two URLs are same:
25+
Questi due URL sono identici:
2626

2727
```js run
2828
let url1 = new URL('https://javascript.info/profile/admin');
@@ -32,7 +32,7 @@ alert(url1); // https://javascript.info/profile/admin
3232
alert(url2); // https://javascript.info/profile/admin
3333
```
3434

35-
We can easily create a new URL based on the path relative to an existing URL:
35+
Possiamo facilemnte creare un nuovo URL basato sul path relativo ad un URL già esistente:
3636

3737
```js run
3838
let url = new URL('https://javascript.info/profile/admin');
@@ -41,7 +41,7 @@ let newUrl = new URL('tester', url);
4141
alert(newUrl); // https://javascript.info/profile/tester
4242
```
4343

44-
The `URL` object immediately allows us to access its components, so it's a nice way to parse the url, e.g.:
44+
L'oggetto `URL` ci permette immediatamente di accedere ai suoi componenti, in modo da avere un bel modo di effettuare il parse dell'url, come per esempio:
4545

4646
```js run
4747
let url = new URL('https://javascript.info/url');
@@ -51,63 +51,63 @@ alert(url.host); // javascript.info
5151
alert(url.pathname); // /url
5252
```
5353

54-
Here's the cheatsheet for URL components:
54+
Ecco una tabella informativa per le componenti dell'URL:
5555

5656
![](url-object.svg)
5757

58-
- `href` is the full url, same as `url.toString()`
59-
- `protocol` ends with the colon character `:`
60-
- `search` - a string of parameters, starts with the question mark `?`
61-
- `hash` starts with the hash character `#`
62-
- there may be also `user` and `password` properties if HTTP authentication is present: `http://login:password@site.com` (not painted above, rarely used).
58+
- `href` è l'url completo, equivalente di `url.toString()`
59+
- `protocol` termina con il carattere `:`
60+
- `search` - una stringa contenente parametri, comincia con il punto interrogativo `?`
61+
- `hash` cominca con il carattere cancelletto `#`
62+
- possono essere presenti anche le proprietà `user` e `password` se è presente l'autenticazione HTTP: `http://login:password@site.com` (non illustrata sopra, perché usata raramente).
6363

6464

65-
```smart header="We can pass `URL` objects to networking (and most other) methods instead of a string"
66-
We can use a `URL` object in `fetch` or `XMLHttpRequest`, almost everywhere where a URL-string is expected.
65+
```smart header="Possiamo passare gli oggetti `URL` ai metodi di networking (e molti altri) anziché una stringa"
66+
Possiamo usare un oggetto `URL` dentro `fetch` o `XMLHttpRequest`, quasi ovunque ci si aspetti una stringa.
6767

68-
Generally, the `URL` object can be passed to any method instead of a string, as most methods will perform the string conversion, that turns a `URL` object into a string with full URL.
68+
Generalmente, l'oggetto `URL` può essere passato a qualunque metodo al posto di una stringa, dal momento che la maggior parte dei metodi effettueranno una conversione in stringa, e trasformeneranno un oggetto `URL` in una stringa con l'URL completo.
6969
```
7070
7171
## SearchParams "?..."
7272
73-
Let's say we want to create a url with given search params, for instance, `https://google.com/search?query=JavaScript`.
73+
Mettiamo il caso che volessimo creare un url con dei parametri prestabiliti, ad esmepio, `https://google.com/search?query=JavaScript`.
7474
75-
We can provide them in the URL string:
75+
Possiamo inserirli dentro la stringa URL:
7676
7777
```js
7878
new URL('https://google.com/search?query=JavaScript')
7979
```
8080

81-
...But parameters need to be encoded if they contain spaces, non-latin letters, etc (more about that below).
81+
...Ma i parametri hanno bisogno di essere encodati se contengono spazi, lettere non latine, etc (più informazioni su questo in basso).
8282

83-
So there's a URL property for that: `url.searchParams`, an object of type [URLSearchParams](https://url.spec.whatwg.org/#urlsearchparams).
83+
Abbiamo una proprietà URL appositamente per questo: `url.searchParams`, un oggetto di tipo [URLSearchParams](https://url.spec.whatwg.org/#urlsearchparams).
8484

85-
It provides convenient methods for search parameters:
85+
Fornisce metodi comodi per i parametri di ricerca:
8686

87-
- **`append(name, value)`** -- add the parameter by `name`,
88-
- **`delete(name)`** -- remove the parameter by `name`,
89-
- **`get(name)`** -- get the parameter by `name`,
90-
- **`getAll(name)`** -- get all parameters with the same `name` (that's possible, e.g. `?user=John&user=Pete`),
91-
- **`has(name)`** -- check for the existence of the parameter by `name`,
92-
- **`set(name, value)`** -- set/replace the parameter,
93-
- **`sort()`** -- sort parameters by name, rarely needed,
94-
- ...and it's also iterable, similar to `Map`.
87+
- **`append(name, value)`** -- aggiunge il parametro per nome `name`,
88+
- **`delete(name)`** -- rimuove il parametro partendo dal `name`,
89+
- **`get(name)`** -- recupera il parametro dal nome `name`,
90+
- **`getAll(name)`** -- recupera tutti i parametri con lo stesso `name` (un caso reale potrebbe essere ad esempio `?user=John&user=Pete`, nel caso di una select a scelta multipla),
91+
- **`has(name)`** -- controlla l'esistenza del parametro a partire dal nome `name`,
92+
- **`set(name, value)`** -- imposta/sostituisce il parametro,
93+
- **`sort()`** -- ordina i parametri per nome, raramente necessario,
94+
- ...ed è anche iterabile, similmente a `Map`.
9595

96-
An example with parameters that contain spaces and punctuation marks:
96+
Ecco un esempio con parametri che contengono spazi e segni di punteggiatura:
9797

9898
```js run
9999
let url = new URL('https://google.com/search');
100100

101-
url.searchParams.set('q', 'test me!'); // added parameter with a space and !
101+
url.searchParams.set('q', 'test me!'); // aggiunto un parametro con spazio e !
102102

103103
alert(url); // https://google.com/search?q=test+me%21
104104

105-
url.searchParams.set('tbs', 'qdr:y'); // added parameter with a colon :
105+
url.searchParams.set('tbs', 'qdr:y'); // aggiunto un parametrio con due punti :
106106

107-
// parameters are automatically encoded
107+
// i parametri vengono codificati automaticamente
108108
alert(url); // https://google.com/search?q=test+me%21&tbs=qdr%3Ay
109109

110-
// iterate over search parameters (decoded)
110+
// itera i parametri di ricerca (decodificati)
111111
for(let [name, value] of url.searchParams) {
112112
alert(`${name}=${value}`); // q=test me!, then tbs=qdr:y
113113
}

0 commit comments

Comments
 (0)