You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/ui/packages/consul-ui/app/services/encoder.js

34 lines
755 B

import Service from '@ember/service';
import atob from 'consul-ui/utils/atob';
import btoa from 'consul-ui/utils/btoa';
export default class EncoderService extends Service {
uriComponent = encodeURIComponent;
atob() {
return atob(...arguments);
}
btoa() {
return btoa(...arguments);
}
uriJoin() {
return this.joiner(this.uriComponent, '/', '')(...arguments);
}
uriTag() {
return this.tag(this.uriJoin.bind(this));
}
joiner = (encoder, joiner = '', defaultValue = '') => (values, strs) =>
(strs || Array(values.length).fill(joiner)).reduce(
(prev, item, i) => `${prev}${item}${encoder(values[i] || defaultValue)}`,
''
);
tag(join) {
return (strs, ...values) => join(values, strs);
}
}