index.js 785 B

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. // Dependencies
  3. var protocols = require("protocols");
  4. /**
  5. * isSsh
  6. * Checks if an input value is a ssh url or not.
  7. *
  8. * @name isSsh
  9. * @function
  10. * @param {String|Array} input The input url or an array of protocols.
  11. * @return {Boolean} `true` if the input is a ssh url, `false` otherwise.
  12. */
  13. function isSsh(input) {
  14. if (Array.isArray(input)) {
  15. return input.indexOf("ssh") !== -1 || input.indexOf("rsync") !== -1;
  16. }
  17. if (typeof input !== "string") {
  18. return false;
  19. }
  20. var prots = protocols(input);
  21. input = input.substring(input.indexOf("://") + 3);
  22. if (isSsh(prots)) {
  23. return true;
  24. }
  25. // TODO This probably could be improved :)
  26. return input.indexOf("@") < input.indexOf(":");
  27. }
  28. module.exports = isSsh;