a738673e291a1c00e087801a4de43884b55b2b6a92054f60c85f10700e27bb490a56eeccf03ee96237d2dc95a80276f98a3d9bb2d62f45cd7966c8511bcf6c 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. ## Web
  3. */
  4. module.exports = {
  5. /*
  6. 随机生成一个 URL。
  7. [URL 规范](http://www.w3.org/Addressing/URL/url-spec.txt)
  8. http Hypertext Transfer Protocol
  9. ftp File Transfer protocol
  10. gopher The Gopher protocol
  11. mailto Electronic mail address
  12. mid Message identifiers for electronic mail
  13. cid Content identifiers for MIME body part
  14. news Usenet news
  15. nntp Usenet news for local NNTP access only
  16. prospero Access using the prospero protocols
  17. telnet rlogin tn3270 Reference to interactive sessions
  18. wais Wide Area Information Servers
  19. */
  20. url: function(protocol, host) {
  21. return (protocol || this.protocol()) + '://' + // protocol?
  22. (host || this.domain()) + // host?
  23. '/' + this.word()
  24. },
  25. // 随机生成一个 URL 协议。
  26. protocol: function() {
  27. return this.pick(
  28. // 协议簇
  29. 'http ftp gopher mailto mid cid news nntp prospero telnet rlogin tn3270 wais'.split(' ')
  30. )
  31. },
  32. // 随机生成一个域名。
  33. domain: function(tld) {
  34. return this.word() + '.' + (tld || this.tld())
  35. },
  36. /*
  37. 随机生成一个顶级域名。
  38. 国际顶级域名 international top-level domain-names, iTLDs
  39. 国家顶级域名 national top-level domainnames, nTLDs
  40. [域名后缀大全](http://www.163ns.com/zixun/post/4417.html)
  41. */
  42. tld: function() { // Top Level Domain
  43. return this.pick(
  44. (
  45. // 域名后缀
  46. 'com net org edu gov int mil cn ' +
  47. // 国内域名
  48. 'com.cn net.cn gov.cn org.cn ' +
  49. // 中文国内域名
  50. '中国 中国互联.公司 中国互联.网络 ' +
  51. // 新国际域名
  52. 'tel biz cc tv info name hk mobi asia cd travel pro museum coop aero ' +
  53. // 世界各国域名后缀
  54. 'ad ae af ag ai al am an ao aq ar as at au aw az ba bb bd be bf bg bh bi bj bm bn bo br bs bt bv bw by bz ca cc cf cg ch ci ck cl cm cn co cq cr cu cv cx cy cz de dj dk dm do dz ec ee eg eh es et ev fi fj fk fm fo fr ga gb gd ge gf gh gi gl gm gn gp gr gt gu gw gy hk hm hn hr ht hu id ie il in io iq ir is it jm jo jp ke kg kh ki km kn kp kr kw ky kz la lb lc li lk lr ls lt lu lv ly ma mc md mg mh ml mm mn mo mp mq mr ms mt mv mw mx my mz na nc ne nf ng ni nl no np nr nt nu nz om qa pa pe pf pg ph pk pl pm pn pr pt pw py re ro ru rw sa sb sc sd se sg sh si sj sk sl sm sn so sr st su sy sz tc td tf tg th tj tk tm tn to tp tr tt tv tw tz ua ug uk us uy va vc ve vg vn vu wf ws ye yu za zm zr zw'
  55. ).split(' ')
  56. )
  57. },
  58. // 随机生成一个邮件地址。
  59. email: function(domain) {
  60. return this.character('lower') + '.' + this.word() + '@' +
  61. (
  62. domain ||
  63. (this.word() + '.' + this.tld())
  64. )
  65. // return this.character('lower') + '.' + this.last().toLowerCase() + '@' + this.last().toLowerCase() + '.' + this.tld()
  66. // return this.word() + '@' + (domain || this.domain())
  67. },
  68. // 随机生成一个 IP 地址。
  69. ip: function() {
  70. return this.natural(0, 255) + '.' +
  71. this.natural(0, 255) + '.' +
  72. this.natural(0, 255) + '.' +
  73. this.natural(0, 255)
  74. }
  75. }