User documentation and guides for products sold on the Libre Tech Shop. https://docs.libretech.shop
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6707 lines
662 KiB

  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.lunr || (g.lunr = {})).wordcut = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. var _ = require("underscore");
  3. var Acceptors = {
  4. creators: null,
  5. current: null,
  6. tag: null,
  7. init: function() {
  8. this.creators = [];
  9. this.current = [];
  10. this.tag = {};
  11. },
  12. reset: function() {
  13. this.current = [];
  14. this.tag = {}
  15. },
  16. transit: function(ch) {
  17. var self = this;
  18. self.creators.forEach(function(creator) {
  19. var acceptor = creator.createAcceptor(self.tag);
  20. if (acceptor)
  21. self.current.push(acceptor);
  22. });
  23. var _current = [];
  24. self.tag = {};
  25. for (var i = 0; i < self.current.length; i++) {
  26. var _acceptor = self.current[i]
  27. , acceptor = _acceptor.transit(ch);
  28. if (!acceptor.isError) {
  29. _current.push(acceptor);
  30. self.tag[acceptor.tag] = acceptor;
  31. }
  32. }
  33. self.current = _current;
  34. },
  35. getFinalAcceptors: function() {
  36. return this.current.filter(function(acceptor) {
  37. return acceptor.isFinal;
  38. });
  39. }
  40. };
  41. module.exports = function() {
  42. var acceptors = _.clone(Acceptors);
  43. acceptors.init();
  44. return acceptors;
  45. };
  46. },{"underscore":25}],2:[function(require,module,exports){
  47. (function (__dirname){
  48. var LEFT = 0;
  49. var RIGHT = 1;
  50. var path = require("path");
  51. var glob = require("glob");
  52. var WordcutDict = {
  53. init: function (dictPathFile, withDefault, words) {
  54. withDefault = withDefault || false
  55. defaultDict = path.normalize(__dirname + "/..") + "/data/tdict-*.txt";
  56. this.dict=[]
  57. var dictPathIsDefined = dictPathFile !== undefined
  58. var dictPath = (withDefault || !dictPathIsDefined) ? [defaultDict]: [];
  59. var dictPathFile = dictPathFile || defaultDict
  60. if(dictPathIsDefined){
  61. if (Array.isArray(dictPathFile)) {
  62. dictPath.concat.apply(dictPath, dictPathFile);
  63. } else {
  64. dictPath.push(dictPathFile)
  65. }
  66. }
  67. this.addFiles(dictPath, false)
  68. if(words!==undefined){
  69. this.addWords(words, false)
  70. }
  71. this.finalizeDict();
  72. },
  73. addWords: function(words, finalize){
  74. finalize = finalize===undefined || finalize;
  75. this.dict.push.apply(this.dict, words)
  76. if(finalize){
  77. this.finalizeDict();
  78. }
  79. },
  80. finalizeDict: function(){
  81. this.dict = this.sortuniq(this.dict);
  82. },
  83. addFiles: function(files, finalize){
  84. finalize = finalize===undefined || finalize;
  85. for (var i = 0; i < 1; i++) {
  86. words = "..\nก...\nก...\nก..\nก..\nก...\nก..\nก..\nก...\nก...\nก.ตร.\nก..\nก...\nก.บช.\nก.บถ.\nก...\nก..\nก..\nก..\nก..\nก...\nก..\nก...\nก...\nก...\nก...\nก..\nกก.ตชด.\nกก.ตร..\nกก..จว.\nกก.รสช.\nกกบ.ขส.ทบ.\nกกล.รพน.\nกง.กห.\nกง.ทบ.\nกง.ทร.\nกซข..\nกซม..\nกทม.กรุงเทพมหานคร\nกบ.ทบ.\nกป.สป.\nกพ.ทบ.\nกพ.ทร.\nกพ.ทหาร\nกร.ทบ.\nกรป.กลาง\nกรอ.พอ.\nกศ..\nกศ..\nกศ.บป.\nกศ..\nกษ..\nกษ..\nกษ..\nกส..\nกส.ทบ.\nกส..\nกส..\nกอ.ปค.\nกอ.รพน.\nกอ.รมน.\nกอ.รสต.\nข...\nขว.ทบ.\nขว.ทร.\nขว.ทหาร\nขส.ทบ.\nขส.ทร.\nขส.ทอ.\nค..\nค..\nค...\nค..\nค...\nค...\nค...\nค..\nค...\nค...\nค...\nคศ..\nคศ..\nคศ..\nง..\nจ..\nจ...\nจ..\nจ..\nจ..\nจ...\nจ..\nจ..\nจ...\nจ...\nจ...\nจ..\nจ...\nจ.๑๘\nจก.ธน.\nจก.สน.\nช..\nช...\nช...\nช..\nช...\nฌ...\nฌ...\nฌ...\nฐท.สห.\nด..\nด..\nด..\nด...\nด...\nดย.ทร.\nต..\nต..\nต..\nต...\nต..\nต..\nต..\nต..\nต..\nต...\nต..\nต..\nต...\nตร.กม.\nตร.ซม.\nตร..\nตร.ทล.\nตร..\nตร.ปม.\nตร..\nตร..\nตร.รฟ.\nตร..\nตร..\nตร.สข.\nท..\nท...\nท..\nท..\nท..\nท...\nท.ทบ.\nท..\nท..\nท..\nท..\nทก..\nทก..\nทก..\nทส.ปช.\nทส.รมว.กห.\nทุ..นิ..\nธ...\nธ..\nธ.\nธ..\nน..\nน..\nน..\nน..\nน..\nน..\nน..\nน...\nน...\nน..\nน..\nน..\nน..\nน..\nน..\nน...\nน..๓\nน.สพ.\nน..\nนปพ..\nนศ..\nนศ..\nนศ..\nบ..\nบ...\nบ..\nบ...\nบ.ตร.\nบ..\nบ..\nบก.จร.\nบก.ตชด.\nบก.ตม.\nบก.ทล.\nบก..\nบก..\nบก.ปค.\nบก.ปม.\nบก..เขต\nบก.รน.\nบก.รฟ.\nบก.ร้อย.ตชด.\nบก..\nบกข..\nบจพ..\nบช..\nบช..\nบช.ตชด.\nบช..\nบช..\nบช.ปส.\nบช..\nบช..\nบชท..\nบชน..\nบชส..\nบธ..\nบธ..\nบธ..\nบนท..\nบนอ..\nบปช..\nป.กท.\nป.กศ.\nป.กศ.สูง\nป..\nป...\nป..\nป..\nป..\nป...\nป...\nป...\nป...\nป...\nป..\nป...\nป.พย.\nป..\nป...\nป...\nป...\nป...\nป...\nป...๔\nป...๕\nป...๖\nป..\nป...\nป.วิ..\nป...\nป..\nป....\nป.๑\nปม.วส.\nปอ..\nผกก..\nผช.ผอ.\nผต.มท.\nผบ.ตร.\nผบ.ทบ.\nผบ.ทร.\nผบ.ทสส.\nผบ.ทอ.\nผบก..\nผบก..\nผบก.ปค.\nผบก.ปม.\nผบก..\nผบช..\nผบช.ตชด.\nผบช..\nผบช..\nผว.กทม.\nผอ.ปจ.\nพ...\nพ.กศ.\nพ...\nพ..\nพ...\nพ...\nพ...\nพ...\nพ...\nพ...\nพ..\nพ...\nพ..\nพ..\nพ...\nพ...\nพ...\
  87. .split(/[\r\n]+/)
  88. .filter(function (w) {
  89. return w.length > 1;
  90. })
  91. this.addWords(words, false)
  92. }
  93. if(finalize){
  94. this.finalizeDict();
  95. }
  96. },
  97. dictSeek: function (l, r, ch, strOffset, pos) {
  98. var ans = null;
  99. while (l <= r) {
  100. var m = Math.floor((l + r) / 2),
  101. dict_item = this.dict[m],
  102. len = dict_item.length;
  103. if (len <= strOffset) {
  104. l = m + 1;
  105. } else {
  106. var ch_ = dict_item[strOffset];
  107. if (ch_ < ch) {
  108. l = m + 1;
  109. } else if (ch_ > ch) {
  110. r = m - 1;
  111. } else {
  112. ans = m;
  113. if (pos == LEFT) {
  114. r = m - 1;
  115. } else {
  116. l = m + 1;
  117. }
  118. }
  119. }
  120. }
  121. return ans;
  122. },
  123. isFinal: function (acceptor) {
  124. return this.dict[acceptor.l].length == acceptor.strOffset;
  125. },
  126. createAcceptor: function () {
  127. return {
  128. l: 0,
  129. r: this.dict.length - 1,
  130. strOffset: 0,
  131. isFinal: false,
  132. dict: this,
  133. transit: function (ch) {
  134. return this.dict.transit(this, ch);
  135. },
  136. isError: false,
  137. tag: "DICT",
  138. w: 1,
  139. type: "DICT"
  140. };
  141. },
  142. transit: function (acceptor, ch) {
  143. var l = this.dictSeek(acceptor.l,
  144. acceptor.r,
  145. ch,
  146. acceptor.strOffset,
  147. LEFT);
  148. if (l !== null) {
  149. var r = this.dictSeek(l,
  150. acceptor.r,
  151. ch,
  152. acceptor.strOffset,
  153. RIGHT);
  154. acceptor.l = l;
  155. acceptor.r = r;
  156. acceptor.strOffset++;
  157. acceptor.isFinal = this.isFinal(acceptor);
  158. } else {
  159. acceptor.isError = true;
  160. }
  161. return acceptor;
  162. },
  163. sortuniq: function(a){
  164. return a.sort().filter(function(item, pos, arr){
  165. return !pos || item != arr[pos - 1];
  166. })
  167. },
  168. flatten: function(a){
  169. //[[1,2],[3]] -> [1,2,3]
  170. return [].concat.apply([], a);
  171. }
  172. };
  173. module.exports = WordcutDict;
  174. }).call(this,"/dist/tmp")
  175. },{"glob":16,"path":22}],3:[function(require,module,exports){
  176. var WordRule = {
  177. createAcceptor: function(tag) {
  178. if (tag["WORD_RULE"])
  179. return null;
  180. return {strOffset: 0,
  181. isFinal: false,
  182. transit: function(ch) {
  183. var lch = ch.toLowerCase();
  184. if (lch >= "a" && lch <= "z") {
  185. this.isFinal = true;
  186. this.strOffset++;
  187. } else {
  188. this.isError = true;
  189. }
  190. return this;
  191. },
  192. isError: false,
  193. tag: "WORD_RULE",
  194. type: "WORD_RULE",
  195. w: 1};
  196. }
  197. };
  198. var NumberRule = {
  199. createAcceptor: function(tag) {
  200. if (tag["NUMBER_RULE"])
  201. return null;
  202. return {strOffset: 0,
  203. isFinal: false,
  204. transit: function(ch) {
  205. if (ch >= "0" && ch <= "9") {
  206. this.isFinal = true;
  207. this.strOffset++;
  208. } else {
  209. this.isError = true;
  210. }
  211. return this;
  212. },
  213. isError: false,
  214. tag: "NUMBER_RULE",
  215. type: "NUMBER_RULE",
  216. w: 1};
  217. }
  218. };
  219. var SpaceRule = {
  220. tag: "SPACE_RULE",
  221. createAcceptor: function(tag) {
  222. if (tag["SPACE_RULE"])
  223. return null;
  224. return {strOffset: 0,
  225. isFinal: false,
  226. transit: function(ch) {
  227. if (ch == " " || ch == "\t" || ch == "\r" || ch == "\n" ||
  228. ch == "\u00A0" || ch=="\u2003"//nbsp and emsp
  229. ) {
  230. this.isFinal = true;
  231. this.strOffset++;
  232. } else {
  233. this.isError = true;
  234. }
  235. return this;
  236. },
  237. isError: false,
  238. tag: SpaceRule.tag,
  239. w: 1,
  240. type: "SPACE_RULE"};
  241. }
  242. }
  243. var SingleSymbolRule = {
  244. tag: "SINSYM",
  245. createAcceptor: function(tag) {
  246. return {strOffset: 0,
  247. isFinal: false,
  248. transit: function(ch) {
  249. if (this.strOffset == 0 && ch.match(/^[\@\(\)\/\,\-\."`]$/)) {
  250. this.isFinal = true;
  251. this.strOffset++;
  252. } else {
  253. this.isError = true;
  254. }
  255. return this;
  256. },
  257. isError: false,
  258. tag: "SINSYM",
  259. w: 1,
  260. type: "SINSYM"};
  261. }
  262. }
  263. var LatinRules = [WordRule, SpaceRule, SingleSymbolRule, NumberRule];
  264. module.exports = LatinRules;
  265. },{}],4:[function(require,module,exports){
  266. var _ = require("underscore")
  267. , WordcutCore = require("./wordcut_core");
  268. var PathInfoBuilder = {
  269. /*
  270. buildByPartAcceptors: function(path, acceptors, i) {
  271. var
  272. var genInfos = partAcceptors.reduce(function(genInfos, acceptor) {
  273. }, []);
  274. return genInfos;
  275. }
  276. */
  277. buildByAcceptors: function(path, finalAcceptors, i) {
  278. var self = this;
  279. var infos = finalAcceptors.map(function(acceptor) {
  280. var p = i - acceptor.strOffset + 1
  281. , _info = path[p];
  282. var info = {p: p,
  283. mw: _info.mw + (acceptor.mw === undefined ? 0 : acceptor.mw),
  284. w: acceptor.w + _info.w,
  285. unk: (acceptor.unk ? acceptor.unk : 0) + _info.unk,
  286. type: acceptor.type};
  287. if (acceptor.type == "PART") {
  288. for(var j = p + 1; j <= i; j++) {
  289. path[j].merge = p;
  290. }
  291. info.merge = p;
  292. }
  293. return info;
  294. });
  295. return infos.filter(function(info) { return info; });
  296. },
  297. fallback: function(path, leftBoundary, text, i) {
  298. var _info = path[leftBoundary];
  299. if (text[i].match(/[\u0E48-\u0E4E]/)) {
  300. if (leftBoundary != 0)
  301. leftBoundary = path[leftBoundary].p;
  302. return {p: leftBoundary,
  303. mw: 0,
  304. w: 1 + _info.w,
  305. unk: 1 + _info.unk,
  306. type: "UNK"};
  307. /* } else if(leftBoundary > 0 && path[leftBoundary].type !== "UNK") {
  308. leftBoundary = path[leftBoundary].p;
  309. return {p: leftBoundary,
  310. w: 1 + _info.w,
  311. unk: 1 + _info.unk,
  312. type: "UNK"}; */
  313. } else {
  314. return {p: leftBoundary,
  315. mw: _info.mw,
  316. w: 1 + _info.w,
  317. unk: 1 + _info.unk,
  318. type: "UNK"};
  319. }
  320. },
  321. build: function(path, finalAcceptors, i, leftBoundary, text) {
  322. var basicPathInfos = this.buildByAcceptors(path, finalAcceptors, i);
  323. if (basicPathInfos.length > 0) {
  324. return basicPathInfos;
  325. } else {
  326. return [this.fallback(path, leftBoundary, text, i)];
  327. }
  328. }
  329. };
  330. module.exports = function() {
  331. return _.clone(PathInfoBuilder);
  332. }
  333. },{"./wordcut_core":8,"underscore":25}],5:[function(require,module,exports){
  334. var _ = require("underscore");
  335. var PathSelector = {
  336. selectPath: function(paths) {
  337. var path = paths.reduce(function(selectedPath, path) {
  338. if (selectedPath == null) {
  339. return path;
  340. } else {
  341. if (path.unk < selectedPath.unk)
  342. return path;
  343. if (path.unk == selectedPath.unk) {
  344. if (path.mw < selectedPath.mw)
  345. return path
  346. if (path.mw == selectedPath.mw) {
  347. if (path.w < selectedPath.w)
  348. return path;
  349. }
  350. }
  351. return selectedPath;
  352. }
  353. }, null);
  354. return path;
  355. },
  356. createPath: function() {
  357. return [{p:null, w:0, unk:0, type: "INIT", mw:0}];
  358. }
  359. };
  360. module.exports = function() {
  361. return _.clone(PathSelector);
  362. };
  363. },{"underscore":25}],6:[function(require,module,exports){
  364. function isMatch(pat, offset, ch) {
  365. if (pat.length <= offset)
  366. return false;
  367. var _ch = pat[offset];
  368. return _ch == ch ||
  369. (_ch.match(/[กข]/) && ch.match(/[ก-ฮ]/)) ||
  370. (_ch.match(/[มบ]/) && ch.match(/[ก-ฮ]/)) ||
  371. (_ch.match(/\u0E49/) && ch.match(/[\u0E48-\u0E4B]/));
  372. }
  373. var Rule0 = {
  374. pat: "เหก็ม",
  375. createAcceptor: function(tag) {
  376. return {strOffset: 0,
  377. isFinal: false,
  378. transit: function(ch) {
  379. if (isMatch(Rule0.pat, this.strOffset,ch)) {
  380. this.isFinal = (this.strOffset + 1 == Rule0.pat.length);
  381. this.strOffset++;
  382. } else {
  383. this.isError = true;
  384. }
  385. return this;
  386. },
  387. isError: false,
  388. tag: "THAI_RULE",
  389. type: "THAI_RULE",
  390. w: 1};
  391. }
  392. };
  393. var PartRule = {
  394. createAcceptor: function(tag) {
  395. return {strOffset: 0,
  396. patterns: [
  397. "แก", "เก", "ก้", "กก์", "กา", "กี", "กิ", "กืก"
  398. ],
  399. isFinal: false,
  400. transit: function(ch) {
  401. var offset = this.strOffset;
  402. this.patterns = this.patterns.filter(function(pat) {
  403. return isMatch(pat, offset, ch);
  404. });
  405. if (this.patterns.length > 0) {
  406. var len = 1 + offset;
  407. this.isFinal = this.patterns.some(function(pat) {
  408. return pat.length == len;
  409. });
  410. this.strOffset++;
  411. } else {
  412. this.isError = true;
  413. }
  414. return this;
  415. },
  416. isError: false,
  417. tag: "PART",
  418. type: "PART",
  419. unk: 1,
  420. w: 1};
  421. }
  422. };
  423. var ThaiRules = [Rule0, PartRule];
  424. module.exports = ThaiRules;
  425. },{}],7:[function(require,module,exports){
  426. var sys = require("sys")
  427. , WordcutDict = require("./dict")
  428. , WordcutCore = require("./wordcut_core")
  429. , PathInfoBuilder = require("./path_info_builder")
  430. , PathSelector = require("./path_selector")
  431. , Acceptors = require("./acceptors")
  432. , latinRules = require("./latin_rules")
  433. , thaiRules = require("./thai_rules")
  434. , _ = require("underscore");
  435. var Wordcut = Object.create(WordcutCore);
  436. Wordcut.defaultPathInfoBuilder = PathInfoBuilder;
  437. Wordcut.defaultPathSelector = PathSelector;
  438. Wordcut.defaultAcceptors = Acceptors;
  439. Wordcut.defaultLatinRules = latinRules;
  440. Wordcut.defaultThaiRules = thaiRules;
  441. Wordcut.defaultDict = WordcutDict;
  442. Wordcut.initNoDict = function(dict_path) {
  443. var self = this;
  444. self.pathInfoBuilder = new self.defaultPathInfoBuilder;
  445. self.pathSelector = new self.defaultPathSelector;
  446. self.acceptors = new self.defaultAcceptors;
  447. self.defaultLatinRules.forEach(function(rule) {
  448. self.acceptors.creators.push(rule);
  449. });
  450. self.defaultThaiRules.forEach(function(rule) {
  451. self.acceptors.creators.push(rule);
  452. });
  453. };
  454. Wordcut.init = function(dict_path, withDefault, additionalWords) {
  455. withDefault = withDefault || false;
  456. this.initNoDict();
  457. var dict = _.clone(this.defaultDict);
  458. dict.init(dict_path, withDefault, additionalWords);
  459. this.acceptors.creators.push(dict);
  460. };
  461. module.exports = Wordcut;
  462. },{"./acceptors":1,"./dict":2,"./latin_rules":3,"./path_info_builder":4,"./path_selector":5,"./thai_rules":6,"./wordcut_core":8,"sys":28,"underscore":25}],8:[function(require,module,exports){
  463. var WordcutCore = {
  464. buildPath: function(text) {
  465. var self = this
  466. , path = self.pathSelector.createPath()
  467. , leftBoundary = 0;
  468. self.acceptors.reset();
  469. for (var i = 0; i < text.length; i++) {
  470. var ch = text[i];
  471. self.acceptors.transit(ch);
  472. var possiblePathInfos = self
  473. .pathInfoBuilder
  474. .build(path,
  475. self.acceptors.getFinalAcceptors(),
  476. i,
  477. leftBoundary,
  478. text);
  479. var selectedPath = self.pathSelector.selectPath(possiblePathInfos)
  480. path.push(selectedPath);
  481. if (selectedPath.type !== "UNK") {
  482. leftBoundary = i;
  483. }
  484. }
  485. return path;
  486. },
  487. pathToRanges: function(path) {
  488. var e = path.length - 1
  489. , ranges = [];
  490. while (e > 0) {
  491. var info = path[e]
  492. , s = info.p;
  493. if (info.merge !== undefined && ranges.length > 0) {
  494. var r = ranges[ranges.length - 1];
  495. r.s = info.merge;
  496. s = r.s;
  497. } else {
  498. ranges.push({s:s, e:e});
  499. }
  500. e = s;
  501. }
  502. return ranges.reverse();
  503. },
  504. rangesToText: function(text, ranges, delimiter) {
  505. return ranges.map(function(r) {
  506. return text.substring(r.s, r.e);
  507. }).join(delimiter);
  508. },
  509. cut: function(text, delimiter) {
  510. var path = this.buildPath(text)
  511. , ranges = this.pathToRanges(path);
  512. return this
  513. .rangesToText(text, ranges,
  514. (delimiter === undefined ? "|" : delimiter));
  515. },
  516. cutIntoRanges: function(text, noText) {
  517. var path = this.buildPath(text)
  518. , ranges = this.pathToRanges(path);
  519. if (!noText) {
  520. ranges.forEach(function(r) {
  521. r.text = text.substring(r.s, r.e);
  522. });
  523. }
  524. return ranges;
  525. },
  526. cutIntoArray: function(text) {
  527. var path = this.buildPath(text)
  528. , ranges = this.pathToRanges(path);
  529. return ranges.map(function(r) {
  530. return text.substring(r.s, r.e)
  531. });
  532. }
  533. };
  534. module.exports = WordcutCore;
  535. },{}],9:[function(require,module,exports){
  536. // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
  537. //
  538. // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
  539. //
  540. // Originally from narwhal.js (http://narwhaljs.org)
  541. // Copyright (c) 2009 Thomas Robinson <280north.com>
  542. //
  543. // Permission is hereby granted, free of charge, to any person obtaining a copy
  544. // of this software and associated documentation files (the 'Software'), to
  545. // deal in the Software without restriction, including without limitation the
  546. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  547. // sell copies of the Software, and to permit persons to whom the Software is
  548. // furnished to do so, subject to the following conditions:
  549. //
  550. // The above copyright notice and this permission notice shall be included in
  551. // all copies or substantial portions of the Software.
  552. //
  553. // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  554. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  555. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  556. // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  557. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  558. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  559. // when used in node, this will actually load the util module we depend on
  560. // versus loading the builtin util module as happens otherwise
  561. // this is a bug in node module loading as far as I am concerned
  562. var util = require('util/');
  563. var pSlice = Array.prototype.slice;
  564. var hasOwn = Object.prototype.hasOwnProperty;
  565. // 1. The assert module provides functions that throw
  566. // AssertionError's when particular conditions are not met. The
  567. // assert module must conform to the following interface.
  568. var assert = module.exports = ok;
  569. // 2. The AssertionError is defined in assert.
  570. // new assert.AssertionError({ message: message,
  571. // actual: actual,
  572. // expected: expected })
  573. assert.AssertionError = function AssertionError(options) {
  574. this.name = 'AssertionError';
  575. this.actual = options.actual;
  576. this.expected = options.expected;
  577. this.operator = options.operator;
  578. if (options.message) {
  579. this.message = options.message;
  580. this.generatedMessage = false;
  581. } else {
  582. this.message = getMessage(this);
  583. this.generatedMessage = true;
  584. }
  585. var stackStartFunction = options.stackStartFunction || fail;
  586. if (Error.captureStackTrace) {
  587. Error.captureStackTrace(this, stackStartFunction);
  588. }
  589. else {
  590. // non v8 browsers so we can have a stacktrace
  591. var err = new Error();
  592. if (err.stack) {
  593. var out = err.stack;
  594. // try to strip useless frames
  595. var fn_name = stackStartFunction.name;
  596. var idx = out.indexOf('\n' + fn_name);
  597. if (idx >= 0) {
  598. // once we have located the function frame
  599. // we need to strip out everything before it (and its line)
  600. var next_line = out.indexOf('\n', idx + 1);
  601. out = out.substring(next_line + 1);
  602. }
  603. this.stack = out;
  604. }
  605. }
  606. };
  607. // assert.AssertionError instanceof Error
  608. util.inherits(assert.AssertionError, Error);
  609. function replacer(key, value) {
  610. if (util.isUndefined(value)) {
  611. return '' + value;
  612. }
  613. if (util.isNumber(value) && !isFinite(value)) {
  614. return value.toString();
  615. }
  616. if (util.isFunction(value) || util.isRegExp(value)) {
  617. return value.toString();
  618. }
  619. return value;
  620. }
  621. function truncate(s, n) {
  622. if (util.isString(s)) {
  623. return s.length < n ? s : s.slice(0, n);
  624. } else {
  625. return s;
  626. }
  627. }
  628. function getMessage(self) {
  629. return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
  630. self.operator + ' ' +
  631. truncate(JSON.stringify(self.expected, replacer), 128);
  632. }
  633. // At present only the three keys mentioned above are used and
  634. // understood by the spec. Implementations or sub modules can pass
  635. // other keys to the AssertionError's constructor - they will be
  636. // ignored.
  637. // 3. All of the following functions must throw an AssertionError
  638. // when a corresponding condition is not met, with a message that
  639. // may be undefined if not provided. All assertion methods provide
  640. // both the actual and expected values to the assertion error for
  641. // display purposes.
  642. function fail(actual, expected, message, operator, stackStartFunction) {
  643. throw new assert.AssertionError({
  644. message: message,
  645. actual: actual,
  646. expected: expected,
  647. operator: operator,
  648. stackStartFunction: stackStartFunction
  649. });
  650. }
  651. // EXTENSION! allows for well behaved errors defined elsewhere.
  652. assert.fail = fail;
  653. // 4. Pure assertion tests whether a value is truthy, as determined
  654. // by !!guard.
  655. // assert.ok(guard, message_opt);
  656. // This statement is equivalent to assert.equal(true, !!guard,
  657. // message_opt);. To test strictly for the value true, use
  658. // assert.strictEqual(true, guard, message_opt);.
  659. function ok(value, message) {
  660. if (!value) fail(value, true, message, '==', assert.ok);
  661. }
  662. assert.ok = ok;
  663. // 5. The equality assertion tests shallow, coercive equality with
  664. // ==.
  665. // assert.equal(actual, expected, message_opt);
  666. assert.equal = function equal(actual, expected, message) {
  667. if (actual != expected) fail(actual, expected, message, '==', assert.equal);
  668. };
  669. // 6. The non-equality assertion tests for whether two objects are not equal
  670. // with != assert.notEqual(actual, expected, message_opt);
  671. assert.notEqual = function notEqual(actual, expected, message) {
  672. if (actual == expected) {
  673. fail(actual, expected, message, '!=', assert.notEqual);
  674. }
  675. };
  676. // 7. The equivalence assertion tests a deep equality relation.
  677. // assert.deepEqual(actual, expected, message_opt);
  678. assert.deepEqual = function deepEqual(actual, expected, message) {
  679. if (!_deepEqual(actual, expected)) {
  680. fail(actual, expected, message, 'deepEqual', assert.deepEqual);
  681. }
  682. };
  683. function _deepEqual(actual, expected) {
  684. // 7.1. All identical values are equivalent, as determined by ===.
  685. if (actual === expected) {
  686. return true;
  687. } else if (util.isBuffer(actual) && util.isBuffer(expected)) {
  688. if (actual.length != expected.length) return false;
  689. for (var i = 0; i < actual.length; i++) {
  690. if (actual[i] !== expected[i]) return false;
  691. }
  692. return true;
  693. // 7.2. If the expected value is a Date object, the actual value is
  694. // equivalent if it is also a Date object that refers to the same time.
  695. } else if (util.isDate(actual) && util.isDate(expected)) {
  696. return actual.getTime() === expected.getTime();
  697. // 7.3 If the expected value is a RegExp object, the actual value is
  698. // equivalent if it is also a RegExp object with the same source and
  699. // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
  700. } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
  701. return actual.source === expected.source &&
  702. actual.global === expected.global &&
  703. actual.multiline === expected.multiline &&
  704. actual.lastIndex === expected.lastIndex &&
  705. actual.ignoreCase === expected.ignoreCase;
  706. // 7.4. Other pairs that do not both pass typeof value == 'object',
  707. // equivalence is determined by ==.
  708. } else if (!util.isObject(actual) && !util.isObject(expected)) {
  709. return actual == expected;
  710. // 7.5 For all other Object pairs, including Array objects, equivalence is
  711. // determined by having the same number of owned properties (as verified
  712. // with Object.prototype.hasOwnProperty.call), the same set of keys
  713. // (although not necessarily the same order), equivalent values for every
  714. // corresponding key, and an identical 'prototype' property. Note: this
  715. // accounts for both named and indexed properties on Arrays.
  716. } else {
  717. return objEquiv(actual, expected);
  718. }
  719. }
  720. function isArguments(object) {
  721. return Object.prototype.toString.call(object) == '[object Arguments]';
  722. }
  723. function objEquiv(a, b) {
  724. if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
  725. return false;
  726. // an identical 'prototype' property.
  727. if (a.prototype !== b.prototype) return false;
  728. // if one is a primitive, the other must be same
  729. if (util.isPrimitive(a) || util.isPrimitive(b)) {
  730. return a === b;
  731. }
  732. var aIsArgs = isArguments(a),
  733. bIsArgs = isArguments(b);
  734. if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
  735. return false;
  736. if (aIsArgs) {
  737. a = pSlice.call(a);
  738. b = pSlice.call(b);
  739. return _deepEqual(a, b);
  740. }
  741. var ka = objectKeys(a),
  742. kb = objectKeys(b),
  743. key, i;
  744. // having the same number of owned properties (keys incorporates
  745. // hasOwnProperty)
  746. if (ka.length != kb.length)
  747. return false;
  748. //the same set of keys (although not necessarily the same order),
  749. ka.sort();
  750. kb.sort();
  751. //~~~cheap key test
  752. for (i = ka.length - 1; i >= 0; i--) {
  753. if (ka[i] != kb[i])
  754. return false;
  755. }
  756. //equivalent values for every corresponding key, and
  757. //~~~possibly expensive deep test
  758. for (i = ka.length - 1; i >= 0; i--) {
  759. key = ka[i];
  760. if (!_deepEqual(a[key], b[key])) return false;
  761. }
  762. return true;
  763. }
  764. // 8. The non-equivalence assertion tests for any deep inequality.
  765. // assert.notDeepEqual(actual, expected, message_opt);
  766. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  767. if (_deepEqual(actual, expected)) {
  768. fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
  769. }
  770. };
  771. // 9. The strict equality assertion tests strict equality, as determined by ===.
  772. // assert.strictEqual(actual, expected, message_opt);
  773. assert.strictEqual = function strictEqual(actual, expected, message) {
  774. if (actual !== expected) {
  775. fail(actual, expected, message, '===', assert.strictEqual);
  776. }
  777. };
  778. // 10. The strict non-equality assertion tests for strict inequality, as
  779. // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
  780. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  781. if (actual === expected) {
  782. fail(actual, expected, message, '!==', assert.notStrictEqual);
  783. }
  784. };
  785. function expectedException(actual, expected) {
  786. if (!actual || !expected) {
  787. return false;
  788. }
  789. if (Object.prototype.toString.call(expected) == '[object RegExp]') {
  790. return expected.test(actual);
  791. } else if (actual instanceof expected) {
  792. return true;
  793. } else if (expected.call({}, actual) === true) {
  794. return true;
  795. }
  796. return false;
  797. }
  798. function _throws(shouldThrow, block, expected, message) {
  799. var actual;
  800. if (util.isString(expected)) {
  801. message = expected;
  802. expected = null;
  803. }
  804. try {
  805. block();
  806. } catch (e) {
  807. actual = e;
  808. }
  809. message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
  810. (message ? ' ' + message : '.');
  811. if (shouldThrow && !actual) {
  812. fail(actual, expected, 'Missing expected exception' + message);
  813. }
  814. if (!shouldThrow && expectedException(actual, expected)) {
  815. fail(actual, expected, 'Got unwanted exception' + message);
  816. }
  817. if ((shouldThrow && actual && expected &&
  818. !expectedException(actual, expected)) || (!shouldThrow && actual)) {
  819. throw actual;
  820. }
  821. }
  822. // 11. Expected to throw an error:
  823. // assert.throws(block, Error_opt, message_opt);
  824. assert.throws = function(block, /*optional*/error, /*optional*/message) {
  825. _throws.apply(this, [true].concat(pSlice.call(arguments)));
  826. };
  827. // EXTENSION! This is annoying to write outside this module.
  828. assert.doesNotThrow = function(block, /*optional*/message) {
  829. _throws.apply(this, [false].concat(pSlice.call(arguments)));
  830. };
  831. assert.ifError = function(err) { if (err) {throw err;}};
  832. var objectKeys = Object.keys || function (obj) {
  833. var keys = [];
  834. for (var key in obj) {
  835. if (hasOwn.call(obj, key)) keys.push(key);
  836. }
  837. return keys;
  838. };
  839. },{"util/":28}],10:[function(require,module,exports){
  840. 'use strict';
  841. module.exports = balanced;
  842. function balanced(a, b, str) {
  843. if (a instanceof RegExp) a = maybeMatch(a, str);
  844. if (b instanceof RegExp) b = maybeMatch(b, str);
  845. var r = range(a, b, str);
  846. return r && {
  847. start: r[0],
  848. end: r[1],
  849. pre: str.slice(0, r[0]),
  850. body: str.slice(r[0] + a.length, r[1]),
  851. post: str.slice(r[1] + b.length)
  852. };
  853. }
  854. function maybeMatch(reg, str) {
  855. var m = str.match(reg);
  856. return m ? m[0] : null;
  857. }
  858. balanced.range = range;
  859. function range(a, b, str) {
  860. var begs, beg, left, right, result;
  861. var ai = str.indexOf(a);
  862. var bi = str.indexOf(b, ai + 1);
  863. var i = ai;
  864. if (ai >= 0 && bi > 0) {
  865. begs = [];
  866. left = str.length;
  867. while (i >= 0 && !result) {
  868. if (i == ai) {
  869. begs.push(i);
  870. ai = str.indexOf(a, i + 1);
  871. } else if (begs.length == 1) {
  872. result = [ begs.pop(), bi ];
  873. } else {
  874. beg = begs.pop();
  875. if (beg < left) {
  876. left = beg;
  877. right = bi;
  878. }
  879. bi = str.indexOf(b, i + 1);
  880. }
  881. i = ai < bi && ai >= 0 ? ai : bi;
  882. }
  883. if (begs.length) {
  884. result = [ left, right ];
  885. }
  886. }
  887. return result;
  888. }
  889. },{}],11:[function(require,module,exports){
  890. var concatMap = require('concat-map');
  891. var balanced = require('balanced-match');
  892. module.exports = expandTop;
  893. var escSlash = '\0SLASH'+Math.random()+'\0';
  894. var escOpen = '\0OPEN'+Math.random()+'\0';
  895. var escClose = '\0CLOSE'+Math.random()+'\0';
  896. var escComma = '\0COMMA'+Math.random()+'\0';
  897. var escPeriod = '\0PERIOD'+Math.random()+'\0';
  898. function numeric(str) {
  899. return parseInt(str, 10) == str
  900. ? parseInt(str, 10)
  901. : str.charCodeAt(0);
  902. }
  903. function escapeBraces(str) {
  904. return str.split('\\\\').join(escSlash)
  905. .split('\\{').join(escOpen)
  906. .split('\\}').join(escClose)
  907. .split('\\,').join(escComma)
  908. .split('\\.').join(escPeriod);
  909. }
  910. function unescapeBraces(str) {
  911. return str.split(escSlash).join('\\')
  912. .split(escOpen).join('{')
  913. .split(escClose).join('}')
  914. .split(escComma).join(',')
  915. .split(escPeriod).join('.');
  916. }
  917. // Basically just str.split(","), but handling cases
  918. // where we have nested braced sections, which should be
  919. // treated as individual members, like {a,{b,c},d}
  920. function parseCommaParts(str) {
  921. if (!str)
  922. return [''];
  923. var parts = [];
  924. var m = balanced('{', '}', str);
  925. if (!m)
  926. return str.split(',');
  927. var pre = m.pre;
  928. var body = m.body;
  929. var post = m.post;
  930. var p = pre.split(',');
  931. p[p.length-1] += '{' + body + '}';
  932. var postParts = parseCommaParts(post);
  933. if (post.length) {
  934. p[p.length-1] += postParts.shift();
  935. p.push.apply(p, postParts);
  936. }
  937. parts.push.apply(parts, p);
  938. return parts;
  939. }
  940. function expandTop(str) {
  941. if (!str)
  942. return [];
  943. // I don't know why Bash 4.3 does this, but it does.
  944. // Anything starting with {} will have the first two bytes preserved
  945. // but *only* at the top level, so {},a}b will not expand to anything,
  946. // but a{},b}c will be expanded to [a}c,abc].
  947. // One could argue that this is a bug in Bash, but since the goal of
  948. // this module is to match Bash's rules, we escape a leading {}
  949. if (str.substr(0, 2) === '{}') {
  950. str = '\\{\\}' + str.substr(2);
  951. }
  952. return expand(escapeBraces(str), true).map(unescapeBraces);
  953. }
  954. function identity(e) {
  955. return e;
  956. }
  957. function embrace(str) {
  958. return '{' + str + '}';
  959. }
  960. function isPadded(el) {
  961. return /^-?0\d/.test(el);
  962. }
  963. function lte(i, y) {
  964. return i <= y;
  965. }
  966. function gte(i, y) {
  967. return i >= y;
  968. }
  969. function expand(str, isTop) {
  970. var expansions = [];
  971. var m = balanced('{', '}', str);
  972. if (!m || /\$$/.test(m.pre)) return [str];
  973. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  974. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  975. var isSequence = isNumericSequence || isAlphaSequence;
  976. var isOptions = m.body.indexOf(',') >= 0;
  977. if (!isSequence && !isOptions) {
  978. // {a},b}
  979. if (m.post.match(/,.*\}/)) {
  980. str = m.pre + '{' + m.body + escClose + m.post;
  981. return expand(str);
  982. }
  983. return [str];
  984. }
  985. var n;
  986. if (isSequence) {
  987. n = m.body.split(/\.\./);
  988. } else {
  989. n = parseCommaParts(m.body);
  990. if (n.length === 1) {
  991. // x{{a,b}}y ==> x{a}y x{b}y
  992. n = expand(n[0], false).map(embrace);
  993. if (n.length === 1) {
  994. var post = m.post.length
  995. ? expand(m.post, false)
  996. : [''];
  997. return post.map(function(p) {
  998. return m.pre + n[0] + p;
  999. });
  1000. }
  1001. }
  1002. }
  1003. // at this point, n is the parts, and we know it's not a comma set
  1004. // with a single entry.
  1005. // no need to expand pre, since it is guaranteed to be free of brace-sets
  1006. var pre = m.pre;
  1007. var post = m.post.length
  1008. ? expand(m.post, false)
  1009. : [''];
  1010. var N;
  1011. if (isSequence) {
  1012. var x = numeric(n[0]);
  1013. var y = numeric(n[1]);
  1014. var width = Math.max(n[0].length, n[1].length)
  1015. var incr = n.length == 3
  1016. ? Math.abs(numeric(n[2]))
  1017. : 1;
  1018. var test = lte;
  1019. var reverse = y < x;
  1020. if (reverse) {
  1021. incr *= -1;
  1022. test = gte;
  1023. }
  1024. var pad = n.some(isPadded);
  1025. N = [];
  1026. for (var i = x; test(i, y); i += incr) {
  1027. var c;
  1028. if (isAlphaSequence) {
  1029. c = String.fromCharCode(i);
  1030. if (c === '\\')
  1031. c = '';
  1032. } else {
  1033. c = String(i);
  1034. if (pad) {
  1035. var need = width - c.length;
  1036. if (need > 0) {
  1037. var z = new Array(need + 1).join('0');
  1038. if (i < 0)
  1039. c = '-' + z + c.slice(1);
  1040. else
  1041. c = z + c;
  1042. }
  1043. }
  1044. }
  1045. N.push(c);
  1046. }
  1047. } else {
  1048. N = concatMap(n, function(el) { return expand(el, false) });
  1049. }
  1050. for (var j = 0; j < N.length; j++) {
  1051. for (var k = 0; k < post.length; k++) {
  1052. var expansion = pre + N[j] + post[k];
  1053. if (!isTop || isSequence || expansion)
  1054. expansions.push(expansion);
  1055. }
  1056. }
  1057. return expansions;
  1058. }
  1059. },{"balanced-match":10,"concat-map":13}],12:[function(require,module,exports){
  1060. },{}],13:[function(require,module,exports){
  1061. module.exports = function (xs, fn) {
  1062. var res = [];
  1063. for (var i = 0; i < xs.length; i++) {
  1064. var x = fn(xs[i], i);
  1065. if (isArray(x)) res.push.apply(res, x);
  1066. else res.push(x);
  1067. }
  1068. return res;
  1069. };
  1070. var isArray = Array.isArray || function (xs) {
  1071. return Object.prototype.toString.call(xs) === '[object Array]';
  1072. };
  1073. },{}],14:[function(require,module,exports){
  1074. // Copyright Joyent, Inc. and other Node contributors.
  1075. //
  1076. // Permission is hereby granted, free of charge, to any person obtaining a
  1077. // copy of this software and associated documentation files (the
  1078. // "Software"), to deal in the Software without restriction, including
  1079. // without limitation the rights to use, copy, modify, merge, publish,
  1080. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1081. // persons to whom the Software is furnished to do so, subject to the
  1082. // following conditions:
  1083. //
  1084. // The above copyright notice and this permission notice shall be included
  1085. // in all copies or substantial portions of the Software.
  1086. //
  1087. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1088. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1089. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1090. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1091. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1092. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1093. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1094. function EventEmitter() {
  1095. this._events = this._events || {};
  1096. this._maxListeners = this._maxListeners || undefined;
  1097. }
  1098. module.exports = EventEmitter;
  1099. // Backwards-compat with node 0.10.x
  1100. EventEmitter.EventEmitter = EventEmitter;
  1101. EventEmitter.prototype._events = undefined;
  1102. EventEmitter.prototype._maxListeners = undefined;
  1103. // By default EventEmitters will print a warning if more than 10 listeners are
  1104. // added to it. This is a useful default which helps finding memory leaks.
  1105. EventEmitter.defaultMaxListeners = 10;
  1106. // Obviously not all Emitters should be limited to 10. This function allows
  1107. // that to be increased. Set to zero for unlimited.
  1108. EventEmitter.prototype.setMaxListeners = function(n) {
  1109. if (!isNumber(n) || n < 0 || isNaN(n))
  1110. throw TypeError('n must be a positive number');
  1111. this._maxListeners = n;
  1112. return this;
  1113. };
  1114. EventEmitter.prototype.emit = function(type) {
  1115. var er, handler, len, args, i, listeners;
  1116. if (!this._events)
  1117. this._events = {};
  1118. // If there is no 'error' event listener then throw.
  1119. if (type === 'error') {
  1120. if (!this._events.error ||
  1121. (isObject(this._events.error) && !this._events.error.length)) {
  1122. er = arguments[1];
  1123. if (er instanceof Error) {
  1124. throw er; // Unhandled 'error' event
  1125. }
  1126. throw TypeError('Uncaught, unspecified "error" event.');
  1127. }
  1128. }
  1129. handler = this._events[type];
  1130. if (isUndefined(handler))
  1131. return false;
  1132. if (isFunction(handler)) {
  1133. switch (arguments.length) {
  1134. // fast cases
  1135. case 1:
  1136. handler.call(this);
  1137. break;
  1138. case 2:
  1139. handler.call(this, arguments[1]);
  1140. break;
  1141. case 3:
  1142. handler.call(this, arguments[1], arguments[2]);
  1143. break;
  1144. // slower
  1145. default:
  1146. len = arguments.length;
  1147. args = new Array(len - 1);
  1148. for (i = 1; i < len; i++)
  1149. args[i - 1] = arguments[i];
  1150. handler.apply(this, args);
  1151. }
  1152. } else if (isObject(handler)) {
  1153. len = arguments.length;
  1154. args = new Array(len - 1);
  1155. for (i = 1; i < len; i++)
  1156. args[i - 1] = arguments[i];
  1157. listeners = handler.slice();
  1158. len = listeners.length;
  1159. for (i = 0; i < len; i++)
  1160. listeners[i].apply(this, args);
  1161. }
  1162. return true;
  1163. };
  1164. EventEmitter.prototype.addListener = function(type, listener) {
  1165. var m;
  1166. if (!isFunction(listener))
  1167. throw TypeError('listener must be a function');
  1168. if (!this._events)
  1169. this._events = {};
  1170. // To avoid recursion in the case that type === "newListener"! Before
  1171. // adding it to the listeners, first emit "newListener".
  1172. if (this._events.newListener)
  1173. this.emit('newListener', type,
  1174. isFunction(listener.listener) ?
  1175. listener.listener : listener);
  1176. if (!this._events[type])
  1177. // Optimize the case of one listener. Don't need the extra array object.
  1178. this._events[type] = listener;
  1179. else if (isObject(this._events[type]))
  1180. // If we've already got an array, just append.
  1181. this._events[type].push(listener);
  1182. else
  1183. // Adding the second element, need to change to array.
  1184. this._events[type] = [this._events[type], listener];
  1185. // Check for listener leak
  1186. if (isObject(this._events[type]) && !this._events[type].warned) {
  1187. var m;
  1188. if (!isUndefined(this._maxListeners)) {
  1189. m = this._maxListeners;
  1190. } else {
  1191. m = EventEmitter.defaultMaxListeners;
  1192. }
  1193. if (m && m > 0 && this._events[type].length > m) {
  1194. this._events[type].warned = true;
  1195. console.error('(node) warning: possible EventEmitter memory ' +
  1196. 'leak detected. %d listeners added. ' +
  1197. 'Use emitter.setMaxListeners() to increase limit.',
  1198. this._events[type].length);
  1199. if (typeof console.trace === 'function') {
  1200. // not supported in IE 10
  1201. console.trace();
  1202. }
  1203. }
  1204. }
  1205. return this;
  1206. };
  1207. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  1208. EventEmitter.prototype.once = function(type, listener) {
  1209. if (!isFunction(listener))
  1210. throw TypeError('listener must be a function');
  1211. var fired = false;
  1212. function g() {
  1213. this.removeListener(type, g);
  1214. if (!fired) {
  1215. fired = true;
  1216. listener.apply(this, arguments);
  1217. }
  1218. }
  1219. g.listener = listener;
  1220. this.on(type, g);
  1221. return this;
  1222. };
  1223. // emits a 'removeListener' event iff the listener was removed
  1224. EventEmitter.prototype.removeListener = function(type, listener) {
  1225. var list, position, length, i;
  1226. if (!isFunction(listener))
  1227. throw TypeError('listener must be a function');
  1228. if (!this._events || !this._events[type])
  1229. return this;
  1230. list = this._events[type];
  1231. length = list.length;
  1232. position = -1;
  1233. if (list === listener ||
  1234. (isFunction(list.listener) && list.listener === listener)) {
  1235. delete this._events[type];
  1236. if (this._events.removeListener)
  1237. this.emit('removeListener', type, listener);
  1238. } else if (isObject(list)) {
  1239. for (i = length; i-- > 0;) {
  1240. if (list[i] === listener ||
  1241. (list[i].listener && list[i].listener === listener)) {
  1242. position = i;
  1243. break;
  1244. }
  1245. }
  1246. if (position < 0)
  1247. return this;
  1248. if (list.length === 1) {
  1249. list.length = 0;
  1250. delete this._events[type];
  1251. } else {
  1252. list.splice(position, 1);
  1253. }
  1254. if (this._events.removeListener)
  1255. this.emit('removeListener', type, listener);
  1256. }
  1257. return this;
  1258. };
  1259. EventEmitter.prototype.removeAllListeners = function(type) {
  1260. var key, listeners;
  1261. if (!this._events)
  1262. return this;
  1263. // not listening for removeListener, no need to emit
  1264. if (!this._events.removeListener) {
  1265. if (arguments.length === 0)
  1266. this._events = {};
  1267. else if (this._events[type])
  1268. delete this._events[type];
  1269. return this;
  1270. }
  1271. // emit removeListener for all listeners on all events
  1272. if (arguments.length === 0) {
  1273. for (key in this._events) {
  1274. if (key === 'removeListener') continue;
  1275. this.removeAllListeners(key);
  1276. }
  1277. this.removeAllListeners('removeListener');
  1278. this._events = {};
  1279. return this;
  1280. }
  1281. listeners = this._events[type];
  1282. if (isFunction(listeners)) {
  1283. this.removeListener(type, listeners);
  1284. } else {
  1285. // LIFO order
  1286. while (listeners.length)
  1287. this.removeListener(type, listeners[listeners.length - 1]);
  1288. }
  1289. delete this._events[type];
  1290. return this;
  1291. };
  1292. EventEmitter.prototype.listeners = function(type) {
  1293. var ret;
  1294. if (!this._events || !this._events[type])
  1295. ret = [];
  1296. else if (isFunction(this._events[type]))
  1297. ret = [this._events[type]];
  1298. else
  1299. ret = this._events[type].slice();
  1300. return ret;
  1301. };
  1302. EventEmitter.listenerCount = function(emitter, type) {
  1303. var ret;
  1304. if (!emitter._events || !emitter._events[type])
  1305. ret = 0;
  1306. else if (isFunction(emitter._events[type]))
  1307. ret = 1;
  1308. else
  1309. ret = emitter._events[type].length;
  1310. return ret;
  1311. };
  1312. function isFunction(arg) {
  1313. return typeof arg === 'function';
  1314. }
  1315. function isNumber(arg) {
  1316. return typeof arg === 'number';
  1317. }
  1318. function isObject(arg) {
  1319. return typeof arg === 'object' && arg !== null;
  1320. }
  1321. function isUndefined(arg) {
  1322. return arg === void 0;
  1323. }
  1324. },{}],15:[function(require,module,exports){
  1325. (function (process){
  1326. exports.alphasort = alphasort
  1327. exports.alphasorti = alphasorti
  1328. exports.setopts = setopts
  1329. exports.ownProp = ownProp
  1330. exports.makeAbs = makeAbs
  1331. exports.finish = finish
  1332. exports.mark = mark
  1333. exports.isIgnored = isIgnored
  1334. exports.childrenIgnored = childrenIgnored
  1335. function ownProp (obj, field) {
  1336. return Object.prototype.hasOwnProperty.call(obj, field)
  1337. }
  1338. var path = require("path")
  1339. var minimatch = require("minimatch")
  1340. var isAbsolute = require("path-is-absolute")
  1341. var Minimatch = minimatch.Minimatch
  1342. function alphasorti (a, b) {
  1343. return a.toLowerCase().localeCompare(b.toLowerCase())
  1344. }
  1345. function alphasort (a, b) {
  1346. return a.localeCompare(b)
  1347. }
  1348. function setupIgnores (self, options) {
  1349. self.ignore = options.ignore || []
  1350. if (!Array.isArray(self.ignore))
  1351. self.ignore = [self.ignore]
  1352. if (self.ignore.length) {
  1353. self.ignore = self.ignore.map(ignoreMap)
  1354. }
  1355. }
  1356. function ignoreMap (pattern) {
  1357. var gmatcher = null
  1358. if (pattern.slice(-3) === '/**') {
  1359. var gpattern = pattern.replace(/(\/\*\*)+$/, '')
  1360. gmatcher = new Minimatch(gpattern)
  1361. }
  1362. return {
  1363. matcher: new Minimatch(pattern),
  1364. gmatcher: gmatcher
  1365. }
  1366. }
  1367. function setopts (self, pattern, options) {
  1368. if (!options)
  1369. options = {}
  1370. // base-matching: just use globstar for that.
  1371. if (options.matchBase && -1 === pattern.indexOf("/")) {
  1372. if (options.noglobstar) {
  1373. throw new Error("base matching requires globstar")
  1374. }
  1375. pattern = "**/" + pattern
  1376. }
  1377. self.silent = !!options.silent
  1378. self.pattern = pattern
  1379. self.strict = options.strict !== false
  1380. self.realpath = !!options.realpath
  1381. self.realpathCache = options.realpathCache || Object.create(null)
  1382. self.follow = !!options.follow
  1383. self.dot = !!options.dot
  1384. self.mark = !!options.mark
  1385. self.nodir = !!options.nodir
  1386. if (self.nodir)
  1387. self.mark = true
  1388. self.sync = !!options.sync
  1389. self.nounique = !!options.nounique
  1390. self.nonull = !!options.nonull
  1391. self.nosort = !!options.nosort
  1392. self.nocase = !!options.nocase
  1393. self.stat = !!options.stat
  1394. self.noprocess = !!options.noprocess
  1395. self.maxLength = options.maxLength || Infinity
  1396. self.cache = options.cache || Object.create(null)
  1397. self.statCache = options.statCache || Object.create(null)
  1398. self.symlinks = options.symlinks || Object.create(null)
  1399. setupIgnores(self, options)
  1400. self.changedCwd = false
  1401. var cwd = process.cwd()
  1402. if (!ownProp(options, "cwd"))
  1403. self.cwd = cwd
  1404. else {
  1405. self.cwd = options.cwd
  1406. self.changedCwd = path.resolve(options.cwd) !== cwd
  1407. }
  1408. self.root = options.root || path.resolve(self.cwd, "/")
  1409. self.root = path.resolve(self.root)
  1410. if (process.platform === "win32")
  1411. self.root = self.root.replace(/\\/g, "/")
  1412. self.nomount = !!options.nomount
  1413. // disable comments and negation unless the user explicitly
  1414. // passes in false as the option.
  1415. options.nonegate = options.nonegate === false ? false : true
  1416. options.nocomment = options.nocomment === false ? false : true
  1417. deprecationWarning(options)
  1418. self.minimatch = new Minimatch(pattern, options)
  1419. self.options = self.minimatch.options
  1420. }
  1421. // TODO(isaacs): remove entirely in v6
  1422. // exported to reset in tests
  1423. exports.deprecationWarned
  1424. function deprecationWarning(options) {
  1425. if (!options.nonegate || !options.nocomment) {
  1426. if (process.noDeprecation !== true && !exports.deprecationWarned) {
  1427. var msg = 'glob WARNING: comments and negation will be disabled in v6'
  1428. if (process.throwDeprecation)
  1429. throw new Error(msg)
  1430. else if (process.traceDeprecation)
  1431. console.trace(msg)
  1432. else
  1433. console.error(msg)
  1434. exports.deprecationWarned = true
  1435. }
  1436. }
  1437. }
  1438. function finish (self) {
  1439. var nou = self.nounique
  1440. var all = nou ? [] : Object.create(null)
  1441. for (var i = 0, l = self.matches.length; i < l; i ++) {
  1442. var matches = self.matches[i]
  1443. if (!matches || Object.keys(matches).length === 0) {
  1444. if (self.nonull) {
  1445. // do like the shell, and spit out the literal glob
  1446. var literal = self.minimatch.globSet[i]
  1447. if (nou)
  1448. all.push(literal)
  1449. else
  1450. all[literal] = true
  1451. }
  1452. } else {
  1453. // had matches
  1454. var m = Object.keys(matches)
  1455. if (nou)
  1456. all.push.apply(all, m)
  1457. else
  1458. m.forEach(function (m) {
  1459. all[m] = true
  1460. })
  1461. }
  1462. }
  1463. if (!nou)
  1464. all = Object.keys(all)
  1465. if (!self.nosort)
  1466. all = all.sort(self.nocase ? alphasorti : alphasort)
  1467. // at *some* point we statted all of these
  1468. if (self.mark) {
  1469. for (var i = 0; i < all.length; i++) {
  1470. all[i] = self._mark(all[i])
  1471. }
  1472. if (self.nodir) {
  1473. all = all.filter(function (e) {
  1474. return !(/\/$/.test(e))
  1475. })
  1476. }
  1477. }
  1478. if (self.ignore.length)
  1479. all = all.filter(function(m) {
  1480. return !isIgnored(self, m)
  1481. })
  1482. self.found = all
  1483. }
  1484. function mark (self, p) {
  1485. var abs = makeAbs(self, p)
  1486. var c = self.cache[abs]
  1487. var m = p
  1488. if (c) {
  1489. var isDir = c === 'DIR' || Array.isArray(c)
  1490. var slash = p.slice(-1) === '/'
  1491. if (isDir && !slash)
  1492. m += '/'
  1493. else if (!isDir && slash)
  1494. m = m.slice(0, -1)
  1495. if (m !== p) {
  1496. var mabs = makeAbs(self, m)
  1497. self.statCache[mabs] = self.statCache[abs]
  1498. self.cache[mabs] = self.cache[abs]
  1499. }
  1500. }
  1501. return m
  1502. }
  1503. // lotta situps...
  1504. function makeAbs (self, f) {
  1505. var abs = f
  1506. if (f.charAt(0) === '/') {
  1507. abs = path.join(self.root, f)
  1508. } else if (isAbsolute(f) || f === '') {
  1509. abs = f
  1510. } else if (self.changedCwd) {
  1511. abs = path.resolve(self.cwd, f)
  1512. } else {
  1513. abs = path.resolve(f)
  1514. }
  1515. return abs
  1516. }
  1517. // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  1518. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  1519. function isIgnored (self, path) {
  1520. if (!self.ignore.length)
  1521. return false
  1522. return self.ignore.some(function(item) {
  1523. return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path))
  1524. })
  1525. }
  1526. function childrenIgnored (self, path) {
  1527. if (!self.ignore.length)
  1528. return false
  1529. return self.ignore.some(function(item) {
  1530. return !!(item.gmatcher && item.gmatcher.match(path))
  1531. })
  1532. }
  1533. }).call(this,require('_process'))
  1534. },{"_process":24,"minimatch":20,"path":22,"path-is-absolute":23}],16:[function(require,module,exports){
  1535. (function (process){
  1536. // Approach:
  1537. //
  1538. // 1. Get the minimatch set
  1539. // 2. For each pattern in the set, PROCESS(pattern, false)
  1540. // 3. Store matches per-set, then uniq them
  1541. //
  1542. // PROCESS(pattern, inGlobStar)
  1543. // Get the first [n] items from pattern that are all strings
  1544. // Join these together. This is PREFIX.
  1545. // If there is no more remaining, then stat(PREFIX) and
  1546. // add to matches if it succeeds. END.
  1547. //
  1548. // If inGlobStar and PREFIX is symlink and points to dir
  1549. // set ENTRIES = []
  1550. // else readdir(PREFIX) as ENTRIES
  1551. // If fail, END
  1552. //
  1553. // with ENTRIES
  1554. // If pattern[n] is GLOBSTAR
  1555. // // handle the case where the globstar match is empty
  1556. // // by pruning it out, and testing the resulting pattern
  1557. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  1558. // // handle other cases.
  1559. // for ENTRY in ENTRIES (not dotfiles)
  1560. // // attach globstar + tail onto the entry
  1561. // // Mark that this entry is a globstar match
  1562. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  1563. //
  1564. // else // not globstar
  1565. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  1566. // Test ENTRY against pattern[n]
  1567. // If fails, continue
  1568. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  1569. //
  1570. // Caveat:
  1571. // Cache all stats and readdirs results to minimize syscall. Since all
  1572. // we ever care about is existence and directory-ness, we can just keep
  1573. // `true` for files, and [children,...] for directories, or `false` for
  1574. // things that don't exist.
  1575. module.exports = glob
  1576. var fs = require('fs')
  1577. var minimatch = require('minimatch')
  1578. var Minimatch = minimatch.Minimatch
  1579. var inherits = require('inherits')
  1580. var EE = require('events').EventEmitter
  1581. var path = require('path')
  1582. var assert = require('assert')
  1583. var isAbsolute = require('path-is-absolute')
  1584. var globSync = require('./sync.js')
  1585. var common = require('./common.js')
  1586. var alphasort = common.alphasort
  1587. var alphasorti = common.alphasorti
  1588. var setopts = common.setopts
  1589. var ownProp = common.ownProp
  1590. var inflight = require('inflight')
  1591. var util = require('util')
  1592. var childrenIgnored = common.childrenIgnored
  1593. var isIgnored = common.isIgnored
  1594. var once = require('once')
  1595. function glob (pattern, options, cb) {
  1596. if (typeof options === 'function') cb = options, options = {}
  1597. if (!options) options = {}
  1598. if (options.sync) {
  1599. if (cb)
  1600. throw new TypeError('callback provided to sync glob')
  1601. return globSync(pattern, options)
  1602. }
  1603. return new Glob(pattern, options, cb)
  1604. }
  1605. glob.sync = globSync
  1606. var GlobSync = glob.GlobSync = globSync.GlobSync
  1607. // old api surface
  1608. glob.glob = glob
  1609. glob.hasMagic = function (pattern, options_) {
  1610. var options = util._extend({}, options_)
  1611. options.noprocess = true
  1612. var g = new Glob(pattern, options)
  1613. var set = g.minimatch.set
  1614. if (set.length > 1)
  1615. return true
  1616. for (var j = 0; j < set[0].length; j++) {
  1617. if (typeof set[0][j] !== 'string')
  1618. return true
  1619. }
  1620. return false
  1621. }
  1622. glob.Glob = Glob
  1623. inherits(Glob, EE)
  1624. function Glob (pattern, options, cb) {
  1625. if (typeof options === 'function') {
  1626. cb = options
  1627. options = null
  1628. }
  1629. if (options && options.sync) {
  1630. if (cb)
  1631. throw new TypeError('callback provided to sync glob')
  1632. return new GlobSync(pattern, options)
  1633. }
  1634. if (!(this instanceof Glob))
  1635. return new Glob(pattern, options, cb)
  1636. setopts(this, pattern, options)
  1637. this._didRealPath = false
  1638. // process each pattern in the minimatch set
  1639. var n = this.minimatch.set.length
  1640. // The matches are stored as {<filename>: true,...} so that
  1641. // duplicates are automagically pruned.
  1642. // Later, we do an Object.keys() on these.
  1643. // Keep them as a list so we can fill in when nonull is set.
  1644. this.matches = new Array(n)
  1645. if (typeof cb === 'function') {
  1646. cb = once(cb)
  1647. this.on('error', cb)
  1648. this.on('end', function (matches) {
  1649. cb(null, matches)
  1650. })
  1651. }
  1652. var self = this
  1653. var n = this.minimatch.set.length
  1654. this._processing = 0
  1655. this.matches = new Array(n)
  1656. this._emitQueue = []
  1657. this._processQueue = []
  1658. this.paused = false
  1659. if (this.noprocess)
  1660. return this
  1661. if (n === 0)
  1662. return done()
  1663. for (var i = 0; i < n; i ++) {
  1664. this._process(this.minimatch.set[i], i, false, done)
  1665. }
  1666. function done () {
  1667. --self._processing
  1668. if (self._processing <= 0)
  1669. self._finish()
  1670. }
  1671. }
  1672. Glob.prototype._finish = function () {
  1673. assert(this instanceof Glob)
  1674. if (this.aborted)
  1675. return
  1676. if (this.realpath && !this._didRealpath)
  1677. return this._realpath()
  1678. common.finish(this)
  1679. this.emit('end', this.found)
  1680. }
  1681. Glob.prototype._realpath = function () {
  1682. if (this._didRealpath)
  1683. return
  1684. this._didRealpath = true
  1685. var n = this.matches.length
  1686. if (n === 0)
  1687. return this._finish()
  1688. var self = this
  1689. for (var i = 0; i < this.matches.length; i++)
  1690. this._realpathSet(i, next)
  1691. function next () {
  1692. if (--n === 0)
  1693. self._finish()
  1694. }
  1695. }
  1696. Glob.prototype._realpathSet = function (index, cb) {
  1697. var matchset = this.matches[index]
  1698. if (!matchset)
  1699. return cb()
  1700. var found = Object.keys(matchset)
  1701. var self = this
  1702. var n = found.length
  1703. if (n === 0)
  1704. return cb()
  1705. var set = this.matches[index] = Object.create(null)
  1706. found.forEach(function (p, i) {
  1707. // If there's a problem with the stat, then it means that
  1708. // one or more of the links in the realpath couldn't be
  1709. // resolved. just return the abs value in that case.
  1710. p = self._makeAbs(p)
  1711. fs.realpath(p, self.realpathCache, function (er, real) {
  1712. if (!er)
  1713. set[real] = true
  1714. else if (er.syscall === 'stat')
  1715. set[p] = true
  1716. else
  1717. self.emit('error', er) // srsly wtf right here
  1718. if (--n === 0) {
  1719. self.matches[index] = set
  1720. cb()
  1721. }
  1722. })
  1723. })
  1724. }
  1725. Glob.prototype._mark = function (p) {
  1726. return common.mark(this, p)
  1727. }
  1728. Glob.prototype._makeAbs = function (f) {
  1729. return common.makeAbs(this, f)
  1730. }
  1731. Glob.prototype.abort = function () {
  1732. this.aborted = true
  1733. this.emit('abort')
  1734. }
  1735. Glob.prototype.pause = function () {
  1736. if (!this.paused) {
  1737. this.paused = true
  1738. this.emit('pause')
  1739. }
  1740. }
  1741. Glob.prototype.resume = function () {
  1742. if (this.paused) {
  1743. this.emit('resume')
  1744. this.paused = false
  1745. if (this._emitQueue.length) {
  1746. var eq = this._emitQueue.slice(0)
  1747. this._emitQueue.length = 0
  1748. for (var i = 0; i < eq.length; i ++) {
  1749. var e = eq[i]
  1750. this._emitMatch(e[0], e[1])
  1751. }
  1752. }
  1753. if (this._processQueue.length) {
  1754. var pq = this._processQueue.slice(0)
  1755. this._processQueue.length = 0
  1756. for (var i = 0; i < pq.length; i ++) {
  1757. var p = pq[i]
  1758. this._processing--
  1759. this._process(p[0], p[1], p[2], p[3])
  1760. }
  1761. }
  1762. }
  1763. }
  1764. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  1765. assert(this instanceof Glob)
  1766. assert(typeof cb === 'function')
  1767. if (this.aborted)
  1768. return
  1769. this._processing++
  1770. if (this.paused) {
  1771. this._processQueue.push([pattern, index, inGlobStar, cb])
  1772. return
  1773. }
  1774. //console.error('PROCESS %d', this._processing, pattern)
  1775. // Get the first [n] parts of pattern that are all strings.
  1776. var n = 0
  1777. while (typeof pattern[n] === 'string') {
  1778. n ++
  1779. }
  1780. // now n is the index of the first one that is *not* a string.
  1781. // see if there's anything else
  1782. var prefix
  1783. switch (n) {
  1784. // if not, then this is rather simple
  1785. case pattern.length:
  1786. this._processSimple(pattern.join('/'), index, cb)
  1787. return
  1788. case 0:
  1789. // pattern *starts* with some non-trivial item.
  1790. // going to readdir(cwd), but not include the prefix in matches.
  1791. prefix = null
  1792. break
  1793. default:
  1794. // pattern has some string bits in the front.
  1795. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  1796. // or 'relative' like '../baz'
  1797. prefix = pattern.slice(0, n).join('/')
  1798. break
  1799. }
  1800. var remain = pattern.slice(n)
  1801. // get the list of entries.
  1802. var read
  1803. if (prefix === null)
  1804. read = '.'
  1805. else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
  1806. if (!prefix || !isAbsolute(prefix))
  1807. prefix = '/' + prefix
  1808. read = prefix
  1809. } else
  1810. read = prefix
  1811. var abs = this._makeAbs(read)
  1812. //if ignored, skip _processing
  1813. if (childrenIgnored(this, read))
  1814. return cb()
  1815. var isGlobStar = remain[0] === minimatch.GLOBSTAR
  1816. if (isGlobStar)
  1817. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb)
  1818. else
  1819. this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb)
  1820. }
  1821. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  1822. var self = this
  1823. this._readdir(abs, inGlobStar, function (er, entries) {
  1824. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  1825. })
  1826. }
  1827. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  1828. // if the abs isn't a dir, then nothing can match!
  1829. if (!entries)
  1830. return cb()
  1831. // It will only match dot entries if it starts with a dot, or if
  1832. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  1833. var pn = remain[0]
  1834. var negate = !!this.minimatch.negate
  1835. var rawGlob = pn._glob
  1836. var dotOk = this.dot || rawGlob.charAt(0) === '.'
  1837. var matchedEntries = []
  1838. for (var i = 0; i < entries.length; i++) {
  1839. var e = entries[i]
  1840. if (e.charAt(0) !== '.' || dotOk) {
  1841. var m
  1842. if (negate && !prefix) {
  1843. m = !e.match(pn)
  1844. } else {
  1845. m = e.match(pn)
  1846. }
  1847. if (m)
  1848. matchedEntries.push(e)
  1849. }
  1850. }
  1851. //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  1852. var len = matchedEntries.length
  1853. // If there are no matched entries, then nothing matches.
  1854. if (len === 0)
  1855. return cb()
  1856. // if this is the last remaining pattern bit, then no need for
  1857. // an additional stat *unless* the user has specified mark or
  1858. // stat explicitly. We know they exist, since readdir returned
  1859. // them.
  1860. if (remain.length === 1 && !this.mark && !this.stat) {
  1861. if (!this.matches[index])
  1862. this.matches[index] = Object.create(null)
  1863. for (var i = 0; i < len; i ++) {
  1864. var e = matchedEntries[i]
  1865. if (prefix) {
  1866. if (prefix !== '/')
  1867. e = prefix + '/' + e
  1868. else
  1869. e = prefix + e
  1870. }
  1871. if (e.charAt(0) === '/' && !this.nomount) {
  1872. e = path.join(this.root, e)
  1873. }
  1874. this._emitMatch(index, e)
  1875. }
  1876. // This was the last one, and no stats were needed
  1877. return cb()
  1878. }
  1879. // now test all matched entries as stand-ins for that part
  1880. // of the pattern.
  1881. remain.shift()
  1882. for (var i = 0; i < len; i ++) {
  1883. var e = matchedEntries[i]
  1884. var newPattern
  1885. if (prefix) {
  1886. if (prefix !== '/')
  1887. e = prefix + '/' + e
  1888. else
  1889. e = prefix + e
  1890. }
  1891. this._process([e].concat(remain), index, inGlobStar, cb)
  1892. }
  1893. cb()
  1894. }
  1895. Glob.prototype._emitMatch = function (index, e) {
  1896. if (this.aborted)
  1897. return
  1898. if (this.matches[index][e])
  1899. return
  1900. if (isIgnored(this, e))
  1901. return
  1902. if (this.paused) {
  1903. this._emitQueue.push([index, e])
  1904. return
  1905. }
  1906. var abs = this._makeAbs(e)
  1907. if (this.nodir) {
  1908. var c = this.cache[abs]
  1909. if (c === 'DIR' || Array.isArray(c))
  1910. return
  1911. }
  1912. if (this.mark)
  1913. e = this._mark(e)
  1914. this.matches[index][e] = true
  1915. var st = this.statCache[abs]
  1916. if (st)
  1917. this.emit('stat', e, st)
  1918. this.emit('match', e)
  1919. }
  1920. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  1921. if (this.aborted)
  1922. return
  1923. // follow all symlinked directories forever
  1924. // just proceed as if this is a non-globstar situation
  1925. if (this.follow)
  1926. return this._readdir(abs, false, cb)
  1927. var lstatkey = 'lstat\0' + abs
  1928. var self = this
  1929. var lstatcb = inflight(lstatkey, lstatcb_)
  1930. if (lstatcb)
  1931. fs.lstat(abs, lstatcb)
  1932. function lstatcb_ (er, lstat) {
  1933. if (er)
  1934. return cb()
  1935. var isSym = lstat.isSymbolicLink()
  1936. self.symlinks[abs] = isSym
  1937. // If it's not a symlink or a dir, then it's definitely a regular file.
  1938. // don't bother doing a readdir in that case.
  1939. if (!isSym && !lstat.isDirectory()) {
  1940. self.cache[abs] = 'FILE'
  1941. cb()
  1942. } else
  1943. self._readdir(abs, false, cb)
  1944. }
  1945. }
  1946. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  1947. if (this.aborted)
  1948. return
  1949. cb = inflight('readdir\0'+abs+'\0'+inGlobStar, cb)
  1950. if (!cb)
  1951. return
  1952. //console.error('RD %j %j', +inGlobStar, abs)
  1953. if (inGlobStar && !ownProp(this.symlinks, abs))
  1954. return this._readdirInGlobStar(abs, cb)
  1955. if (ownProp(this.cache, abs)) {
  1956. var c = this.cache[abs]
  1957. if (!c || c === 'FILE')
  1958. return cb()
  1959. if (Array.isArray(c))
  1960. return cb(null, c)
  1961. }
  1962. var self = this
  1963. fs.readdir(abs, readdirCb(this, abs, cb))
  1964. }
  1965. function readdirCb (self, abs, cb) {
  1966. return function (er, entries) {
  1967. if (er)
  1968. self._readdirError(abs, er, cb)
  1969. else
  1970. self._readdirEntries(abs, entries, cb)
  1971. }
  1972. }
  1973. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  1974. if (this.aborted)
  1975. return
  1976. // if we haven't asked to stat everything, then just
  1977. // assume that everything in there exists, so we can avoid
  1978. // having to stat it a second time.
  1979. if (!this.mark && !this.stat) {
  1980. for (var i = 0; i < entries.length; i ++) {
  1981. var e = entries[i]
  1982. if (abs === '/')
  1983. e = abs + e
  1984. else
  1985. e = abs + '/' + e
  1986. this.cache[e] = true
  1987. }
  1988. }
  1989. this.cache[abs] = entries
  1990. return cb(null, entries)
  1991. }
  1992. Glob.prototype._readdirError = function (f, er, cb) {
  1993. if (this.aborted)
  1994. return
  1995. // handle errors, and cache the information
  1996. switch (er.code) {
  1997. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  1998. case 'ENOTDIR': // totally normal. means it *does* exist.
  1999. this.cache[this._makeAbs(f)] = 'FILE'
  2000. break
  2001. case 'ENOENT': // not terribly unusual
  2002. case 'ELOOP':
  2003. case 'ENAMETOOLONG':
  2004. case 'UNKNOWN':
  2005. this.cache[this._makeAbs(f)] = false
  2006. break
  2007. default: // some unusual error. Treat as failure.
  2008. this.cache[this._makeAbs(f)] = false
  2009. if (this.strict) {
  2010. this.emit('error', er)
  2011. // If the error is handled, then we abort
  2012. // if not, we threw out of here
  2013. this.abort()
  2014. }
  2015. if (!this.silent)
  2016. console.error('glob error', er)
  2017. break
  2018. }
  2019. return cb()
  2020. }
  2021. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  2022. var self = this
  2023. this._readdir(abs, inGlobStar, function (er, entries) {
  2024. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  2025. })
  2026. }
  2027. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  2028. //console.error('pgs2', prefix, remain[0], entries)
  2029. // no entries means not a dir, so it can never have matches
  2030. // foo.txt/** doesn't match foo.txt
  2031. if (!entries)
  2032. return cb()
  2033. // test without the globstar, and with every child both below
  2034. // and replacing the globstar.
  2035. var remainWithoutGlobStar = remain.slice(1)
  2036. var gspref = prefix ? [ prefix ] : []
  2037. var noGlobStar = gspref.concat(remainWithoutGlobStar)
  2038. // the noGlobStar pattern exits the inGlobStar state
  2039. this._process(noGlobStar, index, false, cb)
  2040. var isSym = this.symlinks[abs]
  2041. var len = entries.length
  2042. // If it's a symlink, and we're in a globstar, then stop
  2043. if (isSym && inGlobStar)
  2044. return cb()
  2045. for (var i = 0; i < len; i++) {
  2046. var e = entries[i]
  2047. if (e.charAt(0) === '.' && !this.dot)
  2048. continue
  2049. // these two cases enter the inGlobStar state
  2050. var instead = gspref.concat(entries[i], remainWithoutGlobStar)
  2051. this._process(instead, index, true, cb)
  2052. var below = gspref.concat(entries[i], remain)
  2053. this._process(below, index, true, cb)
  2054. }
  2055. cb()
  2056. }
  2057. Glob.prototype._processSimple = function (prefix, index, cb) {
  2058. // XXX review this. Shouldn't it be doing the mounting etc
  2059. // before doing stat? kinda weird?
  2060. var self = this
  2061. this._stat(prefix, function (er, exists) {
  2062. self._processSimple2(prefix, index, er, exists, cb)
  2063. })
  2064. }
  2065. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  2066. //console.error('ps2', prefix, exists)
  2067. if (!this.matches[index])
  2068. this.matches[index] = Object.create(null)
  2069. // If it doesn't exist, then just mark the lack of results
  2070. if (!exists)
  2071. return cb()
  2072. if (prefix && isAbsolute(prefix) && !this.nomount) {
  2073. var trail = /[\/\\]$/.test(prefix)
  2074. if (prefix.charAt(0) === '/') {
  2075. prefix = path.join(this.root, prefix)
  2076. } else {
  2077. prefix = path.resolve(this.root, prefix)
  2078. if (trail)
  2079. prefix += '/'
  2080. }
  2081. }
  2082. if (process.platform === 'win32')
  2083. prefix = prefix.replace(/\\/g, '/')
  2084. // Mark this as a match
  2085. this._emitMatch(index, prefix)
  2086. cb()
  2087. }
  2088. // Returns either 'DIR', 'FILE', or false
  2089. Glob.prototype._stat = function (f, cb) {
  2090. var abs = this._makeAbs(f)
  2091. var needDir = f.slice(-1) === '/'
  2092. if (f.length > this.maxLength)
  2093. return cb()
  2094. if (!this.stat && ownProp(this.cache, abs)) {
  2095. var c = this.cache[abs]
  2096. if (Array.isArray(c))
  2097. c = 'DIR'
  2098. // It exists, but maybe not how we need it
  2099. if (!needDir || c === 'DIR')
  2100. return cb(null, c)
  2101. if (needDir && c === 'FILE')
  2102. return cb()
  2103. // otherwise we have to stat, because maybe c=true
  2104. // if we know it exists, but not what it is.
  2105. }
  2106. var exists
  2107. var stat = this.statCache[abs]
  2108. if (stat !== undefined) {
  2109. if (stat === false)
  2110. return cb(null, stat)
  2111. else {
  2112. var type = stat.isDirectory() ? 'DIR' : 'FILE'
  2113. if (needDir && type === 'FILE')
  2114. return cb()
  2115. else
  2116. return cb(null, type, stat)
  2117. }
  2118. }
  2119. var self = this
  2120. var statcb = inflight('stat\0' + abs, lstatcb_)
  2121. if (statcb)
  2122. fs.lstat(abs, statcb)
  2123. function lstatcb_ (er, lstat) {
  2124. if (lstat && lstat.isSymbolicLink()) {
  2125. // If it's a symlink, then treat it as the target, unless
  2126. // the target does not exist, then treat it as a file.
  2127. return fs.stat(abs, function (er, stat) {
  2128. if (er)
  2129. self._stat2(f, abs, null, lstat, cb)
  2130. else
  2131. self._stat2(f, abs, er, stat, cb)
  2132. })
  2133. } else {
  2134. self._stat2(f, abs, er, lstat, cb)
  2135. }
  2136. }
  2137. }
  2138. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  2139. if (er) {
  2140. this.statCache[abs] = false
  2141. return cb()
  2142. }
  2143. var needDir = f.slice(-1) === '/'
  2144. this.statCache[abs] = stat
  2145. if (abs.slice(-1) === '/' && !stat.isDirectory())
  2146. return cb(null, false, stat)
  2147. var c = stat.isDirectory() ? 'DIR' : 'FILE'
  2148. this.cache[abs] = this.cache[abs] || c
  2149. if (needDir && c !== 'DIR')
  2150. return cb()
  2151. return cb(null, c, stat)
  2152. }
  2153. }).call(this,require('_process'))
  2154. },{"./common.js":15,"./sync.js":17,"_process":24,"assert":9,"events":14,"fs":12,"inflight":18,"inherits":19,"minimatch":20,"once":21,"path":22,"path-is-absolute":23,"util":28}],17:[function(require,module,exports){
  2155. (function (process){
  2156. module.exports = globSync
  2157. globSync.GlobSync = GlobSync
  2158. var fs = require('fs')
  2159. var minimatch = require('minimatch')
  2160. var Minimatch = minimatch.Minimatch
  2161. var Glob = require('./glob.js').Glob
  2162. var util = require('util')
  2163. var path = require('path')
  2164. var assert = require('assert')
  2165. var isAbsolute = require('path-is-absolute')
  2166. var common = require('./common.js')
  2167. var alphasort = common.alphasort
  2168. var alphasorti = common.alphasorti
  2169. var setopts = common.setopts
  2170. var ownProp = common.ownProp
  2171. var childrenIgnored = common.childrenIgnored
  2172. function globSync (pattern, options) {
  2173. if (typeof options === 'function' || arguments.length === 3)
  2174. throw new TypeError('callback provided to sync glob\n'+
  2175. 'See: https://github.com/isaacs/node-glob/issues/167')
  2176. return new GlobSync(pattern, options).found
  2177. }
  2178. function GlobSync (pattern, options) {
  2179. if (!pattern)
  2180. throw new Error('must provide pattern')
  2181. if (typeof options === 'function' || arguments.length === 3)
  2182. throw new TypeError('callback provided to sync glob\n'+
  2183. 'See: https://github.com/isaacs/node-glob/issues/167')
  2184. if (!(this instanceof GlobSync))
  2185. return new GlobSync(pattern, options)
  2186. setopts(this, pattern, options)
  2187. if (this.noprocess)
  2188. return this
  2189. var n = this.minimatch.set.length
  2190. this.matches = new Array(n)
  2191. for (var i = 0; i < n; i ++) {
  2192. this._process(this.minimatch.set[i], i, false)
  2193. }
  2194. this._finish()
  2195. }
  2196. GlobSync.prototype._finish = function () {
  2197. assert(this instanceof GlobSync)
  2198. if (this.realpath) {
  2199. var self = this
  2200. this.matches.forEach(function (matchset, index) {
  2201. var set = self.matches[index] = Object.create(null)
  2202. for (var p in matchset) {
  2203. try {
  2204. p = self._makeAbs(p)
  2205. var real = fs.realpathSync(p, self.realpathCache)
  2206. set[real] = true
  2207. } catch (er) {
  2208. if (er.syscall === 'stat')
  2209. set[self._makeAbs(p)] = true
  2210. else
  2211. throw er
  2212. }
  2213. }
  2214. })
  2215. }
  2216. common.finish(this)
  2217. }
  2218. GlobSync.prototype._process = function (pattern, index, inGlobStar) {
  2219. assert(this instanceof GlobSync)
  2220. // Get the first [n] parts of pattern that are all strings.
  2221. var n = 0
  2222. while (typeof pattern[n] === 'string') {
  2223. n ++
  2224. }
  2225. // now n is the index of the first one that is *not* a string.
  2226. // See if there's anything else
  2227. var prefix
  2228. switch (n) {
  2229. // if not, then this is rather simple
  2230. case pattern.length:
  2231. this._processSimple(pattern.join('/'), index)
  2232. return
  2233. case 0:
  2234. // pattern *starts* with some non-trivial item.
  2235. // going to readdir(cwd), but not include the prefix in matches.
  2236. prefix = null
  2237. break
  2238. default:
  2239. // pattern has some string bits in the front.
  2240. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  2241. // or 'relative' like '../baz'
  2242. prefix = pattern.slice(0, n).join('/')
  2243. break
  2244. }
  2245. var remain = pattern.slice(n)
  2246. // get the list of entries.
  2247. var read
  2248. if (prefix === null)
  2249. read = '.'
  2250. else if (isAbsolute(prefix) || isAbsolute(pattern.join('/'))) {
  2251. if (!prefix || !isAbsolute(prefix))
  2252. prefix = '/' + prefix
  2253. read = prefix
  2254. } else
  2255. read = prefix
  2256. var abs = this._makeAbs(read)
  2257. //if ignored, skip processing
  2258. if (childrenIgnored(this, read))
  2259. return
  2260. var isGlobStar = remain[0] === minimatch.GLOBSTAR
  2261. if (isGlobStar)
  2262. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar)
  2263. else
  2264. this._processReaddir(prefix, read, abs, remain, index, inGlobStar)
  2265. }
  2266. GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  2267. var entries = this._readdir(abs, inGlobStar)
  2268. // if the abs isn't a dir, then nothing can match!
  2269. if (!entries)
  2270. return
  2271. // It will only match dot entries if it starts with a dot, or if
  2272. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  2273. var pn = remain[0]
  2274. var negate = !!this.minimatch.negate
  2275. var rawGlob = pn._glob
  2276. var dotOk = this.dot || rawGlob.charAt(0) === '.'
  2277. var matchedEntries = []
  2278. for (var i = 0; i < entries.length; i++) {
  2279. var e = entries[i]
  2280. if (e.charAt(0) !== '.' || dotOk) {
  2281. var m
  2282. if (negate && !prefix) {
  2283. m = !e.match(pn)
  2284. } else {
  2285. m = e.match(pn)
  2286. }
  2287. if (m)
  2288. matchedEntries.push(e)
  2289. }
  2290. }
  2291. var len = matchedEntries.length
  2292. // If there are no matched entries, then nothing matches.
  2293. if (len === 0)
  2294. return
  2295. // if this is the last remaining pattern bit, then no need for
  2296. // an additional stat *unless* the user has specified mark or
  2297. // stat explicitly. We know they exist, since readdir returned
  2298. // them.
  2299. if (remain.length === 1 && !this.mark && !this.stat) {
  2300. if (!this.matches[index])
  2301. this.matches[index] = Object.create(null)
  2302. for (var i = 0; i < len; i ++) {
  2303. var e = matchedEntries[i]
  2304. if (prefix) {
  2305. if (prefix.slice(-1) !== '/')
  2306. e = prefix + '/' + e
  2307. else
  2308. e = prefix + e
  2309. }
  2310. if (e.charAt(0) === '/' && !this.nomount) {
  2311. e = path.join(this.root, e)
  2312. }
  2313. this.matches[index][e] = true
  2314. }
  2315. // This was the last one, and no stats were needed
  2316. return
  2317. }
  2318. // now test all matched entries as stand-ins for that part
  2319. // of the pattern.
  2320. remain.shift()
  2321. for (var i = 0; i < len; i ++) {
  2322. var e = matchedEntries[i]
  2323. var newPattern
  2324. if (prefix)
  2325. newPattern = [prefix, e]
  2326. else
  2327. newPattern = [e]
  2328. this._process(newPattern.concat(remain), index, inGlobStar)
  2329. }
  2330. }
  2331. GlobSync.prototype._emitMatch = function (index, e) {
  2332. var abs = this._makeAbs(e)
  2333. if (this.mark)
  2334. e = this._mark(e)
  2335. if (this.matches[index][e])
  2336. return
  2337. if (this.nodir) {
  2338. var c = this.cache[this._makeAbs(e)]
  2339. if (c === 'DIR' || Array.isArray(c))
  2340. return
  2341. }
  2342. this.matches[index][e] = true
  2343. if (this.stat)
  2344. this._stat(e)
  2345. }
  2346. GlobSync.prototype._readdirInGlobStar = function (abs) {
  2347. // follow all symlinked directories forever
  2348. // just proceed as if this is a non-globstar situation
  2349. if (this.follow)
  2350. return this._readdir(abs, false)
  2351. var entries
  2352. var lstat
  2353. var stat
  2354. try {
  2355. lstat = fs.lstatSync(abs)
  2356. } catch (er) {
  2357. // lstat failed, doesn't exist
  2358. return null
  2359. }
  2360. var isSym = lstat.isSymbolicLink()
  2361. this.symlinks[abs] = isSym
  2362. // If it's not a symlink or a dir, then it's definitely a regular file.
  2363. // don't bother doing a readdir in that case.
  2364. if (!isSym && !lstat.isDirectory())
  2365. this.cache[abs] = 'FILE'
  2366. else
  2367. entries = this._readdir(abs, false)
  2368. return entries
  2369. }
  2370. GlobSync.prototype._readdir = function (abs, inGlobStar) {
  2371. var entries
  2372. if (inGlobStar && !ownProp(this.symlinks, abs))
  2373. return this._readdirInGlobStar(abs)
  2374. if (ownProp(this.cache, abs)) {
  2375. var c = this.cache[abs]
  2376. if (!c || c === 'FILE')
  2377. return null
  2378. if (Array.isArray(c))
  2379. return c
  2380. }
  2381. try {
  2382. return this._readdirEntries(abs, fs.readdirSync(abs))
  2383. } catch (er) {
  2384. this._readdirError(abs, er)
  2385. return null
  2386. }
  2387. }
  2388. GlobSync.prototype._readdirEntries = function (abs, entries) {
  2389. // if we haven't asked to stat everything, then just
  2390. // assume that everything in there exists, so we can avoid
  2391. // having to stat it a second time.
  2392. if (!this.mark && !this.stat) {
  2393. for (var i = 0; i < entries.length; i ++) {
  2394. var e = entries[i]
  2395. if (abs === '/')
  2396. e = abs + e
  2397. else
  2398. e = abs + '/' + e
  2399. this.cache[e] = true
  2400. }
  2401. }
  2402. this.cache[abs] = entries
  2403. // mark and cache dir-ness
  2404. return entries
  2405. }
  2406. GlobSync.prototype._readdirError = function (f, er) {
  2407. // handle errors, and cache the information
  2408. switch (er.code) {
  2409. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  2410. case 'ENOTDIR': // totally normal. means it *does* exist.
  2411. this.cache[this._makeAbs(f)] = 'FILE'
  2412. break
  2413. case 'ENOENT': // not terribly unusual
  2414. case 'ELOOP':
  2415. case 'ENAMETOOLONG':
  2416. case 'UNKNOWN':
  2417. this.cache[this._makeAbs(f)] = false
  2418. break
  2419. default: // some unusual error. Treat as failure.
  2420. this.cache[this._makeAbs(f)] = false
  2421. if (this.strict)
  2422. throw er
  2423. if (!this.silent)
  2424. console.error('glob error', er)
  2425. break
  2426. }
  2427. }
  2428. GlobSync.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  2429. var entries = this._readdir(abs, inGlobStar)
  2430. // no entries means not a dir, so it can never have matches
  2431. // foo.txt/** doesn't match foo.txt
  2432. if (!entries)
  2433. return
  2434. // test without the globstar, and with every child both below
  2435. // and replacing the globstar.
  2436. var remainWithoutGlobStar = remain.slice(1)
  2437. var gspref = prefix ? [ prefix ] : []
  2438. var noGlobStar = gspref.concat(remainWithoutGlobStar)
  2439. // the noGlobStar pattern exits the inGlobStar state
  2440. this._process(noGlobStar, index, false)
  2441. var len = entries.length
  2442. var isSym = this.symlinks[abs]
  2443. // If it's a symlink, and we're in a globstar, then stop
  2444. if (isSym && inGlobStar)
  2445. return
  2446. for (var i = 0; i < len; i++) {
  2447. var e = entries[i]
  2448. if (e.charAt(0) === '.' && !this.dot)
  2449. continue
  2450. // these two cases enter the inGlobStar state
  2451. var instead = gspref.concat(entries[i], remainWithoutGlobStar)
  2452. this._process(instead, index, true)
  2453. var below = gspref.concat(entries[i], remain)
  2454. this._process(below, index, true)
  2455. }
  2456. }
  2457. GlobSync.prototype._processSimple = function (prefix, index) {
  2458. // XXX review this. Shouldn't it be doing the mounting etc
  2459. // before doing stat? kinda weird?
  2460. var exists = this._stat(prefix)
  2461. if (!this.matches[index])
  2462. this.matches[index] = Object.create(null)
  2463. // If it doesn't exist, then just mark the lack of results
  2464. if (!exists)
  2465. return
  2466. if (prefix && isAbsolute(prefix) && !this.nomount) {
  2467. var trail = /[\/\\]$/.test(prefix)
  2468. if (prefix.charAt(0) === '/') {
  2469. prefix = path.join(this.root, prefix)
  2470. } else {
  2471. prefix = path.resolve(this.root, prefix)
  2472. if (trail)
  2473. prefix += '/'
  2474. }
  2475. }
  2476. if (process.platform === 'win32')
  2477. prefix = prefix.replace(/\\/g, '/')
  2478. // Mark this as a match
  2479. this.matches[index][prefix] = true
  2480. }
  2481. // Returns either 'DIR', 'FILE', or false
  2482. GlobSync.prototype._stat = function (f) {
  2483. var abs = this._makeAbs(f)
  2484. var needDir = f.slice(-1) === '/'
  2485. if (f.length > this.maxLength)
  2486. return false
  2487. if (!this.stat && ownProp(this.cache, abs)) {
  2488. var c = this.cache[abs]
  2489. if (Array.isArray(c))
  2490. c = 'DIR'
  2491. // It exists, but maybe not how we need it
  2492. if (!needDir || c === 'DIR')
  2493. return c
  2494. if (needDir && c === 'FILE')
  2495. return false
  2496. // otherwise we have to stat, because maybe c=true
  2497. // if we know it exists, but not what it is.
  2498. }
  2499. var exists
  2500. var stat = this.statCache[abs]
  2501. if (!stat) {
  2502. var lstat
  2503. try {
  2504. lstat = fs.lstatSync(abs)
  2505. } catch (er) {
  2506. return false
  2507. }
  2508. if (lstat.isSymbolicLink()) {
  2509. try {
  2510. stat = fs.statSync(abs)
  2511. } catch (er) {
  2512. stat = lstat
  2513. }
  2514. } else {
  2515. stat = lstat
  2516. }
  2517. }
  2518. this.statCache[abs] = stat
  2519. var c = stat.isDirectory() ? 'DIR' : 'FILE'
  2520. this.cache[abs] = this.cache[abs] || c
  2521. if (needDir && c !== 'DIR')
  2522. return false
  2523. return c
  2524. }
  2525. GlobSync.prototype._mark = function (p) {
  2526. return common.mark(this, p)
  2527. }
  2528. GlobSync.prototype._makeAbs = function (f) {
  2529. return common.makeAbs(this, f)
  2530. }
  2531. }).call(this,require('_process'))
  2532. },{"./common.js":15,"./glob.js":16,"_process":24,"assert":9,"fs":12,"minimatch":20,"path":22,"path-is-absolute":23,"util":28}],18:[function(require,module,exports){
  2533. (function (process){
  2534. var wrappy = require('wrappy')
  2535. var reqs = Object.create(null)
  2536. var once = require('once')
  2537. module.exports = wrappy(inflight)
  2538. function inflight (key, cb) {
  2539. if (reqs[key]) {
  2540. reqs[key].push(cb)
  2541. return null
  2542. } else {
  2543. reqs[key] = [cb]
  2544. return makeres(key)
  2545. }
  2546. }
  2547. function makeres (key) {
  2548. return once(function RES () {
  2549. var cbs = reqs[key]
  2550. var len = cbs.length
  2551. var args = slice(arguments)
  2552. // XXX It's somewhat ambiguous whether a new callback added in this
  2553. // pass should be queued for later execution if something in the
  2554. // list of callbacks throws, or if it should just be discarded.
  2555. // However, it's such an edge case that it hardly matters, and either
  2556. // choice is likely as surprising as the other.
  2557. // As it happens, we do go ahead and schedule it for later execution.
  2558. try {
  2559. for (var i = 0; i < len; i++) {
  2560. cbs[i].apply(null, args)
  2561. }
  2562. } finally {
  2563. if (cbs.length > len) {
  2564. // added more in the interim.
  2565. // de-zalgo, just in case, but don't call again.
  2566. cbs.splice(0, len)
  2567. process.nextTick(function () {
  2568. RES.apply(null, args)
  2569. })
  2570. } else {
  2571. delete reqs[key]
  2572. }
  2573. }
  2574. })
  2575. }
  2576. function slice (args) {
  2577. var length = args.length
  2578. var array = []
  2579. for (var i = 0; i < length; i++) array[i] = args[i]
  2580. return array
  2581. }
  2582. }).call(this,require('_process'))
  2583. },{"_process":24,"once":21,"wrappy":29}],19:[function(require,module,exports){
  2584. if (typeof Object.create === 'function') {
  2585. // implementation from standard node.js 'util' module
  2586. module.exports = function inherits(ctor, superCtor) {
  2587. ctor.super_ = superCtor
  2588. ctor.prototype = Object.create(superCtor.prototype, {
  2589. constructor: {
  2590. value: ctor,
  2591. enumerable: false,
  2592. writable: true,
  2593. configurable: true
  2594. }
  2595. });
  2596. };
  2597. } else {
  2598. // old school shim for old browsers
  2599. module.exports = function inherits(ctor, superCtor) {
  2600. ctor.super_ = superCtor
  2601. var TempCtor = function () {}
  2602. TempCtor.prototype = superCtor.prototype
  2603. ctor.prototype = new TempCtor()
  2604. ctor.prototype.constructor = ctor
  2605. }
  2606. }
  2607. },{}],20:[function(require,module,exports){
  2608. module.exports = minimatch
  2609. minimatch.Minimatch = Minimatch
  2610. var path = { sep: '/' }
  2611. try {
  2612. path = require('path')
  2613. } catch (er) {}
  2614. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
  2615. var expand = require('brace-expansion')
  2616. var plTypes = {
  2617. '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
  2618. '?': { open: '(?:', close: ')?' },
  2619. '+': { open: '(?:', close: ')+' },
  2620. '*': { open: '(?:', close: ')*' },
  2621. '@': { open: '(?:', close: ')' }
  2622. }
  2623. // any single thing other than /
  2624. // don't need to escape / when using new RegExp()
  2625. var qmark = '[^/]'
  2626. // * => any number of characters
  2627. var star = qmark + '*?'
  2628. // ** when dots are allowed. Anything goes, except .. and .
  2629. // not (^ or / followed by one or two dots followed by $ or /),
  2630. // followed by anything, any number of times.
  2631. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
  2632. // not a ^ or / followed by a dot,
  2633. // followed by anything, any number of times.
  2634. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'
  2635. // characters that need to be escaped in RegExp.
  2636. var reSpecials = charSet('().*{}+?[]^$\\!')
  2637. // "abc" -> { a:true, b:true, c:true }
  2638. function charSet (s) {
  2639. return s.split('').reduce(function (set, c) {
  2640. set[c] = true
  2641. return set
  2642. }, {})
  2643. }
  2644. // normalizes slashes.
  2645. var slashSplit = /\/+/
  2646. minimatch.filter = filter
  2647. function filter (pattern, options) {
  2648. options = options || {}
  2649. return function (p, i, list) {
  2650. return minimatch(p, pattern, options)
  2651. }
  2652. }
  2653. function ext (a, b) {
  2654. a = a || {}
  2655. b = b || {}
  2656. var t = {}
  2657. Object.keys(b).forEach(function (k) {
  2658. t[k] = b[k]
  2659. })
  2660. Object.keys(a).forEach(function (k) {
  2661. t[k] = a[k]
  2662. })
  2663. return t
  2664. }
  2665. minimatch.defaults = function (def) {
  2666. if (!def || !Object.keys(def).length) return minimatch
  2667. var orig = minimatch
  2668. var m = function minimatch (p, pattern, options) {
  2669. return orig.minimatch(p, pattern, ext(def, options))
  2670. }
  2671. m.Minimatch = function Minimatch (pattern, options) {
  2672. return new orig.Minimatch(pattern, ext(def, options))
  2673. }
  2674. return m
  2675. }
  2676. Minimatch.defaults = function (def) {
  2677. if (!def || !Object.keys(def).length) return Minimatch
  2678. return minimatch.defaults(def).Minimatch
  2679. }
  2680. function minimatch (p, pattern, options) {
  2681. if (typeof pattern !== 'string') {
  2682. throw new TypeError('glob pattern string required')
  2683. }
  2684. if (!options) options = {}
  2685. // shortcut: comments match nothing.
  2686. if (!options.nocomment && pattern.charAt(0) === '#') {
  2687. return false
  2688. }
  2689. // "" only matches ""
  2690. if (pattern.trim() === '') return p === ''
  2691. return new Minimatch(pattern, options).match(p)
  2692. }
  2693. function Minimatch (pattern, options) {
  2694. if (!(this instanceof Minimatch)) {
  2695. return new Minimatch(pattern, options)
  2696. }
  2697. if (typeof pattern !== 'string') {
  2698. throw new TypeError('glob pattern string required')
  2699. }
  2700. if (!options) options = {}
  2701. pattern = pattern.trim()
  2702. // windows support: need to use /, not \
  2703. if (path.sep !== '/') {
  2704. pattern = pattern.split(path.sep).join('/')
  2705. }
  2706. this.options = options
  2707. this.set = []
  2708. this.pattern = pattern
  2709. this.regexp = null
  2710. this.negate = false
  2711. this.comment = false
  2712. this.empty = false
  2713. // make the set of regexps etc.
  2714. this.make()
  2715. }
  2716. Minimatch.prototype.debug = function () {}
  2717. Minimatch.prototype.make = make
  2718. function make () {
  2719. // don't do it more than once.
  2720. if (this._made) return
  2721. var pattern = this.pattern
  2722. var options = this.options
  2723. // empty patterns and comments match nothing.
  2724. if (!options.nocomment && pattern.charAt(0) === '#') {
  2725. this.comment = true
  2726. return
  2727. }
  2728. if (!pattern) {
  2729. this.empty = true
  2730. return
  2731. }
  2732. // step 1: figure out negation, etc.
  2733. this.parseNegate()
  2734. // step 2: expand braces
  2735. var set = this.globSet = this.braceExpand()
  2736. if (options.debug) this.debug = console.error
  2737. this.debug(this.pattern, set)
  2738. // step 3: now we have a set, so turn each one into a series of path-portion
  2739. // matching patterns.
  2740. // These will be regexps, except in the case of "**", which is
  2741. // set to the GLOBSTAR object for globstar behavior,
  2742. // and will not contain any / characters
  2743. set = this.globParts = set.map(function (s) {
  2744. return s.split(slashSplit)
  2745. })
  2746. this.debug(this.pattern, set)
  2747. // glob --> regexps
  2748. set = set.map(function (s, si, set) {
  2749. return s.map(this.parse, this)
  2750. }, this)
  2751. this.debug(this.pattern, set)
  2752. // filter out everything that didn't compile properly.
  2753. set = set.filter(function (s) {
  2754. return s.indexOf(false) === -1
  2755. })
  2756. this.debug(this.pattern, set)
  2757. this.set = set
  2758. }
  2759. Minimatch.prototype.parseNegate = parseNegate
  2760. function parseNegate () {
  2761. var pattern = this.pattern
  2762. var negate = false
  2763. var options = this.options
  2764. var negateOffset = 0
  2765. if (options.nonegate) return
  2766. for (var i = 0, l = pattern.length
  2767. ; i < l && pattern.charAt(i) === '!'
  2768. ; i++) {
  2769. negate = !negate
  2770. negateOffset++
  2771. }
  2772. if (negateOffset) this.pattern = pattern.substr(negateOffset)
  2773. this.negate = negate
  2774. }
  2775. // Brace expansion:
  2776. // a{b,c}d -> abd acd
  2777. // a{b,}c -> abc ac
  2778. // a{0..3}d -> a0d a1d a2d a3d
  2779. // a{b,c{d,e}f}g -> abg acdfg acefg
  2780. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  2781. //
  2782. // Invalid sets are not expanded.
  2783. // a{2..}b -> a{2..}b
  2784. // a{b}c -> a{b}c
  2785. minimatch.braceExpand = function (pattern, options) {
  2786. return braceExpand(pattern, options)
  2787. }
  2788. Minimatch.prototype.braceExpand = braceExpand
  2789. function braceExpand (pattern, options) {
  2790. if (!options) {
  2791. if (this instanceof Minimatch) {
  2792. options = this.options
  2793. } else {
  2794. options = {}
  2795. }
  2796. }
  2797. pattern = typeof pattern === 'undefined'
  2798. ? this.pattern : pattern
  2799. if (typeof pattern === 'undefined') {
  2800. throw new TypeError('undefined pattern')
  2801. }
  2802. if (options.nobrace ||
  2803. !pattern.match(/\{.*\}/)) {
  2804. // shortcut. no need to expand.
  2805. return [pattern]
  2806. }
  2807. return expand(pattern)
  2808. }
  2809. // parse a component of the expanded set.
  2810. // At this point, no pattern may contain "/" in it
  2811. // so we're going to return a 2d array, where each entry is the full
  2812. // pattern, split on '/', and then turned into a regular expression.
  2813. // A regexp is made at the end which joins each array with an
  2814. // escaped /, and another full one which joins each regexp with |.
  2815. //
  2816. // Following the lead of Bash 4.1, note that "**" only has special meaning
  2817. // when it is the *only* thing in a path portion. Otherwise, any series
  2818. // of * is equivalent to a single *. Globstar behavior is enabled by
  2819. // default, and can be disabled by setting options.noglobstar.
  2820. Minimatch.prototype.parse = parse
  2821. var SUBPARSE = {}
  2822. function parse (pattern, isSub) {
  2823. if (pattern.length > 1024 * 64) {
  2824. throw new TypeError('pattern is too long')
  2825. }
  2826. var options = this.options
  2827. // shortcuts
  2828. if (!options.noglobstar && pattern === '**') return GLOBSTAR
  2829. if (pattern === '') return ''
  2830. var re = ''
  2831. var hasMagic = !!options.nocase
  2832. var escaping = false
  2833. // ? => one single character
  2834. var patternListStack = []
  2835. var negativeLists = []
  2836. var stateChar
  2837. var inClass = false
  2838. var reClassStart = -1
  2839. var classStart = -1
  2840. // . and .. never match anything that doesn't start with .,
  2841. // even when options.dot is set.
  2842. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  2843. // not (start or / followed by . or .. followed by / or end)
  2844. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
  2845. : '(?!\\.)'
  2846. var self = this
  2847. function clearStateChar () {
  2848. if (stateChar) {
  2849. // we had some state-tracking character
  2850. // that wasn't consumed by this pass.
  2851. switch (stateChar) {
  2852. case '*':
  2853. re += star
  2854. hasMagic = true
  2855. break
  2856. case '?':
  2857. re += qmark
  2858. hasMagic = true
  2859. break
  2860. default:
  2861. re += '\\' + stateChar
  2862. break
  2863. }
  2864. self.debug('clearStateChar %j %j', stateChar, re)
  2865. stateChar = false
  2866. }
  2867. }
  2868. for (var i = 0, len = pattern.length, c
  2869. ; (i < len) && (c = pattern.charAt(i))
  2870. ; i++) {
  2871. this.debug('%s\t%s %s %j', pattern, i, re, c)
  2872. // skip over any that are escaped.
  2873. if (escaping && reSpecials[c]) {
  2874. re += '\\' + c
  2875. escaping = false
  2876. continue
  2877. }
  2878. switch (c) {
  2879. case '/':
  2880. // completely not allowed, even escaped.
  2881. // Should already be path-split by now.
  2882. return false
  2883. case '\\':
  2884. clearStateChar()
  2885. escaping = true
  2886. continue
  2887. // the various stateChar values
  2888. // for the "extglob" stuff.
  2889. case '?':
  2890. case '*':
  2891. case '+':
  2892. case '@':
  2893. case '!':
  2894. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c)
  2895. // all of those are literals inside a class, except that
  2896. // the glob [!a] means [^a] in regexp
  2897. if (inClass) {
  2898. this.debug(' in class')
  2899. if (c === '!' && i === classStart + 1) c = '^'
  2900. re += c
  2901. continue
  2902. }
  2903. // if we already have a stateChar, then it means
  2904. // that there was something like ** or +? in there.
  2905. // Handle the stateChar, then proceed with this one.
  2906. self.debug('call clearStateChar %j', stateChar)
  2907. clearStateChar()
  2908. stateChar = c
  2909. // if extglob is disabled, then +(asdf|foo) isn't a thing.
  2910. // just clear the statechar *now*, rather than even diving into
  2911. // the patternList stuff.
  2912. if (options.noext) clearStateChar()
  2913. continue
  2914. case '(':
  2915. if (inClass) {
  2916. re += '('
  2917. continue
  2918. }
  2919. if (!stateChar) {
  2920. re += '\\('
  2921. continue
  2922. }
  2923. patternListStack.push({
  2924. type: stateChar,
  2925. start: i - 1,
  2926. reStart: re.length,
  2927. open: plTypes[stateChar].open,
  2928. close: plTypes[stateChar].close
  2929. })
  2930. // negation is (?:(?!js)[^/]*)
  2931. re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
  2932. this.debug('plType %j %j', stateChar, re)
  2933. stateChar = false
  2934. continue
  2935. case ')':
  2936. if (inClass || !patternListStack.length) {
  2937. re += '\\)'
  2938. continue
  2939. }
  2940. clearStateChar()
  2941. hasMagic = true
  2942. var pl = patternListStack.pop()
  2943. // negation is (?:(?!js)[^/]*)
  2944. // The others are (?:<pattern>)<type>
  2945. re += pl.close
  2946. if (pl.type === '!') {
  2947. negativeLists.push(pl)
  2948. }
  2949. pl.reEnd = re.length
  2950. continue
  2951. case '|':
  2952. if (inClass || !patternListStack.length || escaping) {
  2953. re += '\\|'
  2954. escaping = false
  2955. continue
  2956. }
  2957. clearStateChar()
  2958. re += '|'
  2959. continue
  2960. // these are mostly the same in regexp and glob
  2961. case '[':
  2962. // swallow any state-tracking char before the [
  2963. clearStateChar()
  2964. if (inClass) {
  2965. re += '\\' + c
  2966. continue
  2967. }
  2968. inClass = true
  2969. classStart = i
  2970. reClassStart = re.length
  2971. re += c
  2972. continue
  2973. case ']':
  2974. // a right bracket shall lose its special
  2975. // meaning and represent itself in
  2976. // a bracket expression if it occurs
  2977. // first in the list. -- POSIX.2 2.8.3.2
  2978. if (i === classStart + 1 || !inClass) {
  2979. re += '\\' + c
  2980. escaping = false
  2981. continue
  2982. }
  2983. // handle the case where we left a class open.
  2984. // "[z-a]" is valid, equivalent to "\[z-a\]"
  2985. if (inClass) {
  2986. // split where the last [ was, make sure we don't have
  2987. // an invalid re. if so, re-walk the contents of the
  2988. // would-be class to re-translate any characters that
  2989. // were passed through as-is
  2990. // TODO: It would probably be faster to determine this
  2991. // without a try/catch and a new RegExp, but it's tricky
  2992. // to do safely. For now, this is safe and works.
  2993. var cs = pattern.substring(classStart + 1, i)
  2994. try {
  2995. RegExp('[' + cs + ']')
  2996. } catch (er) {
  2997. // not a valid class!
  2998. var sp = this.parse(cs, SUBPARSE)
  2999. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
  3000. hasMagic = hasMagic || sp[1]
  3001. inClass = false
  3002. continue
  3003. }
  3004. }
  3005. // finish up the class.
  3006. hasMagic = true
  3007. inClass = false
  3008. re += c
  3009. continue
  3010. default:
  3011. // swallow any state char that wasn't consumed
  3012. clearStateChar()
  3013. if (escaping) {
  3014. // no need
  3015. escaping = false
  3016. } else if (reSpecials[c]
  3017. && !(c === '^' && inClass)) {
  3018. re += '\\'
  3019. }
  3020. re += c
  3021. } // switch
  3022. } // for
  3023. // handle the case where we left a class open.
  3024. // "[abc" is valid, equivalent to "\[abc"
  3025. if (inClass) {
  3026. // split where the last [ was, and escape it
  3027. // this is a huge pita. We now have to re-walk
  3028. // the contents of the would-be class to re-translate
  3029. // any characters that were passed through as-is
  3030. cs = pattern.substr(classStart + 1)
  3031. sp = this.parse(cs, SUBPARSE)
  3032. re = re.substr(0, reClassStart) + '\\[' + sp[0]
  3033. hasMagic = hasMagic || sp[1]
  3034. }
  3035. // handle the case where we had a +( thing at the *end*
  3036. // of the pattern.
  3037. // each pattern list stack adds 3 chars, and we need to go through
  3038. // and escape any | chars that were passed through as-is for the regexp.
  3039. // Go through and escape them, taking care not to double-escape any
  3040. // | chars that were already escaped.
  3041. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  3042. var tail = re.slice(pl.reStart + pl.open.length)
  3043. this.debug('setting tail', re, pl)
  3044. // maybe some even number of \, then maybe 1 \, followed by a |
  3045. tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
  3046. if (!$2) {
  3047. // the | isn't already escaped, so escape it.
  3048. $2 = '\\'
  3049. }
  3050. // need to escape all those slashes *again*, without escaping the
  3051. // one that we need for escaping the | character. As it works out,
  3052. // escaping an even number of slashes can be done by simply repeating
  3053. // it exactly after itself. That's why this trick works.
  3054. //
  3055. // I am sorry that you have to see this.
  3056. return $1 + $1 + $2 + '|'
  3057. })
  3058. this.debug('tail=%j\n %s', tail, tail, pl, re)
  3059. var t = pl.type === '*' ? star
  3060. : pl.type === '?' ? qmark
  3061. : '\\' + pl.type
  3062. hasMagic = true
  3063. re = re.slice(0, pl.reStart) + t + '\\(' + tail
  3064. }
  3065. // handle trailing things that only matter at the very end.
  3066. clearStateChar()
  3067. if (escaping) {
  3068. // trailing \\
  3069. re += '\\\\'
  3070. }
  3071. // only need to apply the nodot start if the re starts with
  3072. // something that could conceivably capture a dot
  3073. var addPatternStart = false
  3074. switch (re.charAt(0)) {
  3075. case '.':
  3076. case '[':
  3077. case '(': addPatternStart = true
  3078. }
  3079. // Hack to work around lack of negative lookbehind in JS
  3080. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  3081. // like 'a.xyz.yz' doesn't match. So, the first negative
  3082. // lookahead, has to look ALL the way ahead, to the end of
  3083. // the pattern.
  3084. for (var n = negativeLists.length - 1; n > -1; n--) {
  3085. var nl = negativeLists[n]
  3086. var nlBefore = re.slice(0, nl.reStart)
  3087. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8)
  3088. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd)
  3089. var nlAfter = re.slice(nl.reEnd)
  3090. nlLast += nlAfter
  3091. // Handle nested stuff like *(*.js|!(*.json)), where open parens
  3092. // mean that we should *not* include the ) in the bit that is considered
  3093. // "after" the negated section.
  3094. var openParensBefore = nlBefore.split('(').length - 1
  3095. var cleanAfter = nlAfter
  3096. for (i = 0; i < openParensBefore; i++) {
  3097. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '')
  3098. }
  3099. nlAfter = cleanAfter
  3100. var dollar = ''
  3101. if (nlAfter === '' && isSub !== SUBPARSE) {
  3102. dollar = '$'
  3103. }
  3104. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast
  3105. re = newRe
  3106. }
  3107. // if the re is not "" at this point, then we need to make sure
  3108. // it doesn't match against an empty path part.
  3109. // Otherwise a/* will match a/, which it should not.
  3110. if (re !== '' && hasMagic) {
  3111. re = '(?=.)' + re
  3112. }
  3113. if (addPatternStart) {
  3114. re = patternStart + re
  3115. }
  3116. // parsing just a piece of a larger pattern.
  3117. if (isSub === SUBPARSE) {
  3118. return [re, hasMagic]
  3119. }
  3120. // skip the regexp for non-magical patterns
  3121. // unescape anything in it, though, so that it'll be
  3122. // an exact match against a file etc.
  3123. if (!hasMagic) {
  3124. return globUnescape(pattern)
  3125. }
  3126. var flags = options.nocase ? 'i' : ''
  3127. try {
  3128. var regExp = new RegExp('^' + re + '$', flags)
  3129. } catch (er) {
  3130. // If it was an invalid regular expression, then it can't match
  3131. // anything. This trick looks for a character after the end of
  3132. // the string, which is of course impossible, except in multi-line
  3133. // mode, but it's not a /m regex.
  3134. return new RegExp('$.')
  3135. }
  3136. regExp._glob = pattern
  3137. regExp._src = re
  3138. return regExp
  3139. }
  3140. minimatch.makeRe = function (pattern, options) {
  3141. return new Minimatch(pattern, options || {}).makeRe()
  3142. }
  3143. Minimatch.prototype.makeRe = makeRe
  3144. function makeRe () {
  3145. if (this.regexp || this.regexp === false) return this.regexp
  3146. // at this point, this.set is a 2d array of partial
  3147. // pattern strings, or "**".
  3148. //
  3149. // It's better to use .match(). This function shouldn't
  3150. // be used, really, but it's pretty convenient sometimes,
  3151. // when you just want to work with a regex.
  3152. var set = this.set
  3153. if (!set.length) {
  3154. this.regexp = false
  3155. return this.regexp
  3156. }
  3157. var options = this.options
  3158. var twoStar = options.noglobstar ? star
  3159. : options.dot ? twoStarDot
  3160. : twoStarNoDot
  3161. var flags = options.nocase ? 'i' : ''
  3162. var re = set.map(function (pattern) {
  3163. return pattern.map(function (p) {
  3164. return (p === GLOBSTAR) ? twoStar
  3165. : (typeof p === 'string') ? regExpEscape(p)
  3166. : p._src
  3167. }).join('\\\/')
  3168. }).join('|')
  3169. // must match entire pattern
  3170. // ending in a * or ** will make it less strict.
  3171. re = '^(?:' + re + ')$'
  3172. // can match anything, as long as it's not this.
  3173. if (this.negate) re = '^(?!' + re + ').*$'
  3174. try {
  3175. this.regexp = new RegExp(re, flags)
  3176. } catch (ex) {
  3177. this.regexp = false
  3178. }
  3179. return this.regexp
  3180. }
  3181. minimatch.match = function (list, pattern, options) {
  3182. options = options || {}
  3183. var mm = new Minimatch(pattern, options)
  3184. list = list.filter(function (f) {
  3185. return mm.match(f)
  3186. })
  3187. if (mm.options.nonull && !list.length) {
  3188. list.push(pattern)
  3189. }
  3190. return list
  3191. }
  3192. Minimatch.prototype.match = match
  3193. function match (f, partial) {
  3194. this.debug('match', f, this.pattern)
  3195. // short-circuit in the case of busted things.
  3196. // comments, etc.
  3197. if (this.comment) return false
  3198. if (this.empty) return f === ''
  3199. if (f === '/' && partial) return true
  3200. var options = this.options
  3201. // windows: need to use /, not \
  3202. if (path.sep !== '/') {
  3203. f = f.split(path.sep).join('/')
  3204. }
  3205. // treat the test path as a set of pathparts.
  3206. f = f.split(slashSplit)
  3207. this.debug(this.pattern, 'split', f)
  3208. // just ONE of the pattern sets in this.set needs to match
  3209. // in order for it to be valid. If negating, then just one
  3210. // match means that we have failed.
  3211. // Either way, return on the first hit.
  3212. var set = this.set
  3213. this.debug(this.pattern, 'set', set)
  3214. // Find the basename of the path by looking for the last non-empty segment
  3215. var filename
  3216. var i
  3217. for (i = f.length - 1; i >= 0; i--) {
  3218. filename = f[i]
  3219. if (filename) break
  3220. }
  3221. for (i = 0; i < set.length; i++) {
  3222. var pattern = set[i]
  3223. var file = f
  3224. if (options.matchBase && pattern.length === 1) {
  3225. file = [filename]
  3226. }
  3227. var hit = this.matchOne(file, pattern, partial)
  3228. if (hit) {
  3229. if (options.flipNegate) return true
  3230. return !this.negate
  3231. }
  3232. }
  3233. // didn't get any hits. this is success if it's a negative
  3234. // pattern, failure otherwise.
  3235. if (options.flipNegate) return false
  3236. return this.negate
  3237. }
  3238. // set partial to true to test if, for example,
  3239. // "/a/b" matches the start of "/*/b/*/d"
  3240. // Partial means, if you run out of file before you run
  3241. // out of pattern, then that's fine, as long as all
  3242. // the parts match.
  3243. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  3244. var options = this.options
  3245. this.debug('matchOne',
  3246. { 'this': this, file: file, pattern: pattern })
  3247. this.debug('matchOne', file.length, pattern.length)
  3248. for (var fi = 0,
  3249. pi = 0,
  3250. fl = file.length,
  3251. pl = pattern.length
  3252. ; (fi < fl) && (pi < pl)
  3253. ; fi++, pi++) {
  3254. this.debug('matchOne loop')
  3255. var p = pattern[pi]
  3256. var f = file[fi]
  3257. this.debug(pattern, p, f)
  3258. // should be impossible.
  3259. // some invalid regexp stuff in the set.
  3260. if (p === false) return false
  3261. if (p === GLOBSTAR) {
  3262. this.debug('GLOBSTAR', [pattern, p, f])
  3263. // "**"
  3264. // a/**/b/**/c would match the following:
  3265. // a/b/x/y/z/c
  3266. // a/x/y/z/b/c
  3267. // a/b/x/b/x/c
  3268. // a/b/c
  3269. // To do this, take the rest of the pattern after
  3270. // the **, and see if it would match the file remainder.
  3271. // If so, return success.
  3272. // If not, the ** "swallows" a segment, and try again.
  3273. // This is recursively awful.
  3274. //
  3275. // a/**/b/**/c matching a/b/x/y/z/c
  3276. // - a matches a
  3277. // - doublestar
  3278. // - matchOne(b/x/y/z/c, b/**/c)
  3279. // - b matches b
  3280. // - doublestar
  3281. // - matchOne(x/y/z/c, c) -> no
  3282. // - matchOne(y/z/c, c) -> no
  3283. // - matchOne(z/c, c) -> no
  3284. // - matchOne(c, c) yes, hit
  3285. var fr = fi
  3286. var pr = pi + 1
  3287. if (pr === pl) {
  3288. this.debug('** at the end')
  3289. // a ** at the end will just swallow the rest.
  3290. // We have found a match.
  3291. // however, it will not swallow /.x, unless
  3292. // options.dot is set.
  3293. // . and .. are *never* matched by **, for explosively
  3294. // exponential reasons.
  3295. for (; fi < fl; fi++) {
  3296. if (file[fi] === '.' || file[fi] === '..' ||
  3297. (!options.dot && file[fi].charAt(0) === '.')) return false
  3298. }
  3299. return true
  3300. }
  3301. // ok, let's see if we can swallow whatever we can.
  3302. while (fr < fl) {
  3303. var swallowee = file[fr]
  3304. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee)
  3305. // XXX remove this slice. Just pass the start index.
  3306. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  3307. this.debug('globstar found match!', fr, fl, swallowee)
  3308. // found a match.
  3309. return true
  3310. } else {
  3311. // can't swallow "." or ".." ever.
  3312. // can only swallow ".foo" when explicitly asked.
  3313. if (swallowee === '.' || swallowee === '..' ||
  3314. (!options.dot && swallowee.charAt(0) === '.')) {
  3315. this.debug('dot detected!', file, fr, pattern, pr)
  3316. break
  3317. }
  3318. // ** swallows a segment, and continue.
  3319. this.debug('globstar swallow a segment, and continue')
  3320. fr++
  3321. }
  3322. }
  3323. // no match was found.
  3324. // However, in partial mode, we can't say this is necessarily over.
  3325. // If there's more *pattern* left, then
  3326. if (partial) {
  3327. // ran out of file
  3328. this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
  3329. if (fr === fl) return true
  3330. }
  3331. return false
  3332. }
  3333. // something other than **
  3334. // non-magic patterns just have to match exactly
  3335. // patterns with magic have been turned into regexps.
  3336. var hit
  3337. if (typeof p === 'string') {
  3338. if (options.nocase) {
  3339. hit = f.toLowerCase() === p.toLowerCase()
  3340. } else {
  3341. hit = f === p
  3342. }
  3343. this.debug('string match', p, f, hit)
  3344. } else {
  3345. hit = f.match(p)
  3346. this.debug('pattern match', p, f, hit)
  3347. }
  3348. if (!hit) return false
  3349. }
  3350. // Note: ending in / means that we'll get a final ""
  3351. // at the end of the pattern. This can only match a
  3352. // corresponding "" at the end of the file.
  3353. // If the file ends in /, then it can only match a
  3354. // a pattern that ends in /, unless the pattern just
  3355. // doesn't have any more for it. But, a/b/ should *not*
  3356. // match "a/b/*", even though "" matches against the
  3357. // [^/]*? pattern, except in partial mode, where it might
  3358. // simply not be reached yet.
  3359. // However, a/b/ should still satisfy a/*
  3360. // now either we fell off the end of the pattern, or we're done.
  3361. if (fi === fl && pi === pl) {
  3362. // ran out of pattern and filename at the same time.
  3363. // an exact hit!
  3364. return true
  3365. } else if (fi === fl) {
  3366. // ran out of file, but still had pattern left.
  3367. // this is ok if we're doing the match as part of
  3368. // a glob fs traversal.
  3369. return partial
  3370. } else if (pi === pl) {
  3371. // ran out of pattern, still have file left.
  3372. // this is only acceptable if we're on the very last
  3373. // empty segment of a file with a trailing slash.
  3374. // a/* should match a/b/
  3375. var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
  3376. return emptyFileEnd
  3377. }
  3378. // should be unreachable.
  3379. throw new Error('wtf?')
  3380. }
  3381. // replace stuff like \* with *
  3382. function globUnescape (s) {
  3383. return s.replace(/\\(.)/g, '$1')
  3384. }
  3385. function regExpEscape (s) {
  3386. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
  3387. }
  3388. },{"brace-expansion":11,"path":22}],21:[function(require,module,exports){
  3389. var wrappy = require('wrappy')
  3390. module.exports = wrappy(once)
  3391. module.exports.strict = wrappy(onceStrict)
  3392. once.proto = once(function () {
  3393. Object.defineProperty(Function.prototype, 'once', {
  3394. value: function () {
  3395. return once(this)
  3396. },
  3397. configurable: true
  3398. })
  3399. Object.defineProperty(Function.prototype, 'onceStrict', {
  3400. value: function () {
  3401. return onceStrict(this)
  3402. },
  3403. configurable: true
  3404. })
  3405. })
  3406. function once (fn) {
  3407. var f = function () {
  3408. if (f.called) return f.value
  3409. f.called = true
  3410. return f.value = fn.apply(this, arguments)
  3411. }
  3412. f.called = false
  3413. return f
  3414. }
  3415. function onceStrict (fn) {
  3416. var f = function () {
  3417. if (f.called)
  3418. throw new Error(f.onceError)
  3419. f.called = true
  3420. return f.value = fn.apply(this, arguments)
  3421. }
  3422. var name = fn.name || 'Function wrapped with `once`'
  3423. f.onceError = name + " shouldn't be called more than once"
  3424. f.called = false
  3425. return f
  3426. }
  3427. },{"wrappy":29}],22:[function(require,module,exports){
  3428. (function (process){
  3429. // Copyright Joyent, Inc. and other Node contributors.
  3430. //
  3431. // Permission is hereby granted, free of charge, to any person obtaining a
  3432. // copy of this software and associated documentation files (the
  3433. // "Software"), to deal in the Software without restriction, including
  3434. // without limitation the rights to use, copy, modify, merge, publish,
  3435. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3436. // persons to whom the Software is furnished to do so, subject to the
  3437. // following conditions:
  3438. //
  3439. // The above copyright notice and this permission notice shall be included
  3440. // in all copies or substantial portions of the Software.
  3441. //
  3442. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3443. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3444. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3445. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3446. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3447. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3448. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3449. // resolves . and .. elements in a path array with directory names there
  3450. // must be no slashes, empty elements, or device names (c:\) in the array
  3451. // (so also no leading and trailing slashes - it does not distinguish
  3452. // relative and absolute paths)
  3453. function normalizeArray(parts, allowAboveRoot) {
  3454. // if the path tries to go above the root, `up` ends up > 0
  3455. var up = 0;
  3456. for (var i = parts.length - 1; i >= 0; i--) {
  3457. var last = parts[i];
  3458. if (last === '.') {
  3459. parts.splice(i, 1);
  3460. } else if (last === '..') {
  3461. parts.splice(i, 1);
  3462. up++;
  3463. } else if (up) {
  3464. parts.splice(i, 1);
  3465. up--;
  3466. }
  3467. }
  3468. // if the path is allowed to go above the root, restore leading ..s
  3469. if (allowAboveRoot) {
  3470. for (; up--; up) {
  3471. parts.unshift('..');
  3472. }
  3473. }
  3474. return parts;
  3475. }
  3476. // Split a filename into [root, dir, basename, ext], unix version
  3477. // 'root' is just a slash, or nothing.
  3478. var splitPathRe =
  3479. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  3480. var splitPath = function(filename) {
  3481. return splitPathRe.exec(filename).slice(1);
  3482. };
  3483. // path.resolve([from ...], to)
  3484. // posix version
  3485. exports.resolve = function() {
  3486. var resolvedPath = '',
  3487. resolvedAbsolute = false;
  3488. for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  3489. var path = (i >= 0) ? arguments[i] : process.cwd();
  3490. // Skip empty and invalid entries
  3491. if (typeof path !== 'string') {
  3492. throw new TypeError('Arguments to path.resolve must be strings');
  3493. } else if (!path) {
  3494. continue;
  3495. }
  3496. resolvedPath = path + '/' + resolvedPath;
  3497. resolvedAbsolute = path.charAt(0) === '/';
  3498. }
  3499. // At this point the path should be resolved to a full absolute path, but
  3500. // handle relative paths to be safe (might happen when process.cwd() fails)
  3501. // Normalize the path
  3502. resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
  3503. return !!p;
  3504. }), !resolvedAbsolute).join('/');
  3505. return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
  3506. };
  3507. // path.normalize(path)
  3508. // posix version
  3509. exports.normalize = function(path) {
  3510. var isAbsolute = exports.isAbsolute(path),
  3511. trailingSlash = substr(path, -1) === '/';
  3512. // Normalize the path
  3513. path = normalizeArray(filter(path.split('/'), function(p) {
  3514. return !!p;
  3515. }), !isAbsolute).join('/');
  3516. if (!path && !isAbsolute) {
  3517. path = '.';
  3518. }
  3519. if (path && trailingSlash) {
  3520. path += '/';
  3521. }
  3522. return (isAbsolute ? '/' : '') + path;
  3523. };
  3524. // posix version
  3525. exports.isAbsolute = function(path) {
  3526. return path.charAt(0) === '/';
  3527. };
  3528. // posix version
  3529. exports.join = function() {
  3530. var paths = Array.prototype.slice.call(arguments, 0);
  3531. return exports.normalize(filter(paths, function(p, index) {
  3532. if (typeof p !== 'string') {
  3533. throw new TypeError('Arguments to path.join must be strings');
  3534. }
  3535. return p;
  3536. }).join('/'));
  3537. };
  3538. // path.relative(from, to)
  3539. // posix version
  3540. exports.relative = function(from, to) {
  3541. from = exports.resolve(from).substr(1);
  3542. to = exports.resolve(to).substr(1);
  3543. function trim(arr) {
  3544. var start = 0;
  3545. for (; start < arr.length; start++) {
  3546. if (arr[start] !== '') break;
  3547. }
  3548. var end = arr.length - 1;
  3549. for (; end >= 0; end--) {
  3550. if (arr[end] !== '') break;
  3551. }
  3552. if (start > end) return [];
  3553. return arr.slice(start, end - start + 1);
  3554. }
  3555. var fromParts = trim(from.split('/'));
  3556. var toParts = trim(to.split('/'));
  3557. var length = Math.min(fromParts.length, toParts.length);
  3558. var samePartsLength = length;
  3559. for (var i = 0; i < length; i++) {
  3560. if (fromParts[i] !== toParts[i]) {
  3561. samePartsLength = i;
  3562. break;
  3563. }
  3564. }
  3565. var outputParts = [];
  3566. for (var i = samePartsLength; i < fromParts.length; i++) {
  3567. outputParts.push('..');
  3568. }
  3569. outputParts = outputParts.concat(toParts.slice(samePartsLength));
  3570. return outputParts.join('/');
  3571. };
  3572. exports.sep = '/';
  3573. exports.delimiter = ':';
  3574. exports.dirname = function(path) {
  3575. var result = splitPath(path),
  3576. root = result[0],
  3577. dir = result[1];
  3578. if (!root && !dir) {
  3579. // No dirname whatsoever
  3580. return '.';
  3581. }
  3582. if (dir) {
  3583. // It has a dirname, strip trailing slash
  3584. dir = dir.substr(0, dir.length - 1);
  3585. }
  3586. return root + dir;
  3587. };
  3588. exports.basename = function(path, ext) {
  3589. var f = splitPath(path)[2];
  3590. // TODO: make this comparison case-insensitive on windows?
  3591. if (ext && f.substr(-1 * ext.length) === ext) {
  3592. f = f.substr(0, f.length - ext.length);
  3593. }
  3594. return f;
  3595. };
  3596. exports.extname = function(path) {
  3597. return splitPath(path)[3];
  3598. };
  3599. function filter (xs, f) {
  3600. if (xs.filter) return xs.filter(f);
  3601. var res = [];
  3602. for (var i = 0; i < xs.length; i++) {
  3603. if (f(xs[i], i, xs)) res.push(xs[i]);
  3604. }
  3605. return res;
  3606. }
  3607. // String.prototype.substr - negative index don't work in IE8
  3608. var substr = 'ab'.substr(-1) === 'b'
  3609. ? function (str, start, len) { return str.substr(start, len) }
  3610. : function (str, start, len) {
  3611. if (start < 0) start = str.length + start;
  3612. return str.substr(start, len);
  3613. }
  3614. ;
  3615. }).call(this,require('_process'))
  3616. },{"_process":24}],23:[function(require,module,exports){
  3617. (function (process){
  3618. 'use strict';
  3619. function posix(path) {
  3620. return path.charAt(0) === '/';
  3621. }
  3622. function win32(path) {
  3623. // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
  3624. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  3625. var result = splitDeviceRe.exec(path);
  3626. var device = result[1] || '';
  3627. var isUnc = Boolean(device && device.charAt(1) !== ':');
  3628. // UNC paths are always absolute
  3629. return Boolean(result[2] || isUnc);
  3630. }
  3631. module.exports = process.platform === 'win32' ? win32 : posix;
  3632. module.exports.posix = posix;
  3633. module.exports.win32 = win32;
  3634. }).call(this,require('_process'))
  3635. },{"_process":24}],24:[function(require,module,exports){
  3636. // shim for using process in browser
  3637. var process = module.exports = {};
  3638. // cached from whatever global is present so that test runners that stub it
  3639. // don't break things. But we need to wrap it in a try catch in case it is
  3640. // wrapped in strict mode code which doesn't define any globals. It's inside a
  3641. // function because try/catches deoptimize in certain engines.
  3642. var cachedSetTimeout;
  3643. var cachedClearTimeout;
  3644. function defaultSetTimout() {
  3645. throw new Error('setTimeout has not been defined');
  3646. }
  3647. function defaultClearTimeout () {
  3648. throw new Error('clearTimeout has not been defined');
  3649. }
  3650. (function () {
  3651. try {
  3652. if (typeof setTimeout === 'function') {
  3653. cachedSetTimeout = setTimeout;
  3654. } else {
  3655. cachedSetTimeout = defaultSetTimout;
  3656. }
  3657. } catch (e) {
  3658. cachedSetTimeout = defaultSetTimout;
  3659. }
  3660. try {
  3661. if (typeof clearTimeout === 'function') {
  3662. cachedClearTimeout = clearTimeout;
  3663. } else {
  3664. cachedClearTimeout = defaultClearTimeout;
  3665. }
  3666. } catch (e) {
  3667. cachedClearTimeout = defaultClearTimeout;
  3668. }
  3669. } ())
  3670. function runTimeout(fun) {
  3671. if (cachedSetTimeout === setTimeout) {
  3672. //normal enviroments in sane situations
  3673. return setTimeout(fun, 0);
  3674. }
  3675. // if setTimeout wasn't available but was latter defined
  3676. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  3677. cachedSetTimeout = setTimeout;
  3678. return setTimeout(fun, 0);
  3679. }
  3680. try {
  3681. // when when somebody has screwed with setTimeout but no I.E. maddness
  3682. return cachedSetTimeout(fun, 0);
  3683. } catch(e){
  3684. try {
  3685. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  3686. return cachedSetTimeout.call(null, fun, 0);
  3687. } catch(e){
  3688. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  3689. return cachedSetTimeout.call(this, fun, 0);
  3690. }
  3691. }
  3692. }
  3693. function runClearTimeout(marker) {
  3694. if (cachedClearTimeout === clearTimeout) {
  3695. //normal enviroments in sane situations
  3696. return clearTimeout(marker);
  3697. }
  3698. // if clearTimeout wasn't available but was latter defined
  3699. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  3700. cachedClearTimeout = clearTimeout;
  3701. return clearTimeout(marker);
  3702. }
  3703. try {
  3704. // when when somebody has screwed with setTimeout but no I.E. maddness
  3705. return cachedClearTimeout(marker);
  3706. } catch (e){
  3707. try {
  3708. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  3709. return cachedClearTimeout.call(null, marker);
  3710. } catch (e){
  3711. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  3712. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  3713. return cachedClearTimeout.call(this, marker);
  3714. }
  3715. }
  3716. }
  3717. var queue = [];
  3718. var draining = false;
  3719. var currentQueue;
  3720. var queueIndex = -1;
  3721. function cleanUpNextTick() {
  3722. if (!draining || !currentQueue) {
  3723. return;
  3724. }
  3725. draining = false;
  3726. if (currentQueue.length) {
  3727. queue = currentQueue.concat(queue);
  3728. } else {
  3729. queueIndex = -1;
  3730. }
  3731. if (queue.length) {
  3732. drainQueue();
  3733. }
  3734. }
  3735. function drainQueue() {
  3736. if (draining) {
  3737. return;
  3738. }
  3739. var timeout = runTimeout(cleanUpNextTick);
  3740. draining = true;
  3741. var len = queue.length;
  3742. while(len) {
  3743. currentQueue = queue;
  3744. queue = [];
  3745. while (++queueIndex < len) {
  3746. if (currentQueue) {
  3747. currentQueue[queueIndex].run();
  3748. }
  3749. }
  3750. queueIndex = -1;
  3751. len = queue.length;
  3752. }
  3753. currentQueue = null;
  3754. draining = false;
  3755. runClearTimeout(timeout);
  3756. }
  3757. process.nextTick = function (fun) {
  3758. var args = new Array(arguments.length - 1);
  3759. if (arguments.length > 1) {
  3760. for (var i = 1; i < arguments.length; i++) {
  3761. args[i - 1] = arguments[i];
  3762. }
  3763. }
  3764. queue.push(new Item(fun, args));
  3765. if (queue.length === 1 && !draining) {
  3766. runTimeout(drainQueue);
  3767. }
  3768. };
  3769. // v8 likes predictible objects
  3770. function Item(fun, array) {
  3771. this.fun = fun;
  3772. this.array = array;
  3773. }
  3774. Item.prototype.run = function () {
  3775. this.fun.apply(null, this.array);
  3776. };
  3777. process.title = 'browser';
  3778. process.browser = true;
  3779. process.env = {};
  3780. process.argv = [];
  3781. process.version = ''; // empty string to avoid regexp issues
  3782. process.versions = {};
  3783. function noop() {}
  3784. process.on = noop;
  3785. process.addListener = noop;
  3786. process.once = noop;
  3787. process.off = noop;
  3788. process.removeListener = noop;
  3789. process.removeAllListeners = noop;
  3790. process.emit = noop;
  3791. process.prependListener = noop;
  3792. process.prependOnceListener = noop;
  3793. process.listeners = function (name) { return [] }
  3794. process.binding = function (name) {
  3795. throw new Error('process.binding is not supported');
  3796. };
  3797. process.cwd = function () { return '/' };
  3798. process.chdir = function (dir) {
  3799. throw new Error('process.chdir is not supported');
  3800. };
  3801. process.umask = function() { return 0; };
  3802. },{}],25:[function(require,module,exports){
  3803. // Underscore.js 1.8.3
  3804. // http://underscorejs.org
  3805. // (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  3806. // Underscore may be freely distributed under the MIT license.
  3807. (function() {
  3808. // Baseline setup
  3809. // --------------
  3810. // Establish the root object, `window` in the browser, or `exports` on the server.
  3811. var root = this;
  3812. // Save the previous value of the `_` variable.
  3813. var previousUnderscore = root._;
  3814. // Save bytes in the minified (but not gzipped) version:
  3815. var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
  3816. // Create quick reference variables for speed access to core prototypes.
  3817. var
  3818. push = ArrayProto.push,
  3819. slice = ArrayProto.slice,
  3820. toString = ObjProto.toString,
  3821. hasOwnProperty = ObjProto.hasOwnProperty;
  3822. // All **ECMAScript 5** native function implementations that we hope to use
  3823. // are declared here.
  3824. var
  3825. nativeIsArray = Array.isArray,
  3826. nativeKeys = Object.keys,
  3827. nativeBind = FuncProto.bind,
  3828. nativeCreate = Object.create;
  3829. // Naked function reference for surrogate-prototype-swapping.
  3830. var Ctor = function(){};
  3831. // Create a safe reference to the Underscore object for use below.
  3832. var _ = function(obj) {
  3833. if (obj instanceof _) return obj;
  3834. if (!(this instanceof _)) return new _(obj);
  3835. this._wrapped = obj;
  3836. };
  3837. // Export the Underscore object for **Node.js**, with
  3838. // backwards-compatibility for the old `require()` API. If we're in
  3839. // the browser, add `_` as a global object.
  3840. if (typeof exports !== 'undefined') {
  3841. if (typeof module !== 'undefined' && module.exports) {
  3842. exports = module.exports = _;
  3843. }
  3844. exports._ = _;
  3845. } else {
  3846. root._ = _;
  3847. }
  3848. // Current version.
  3849. _.VERSION = '1.8.3';
  3850. // Internal function that returns an efficient (for current engines) version
  3851. // of the passed-in callback, to be repeatedly applied in other Underscore
  3852. // functions.
  3853. var optimizeCb = function(func, context, argCount) {
  3854. if (context === void 0) return func;
  3855. switch (argCount == null ? 3 : argCount) {
  3856. case 1: return function(value) {
  3857. return func.call(context, value);
  3858. };
  3859. case 2: return function(value, other) {
  3860. return func.call(context, value, other);
  3861. };
  3862. case 3: return function(value, index, collection) {
  3863. return func.call(context, value, index, collection);
  3864. };
  3865. case 4: return function(accumulator, value, index, collection) {
  3866. return func.call(context, accumulator, value, index, collection);
  3867. };
  3868. }
  3869. return function() {
  3870. return func.apply(context, arguments);
  3871. };
  3872. };
  3873. // A mostly-internal function to generate callbacks that can be applied
  3874. // to each element in a collection, returning the desired result — either
  3875. // identity, an arbitrary callback, a property matcher, or a property accessor.
  3876. var cb = function(value, context, argCount) {
  3877. if (value == null) return _.identity;
  3878. if (_.isFunction(value)) return optimizeCb(value, context, argCount);
  3879. if (_.isObject(value)) return _.matcher(value);
  3880. return _.property(value);
  3881. };
  3882. _.iteratee = function(value, context) {
  3883. return cb(value, context, Infinity);
  3884. };
  3885. // An internal function for creating assigner functions.
  3886. var createAssigner = function(keysFunc, undefinedOnly) {
  3887. return function(obj) {
  3888. var length = arguments.length;
  3889. if (length < 2 || obj == null) return obj;
  3890. for (var index = 1; index < length; index++) {
  3891. var source = arguments[index],
  3892. keys = keysFunc(source),
  3893. l = keys.length;
  3894. for (var i = 0; i < l; i++) {
  3895. var key = keys[i];
  3896. if (!undefinedOnly || obj[key] === void 0) obj[key] = source[key];
  3897. }
  3898. }
  3899. return obj;
  3900. };
  3901. };
  3902. // An internal function for creating a new object that inherits from another.
  3903. var baseCreate = function(prototype) {
  3904. if (!_.isObject(prototype)) return {};
  3905. if (nativeCreate) return nativeCreate(prototype);
  3906. Ctor.prototype = prototype;
  3907. var result = new Ctor;
  3908. Ctor.prototype = null;
  3909. return result;
  3910. };
  3911. var property = function(key) {
  3912. return function(obj) {
  3913. return obj == null ? void 0 : obj[key];
  3914. };
  3915. };
  3916. // Helper for collection methods to determine whether a collection
  3917. // should be iterated as an array or as an object
  3918. // Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
  3919. // Avoids a very nasty iOS 8 JIT bug on ARM-64. #2094
  3920. var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
  3921. var getLength = property('length');
  3922. var isArrayLike = function(collection) {
  3923. var length = getLength(collection);
  3924. return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX;
  3925. };
  3926. // Collection Functions
  3927. // --------------------
  3928. // The cornerstone, an `each` implementation, aka `forEach`.
  3929. // Handles raw objects in addition to array-likes. Treats all
  3930. // sparse array-likes as if they were dense.
  3931. _.each = _.forEach = function(obj, iteratee, context) {
  3932. iteratee = optimizeCb(iteratee, context);
  3933. var i, length;
  3934. if (isArrayLike(obj)) {
  3935. for (i = 0, length = obj.length; i < length; i++) {
  3936. iteratee(obj[i], i, obj);
  3937. }
  3938. } else {
  3939. var keys = _.keys(obj);
  3940. for (i = 0, length = keys.length; i < length; i++) {
  3941. iteratee(obj[keys[i]], keys[i], obj);
  3942. }
  3943. }
  3944. return obj;
  3945. };
  3946. // Return the results of applying the iteratee to each element.
  3947. _.map = _.collect = function(obj, iteratee, context) {
  3948. iteratee = cb(iteratee, context);
  3949. var keys = !isArrayLike(obj) && _.keys(obj),
  3950. length = (keys || obj).length,
  3951. results = Array(length);
  3952. for (var index = 0; index < length; index++) {
  3953. var currentKey = keys ? keys[index] : index;
  3954. results[index] = iteratee(obj[currentKey], currentKey, obj);
  3955. }
  3956. return results;
  3957. };
  3958. // Create a reducing function iterating left or right.
  3959. function createReduce(dir) {
  3960. // Optimized iterator function as using arguments.length
  3961. // in the main function will deoptimize the, see #1991.
  3962. function iterator(obj, iteratee, memo, keys, index, length) {
  3963. for (; index >= 0 && index < length; index += dir) {
  3964. var currentKey = keys ? keys[index] : index;
  3965. memo = iteratee(memo, obj[currentKey], currentKey, obj);
  3966. }
  3967. return memo;
  3968. }
  3969. return function(obj, iteratee, memo, context) {
  3970. iteratee = optimizeCb(iteratee, context, 4);
  3971. var keys = !isArrayLike(obj) && _.keys(obj),
  3972. length = (keys || obj).length,
  3973. index = dir > 0 ? 0 : length - 1;
  3974. // Determine the initial value if none is provided.
  3975. if (arguments.length < 3) {
  3976. memo = obj[keys ? keys[index] : index];
  3977. index += dir;
  3978. }
  3979. return iterator(obj, iteratee, memo, keys, index, length);
  3980. };
  3981. }
  3982. // **Reduce** builds up a single result from a list of values, aka `inject`,
  3983. // or `foldl`.
  3984. _.reduce = _.foldl = _.inject = createReduce(1);
  3985. // The right-associative version of reduce, also known as `foldr`.
  3986. _.reduceRight = _.foldr = createReduce(-1);
  3987. // Return the first value which passes a truth test. Aliased as `detect`.
  3988. _.find = _.detect = function(obj, predicate, context) {
  3989. var key;
  3990. if (isArrayLike(obj)) {
  3991. key = _.findIndex(obj, predicate, context);
  3992. } else {
  3993. key = _.findKey(obj, predicate, context);
  3994. }
  3995. if (key !== void 0 && key !== -1) return obj[key];
  3996. };
  3997. // Return all the elements that pass a truth test.
  3998. // Aliased as `select`.
  3999. _.filter = _.select = function(obj, predicate, context) {
  4000. var results = [];
  4001. predicate = cb(predicate, context);
  4002. _.each(obj, function(value, index, list) {
  4003. if (predicate(value, index, list)) results.push(value);
  4004. });
  4005. return results;
  4006. };
  4007. // Return all the elements for which a truth test fails.
  4008. _.reject = function(obj, predicate, context) {
  4009. return _.filter(obj, _.negate(cb(predicate)), context);
  4010. };
  4011. // Determine whether all of the elements match a truth test.
  4012. // Aliased as `all`.
  4013. _.every = _.all = function(obj, predicate, context) {
  4014. predicate = cb(predicate, context);
  4015. var keys = !isArrayLike(obj) && _.keys(obj),
  4016. length = (keys || obj).length;
  4017. for (var index = 0; index < length; index++) {
  4018. var currentKey = keys ? keys[index] : index;
  4019. if (!predicate(obj[currentKey], currentKey, obj)) return false;
  4020. }
  4021. return true;
  4022. };
  4023. // Determine if at least one element in the object matches a truth test.
  4024. // Aliased as `any`.
  4025. _.some = _.any = function(obj, predicate, context) {
  4026. predicate = cb(predicate, context);
  4027. var keys = !isArrayLike(obj) && _.keys(obj),
  4028. length = (keys || obj).length;
  4029. for (var index = 0; index < length; index++) {
  4030. var currentKey = keys ? keys[index] : index;
  4031. if (predicate(obj[currentKey], currentKey, obj)) return true;
  4032. }
  4033. return false;
  4034. };
  4035. // Determine if the array or object contains a given item (using `===`).
  4036. // Aliased as `includes` and `include`.
  4037. _.contains = _.includes = _.include = function(obj, item, fromIndex, guard) {
  4038. if (!isArrayLike(obj)) obj = _.values(obj);
  4039. if (typeof fromIndex != 'number' || guard) fromIndex = 0;
  4040. return _.indexOf(obj, item, fromIndex) >= 0;
  4041. };
  4042. // Invoke a method (with arguments) on every item in a collection.
  4043. _.invoke = function(obj, method) {
  4044. var args = slice.call(arguments, 2);
  4045. var isFunc = _.isFunction(method);
  4046. return _.map(obj, function(value) {
  4047. var func = isFunc ? method : value[method];
  4048. return func == null ? func : func.apply(value, args);
  4049. });
  4050. };
  4051. // Convenience version of a common use case of `map`: fetching a property.
  4052. _.pluck = function(obj, key) {
  4053. return _.map(obj, _.property(key));
  4054. };
  4055. // Convenience version of a common use case of `filter`: selecting only objects
  4056. // containing specific `key:value` pairs.
  4057. _.where = function(obj, attrs) {
  4058. return _.filter(obj, _.matcher(attrs));
  4059. };
  4060. // Convenience version of a common use case of `find`: getting the first object
  4061. // containing specific `key:value` pairs.
  4062. _.findWhere = function(obj, attrs) {
  4063. return _.find(obj, _.matcher(attrs));
  4064. };
  4065. // Return the maximum element (or element-based computation).
  4066. _.max = function(obj, iteratee, context) {
  4067. var result = -Infinity, lastComputed = -Infinity,
  4068. value, computed;
  4069. if (iteratee == null && obj != null) {
  4070. obj = isArrayLike(obj) ? obj : _.values(obj);
  4071. for (var i = 0, length = obj.length; i < length; i++) {
  4072. value = obj[i];
  4073. if (value > result) {
  4074. result = value;
  4075. }
  4076. }
  4077. } else {
  4078. iteratee = cb(iteratee, context);
  4079. _.each(obj, function(value, index, list) {
  4080. computed = iteratee(value, index, list);
  4081. if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
  4082. result = value;
  4083. lastComputed = computed;
  4084. }
  4085. });
  4086. }
  4087. return result;
  4088. };
  4089. // Return the minimum element (or element-based computation).
  4090. _.min = function(obj, iteratee, context) {
  4091. var result = Infinity, lastComputed = Infinity,
  4092. value, computed;
  4093. if (iteratee == null && obj != null) {
  4094. obj = isArrayLike(obj) ? obj : _.values(obj);
  4095. for (var i = 0, length = obj.length; i < length; i++) {
  4096. value = obj[i];
  4097. if (value < result) {
  4098. result = value;
  4099. }
  4100. }
  4101. } else {
  4102. iteratee = cb(iteratee, context);
  4103. _.each(obj, function(value, index, list) {
  4104. computed = iteratee(value, index, list);
  4105. if (computed < lastComputed || computed === Infinity && result === Infinity) {
  4106. result = value;
  4107. lastComputed = computed;
  4108. }
  4109. });
  4110. }
  4111. return result;
  4112. };
  4113. // Shuffle a collection, using the modern version of the
  4114. // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
  4115. _.shuffle = function(obj) {
  4116. var set = isArrayLike(obj) ? obj : _.values(obj);
  4117. var length = set.length;
  4118. var shuffled = Array(length);
  4119. for (var index = 0, rand; index < length; index++) {
  4120. rand = _.random(0, index);
  4121. if (rand !== index) shuffled[index] = shuffled[rand];
  4122. shuffled[rand] = set[index];
  4123. }
  4124. return shuffled;
  4125. };
  4126. // Sample **n** random values from a collection.
  4127. // If **n** is not specified, returns a single random element.
  4128. // The internal `guard` argument allows it to work with `map`.
  4129. _.sample = function(obj, n, guard) {
  4130. if (n == null || guard) {
  4131. if (!isArrayLike(obj)) obj = _.values(obj);
  4132. return obj[_.random(obj.length - 1)];
  4133. }
  4134. return _.shuffle(obj).slice(0, Math.max(0, n));
  4135. };
  4136. // Sort the object's values by a criterion produced by an iteratee.
  4137. _.sortBy = function(obj, iteratee, context) {
  4138. iteratee = cb(iteratee, context);
  4139. return _.pluck(_.map(obj, function(value, index, list) {
  4140. return {
  4141. value: value,
  4142. index: index,
  4143. criteria: iteratee(value, index, list)
  4144. };
  4145. }).sort(function(left, right) {
  4146. var a = left.criteria;
  4147. var b = right.criteria;
  4148. if (a !== b) {
  4149. if (a > b || a === void 0) return 1;
  4150. if (a < b || b === void 0) return -1;
  4151. }
  4152. return left.index - right.index;
  4153. }), 'value');
  4154. };
  4155. // An internal function used for aggregate "group by" operations.
  4156. var group = function(behavior) {
  4157. return function(obj, iteratee, context) {
  4158. var result = {};
  4159. iteratee = cb(iteratee, context);
  4160. _.each(obj, function(value, index) {
  4161. var key = iteratee(value, index, obj);
  4162. behavior(result, value, key);
  4163. });
  4164. return result;
  4165. };
  4166. };
  4167. // Groups the object's values by a criterion. Pass either a string attribute
  4168. // to group by, or a function that returns the criterion.
  4169. _.groupBy = group(function(result, value, key) {
  4170. if (_.has(result, key)) result[key].push(value); else result[key] = [value];
  4171. });
  4172. // Indexes the object's values by a criterion, similar to `groupBy`, but for
  4173. // when you know that your index values will be unique.
  4174. _.indexBy = group(function(result, value, key) {
  4175. result[key] = value;
  4176. });
  4177. // Counts instances of an object that group by a certain criterion. Pass
  4178. // either a string attribute to count by, or a function that returns the
  4179. // criterion.
  4180. _.countBy = group(function(result, value, key) {
  4181. if (_.has(result, key)) result[key]++; else result[key] = 1;
  4182. });
  4183. // Safely create a real, live array from anything iterable.
  4184. _.toArray = function(obj) {
  4185. if (!obj) return [];
  4186. if (_.isArray(obj)) return slice.call(obj);
  4187. if (isArrayLike(obj)) return _.map(obj, _.identity);
  4188. return _.values(obj);
  4189. };
  4190. // Return the number of elements in an object.
  4191. _.size = function(obj) {
  4192. if (obj == null) return 0;
  4193. return isArrayLike(obj) ? obj.length : _.keys(obj).length;
  4194. };
  4195. // Split a collection into two arrays: one whose elements all satisfy the given
  4196. // predicate, and one whose elements all do not satisfy the predicate.
  4197. _.partition = function(obj, predicate, context) {
  4198. predicate = cb(predicate, context);
  4199. var pass = [], fail = [];
  4200. _.each(obj, function(value, key, obj) {
  4201. (predicate(value, key, obj) ? pass : fail).push(value);
  4202. });
  4203. return [pass, fail];
  4204. };
  4205. // Array Functions
  4206. // ---------------
  4207. // Get the first element of an array. Passing **n** will return the first N
  4208. // values in the array. Aliased as `head` and `take`. The **guard** check
  4209. // allows it to work with `_.map`.
  4210. _.first = _.head = _.take = function(array, n, guard) {
  4211. if (array == null) return void 0;
  4212. if (n == null || guard) return array[0];
  4213. return _.initial(array, array.length - n);
  4214. };
  4215. // Returns everything but the last entry of the array. Especially useful on
  4216. // the arguments object. Passing **n** will return all the values in
  4217. // the array, excluding the last N.
  4218. _.initial = function(array, n, guard) {
  4219. return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
  4220. };
  4221. // Get the last element of an array. Passing **n** will return the last N
  4222. // values in the array.
  4223. _.last = function(array, n, guard) {
  4224. if (array == null) return void 0;
  4225. if (n == null || guard) return array[array.length - 1];
  4226. return _.rest(array, Math.max(0, array.length - n));
  4227. };
  4228. // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
  4229. // Especially useful on the arguments object. Passing an **n** will return
  4230. // the rest N values in the array.
  4231. _.rest = _.tail = _.drop = function(array, n, guard) {
  4232. return slice.call(array, n == null || guard ? 1 : n);
  4233. };
  4234. // Trim out all falsy values from an array.
  4235. _.compact = function(array) {
  4236. return _.filter(array, _.identity);
  4237. };
  4238. // Internal implementation of a recursive `flatten` function.
  4239. var flatten = function(input, shallow, strict, startIndex) {
  4240. var output = [], idx = 0;
  4241. for (var i = startIndex || 0, length = getLength(input); i < length; i++) {
  4242. var value = input[i];
  4243. if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) {
  4244. //flatten current level of array or arguments object
  4245. if (!shallow) value = flatten(value, shallow, strict);
  4246. var j = 0, len = value.length;
  4247. output.length += len;
  4248. while (j < len) {
  4249. output[idx++] = value[j++];
  4250. }
  4251. } else if (!strict) {
  4252. output[idx++] = value;
  4253. }
  4254. }
  4255. return output;
  4256. };
  4257. // Flatten out an array, either recursively (by default), or just one level.
  4258. _.flatten = function(array, shallow) {
  4259. return flatten(array, shallow, false);
  4260. };
  4261. // Return a version of the array that does not contain the specified value(s).
  4262. _.without = function(array) {
  4263. return _.difference(array, slice.call(arguments, 1));
  4264. };
  4265. // Produce a duplicate-free version of the array. If the array has already
  4266. // been sorted, you have the option of using a faster algorithm.
  4267. // Aliased as `unique`.
  4268. _.uniq = _.unique = function(array, isSorted, iteratee, context) {
  4269. if (!_.isBoolean(isSorted)) {
  4270. context = iteratee;
  4271. iteratee = isSorted;
  4272. isSorted = false;
  4273. }
  4274. if (iteratee != null) iteratee = cb(iteratee, context);
  4275. var result = [];
  4276. var seen = [];
  4277. for (var i = 0, length = getLength(array); i < length; i++) {
  4278. var value = array[i],
  4279. computed = iteratee ? iteratee(value, i, array) : value;
  4280. if (isSorted) {
  4281. if (!i || seen !== computed) result.push(value);
  4282. seen = computed;
  4283. } else if (iteratee) {
  4284. if (!_.contains(seen, computed)) {
  4285. seen.push(computed);
  4286. result.push(value);
  4287. }
  4288. } else if (!_.contains(result, value)) {
  4289. result.push(value);
  4290. }
  4291. }
  4292. return result;
  4293. };
  4294. // Produce an array that contains the union: each distinct element from all of
  4295. // the passed-in arrays.
  4296. _.union = function() {
  4297. return _.uniq(flatten(arguments, true, true));
  4298. };
  4299. // Produce an array that contains every item shared between all the
  4300. // passed-in arrays.
  4301. _.intersection = function(array) {
  4302. var result = [];
  4303. var argsLength = arguments.length;
  4304. for (var i = 0, length = getLength(array); i < length; i++) {
  4305. var item = array[i];
  4306. if (_.contains(result, item)) continue;
  4307. for (var j = 1; j < argsLength; j++) {
  4308. if (!_.contains(arguments[j], item)) break;
  4309. }
  4310. if (j === argsLength) result.push(item);
  4311. }
  4312. return result;
  4313. };
  4314. // Take the difference between one array and a number of other arrays.
  4315. // Only the elements present in just the first array will remain.
  4316. _.difference = function(array) {
  4317. var rest = flatten(arguments, true, true, 1);
  4318. return _.filter(array, function(value){
  4319. return !_.contains(rest, value);
  4320. });
  4321. };
  4322. // Zip together multiple lists into a single array -- elements that share
  4323. // an index go together.
  4324. _.zip = function() {
  4325. return _.unzip(arguments);
  4326. };
  4327. // Complement of _.zip. Unzip accepts an array of arrays and groups
  4328. // each array's elements on shared indices
  4329. _.unzip = function(array) {
  4330. var length = array && _.max(array, getLength).length || 0;
  4331. var result = Array(length);
  4332. for (var index = 0; index < length; index++) {
  4333. result[index] = _.pluck(array, index);
  4334. }
  4335. return result;
  4336. };
  4337. // Converts lists into objects. Pass either a single array of `[key, value]`
  4338. // pairs, or two parallel arrays of the same length -- one of keys, and one of
  4339. // the corresponding values.
  4340. _.object = function(list, values) {
  4341. var result = {};
  4342. for (var i = 0, length = getLength(list); i < length; i++) {
  4343. if (values) {
  4344. result[list[i]] = values[i];
  4345. } else {
  4346. result[list[i][0]] = list[i][1];
  4347. }
  4348. }
  4349. return result;
  4350. };
  4351. // Generator function to create the findIndex and findLastIndex functions
  4352. function createPredicateIndexFinder(dir) {
  4353. return function(array, predicate, context) {
  4354. predicate = cb(predicate, context);
  4355. var length = getLength(array);
  4356. var index = dir > 0 ? 0 : length - 1;
  4357. for (; index >= 0 && index < length; index += dir) {
  4358. if (predicate(array[index], index, array)) return index;
  4359. }
  4360. return -1;
  4361. };
  4362. }
  4363. // Returns the first index on an array-like that passes a predicate test
  4364. _.findIndex = createPredicateIndexFinder(1);
  4365. _.findLastIndex = createPredicateIndexFinder(-1);
  4366. // Use a comparator function to figure out the smallest index at which
  4367. // an object should be inserted so as to maintain order. Uses binary search.
  4368. _.sortedIndex = function(array, obj, iteratee, context) {
  4369. iteratee = cb(iteratee, context, 1);
  4370. var value = iteratee(obj);
  4371. var low = 0, high = getLength(array);
  4372. while (low < high) {
  4373. var mid = Math.floor((low + high) / 2);
  4374. if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
  4375. }
  4376. return low;
  4377. };
  4378. // Generator function to create the indexOf and lastIndexOf functions
  4379. function createIndexFinder(dir, predicateFind, sortedIndex) {
  4380. return function(array, item, idx) {
  4381. var i = 0, length = getLength(array);
  4382. if (typeof idx == 'number') {
  4383. if (dir > 0) {
  4384. i = idx >= 0 ? idx : Math.max(idx + length, i);
  4385. } else {
  4386. length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
  4387. }
  4388. } else if (sortedIndex && idx && length) {
  4389. idx = sortedIndex(array, item);
  4390. return array[idx] === item ? idx : -1;
  4391. }
  4392. if (item !== item) {
  4393. idx = predicateFind(slice.call(array, i, length), _.isNaN);
  4394. return idx >= 0 ? idx + i : -1;
  4395. }
  4396. for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
  4397. if (array[idx] === item) return idx;
  4398. }
  4399. return -1;
  4400. };
  4401. }
  4402. // Return the position of the first occurrence of an item in an array,
  4403. // or -1 if the item is not included in the array.
  4404. // If the array is large and already in sort order, pass `true`
  4405. // for **isSorted** to use binary search.
  4406. _.indexOf = createIndexFinder(1, _.findIndex, _.sortedIndex);
  4407. _.lastIndexOf = createIndexFinder(-1, _.findLastIndex);
  4408. // Generate an integer Array containing an arithmetic progression. A port of
  4409. // the native Python `range()` function. See
  4410. // [the Python documentation](http://docs.python.org/library/functions.html#range).
  4411. _.range = function(start, stop, step) {
  4412. if (stop == null) {
  4413. stop = start || 0;
  4414. start = 0;
  4415. }
  4416. step = step || 1;
  4417. var length = Math.max(Math.ceil((stop - start) / step), 0);
  4418. var range = Array(length);
  4419. for (var idx = 0; idx < length; idx++, start += step) {
  4420. range[idx] = start;
  4421. }
  4422. return range;
  4423. };
  4424. // Function (ahem) Functions
  4425. // ------------------
  4426. // Determines whether to execute a function as a constructor
  4427. // or a normal function with the provided arguments
  4428. var executeBound = function(sourceFunc, boundFunc, context, callingContext, args) {
  4429. if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
  4430. var self = baseCreate(sourceFunc.prototype);
  4431. var result = sourceFunc.apply(self, args);
  4432. if (_.isObject(result)) return result;
  4433. return self;
  4434. };
  4435. // Create a function bound to a given object (assigning `this`, and arguments,
  4436. // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
  4437. // available.
  4438. _.bind = function(func, context) {
  4439. if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
  4440. if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
  4441. var args = slice.call(arguments, 2);
  4442. var bound = function() {
  4443. return executeBound(func, bound, context, this, args.concat(slice.call(arguments)));
  4444. };
  4445. return bound;
  4446. };
  4447. // Partially apply a function by creating a version that has had some of its
  4448. // arguments pre-filled, without changing its dynamic `this` context. _ acts
  4449. // as a placeholder, allowing any combination of arguments to be pre-filled.
  4450. _.partial = function(func) {
  4451. var boundArgs = slice.call(arguments, 1);
  4452. var bound = function() {
  4453. var position = 0, length = boundArgs.length;
  4454. var args = Array(length);
  4455. for (var i = 0; i < length; i++) {
  4456. args[i] = boundArgs[i] === _ ? arguments[position++] : boundArgs[i];
  4457. }
  4458. while (position < arguments.length) args.push(arguments[position++]);
  4459. return executeBound(func, bound, this, this, args);
  4460. };
  4461. return bound;
  4462. };
  4463. // Bind a number of an object's methods to that object. Remaining arguments
  4464. // are the method names to be bound. Useful for ensuring that all callbacks
  4465. // defined on an object belong to it.
  4466. _.bindAll = function(obj) {
  4467. var i, length = arguments.length, key;
  4468. if (length <= 1) throw new Error('bindAll must be passed function names');
  4469. for (i = 1; i < length; i++) {
  4470. key = arguments[i];
  4471. obj[key] = _.bind(obj[key], obj);
  4472. }
  4473. return obj;
  4474. };
  4475. // Memoize an expensive function by storing its results.
  4476. _.memoize = function(func, hasher) {
  4477. var memoize = function(key) {
  4478. var cache = memoize.cache;
  4479. var address = '' + (hasher ? hasher.apply(this, arguments) : key);
  4480. if (!_.has(cache, address)) cache[address] = func.apply(this, arguments);
  4481. return cache[address];
  4482. };
  4483. memoize.cache = {};
  4484. return memoize;
  4485. };
  4486. // Delays a function for the given number of milliseconds, and then calls
  4487. // it with the arguments supplied.
  4488. _.delay = function(func, wait) {
  4489. var args = slice.call(arguments, 2);
  4490. return setTimeout(function(){
  4491. return func.apply(null, args);
  4492. }, wait);
  4493. };
  4494. // Defers a function, scheduling it to run after the current call stack has
  4495. // cleared.
  4496. _.defer = _.partial(_.delay, _, 1);
  4497. // Returns a function, that, when invoked, will only be triggered at most once
  4498. // during a given window of time. Normally, the throttled function will run
  4499. // as much as it can, without ever going more than once per `wait` duration;
  4500. // but if you'd like to disable the execution on the leading edge, pass
  4501. // `{leading: false}`. To disable execution on the trailing edge, ditto.
  4502. _.throttle = function(func, wait, options) {
  4503. var context, args, result;
  4504. var timeout = null;
  4505. var previous = 0;
  4506. if (!options) options = {};
  4507. var later = function() {
  4508. previous = options.leading === false ? 0 : _.now();
  4509. timeout = null;
  4510. result = func.apply(context, args);
  4511. if (!timeout) context = args = null;
  4512. };
  4513. return function() {
  4514. var now = _.now();
  4515. if (!previous && options.leading === false) previous = now;
  4516. var remaining = wait - (now - previous);
  4517. context = this;
  4518. args = arguments;
  4519. if (remaining <= 0 || remaining > wait) {
  4520. if (timeout) {
  4521. clearTimeout(timeout);
  4522. timeout = null;
  4523. }
  4524. previous = now;
  4525. result = func.apply(context, args);
  4526. if (!timeout) context = args = null;
  4527. } else if (!timeout && options.trailing !== false) {
  4528. timeout = setTimeout(later, remaining);
  4529. }
  4530. return result;
  4531. };
  4532. };
  4533. // Returns a function, that, as long as it continues to be invoked, will not
  4534. // be triggered. The function will be called after it stops being called for
  4535. // N milliseconds. If `immediate` is passed, trigger the function on the
  4536. // leading edge, instead of the trailing.
  4537. _.debounce = function(func, wait, immediate) {
  4538. var timeout, args, context, timestamp, result;
  4539. var later = function() {
  4540. var last = _.now() - timestamp;
  4541. if (last < wait && last >= 0) {
  4542. timeout = setTimeout(later, wait - last);
  4543. } else {
  4544. timeout = null;
  4545. if (!immediate) {
  4546. result = func.apply(context, args);
  4547. if (!timeout) context = args = null;
  4548. }
  4549. }
  4550. };
  4551. return function() {
  4552. context = this;
  4553. args = arguments;
  4554. timestamp = _.now();
  4555. var callNow = immediate && !timeout;
  4556. if (!timeout) timeout = setTimeout(later, wait);
  4557. if (callNow) {
  4558. result = func.apply(context, args);
  4559. context = args = null;
  4560. }
  4561. return result;
  4562. };
  4563. };
  4564. // Returns the first function passed as an argument to the second,
  4565. // allowing you to adjust arguments, run code before and after, and
  4566. // conditionally execute the original function.
  4567. _.wrap = function(func, wrapper) {
  4568. return _.partial(wrapper, func);
  4569. };
  4570. // Returns a negated version of the passed-in predicate.
  4571. _.negate = function(predicate) {
  4572. return function() {
  4573. return !predicate.apply(this, arguments);
  4574. };
  4575. };
  4576. // Returns a function that is the composition of a list of functions, each
  4577. // consuming the return value of the function that follows.
  4578. _.compose = function() {
  4579. var args = arguments;
  4580. var start = args.length - 1;
  4581. return function() {
  4582. var i = start;
  4583. var result = args[start].apply(this, arguments);
  4584. while (i--) result = args[i].call(this, result);
  4585. return result;
  4586. };
  4587. };
  4588. // Returns a function that will only be executed on and after the Nth call.
  4589. _.after = function(times, func) {
  4590. return function() {
  4591. if (--times < 1) {
  4592. return func.apply(this, arguments);
  4593. }
  4594. };
  4595. };
  4596. // Returns a function that will only be executed up to (but not including) the Nth call.
  4597. _.before = function(times, func) {
  4598. var memo;
  4599. return function() {
  4600. if (--times > 0) {
  4601. memo = func.apply(this, arguments);
  4602. }
  4603. if (times <= 1) func = null;
  4604. return memo;
  4605. };
  4606. };
  4607. // Returns a function that will be executed at most one time, no matter how
  4608. // often you call it. Useful for lazy initialization.
  4609. _.once = _.partial(_.before, 2);
  4610. // Object Functions
  4611. // ----------------
  4612. // Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
  4613. var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
  4614. var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
  4615. 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
  4616. function collectNonEnumProps(obj, keys) {
  4617. var nonEnumIdx = nonEnumerableProps.length;
  4618. var constructor = obj.constructor;
  4619. var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto;
  4620. // Constructor is a special case.
  4621. var prop = 'constructor';
  4622. if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);
  4623. while (nonEnumIdx--) {
  4624. prop = nonEnumerableProps[nonEnumIdx];
  4625. if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
  4626. keys.push(prop);
  4627. }
  4628. }
  4629. }
  4630. // Retrieve the names of an object's own properties.
  4631. // Delegates to **ECMAScript 5**'s native `Object.keys`
  4632. _.keys = function(obj) {
  4633. if (!_.isObject(obj)) return [];
  4634. if (nativeKeys) return nativeKeys(obj);
  4635. var keys = [];
  4636. for (var key in obj) if (_.has(obj, key)) keys.push(key);
  4637. // Ahem, IE < 9.
  4638. if (hasEnumBug) collectNonEnumProps(obj, keys);
  4639. return keys;
  4640. };
  4641. // Retrieve all the property names of an object.
  4642. _.allKeys = function(obj) {
  4643. if (!_.isObject(obj)) return [];
  4644. var keys = [];
  4645. for (var key in obj) keys.push(key);
  4646. // Ahem, IE < 9.
  4647. if (hasEnumBug) collectNonEnumProps(obj, keys);
  4648. return keys;
  4649. };
  4650. // Retrieve the values of an object's properties.
  4651. _.values = function(obj) {
  4652. var keys = _.keys(obj);
  4653. var length = keys.length;
  4654. var values = Array(length);
  4655. for (var i = 0; i < length; i++) {
  4656. values[i] = obj[keys[i]];
  4657. }
  4658. return values;
  4659. };
  4660. // Returns the results of applying the iteratee to each element of the object
  4661. // In contrast to _.map it returns an object
  4662. _.mapObject = function(obj, iteratee, context) {
  4663. iteratee = cb(iteratee, context);
  4664. var keys = _.keys(obj),
  4665. length = keys.length,
  4666. results = {},
  4667. currentKey;
  4668. for (var index = 0; index < length; index++) {
  4669. currentKey = keys[index];
  4670. results[currentKey] = iteratee(obj[currentKey], currentKey, obj);
  4671. }
  4672. return results;
  4673. };
  4674. // Convert an object into a list of `[key, value]` pairs.
  4675. _.pairs = function(obj) {
  4676. var keys = _.keys(obj);
  4677. var length = keys.length;
  4678. var pairs = Array(length);
  4679. for (var i = 0; i < length; i++) {
  4680. pairs[i] = [keys[i], obj[keys[i]]];
  4681. }
  4682. return pairs;
  4683. };
  4684. // Invert the keys and values of an object. The values must be serializable.
  4685. _.invert = function(obj) {
  4686. var result = {};
  4687. var keys = _.keys(obj);
  4688. for (var i = 0, length = keys.length; i < length; i++) {
  4689. result[obj[keys[i]]] = keys[i];
  4690. }
  4691. return result;
  4692. };
  4693. // Return a sorted list of the function names available on the object.
  4694. // Aliased as `methods`
  4695. _.functions = _.methods = function(obj) {
  4696. var names = [];
  4697. for (var key in obj) {
  4698. if (_.isFunction(obj[key])) names.push(key);
  4699. }
  4700. return names.sort();
  4701. };
  4702. // Extend a given object with all the properties in passed-in object(s).
  4703. _.extend = createAssigner(_.allKeys);
  4704. // Assigns a given object with all the own properties in the passed-in object(s)
  4705. // (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
  4706. _.extendOwn = _.assign = createAssigner(_.keys);
  4707. // Returns the first key on an object that passes a predicate test
  4708. _.findKey = function(obj, predicate, context) {
  4709. predicate = cb(predicate, context);
  4710. var keys = _.keys(obj), key;
  4711. for (var i = 0, length = keys.length; i < length; i++) {
  4712. key = keys[i];
  4713. if (predicate(obj[key], key, obj)) return key;
  4714. }
  4715. };
  4716. // Return a copy of the object only containing the whitelisted properties.
  4717. _.pick = function(object, oiteratee, context) {
  4718. var result = {}, obj = object, iteratee, keys;
  4719. if (obj == null) return result;
  4720. if (_.isFunction(oiteratee)) {
  4721. keys = _.allKeys(obj);
  4722. iteratee = optimizeCb(oiteratee, context);
  4723. } else {
  4724. keys = flatten(arguments, false, false, 1);
  4725. iteratee = function(value, key, obj) { return key in obj; };
  4726. obj = Object(obj);
  4727. }
  4728. for (var i = 0, length = keys.length; i < length; i++) {
  4729. var key = keys[i];
  4730. var value = obj[key];
  4731. if (iteratee(value, key, obj)) result[key] = value;
  4732. }
  4733. return result;
  4734. };
  4735. // Return a copy of the object without the blacklisted properties.
  4736. _.omit = function(obj, iteratee, context) {
  4737. if (_.isFunction(iteratee)) {
  4738. iteratee = _.negate(iteratee);
  4739. } else {
  4740. var keys = _.map(flatten(arguments, false, false, 1), String);
  4741. iteratee = function(value, key) {
  4742. return !_.contains(keys, key);
  4743. };
  4744. }
  4745. return _.pick(obj, iteratee, context);
  4746. };
  4747. // Fill in a given object with default properties.
  4748. _.defaults = createAssigner(_.allKeys, true);
  4749. // Creates an object that inherits from the given prototype object.
  4750. // If additional properties are provided then they will be added to the
  4751. // created object.
  4752. _.create = function(prototype, props) {
  4753. var result = baseCreate(prototype);
  4754. if (props) _.extendOwn(result, props);
  4755. return result;
  4756. };
  4757. // Create a (shallow-cloned) duplicate of an object.
  4758. _.clone = function(obj) {
  4759. if (!_.isObject(obj)) return obj;
  4760. return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
  4761. };
  4762. // Invokes interceptor with the obj, and then returns obj.
  4763. // The primary purpose of this method is to "tap into" a method chain, in
  4764. // order to perform operations on intermediate results within the chain.
  4765. _.tap = function(obj, interceptor) {
  4766. interceptor(obj);
  4767. return obj;
  4768. };
  4769. // Returns whether an object has a given set of `key:value` pairs.
  4770. _.isMatch = function(object, attrs) {
  4771. var keys = _.keys(attrs), length = keys.length;
  4772. if (object == null) return !length;
  4773. var obj = Object(object);
  4774. for (var i = 0; i < length; i++) {
  4775. var key = keys[i];
  4776. if (attrs[key] !== obj[key] || !(key in obj)) return false;
  4777. }
  4778. return true;
  4779. };
  4780. // Internal recursive comparison function for `isEqual`.
  4781. var eq = function(a, b, aStack, bStack) {
  4782. // Identical objects are equal. `0 === -0`, but they aren't identical.
  4783. // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
  4784. if (a === b) return a !== 0 || 1 / a === 1 / b;
  4785. // A strict comparison is necessary because `null == undefined`.
  4786. if (a == null || b == null) return a === b;
  4787. // Unwrap any wrapped objects.
  4788. if (a instanceof _) a = a._wrapped;
  4789. if (b instanceof _) b = b._wrapped;
  4790. // Compare `[[Class]]` names.
  4791. var className = toString.call(a);
  4792. if (className !== toString.call(b)) return false;
  4793. switch (className) {
  4794. // Strings, numbers, regular expressions, dates, and booleans are compared by value.
  4795. case '[object RegExp]':
  4796. // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
  4797. case '[object String]':
  4798. // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
  4799. // equivalent to `new String("5")`.
  4800. return '' + a === '' + b;
  4801. case '[object Number]':
  4802. // `NaN`s are equivalent, but non-reflexive.
  4803. // Object(NaN) is equivalent to NaN
  4804. if (+a !== +a) return +b !== +b;
  4805. // An `egal` comparison is performed for other numeric values.
  4806. return +a === 0 ? 1 / +a === 1 / b : +a === +b;
  4807. case '[object Date]':
  4808. case '[object Boolean]':
  4809. // Coerce dates and booleans to numeric primitive values. Dates are compared by their
  4810. // millisecond representations. Note that invalid dates with millisecond representations
  4811. // of `NaN` are not equivalent.
  4812. return +a === +b;
  4813. }
  4814. var areArrays = className === '[object Array]';
  4815. if (!areArrays) {
  4816. if (typeof a != 'object' || typeof b != 'object') return false;
  4817. // Objects with different constructors are not equivalent, but `Object`s or `Array`s
  4818. // from different frames are.
  4819. var aCtor = a.constructor, bCtor = b.constructor;
  4820. if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
  4821. _.isFunction(bCtor) && bCtor instanceof bCtor)
  4822. && ('constructor' in a && 'constructor' in b)) {
  4823. return false;
  4824. }
  4825. }
  4826. // Assume equality for cyclic structures. The algorithm for detecting cyclic
  4827. // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
  4828. // Initializing stack of traversed objects.
  4829. // It's done here since we only need them for objects and arrays comparison.
  4830. aStack = aStack || [];
  4831. bStack = bStack || [];
  4832. var length = aStack.length;
  4833. while (length--) {
  4834. // Linear search. Performance is inversely proportional to the number of
  4835. // unique nested structures.
  4836. if (aStack[length] === a) return bStack[length] === b;
  4837. }
  4838. // Add the first object to the stack of traversed objects.
  4839. aStack.push(a);
  4840. bStack.push(b);
  4841. // Recursively compare objects and arrays.
  4842. if (areArrays) {
  4843. // Compare array lengths to determine if a deep comparison is necessary.
  4844. length = a.length;
  4845. if (length !== b.length) return false;
  4846. // Deep compare the contents, ignoring non-numeric properties.
  4847. while (length--) {
  4848. if (!eq(a[length], b[length], aStack, bStack)) return false;
  4849. }
  4850. } else {
  4851. // Deep compare objects.
  4852. var keys = _.keys(a), key;
  4853. length = keys.length;
  4854. // Ensure that both objects contain the same number of properties before comparing deep equality.
  4855. if (_.keys(b).length !== length) return false;
  4856. while (length--) {
  4857. // Deep compare each member
  4858. key = keys[length];
  4859. if (!(_.has(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
  4860. }
  4861. }
  4862. // Remove the first object from the stack of traversed objects.
  4863. aStack.pop();
  4864. bStack.pop();
  4865. return true;
  4866. };
  4867. // Perform a deep comparison to check if two objects are equal.
  4868. _.isEqual = function(a, b) {
  4869. return eq(a, b);
  4870. };
  4871. // Is a given array, string, or object empty?
  4872. // An "empty" object has no enumerable own-properties.
  4873. _.isEmpty = function(obj) {
  4874. if (obj == null) return true;
  4875. if (isArrayLike(obj) && (_.isArray(obj) || _.isString(obj) || _.isArguments(obj))) return obj.length === 0;
  4876. return _.keys(obj).length === 0;
  4877. };
  4878. // Is a given value a DOM element?
  4879. _.isElement = function(obj) {
  4880. return !!(obj && obj.nodeType === 1);
  4881. };
  4882. // Is a given value an array?
  4883. // Delegates to ECMA5's native Array.isArray
  4884. _.isArray = nativeIsArray || function(obj) {
  4885. return toString.call(obj) === '[object Array]';
  4886. };
  4887. // Is a given variable an object?
  4888. _.isObject = function(obj) {
  4889. var type = typeof obj;
  4890. return type === 'function' || type === 'object' && !!obj;
  4891. };
  4892. // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
  4893. _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) {
  4894. _['is' + name] = function(obj) {
  4895. return toString.call(obj) === '[object ' + name + ']';
  4896. };
  4897. });
  4898. // Define a fallback version of the method in browsers (ahem, IE < 9), where
  4899. // there isn't any inspectable "Arguments" type.
  4900. if (!_.isArguments(arguments)) {
  4901. _.isArguments = function(obj) {
  4902. return _.has(obj, 'callee');
  4903. };
  4904. }
  4905. // Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
  4906. // IE 11 (#1621), and in Safari 8 (#1929).
  4907. if (typeof /./ != 'function' && typeof Int8Array != 'object') {
  4908. _.isFunction = function(obj) {
  4909. return typeof obj == 'function' || false;
  4910. };
  4911. }
  4912. // Is a given object a finite number?
  4913. _.isFinite = function(obj) {
  4914. return isFinite(obj) && !isNaN(parseFloat(obj));
  4915. };
  4916. // Is the given value `NaN`? (NaN is the only number which does not equal itself).
  4917. _.isNaN = function(obj) {
  4918. return _.isNumber(obj) && obj !== +obj;
  4919. };
  4920. // Is a given value a boolean?
  4921. _.isBoolean = function(obj) {
  4922. return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
  4923. };
  4924. // Is a given value equal to null?
  4925. _.isNull = function(obj) {
  4926. return obj === null;
  4927. };
  4928. // Is a given variable undefined?
  4929. _.isUndefined = function(obj) {
  4930. return obj === void 0;
  4931. };
  4932. // Shortcut function for checking if an object has a given property directly
  4933. // on itself (in other words, not on a prototype).
  4934. _.has = function(obj, key) {
  4935. return obj != null && hasOwnProperty.call(obj, key);
  4936. };
  4937. // Utility Functions
  4938. // -----------------
  4939. // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
  4940. // previous owner. Returns a reference to the Underscore object.
  4941. _.noConflict = function() {
  4942. root._ = previousUnderscore;
  4943. return this;
  4944. };
  4945. // Keep the identity function around for default iteratees.
  4946. _.identity = function(value) {
  4947. return value;
  4948. };
  4949. // Predicate-generating functions. Often useful outside of Underscore.
  4950. _.constant = function(value) {
  4951. return function() {
  4952. return value;
  4953. };
  4954. };
  4955. _.noop = function(){};
  4956. _.property = property;
  4957. // Generates a function for a given object that returns a given property.
  4958. _.propertyOf = function(obj) {
  4959. return obj == null ? function(){} : function(key) {
  4960. return obj[key];
  4961. };
  4962. };
  4963. // Returns a predicate for checking whether an object has a given set of
  4964. // `key:value` pairs.
  4965. _.matcher = _.matches = function(attrs) {
  4966. attrs = _.extendOwn({}, attrs);
  4967. return function(obj) {
  4968. return _.isMatch(obj, attrs);
  4969. };
  4970. };
  4971. // Run a function **n** times.
  4972. _.times = function(n, iteratee, context) {
  4973. var accum = Array(Math.max(0, n));
  4974. iteratee = optimizeCb(iteratee, context, 1);
  4975. for (var i = 0; i < n; i++) accum[i] = iteratee(i);
  4976. return accum;
  4977. };
  4978. // Return a random integer between min and max (inclusive).
  4979. _.random = function(min, max) {
  4980. if (max == null) {
  4981. max = min;
  4982. min = 0;
  4983. }
  4984. return min + Math.floor(Math.random() * (max - min + 1));
  4985. };
  4986. // A (possibly faster) way to get the current timestamp as an integer.
  4987. _.now = Date.now || function() {
  4988. return new Date().getTime();
  4989. };
  4990. // List of HTML entities for escaping.
  4991. var escapeMap = {
  4992. '&': '&amp;',
  4993. '<': '&lt;',
  4994. '>': '&gt;',
  4995. '"': '&quot;',
  4996. "'": '&#x27;',
  4997. '`': '&#x60;'
  4998. };
  4999. var unescapeMap = _.invert(escapeMap);
  5000. // Functions for escaping and unescaping strings to/from HTML interpolation.
  5001. var createEscaper = function(map) {
  5002. var escaper = function(match) {
  5003. return map[match];
  5004. };
  5005. // Regexes for identifying a key that needs to be escaped
  5006. var source = '(?:' + _.keys(map).join('|') + ')';
  5007. var testRegexp = RegExp(source);
  5008. var replaceRegexp = RegExp(source, 'g');
  5009. return function(string) {
  5010. string = string == null ? '' : '' + string;
  5011. return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
  5012. };
  5013. };
  5014. _.escape = createEscaper(escapeMap);
  5015. _.unescape = createEscaper(unescapeMap);
  5016. // If the value of the named `property` is a function then invoke it with the
  5017. // `object` as context; otherwise, return it.
  5018. _.result = function(object, property, fallback) {
  5019. var value = object == null ? void 0 : object[property];
  5020. if (value === void 0) {
  5021. value = fallback;
  5022. }
  5023. return _.isFunction(value) ? value.call(object) : value;
  5024. };
  5025. // Generate a unique integer id (unique within the entire client session).
  5026. // Useful for temporary DOM ids.
  5027. var idCounter = 0;
  5028. _.uniqueId = function(prefix) {
  5029. var id = ++idCounter + '';
  5030. return prefix ? prefix + id : id;
  5031. };
  5032. // By default, Underscore uses ERB-style template delimiters, change the
  5033. // following template settings to use alternative delimiters.
  5034. _.templateSettings = {
  5035. evaluate : /<%([\s\S]+?)%>/g,
  5036. interpolate : /<%=([\s\S]+?)%>/g,
  5037. escape : /<%-([\s\S]+?)%>/g
  5038. };
  5039. // When customizing `templateSettings`, if you don't want to define an
  5040. // interpolation, evaluation or escaping regex, we need one that is
  5041. // guaranteed not to match.
  5042. var noMatch = /(.)^/;
  5043. // Certain characters need to be escaped so that they can be put into a
  5044. // string literal.
  5045. var escapes = {
  5046. "'": "'",
  5047. '\\': '\\',
  5048. '\r': 'r',
  5049. '\n': 'n',
  5050. '\u2028': 'u2028',
  5051. '\u2029': 'u2029'
  5052. };
  5053. var escaper = /\\|'|\r|\n|\u2028|\u2029/g;
  5054. var escapeChar = function(match) {
  5055. return '\\' + escapes[match];
  5056. };
  5057. // JavaScript micro-templating, similar to John Resig's implementation.
  5058. // Underscore templating handles arbitrary delimiters, preserves whitespace,
  5059. // and correctly escapes quotes within interpolated code.
  5060. // NB: `oldSettings` only exists for backwards compatibility.
  5061. _.template = function(text, settings, oldSettings) {
  5062. if (!settings && oldSettings) settings = oldSettings;
  5063. settings = _.defaults({}, settings, _.templateSettings);
  5064. // Combine delimiters into one regular expression via alternation.
  5065. var matcher = RegExp([
  5066. (settings.escape || noMatch).source,
  5067. (settings.interpolate || noMatch).source,
  5068. (settings.evaluate || noMatch).source
  5069. ].join('|') + '|$', 'g');
  5070. // Compile the template source, escaping string literals appropriately.
  5071. var index = 0;
  5072. var source = "__p+='";
  5073. text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
  5074. source += text.slice(index, offset).replace(escaper, escapeChar);
  5075. index = offset + match.length;
  5076. if (escape) {
  5077. source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
  5078. } else if (interpolate) {
  5079. source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
  5080. } else if (evaluate) {
  5081. source += "';\n" + evaluate + "\n__p+='";
  5082. }
  5083. // Adobe VMs need the match returned to produce the correct offest.
  5084. return match;
  5085. });
  5086. source += "';\n";
  5087. // If a variable is not specified, place data values in local scope.
  5088. if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
  5089. source = "var __t,__p='',__j=Array.prototype.join," +
  5090. "print=function(){__p+=__j.call(arguments,'');};\n" +
  5091. source + 'return __p;\n';
  5092. try {
  5093. var render = new Function(settings.variable || 'obj', '_', source);
  5094. } catch (e) {
  5095. e.source = source;
  5096. throw e;
  5097. }
  5098. var template = function(data) {
  5099. return render.call(this, data, _);
  5100. };
  5101. // Provide the compiled source as a convenience for precompilation.
  5102. var argument = settings.variable || 'obj';
  5103. template.source = 'function(' + argument + '){\n' + source + '}';
  5104. return template;
  5105. };
  5106. // Add a "chain" function. Start chaining a wrapped Underscore object.
  5107. _.chain = function(obj) {
  5108. var instance = _(obj);
  5109. instance._chain = true;
  5110. return instance;
  5111. };
  5112. // OOP
  5113. // ---------------
  5114. // If Underscore is called as a function, it returns a wrapped object that
  5115. // can be used OO-style. This wrapper holds altered versions of all the
  5116. // underscore functions. Wrapped objects may be chained.
  5117. // Helper function to continue chaining intermediate results.
  5118. var result = function(instance, obj) {
  5119. return instance._chain ? _(obj).chain() : obj;
  5120. };
  5121. // Add your own custom functions to the Underscore object.
  5122. _.mixin = function(obj) {
  5123. _.each(_.functions(obj), function(name) {
  5124. var func = _[name] = obj[name];
  5125. _.prototype[name] = function() {
  5126. var args = [this._wrapped];
  5127. push.apply(args, arguments);
  5128. return result(this, func.apply(_, args));
  5129. };
  5130. });
  5131. };
  5132. // Add all of the Underscore functions to the wrapper object.
  5133. _.mixin(_);
  5134. // Add all mutator Array functions to the wrapper.
  5135. _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
  5136. var method = ArrayProto[name];
  5137. _.prototype[name] = function() {
  5138. var obj = this._wrapped;
  5139. method.apply(obj, arguments);
  5140. if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
  5141. return result(this, obj);
  5142. };
  5143. });
  5144. // Add all accessor Array functions to the wrapper.
  5145. _.each(['concat', 'join', 'slice'], function(name) {
  5146. var method = ArrayProto[name];
  5147. _.prototype[name] = function() {
  5148. return result(this, method.apply(this._wrapped, arguments));
  5149. };
  5150. });
  5151. // Extracts the result from a wrapped and chained object.
  5152. _.prototype.value = function() {
  5153. return this._wrapped;
  5154. };
  5155. // Provide unwrapping proxy for some methods used in engine operations
  5156. // such as arithmetic and JSON stringification.
  5157. _.prototype.valueOf = _.prototype.toJSON = _.prototype.value;
  5158. _.prototype.toString = function() {
  5159. return '' + this._wrapped;
  5160. };
  5161. // AMD registration happens at the end for compatibility with AMD loaders
  5162. // that may not enforce next-turn semantics on modules. Even though general
  5163. // practice for AMD registration is to be anonymous, underscore registers
  5164. // as a named module because, like jQuery, it is a base library that is
  5165. // popular enough to be bundled in a third party lib, but not be part of
  5166. // an AMD load request. Those cases could generate an error when an
  5167. // anonymous define() is called outside of a loader request.
  5168. if (typeof define === 'function' && define.amd) {
  5169. define('underscore', [], function() {
  5170. return _;
  5171. });
  5172. }
  5173. }.call(this));
  5174. },{}],26:[function(require,module,exports){
  5175. arguments[4][19][0].apply(exports,arguments)
  5176. },{"dup":19}],27:[function(require,module,exports){
  5177. module.exports = function isBuffer(arg) {
  5178. return arg && typeof arg === 'object'
  5179. && typeof arg.copy === 'function'
  5180. && typeof arg.fill === 'function'
  5181. && typeof arg.readUInt8 === 'function';
  5182. }
  5183. },{}],28:[function(require,module,exports){
  5184. (function (process,global){
  5185. // Copyright Joyent, Inc. and other Node contributors.
  5186. //
  5187. // Permission is hereby granted, free of charge, to any person obtaining a
  5188. // copy of this software and associated documentation files (the
  5189. // "Software"), to deal in the Software without restriction, including
  5190. // without limitation the rights to use, copy, modify, merge, publish,
  5191. // distribute, sublicense, and/or sell copies of the Software, and to permit
  5192. // persons to whom the Software is furnished to do so, subject to the
  5193. // following conditions:
  5194. //
  5195. // The above copyright notice and this permission notice shall be included
  5196. // in all copies or substantial portions of the Software.
  5197. //
  5198. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  5199. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  5200. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  5201. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  5202. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  5203. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  5204. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  5205. var formatRegExp = /%[sdj%]/g;
  5206. exports.format = function(f) {
  5207. if (!isString(f)) {
  5208. var objects = [];
  5209. for (var i = 0; i < arguments.length; i++) {
  5210. objects.push(inspect(arguments[i]));
  5211. }
  5212. return objects.join(' ');
  5213. }
  5214. var i = 1;
  5215. var args = arguments;
  5216. var len = args.length;
  5217. var str = String(f).replace(formatRegExp, function(x) {
  5218. if (x === '%%') return '%';
  5219. if (i >= len) return x;
  5220. switch (x) {
  5221. case '%s': return String(args[i++]);
  5222. case '%d': return Number(args[i++]);
  5223. case '%j':
  5224. try {
  5225. return JSON.stringify(args[i++]);
  5226. } catch (_) {
  5227. return '[Circular]';
  5228. }
  5229. default:
  5230. return x;
  5231. }
  5232. });
  5233. for (var x = args[i]; i < len; x = args[++i]) {
  5234. if (isNull(x) || !isObject(x)) {
  5235. str += ' ' + x;
  5236. } else {
  5237. str += ' ' + inspect(x);
  5238. }
  5239. }
  5240. return str;
  5241. };
  5242. // Mark that a method should not be used.
  5243. // Returns a modified function which warns once by default.
  5244. // If --no-deprecation is set, then it is a no-op.
  5245. exports.deprecate = function(fn, msg) {
  5246. // Allow for deprecating things in the process of starting up.
  5247. if (isUndefined(global.process)) {
  5248. return function() {
  5249. return exports.deprecate(fn, msg).apply(this, arguments);
  5250. };
  5251. }
  5252. if (process.noDeprecation === true) {
  5253. return fn;
  5254. }
  5255. var warned = false;
  5256. function deprecated() {
  5257. if (!warned) {
  5258. if (process.throwDeprecation) {
  5259. throw new Error(msg);
  5260. } else if (process.traceDeprecation) {
  5261. console.trace(msg);
  5262. } else {
  5263. console.error(msg);
  5264. }
  5265. warned = true;
  5266. }
  5267. return fn.apply(this, arguments);
  5268. }
  5269. return deprecated;
  5270. };
  5271. var debugs = {};
  5272. var debugEnviron;
  5273. exports.debuglog = function(set) {
  5274. if (isUndefined(debugEnviron))
  5275. debugEnviron = process.env.NODE_DEBUG || '';
  5276. set = set.toUpperCase();
  5277. if (!debugs[set]) {
  5278. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  5279. var pid = process.pid;
  5280. debugs[set] = function() {
  5281. var msg = exports.format.apply(exports, arguments);
  5282. console.error('%s %d: %s', set, pid, msg);
  5283. };
  5284. } else {
  5285. debugs[set] = function() {};
  5286. }
  5287. }
  5288. return debugs[set];
  5289. };
  5290. /**
  5291. * Echos the value of a value. Trys to print the value out
  5292. * in the best way possible given the different types.
  5293. *
  5294. * @param {Object} obj The object to print out.
  5295. * @param {Object} opts Optional options object that alters the output.
  5296. */
  5297. /* legacy: obj, showHidden, depth, colors*/
  5298. function inspect(obj, opts) {
  5299. // default options
  5300. var ctx = {
  5301. seen: [],
  5302. stylize: stylizeNoColor
  5303. };
  5304. // legacy...
  5305. if (arguments.length >= 3) ctx.depth = arguments[2];
  5306. if (arguments.length >= 4) ctx.colors = arguments[3];
  5307. if (isBoolean(opts)) {
  5308. // legacy...
  5309. ctx.showHidden = opts;
  5310. } else if (opts) {
  5311. // got an "options" object
  5312. exports._extend(ctx, opts);
  5313. }
  5314. // set default options
  5315. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  5316. if (isUndefined(ctx.depth)) ctx.depth = 2;
  5317. if (isUndefined(ctx.colors)) ctx.colors = false;
  5318. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  5319. if (ctx.colors) ctx.stylize = stylizeWithColor;
  5320. return formatValue(ctx, obj, ctx.depth);
  5321. }
  5322. exports.inspect = inspect;
  5323. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  5324. inspect.colors = {
  5325. 'bold' : [1, 22],
  5326. 'italic' : [3, 23],
  5327. 'underline' : [4, 24],
  5328. 'inverse' : [7, 27],
  5329. 'white' : [37, 39],
  5330. 'grey' : [90, 39],
  5331. 'black' : [30, 39],
  5332. 'blue' : [34, 39],
  5333. 'cyan' : [36, 39],
  5334. 'green' : [32, 39],
  5335. 'magenta' : [35, 39],
  5336. 'red' : [31, 39],
  5337. 'yellow' : [33, 39]
  5338. };
  5339. // Don't use 'blue' not visible on cmd.exe
  5340. inspect.styles = {
  5341. 'special': 'cyan',
  5342. 'number': 'yellow',
  5343. 'boolean': 'yellow',
  5344. 'undefined': 'grey',
  5345. 'null': 'bold',
  5346. 'string': 'green',
  5347. 'date': 'magenta',
  5348. // "name": intentionally not styling
  5349. 'regexp': 'red'
  5350. };
  5351. function stylizeWithColor(str, styleType) {
  5352. var style = inspect.styles[styleType];
  5353. if (style) {
  5354. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  5355. '\u001b[' + inspect.colors[style][1] + 'm';
  5356. } else {
  5357. return str;
  5358. }
  5359. }
  5360. function stylizeNoColor(str, styleType) {
  5361. return str;
  5362. }
  5363. function arrayToHash(array) {
  5364. var hash = {};
  5365. array.forEach(function(val, idx) {
  5366. hash[val] = true;
  5367. });
  5368. return hash;
  5369. }
  5370. function formatValue(ctx, value, recurseTimes) {
  5371. // Provide a hook for user-specified inspect functions.
  5372. // Check that value is an object with an inspect function on it
  5373. if (ctx.customInspect &&
  5374. value &&
  5375. isFunction(value.inspect) &&
  5376. // Filter out the util module, it's inspect function is special
  5377. value.inspect !== exports.inspect &&
  5378. // Also filter out any prototype objects using the circular check.
  5379. !(value.constructor && value.constructor.prototype === value)) {
  5380. var ret = value.inspect(recurseTimes, ctx);
  5381. if (!isString(ret)) {
  5382. ret = formatValue(ctx, ret, recurseTimes);
  5383. }
  5384. return ret;
  5385. }
  5386. // Primitive types cannot have properties
  5387. var primitive = formatPrimitive(ctx, value);
  5388. if (primitive) {
  5389. return primitive;
  5390. }
  5391. // Look up the keys of the object.
  5392. var keys = Object.keys(value);
  5393. var visibleKeys = arrayToHash(keys);
  5394. if (ctx.showHidden) {
  5395. keys = Object.getOwnPropertyNames(value);
  5396. }
  5397. // IE doesn't make error fields non-enumerable
  5398. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  5399. if (isError(value)
  5400. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  5401. return formatError(value);
  5402. }
  5403. // Some type of object without properties can be shortcutted.
  5404. if (keys.length === 0) {
  5405. if (isFunction(value)) {
  5406. var name = value.name ? ': ' + value.name : '';
  5407. return ctx.stylize('[Function' + name + ']', 'special');
  5408. }
  5409. if (isRegExp(value)) {
  5410. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  5411. }
  5412. if (isDate(value)) {
  5413. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  5414. }
  5415. if (isError(value)) {
  5416. return formatError(value);
  5417. }
  5418. }
  5419. var base = '', array = false, braces = ['{', '}'];
  5420. // Make Array say that they are Array
  5421. if (isArray(value)) {
  5422. array = true;
  5423. braces = ['[', ']'];
  5424. }
  5425. // Make functions say that they are functions
  5426. if (isFunction(value)) {
  5427. var n = value.name ? ': ' + value.name : '';
  5428. base = ' [Function' + n + ']';
  5429. }
  5430. // Make RegExps say that they are RegExps
  5431. if (isRegExp(value)) {
  5432. base = ' ' + RegExp.prototype.toString.call(value);
  5433. }
  5434. // Make dates with properties first say the date
  5435. if (isDate(value)) {
  5436. base = ' ' + Date.prototype.toUTCString.call(value);
  5437. }
  5438. // Make error with message first say the error
  5439. if (isError(value)) {
  5440. base = ' ' + formatError(value);
  5441. }
  5442. if (keys.length === 0 && (!array || value.length == 0)) {
  5443. return braces[0] + base + braces[1];
  5444. }
  5445. if (recurseTimes < 0) {
  5446. if (isRegExp(value)) {
  5447. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  5448. } else {
  5449. return ctx.stylize('[Object]', 'special');
  5450. }
  5451. }
  5452. ctx.seen.push(value);
  5453. var output;
  5454. if (array) {
  5455. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  5456. } else {
  5457. output = keys.map(function(key) {
  5458. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  5459. });
  5460. }
  5461. ctx.seen.pop();
  5462. return reduceToSingleString(output, base, braces);
  5463. }
  5464. function formatPrimitive(ctx, value) {
  5465. if (isUndefined(value))
  5466. return ctx.stylize('undefined', 'undefined');
  5467. if (isString(value)) {
  5468. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  5469. .replace(/'/g, "\\'")
  5470. .replace(/\\"/g, '"') + '\'';
  5471. return ctx.stylize(simple, 'string');
  5472. }
  5473. if (isNumber(value))
  5474. return ctx.stylize('' + value, 'number');
  5475. if (isBoolean(value))
  5476. return ctx.stylize('' + value, 'boolean');
  5477. // For some reason typeof null is "object", so special case here.
  5478. if (isNull(value))
  5479. return ctx.stylize('null', 'null');
  5480. }
  5481. function formatError(value) {
  5482. return '[' + Error.prototype.toString.call(value) + ']';
  5483. }
  5484. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  5485. var output = [];
  5486. for (var i = 0, l = value.length; i < l; ++i) {
  5487. if (hasOwnProperty(value, String(i))) {
  5488. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  5489. String(i), true));
  5490. } else {
  5491. output.push('');
  5492. }
  5493. }
  5494. keys.forEach(function(key) {
  5495. if (!key.match(/^\d+$/)) {
  5496. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  5497. key, true));
  5498. }
  5499. });
  5500. return output;
  5501. }
  5502. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  5503. var name, str, desc;
  5504. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  5505. if (desc.get) {
  5506. if (desc.set) {
  5507. str = ctx.stylize('[Getter/Setter]', 'special');
  5508. } else {
  5509. str = ctx.stylize('[Getter]', 'special');
  5510. }
  5511. } else {
  5512. if (desc.set) {
  5513. str = ctx.stylize('[Setter]', 'special');
  5514. }
  5515. }
  5516. if (!hasOwnProperty(visibleKeys, key)) {
  5517. name = '[' + key + ']';
  5518. }
  5519. if (!str) {
  5520. if (ctx.seen.indexOf(desc.value) < 0) {
  5521. if (isNull(recurseTimes)) {
  5522. str = formatValue(ctx, desc.value, null);
  5523. } else {
  5524. str = formatValue(ctx, desc.value, recurseTimes - 1);
  5525. }
  5526. if (str.indexOf('\n') > -1) {
  5527. if (array) {
  5528. str = str.split('\n').map(function(line) {
  5529. return ' ' + line;
  5530. }).join('\n').substr(2);
  5531. } else {
  5532. str = '\n' + str.split('\n').map(function(line) {
  5533. return ' ' + line;
  5534. }).join('\n');
  5535. }
  5536. }
  5537. } else {
  5538. str = ctx.stylize('[Circular]', 'special');
  5539. }
  5540. }
  5541. if (isUndefined(name)) {
  5542. if (array && key.match(/^\d+$/)) {
  5543. return str;
  5544. }
  5545. name = JSON.stringify('' + key);
  5546. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  5547. name = name.substr(1, name.length - 2);
  5548. name = ctx.stylize(name, 'name');
  5549. } else {
  5550. name = name.replace(/'/g, "\\'")
  5551. .replace(/\\"/g, '"')
  5552. .replace(/(^"|"$)/g, "'");
  5553. name = ctx.stylize(name, 'string');
  5554. }
  5555. }
  5556. return name + ': ' + str;
  5557. }
  5558. function reduceToSingleString(output, base, braces) {
  5559. var numLinesEst = 0;
  5560. var length = output.reduce(function(prev, cur) {
  5561. numLinesEst++;
  5562. if (cur.indexOf('\n') >= 0) numLinesEst++;
  5563. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  5564. }, 0);
  5565. if (length > 60) {
  5566. return braces[0] +
  5567. (base === '' ? '' : base + '\n ') +
  5568. ' ' +
  5569. output.join(',\n ') +
  5570. ' ' +
  5571. braces[1];
  5572. }
  5573. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  5574. }
  5575. // NOTE: These type checking functions intentionally don't use `instanceof`
  5576. // because it is fragile and can be easily faked with `Object.create()`.
  5577. function isArray(ar) {
  5578. return Array.isArray(ar);
  5579. }
  5580. exports.isArray = isArray;
  5581. function isBoolean(arg) {
  5582. return typeof arg === 'boolean';
  5583. }
  5584. exports.isBoolean = isBoolean;
  5585. function isNull(arg) {
  5586. return arg === null;
  5587. }
  5588. exports.isNull = isNull;
  5589. function isNullOrUndefined(arg) {
  5590. return arg == null;
  5591. }
  5592. exports.isNullOrUndefined = isNullOrUndefined;
  5593. function isNumber(arg) {
  5594. return typeof arg === 'number';
  5595. }
  5596. exports.isNumber = isNumber;
  5597. function isString(arg) {
  5598. return typeof arg === 'string';
  5599. }
  5600. exports.isString = isString;
  5601. function isSymbol(arg) {
  5602. return typeof arg === 'symbol';
  5603. }
  5604. exports.isSymbol = isSymbol;
  5605. function isUndefined(arg) {
  5606. return arg === void 0;
  5607. }
  5608. exports.isUndefined = isUndefined;
  5609. function isRegExp(re) {
  5610. return isObject(re) && objectToString(re) === '[object RegExp]';
  5611. }
  5612. exports.isRegExp = isRegExp;
  5613. function isObject(arg) {
  5614. return typeof arg === 'object' && arg !== null;
  5615. }
  5616. exports.isObject = isObject;
  5617. function isDate(d) {
  5618. return isObject(d) && objectToString(d) === '[object Date]';
  5619. }
  5620. exports.isDate = isDate;
  5621. function isError(e) {
  5622. return isObject(e) &&
  5623. (objectToString(e) === '[object Error]' || e instanceof Error);
  5624. }
  5625. exports.isError = isError;
  5626. function isFunction(arg) {
  5627. return typeof arg === 'function';
  5628. }
  5629. exports.isFunction = isFunction;
  5630. function isPrimitive(arg) {
  5631. return arg === null ||
  5632. typeof arg === 'boolean' ||
  5633. typeof arg === 'number' ||
  5634. typeof arg === 'string' ||
  5635. typeof arg === 'symbol' || // ES6 symbol
  5636. typeof arg === 'undefined';
  5637. }
  5638. exports.isPrimitive = isPrimitive;
  5639. exports.isBuffer = require('./support/isBuffer');
  5640. function objectToString(o) {
  5641. return Object.prototype.toString.call(o);
  5642. }
  5643. function pad(n) {
  5644. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  5645. }
  5646. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  5647. 'Oct', 'Nov', 'Dec'];
  5648. // 26 Feb 16:19:34
  5649. function timestamp() {
  5650. var d = new Date();
  5651. var time = [pad(d.getHours()),
  5652. pad(d.getMinutes()),
  5653. pad(d.getSeconds())].join(':');
  5654. return [d.getDate(), months[d.getMonth()], time].join(' ');
  5655. }
  5656. // log is just a thin wrapper to console.log that prepends a timestamp
  5657. exports.log = function() {
  5658. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  5659. };
  5660. /**
  5661. * Inherit the prototype methods from one constructor into another.
  5662. *
  5663. * The Function.prototype.inherits from lang.js rewritten as a standalone
  5664. * function (not on Function.prototype). NOTE: If this file is to be loaded
  5665. * during bootstrapping this function needs to be rewritten using some native
  5666. * functions as prototype setup using normal JavaScript does not work as
  5667. * expected during bootstrapping (see mirror.js in r114903).
  5668. *
  5669. * @param {function} ctor Constructor function which needs to inherit the
  5670. * prototype.
  5671. * @param {function} superCtor Constructor function to inherit prototype from.
  5672. */
  5673. exports.inherits = require('inherits');
  5674. exports._extend = function(origin, add) {
  5675. // Don't do anything if add isn't an object
  5676. if (!add || !isObject(add)) return origin;
  5677. var keys = Object.keys(add);
  5678. var i = keys.length;
  5679. while (i--) {
  5680. origin[keys[i]] = add[keys[i]];
  5681. }
  5682. return origin;
  5683. };
  5684. function hasOwnProperty(obj, prop) {
  5685. return Object.prototype.hasOwnProperty.call(obj, prop);
  5686. }
  5687. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5688. },{"./support/isBuffer":27,"_process":24,"inherits":26}],29:[function(require,module,exports){
  5689. // Returns a wrapper function that returns a wrapped callback
  5690. // The wrapper function should do some stuff, and return a
  5691. // presumably different callback function.
  5692. // This makes sure that own properties are retained, so that
  5693. // decorations and such are not lost along the way.
  5694. module.exports = wrappy
  5695. function wrappy (fn, cb) {
  5696. if (fn && cb) return wrappy(fn)(cb)
  5697. if (typeof fn !== 'function')
  5698. throw new TypeError('need wrapper function')
  5699. Object.keys(fn).forEach(function (k) {
  5700. wrapper[k] = fn[k]
  5701. })
  5702. return wrapper
  5703. function wrapper() {
  5704. var args = new Array(arguments.length)
  5705. for (var i = 0; i < args.length; i++) {
  5706. args[i] = arguments[i]
  5707. }
  5708. var ret = fn.apply(this, args)
  5709. var cb = args[args.length-1]
  5710. if (typeof ret === 'function' && ret !== cb) {
  5711. Object.keys(cb).forEach(function (k) {
  5712. ret[k] = cb[k]
  5713. })
  5714. }
  5715. return ret
  5716. }
  5717. }
  5718. },{}]},{},[7])(7)
  5719. });