UNPKG

mutual

Version:

Scala-inspired Actors that use Redis as a message transport

66 lines (56 loc) 1.5 kB
// Generated by CoffeeScript 1.12.7 (function() { var Pattern, _match, _parse, memoize, slice = [].slice; memoize = require("fairmont").memoize; _parse = function(string) { var error; try { return string.split("."); } catch (error1) { error = error1; throw new Error(string + " is not a valid pattern"); } }; _match = function(pattern, target) { var p, pl, px, t, tl, tx; pl = pattern.length; tl = target.length; if ((pl === tl && tl === 0)) { return true; } else if (pl === 0 || tl === 0) { return false; } else { p = pattern[0], px = 2 <= pattern.length ? slice.call(pattern, 1) : []; t = target[0], tx = 2 <= target.length ? slice.call(target, 1) : []; if (p === "*") { if (_match(px, tx)) { return true; } else { return _match(pattern, tx); } } else if (p === t) { return _match(px, tx); } else { return false; } } }; Pattern = (function() { function Pattern(pattern) { this._pattern = _parse(pattern); } Pattern.prototype.match = function(target) { if (this._match == null) { this._match = memoize((function(_this) { return function(target) { return _match(_this._pattern, _parse(target)); }; })(this)); } return this._match(target); }; return Pattern; })(); module.exports = Pattern; }).call(this);