Files
zulip/static/js/hash_util.js
Tim Abbott 2bc14d256f lint: Ban two spaces after comma in JS code.
We exclude the frontend tests, mostly because the lint rule isn't that
precise, and the test code has some sample user input that's a bit
funny.
2017-10-18 10:22:18 -07:00

46 lines
1.2 KiB
JavaScript

var hash_util = (function () {
var exports = {};
// Some browsers zealously URI-decode the contents of
// window.location.hash. So we hide our URI-encoding
// by replacing % with . (like MediaWiki).
exports.encodeHashComponent = function (str) {
return encodeURIComponent(str)
.replace(/\./g, '%2E')
.replace(/%/g, '.');
};
exports.encode_operand = function (operator, operand) {
if ((operator === 'group-pm-with') || (operator === 'pm-with') || (operator === 'sender')) {
var slug = people.emails_to_slug(operand);
if (slug) {
return slug;
}
}
return exports.encodeHashComponent(operand);
};
exports.decodeHashComponent = function (str) {
return decodeURIComponent(str.replace(/\./g, '%'));
};
exports.decode_operand = function (operator, operand) {
if ((operator === 'group-pm-with') || (operator === 'pm-with') || (operator === 'sender')) {
var emails = people.slug_to_emails(operand);
if (emails) {
return emails;
}
}
return exports.decodeHashComponent(operand);
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = hash_util;
}