function encode(text) {
  if (!text) {
    return "";
  }

  return replaceUsingRegExp(text, /[<>'"&]/g, (input) => {
    let result = references[input];
    if (!result) {
      const code =
        input.length > 1 ? getCodePoint(input, 0) : input.charCodeAt(0);
      result = `&#${code};`;
    }
    return result;
  });
}
@param {string} text text
@returns {string}