tokenize-markdown.js
function isTokenValid( token ) {
    /**
     * Reducer function to check token validity: start the token out as valid,
     * then reduce through the provided filter parameters, updating the validity
     * of the token after checking each value.
     *
     * @param  {Boolean}       valid       Reducer function memo value
     * @param  {String|RegExp} targetValue The expected value of the specified property
     *                                     on this token, or else a RegExp against which
     *                                     to test that property
     * @param  {String}        key         The key within the token to test
     * @return {Boolean}                   Whether the token is still valid, after
     *                                     validating the provided key
     */
    function checkTokenParam( valid, targetValue, key ) {
      // Once invalid, always invalid: fast-fail in this case
      if ( ! valid ) {
        return false;
      }

      // Without a target value, filtering doesn't mean much: move along
      if ( typeof targetValue === 'undefined' ) {
        return true;
      }

      var tokenPropToTest = token[ key ];

      if ( isRegExp( targetValue ) ) {
        // Special-case if the target value is a RegExp
        return targetValue.test( tokenPropToTest );
      }

      return tokenPropToTest === targetValue;
    }

    // Check each property on this token against the provided params
    return reduce( filterParams, checkTokenParam, true );
  }
function isTokenValid( token ) {
    /**
     * Reducer function to check token validity: start the token out as valid,
     * then reduce through the provided filter parameters, updating the validity
     * of the token after checking each value.
     *
     * @param  {Boolean}       valid       Reducer function memo value
     * @param  {String|RegExp} targetValue The expected value of the specified property
     *                                     on this token, or else a RegExp against which
     *                                     to test that property
     * @param  {String}        key         The key within the token to test
     * @return {Boolean}                   Whether the token is still valid, after
     *                                     validating the provided key
     */
    function checkTokenParam( valid, targetValue, key ) {
      // Once invalid, always invalid: fast-fail in this case
      if ( ! valid ) {
        return false;
      }

      // Without a target value, filtering doesn't mean much: move along
      if ( typeof targetValue === 'undefined' ) {
        return true;
      }

      var tokenPropToTest = token[ key ];

      if ( isRegExp( targetValue ) ) {
        // Special-case if the target value is a RegExp
        return targetValue.test( tokenPropToTest );
      }

      return tokenPropToTest === targetValue;
    }

    // Check each property on this token against the provided params
    return reduce( filterParams, checkTokenParam, true );
  }
function isTokenValid ( token ) { /**
     * Reducer function to check token validity: start the token out as valid,
     * then reduce through the provided filter parameters, updating the validity
     * of the token after checking each value.
     *
     * @param  {Boolean}       valid       Reducer function memo value
     * @param  {String|RegExp} targetValue The expected value of the specified property
     *                                     on this token, or else a RegExp against which
     *                                     to test that property
     * @param  {String}        key         The key within the token to test
     * @return {Boolean}                   Whether the token is still valid, after
     *                                     validating the provided key
     */ function checkTokenParam ( valid , targetValue , key ) { // Once invalid, always invalid: fast-fail in this case if ( ! valid ) { return false ; } // Without a target value, filtering doesn't mean much: move along if ( typeof targetValue === 'undefined' ) { return true ; } var tokenPropToTest = token [ key ] ; if ( isRegExp ( targetValue ) ) { // Special-case if the target value is a RegExp return targetValue . test ( tokenPropToTest ) ; } return tokenPropToTest === targetValue ; } // Check each property on this token against the provided params return reduce ( filterParams , checkTokenParam , true ) ; }
Filter method to check whether a token is valid, based on the provided
object of filter parameters

If the filter object defines a RegExp for a key, test the token's property
against that RegExp; otherwise, do a strict equality check between the
provided value and the token's value for a given key.

@param  {Object} token A token object
@return {Boolean}      Whether the provided token object is valid
Filter method to check whether a token is valid based on the provided object of filter parameters