How to use the utility.encodeURIComponent function in utility

To help you get started, we’ve selected a few utility examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cnpm / npminstall / lib / utils.js View on Github external
exports.formatPackageUrl = (registry, name) => {
  if (name[0] === '@') {
    // dont encodeURIComponent @ char, it will be 405
    // https://registry.npmjs.com/%40rstacruz%2Ftap-spec/%3E%3D4.1.1
    name = '@' + utility.encodeURIComponent(name.substring(1));
  }
  const parsed = url.parse(registry);
  if (parsed.pathname.endsWith('/')) {
    parsed.pathname += name;
  } else {
    parsed.pathname += `/${name}`;
  }
  return url.format(parsed);
};
github cnpm / cnpmjs.org / config / index.js View on Github external
url: function(subject, status, options) {
      options = options || {};
      let url = `https://badgen.net/badge/${utility.encodeURIComponent(subject)}/${utility.encodeURIComponent(status)}`;
      if (options.color) {
        url += `/${utility.encodeURIComponent(options.color)}`;
      }
      if (options.icon) {
        url += `?icon=${utility.encodeURIComponent(options.icon)}`;
      }
      return url;
    },
  },
github eggjs / egg-core / lib / utils / router.js View on Github external
url = url.replace(/:([a-zA-Z_]\w*)/g, function($0, key) {
        if (utility.has(args, key)) {
          const values = args[key];
          replacedParams.push(key);
          return utility.encodeURIComponent(Array.isArray(values) ? values[0] : values);
        }
        return $0;
      });
github eggjs / egg-core / lib / utils / router.js View on Github external
url = url.replace(/:([a-zA-Z_]\w*)/g, function($0, key) {
        if (utility.has(args, key)) {
          const values = args[key];
          replacedParams.push(key);
          return utility.encodeURIComponent(Array.isArray(values) ? values[0] : values);
        }
        return $0;
      });

      for (const key in args) {
        if (replacedParams.includes(key)) {
          continue;
        }

        const values = args[key];
        const encodedKey = utility.encodeURIComponent(key);
        if (Array.isArray(values)) {
          for (const val of values) {
            queries.push(`${encodedKey}=${utility.encodeURIComponent(val)}`);
          }
        } else {
          queries.push(`${encodedKey}=${utility.encodeURIComponent(values)}`);
        }
      }
    }

    if (queries.length > 0) {
      const queryStr = queries.join('&');
      if (!url.includes('?')) {
        url = `${url}?${queryStr}`;
      } else {
        url = `${url}&${queryStr}`;
github eggjs / egg-core / lib / utils / router.js View on Github external
replacedParams.push(key);
          return utility.encodeURIComponent(Array.isArray(values) ? values[0] : values);
        }
        return $0;
      });

      for (const key in args) {
        if (replacedParams.includes(key)) {
          continue;
        }

        const values = args[key];
        const encodedKey = utility.encodeURIComponent(key);
        if (Array.isArray(values)) {
          for (const val of values) {
            queries.push(`${encodedKey}=${utility.encodeURIComponent(val)}`);
          }
        } else {
          queries.push(`${encodedKey}=${utility.encodeURIComponent(values)}`);
        }
      }
    }

    if (queries.length > 0) {
      const queryStr = queries.join('&');
      if (!url.includes('?')) {
        url = `${url}?${queryStr}`;
      } else {
        url = `${url}&${queryStr}`;
      }
    }
github eggjs / egg-core / lib / utils / router.js View on Github external
return $0;
      });

      for (const key in args) {
        if (replacedParams.includes(key)) {
          continue;
        }

        const values = args[key];
        const encodedKey = utility.encodeURIComponent(key);
        if (Array.isArray(values)) {
          for (const val of values) {
            queries.push(`${encodedKey}=${utility.encodeURIComponent(val)}`);
          }
        } else {
          queries.push(`${encodedKey}=${utility.encodeURIComponent(values)}`);
        }
      }
    }

    if (queries.length > 0) {
      const queryStr = queries.join('&');
      if (!url.includes('?')) {
        url = `${url}?${queryStr}`;
      } else {
        url = `${url}&${queryStr}`;
      }
    }

    return url;
  }
github ali-sdk / ali-oss / lib / browser / client.js View on Github external
proto._escape = function _escape(name) {
  return utility.encodeURIComponent(name).replace(/%2F/g, '/');
};
github cnpm / cnpmjs.org / config / index.js View on Github external
url: function(subject, status, options) {
      options = options || {};
      let url = `https://badgen.net/badge/${utility.encodeURIComponent(subject)}/${utility.encodeURIComponent(status)}`;
      if (options.color) {
        url += `/${utility.encodeURIComponent(options.color)}`;
      }
      if (options.icon) {
        url += `?icon=${utility.encodeURIComponent(options.icon)}`;
      }
      return url;
    },
  },