Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit ec1bc3b

Browse files
ScallyGamesfknop
authored andcommitted
Added decodeUri and decodeUriComponent pipes (#43)
1 parent a402085 commit ec1bc3b

File tree

7 files changed

+111
-0
lines changed

7 files changed

+111
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ You can find the documentations in the [`docs`](./docs) folder.
110110
* [`template`](./docs/string.md#template)
111111
* [`encodeURI`](./docs/string.md#encodeuri)
112112
* [`encodeURIComponent`](./docs/string.md#encodeuricomponent)
113+
* [`decodeURI`](./docs/string.md#decodeuri)
114+
* [`decodeURIComponent`](./docs/string.md#decodeuricomponent)
113115
* [`repeat`](./docs/string.md#repeat)
114116
* [`truncate`](./docs/string.md#truncate)
115117
* [`slugify`](./docs/string.md#slugify)

docs/string.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* [`template`](#template)
1515
* [`encodeURI`](#encodeuri)
1616
* [`encodeURIComponent`](#encodeuricomponent)
17+
* [`decodeURI`](#decodeuri)
18+
* [`decodeURIComponent`](#decodeuricomponent)
1719
* [`repeat`](#repeat)
1820
* [`truncate`](#truncate)
1921
* [`slugify`](#slugify)
@@ -247,6 +249,26 @@ The encodeURIComponent function.
247249
import { EncodeURIComponentPipe } from 'angular-pipes/src/string/encode-uri-component.pipe';
248250
```
249251

252+
#### decodeuri
253+
254+
The decodeURI function.
255+
256+
##### File
257+
258+
```typescript
259+
import { DecodeURIPipe } from 'angular-pipes/src/string/decode-uri.pipe';
260+
```
261+
262+
#### decodeuricomponent
263+
264+
The decodeURIComponent function.
265+
266+
##### File
267+
268+
```typescript
269+
import { DecodeURIComponentPipe } from 'angular-pipes/src/string/decode-uri-component.pipe';
270+
```
271+
250272
#### repeat
251273

252274
Repeats a string.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { DecodeURIComponentPipe } from './decode-uri-component.pipe';
2+
3+
4+
5+
describe('DecodeURIComponentPipe', () => {
6+
7+
let pipe: DecodeURIComponentPipe;
8+
9+
beforeEach(() => {
10+
pipe = new DecodeURIComponentPipe();
11+
});
12+
13+
it('Should return the value decoded', () => {
14+
const url = 'https%3A%2F%2Ftest.com';
15+
expect(pipe.transform(url)).toEqual(decodeURIComponent(url));
16+
});
17+
18+
it('Should return the value unchanged', () => {
19+
20+
expect(pipe.transform(1)).toEqual(1);
21+
});
22+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
import { isString } from '../utils/utils';
3+
4+
@Pipe({
5+
name: 'decodeURIComponent'
6+
})
7+
export class DecodeURIComponentPipe implements PipeTransform {
8+
9+
transform (input: any) {
10+
11+
if (!isString(input)) {
12+
return input;
13+
}
14+
15+
return decodeURIComponent(input);
16+
}
17+
}

src/string/decode-uri.pipe.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { DecodeURIPipe } from './decode-uri.pipe';
2+
3+
4+
5+
describe('DecodeURIPipe', () => {
6+
7+
let pipe: DecodeURIPipe;
8+
9+
beforeEach(() => {
10+
pipe = new DecodeURIPipe();
11+
});
12+
13+
it('Should return the value decoded', () => {
14+
const word = '%C3%A9%C3%A0';
15+
expect(pipe.transform(word)).toEqual(decodeURI(word));
16+
});
17+
18+
it('Should return the value unchanged', () => {
19+
20+
expect(pipe.transform(1)).toEqual(1);
21+
});
22+
23+
});

src/string/decode-uri.pipe.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
import { isString } from '../utils/utils';
3+
4+
@Pipe({
5+
name: 'decodeURI'
6+
})
7+
export class DecodeURIPipe implements PipeTransform {
8+
9+
transform (input: any) {
10+
11+
if (!isString(input)) {
12+
return input;
13+
}
14+
15+
return decodeURI(input);
16+
}
17+
}

src/string/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {UpperFirstPipe} from './upperfirst.pipe';
1414
import {TemplatePipe} from './template.pipe';
1515
import {EncodeURIPipe} from './encode-uri.pipe';
1616
import {EncodeURIComponentPipe} from './encode-uri-component.pipe';
17+
import {DecodeURIPipe} from './decode-uri.pipe';
18+
import {DecodeURIComponentPipe} from './decode-uri-component.pipe';
1719
import {TruncatePipe} from './truncate.pipe';
1820
import {RepeatPipe} from './repeat.pipe';
1921
import {SlugifyPipe} from './slugify.pipe';
@@ -37,6 +39,8 @@ export * from './upperfirst.pipe';
3739
export * from './template.pipe';
3840
export * from './encode-uri.pipe';
3941
export * from './encode-uri-component.pipe';
42+
export * from './decode-uri.pipe';
43+
export * from './decode-uri-component.pipe';
4044
export * from './truncate.pipe';
4145
export * from './repeat.pipe';
4246
export * from './slugify.pipe';
@@ -62,6 +66,8 @@ export * from './reverse-str.pipe';
6266
TemplatePipe,
6367
EncodeURIPipe,
6468
EncodeURIComponentPipe,
69+
DecodeURIPipe,
70+
DecodeURIComponentPipe,
6571
TruncatePipe,
6672
RepeatPipe,
6773
SlugifyPipe,
@@ -86,6 +92,8 @@ export * from './reverse-str.pipe';
8692
TemplatePipe,
8793
EncodeURIPipe,
8894
EncodeURIComponentPipe,
95+
DecodeURIPipe,
96+
DecodeURIComponentPipe,
8997
TruncatePipe,
9098
RepeatPipe,
9199
SlugifyPipe,

0 commit comments

Comments
 (0)