ac-bundle-module-utils-url

0.0.7 • Public • Published

utils/url.js

A module for ac-bundle-app, published by ac-bundle-module.

Available Methods:


encode

function(url, type) {
  if (app.has(type) !== true) type = "encode";
  var parts = url.split("/");
  var str = "";
  for (var i=0; i<=parts.length-1; i++) {
    if (i > 0) str += "/";
    str += type === "encode" ? encodeURIComponent(parts[i]) : decodeURIComponent(parts[i]);
  }
  return str;
}

decode

function(url) {
  console.log(url);
  return mod.encode(url, "decode");
}

valid

function(str) {
  var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
    '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
    '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
    '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
    '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
    '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
  return !!pattern.test(str);
}

Happy Coding!

Package Sidebar

Install

npm i ac-bundle-module-utils-url

Weekly Downloads

2

Version

0.0.7

License

MIT

Unpacked Size

2.31 kB

Total Files

3

Last publish

Collaborators

  • rehmat