2017-04-15 19:04:49 +02:00
|
|
|
import {Converter} from './converter';
|
2016-09-20 20:45:04 +02:00
|
|
|
|
|
|
|
export class URIComponentEncoder implements Converter {
|
2017-04-15 18:51:22 +02:00
|
|
|
getDisplayname(): string {
|
2017-04-15 19:04:49 +02:00
|
|
|
return 'Encode URI component';
|
2017-04-15 18:51:22 +02:00
|
|
|
}
|
2016-09-20 20:45:04 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
getId(): string {
|
2017-04-15 19:04:49 +02:00
|
|
|
return 'uricomponentencode';
|
2017-04-15 18:51:22 +02:00
|
|
|
}
|
2016-09-20 20:45:04 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
convert(input: string): string {
|
|
|
|
return encodeURIComponent(input).replace(/[!'()*]/g, function (c) {
|
|
|
|
return '%' + c.charCodeAt(0).toString(16);
|
|
|
|
});
|
|
|
|
}
|
2016-09-20 20:45:04 +02:00
|
|
|
}
|