matches.js
function pattern () {
    var targ0 = typeof arguments[0];
    var targ1 = typeof arguments[1];
    var targ2 = typeof arguments[2];
  
    // Shared vars
    var matcherFn, patternObj, patternFn, patternStr, successFn, chain, tree, last;
  
    // pattern(matcherFn, chain)
    if (targ0 == "function" && (targ1 == "undefined" || targ1 == "object")) { 
      matcherFn = arguments[0];
      chain = arguments[1];
  
      // Throw an error if the supplied function does not have a match chain.
      if (!matcherFn.__matchChain) throw new Error("Not a matcher function");
  
      // Splice the chains together.
      if (chain) {
        chain = chain.clone();
        chain.last().next = matcherFn.__matchChain.clone();
      } else {
        chain = matcherFn.__matchChain.clone();
      }
  
      last = chain.pop();
      return matcher(last.patternFn, last.successFn, chain);
    }
  
    // pattern(patternObj, chain)
    else if (targ0 == "object" && (targ1 == "undefined" || targ1 == "object")) {
      patternObj = arguments[0];
      chain = arguments[1] ? arguments[1].clone() : null;
      for (patternStr in patternObj) {
        matcherFn = pattern(patternStr, patternObj[patternStr], chain);
        chain = matcherFn.__matchChain;
      }
      return matcherFn;
    }
  
    // pattern(patternFn, successFn, chain)
    else if (targ0 == "function" && targ1 == "function") {
      chain = arguments[2] ? arguments[2].clone() : null;
      return matcher(arguments[0], arguments[1], chain);
    }
  
    // pattern(patternStr, successFn, chain)
    else {
      patternStr = arguments[0];
      successFn = arguments[1];
      chain = arguments[2] ? arguments[2].clone() : null;
      patternFn = getOrCompile(patternStr);
      return matcher(patternFn, successFn, chain);
    }
  }
function pattern () {
    var targ0 = typeof arguments[0];
    var targ1 = typeof arguments[1];
    var targ2 = typeof arguments[2];
  
    // Shared vars
    var matcherFn, patternObj, patternFn, patternStr, successFn, chain, tree, last;
  
    // pattern(matcherFn, chain)
    if (targ0 == "function" && (targ1 == "undefined" || targ1 == "object")) { 
      matcherFn = arguments[0];
      chain = arguments[1];
  
      // Throw an error if the supplied function does not have a match chain.
      if (!matcherFn.__matchChain) throw new Error("Not a matcher function");
  
      // Splice the chains together.
      if (chain) {
        chain = chain.clone();
        chain.last().next = matcherFn.__matchChain.clone();
      } else {
        chain = matcherFn.__matchChain.clone();
      }
  
      last = chain.pop();
      return matcher(last.patternFn, last.successFn, chain);
    }
  
    // pattern(patternObj, chain)
    else if (targ0 == "object" && (targ1 == "undefined" || targ1 == "object")) {
      patternObj = arguments[0];
      chain = arguments[1] ? arguments[1].clone() : null;
      for (patternStr in patternObj) {
        matcherFn = pattern(patternStr, patternObj[patternStr], chain);
        chain = matcherFn.__matchChain;
      }
      return matcherFn;
    }
  
    // pattern(patternFn, successFn, chain)
    else if (targ0 == "function" && targ1 == "function") {
      chain = arguments[2] ? arguments[2].clone() : null;
      return matcher(arguments[0], arguments[1], chain);
    }
  
    // pattern(patternStr, successFn, chain)
    else {
      patternStr = arguments[0];
      successFn = arguments[1];
      chain = arguments[2] ? arguments[2].clone() : null;
      patternFn = getOrCompile(patternStr);
      return matcher(patternFn, successFn, chain);
    }
  }
function pattern ( ) { var targ0 = typeof arguments [ 0 ] ; var targ1 = typeof arguments [ 1 ] ; var targ2 = typeof arguments [ 2 ] ; // Shared vars var matcherFn , patternObj , patternFn , patternStr , successFn , chain , tree , last ; // pattern(matcherFn, chain) if ( targ0 == "function" && ( targ1 == "undefined" || targ1 == "object" ) ) { matcherFn = arguments [ 0 ] ; chain = arguments [ 1 ] ; // Throw an error if the supplied function does not have a match chain. if ( ! matcherFn . __matchChain ) throw new Error ( "Not a matcher function" ) ; // Splice the chains together. if ( chain ) { chain = chain . clone ( ) ; chain . last ( ) . next = matcherFn . __matchChain . clone ( ) ; } else { chain = matcherFn . __matchChain . clone ( ) ; } last = chain . pop ( ) ; return matcher ( last . patternFn , last . successFn , chain ) ; } // pattern(patternObj, chain) else if ( targ0 == "object" && ( targ1 == "undefined" || targ1 == "object" ) ) { patternObj = arguments [ 0 ] ; chain = arguments [ 1 ] ? arguments [ 1 ] . clone ( ) : null ; for ( patternStr in patternObj ) { matcherFn = pattern ( patternStr , patternObj [ patternStr ] , chain ) ; chain = matcherFn . __matchChain ; } return matcherFn ; } // pattern(patternFn, successFn, chain) else if ( targ0 == "function" && targ1 == "function" ) { chain = arguments [ 2 ] ? arguments [ 2 ] . clone ( ) : null ; return matcher ( arguments [ 0 ] , arguments [ 1 ] , chain ) ; } // pattern(patternStr, successFn, chain) else { patternStr = arguments [ 0 ] ; successFn = arguments [ 1 ] ; chain = arguments [ 2 ] ? arguments [ 2 ] . clone ( ) : null ; patternFn = getOrCompile ( patternStr ) ; return matcher ( patternFn , successFn , chain ) ; } }
Creates a pattern matching function given a string and a fn to execute. The `chain` argument is for internal use only. It's a reference to the chain that we are adding a pattern to.
Creates a pattern matching function given a string and a fn to execute . The chain argument is for internal use only . It s a reference to the chain that we are adding a pattern to .