converter/src/app/converter/uricomponentencoder.ts

18 lines
393 B
TypeScript
Raw Normal View History

2016-09-20 20:45:04 +02:00
import {Converter} from "./converter";
export class URIComponentEncoder implements Converter {
getDisplayname(): string {
return "Encode URI component";
}
2016-09-20 20:45:04 +02:00
getId(): string {
return "uricomponentencode";
}
2016-09-20 20:45:04 +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
}