Sha256: 3f3645879232f30c27cd670cebfa198a99a46851db1629f725277229c19ad4cd

Contents?: true

Size: 1008 Bytes

Versions: 39

Compression:

Stored size: 1008 Bytes

Contents

var utils = require('../utils')
  , nodes = require('../nodes');

var VALID_FLAGS = 'igm';

/**
 * retrieves the matches when matching a `val`(string)
 * against a `pattern`(regular expression).
 *
 * Examples:
 *   $regex = '^(height|width)?([<>=]{1,})(.*)'
 *
 *   match($regex,'height>=sm')
 * 	 // => ('height>=sm' 'height' '>=' 'sm')
 * 	 // => also truthy
 *
 *   match($regex, 'lorem ipsum')
 *   // => null
 *
 * @param {String} pattern
 * @param {String|Ident} val
 * @param {String|Ident} [flags='']
 * @return {String|Null}
 * @api public
 */

module.exports = function match(pattern, val, flags){
  utils.assertType(pattern, 'string', 'pattern');
  utils.assertString(val, 'val');
  var re = new RegExp(pattern.val, validateFlags(flags) ? flags.string : '');
  return val.string.match(re);
};

function validateFlags(flags) {
  flags = flags && flags.string;

  if (flags) {
    return flags.split('').every(function(flag) {
      return ~VALID_FLAGS.indexOf(flag);
    });
  }
  return false;
}

Version data entries

39 entries across 20 versions & 2 rubygems

Version Path
ela-4.1.6 node_modules/stylus/lib/functions/match.js
ela-4.1.6 node_modules/nib/node_modules/stylus/lib/functions/match.js
ela-4.1.5 node_modules/stylus/lib/functions/match.js
ela-4.1.5 node_modules/nib/node_modules/stylus/lib/functions/match.js
ela-4.1.4 node_modules/nib/node_modules/stylus/lib/functions/match.js
ela-4.1.4 node_modules/stylus/lib/functions/match.js
ela-4.1.3 node_modules/stylus/lib/functions/match.js
ela-4.1.3 node_modules/nib/node_modules/stylus/lib/functions/match.js
ela-4.1.2 node_modules/stylus/lib/functions/match.js
ela-4.1.2 node_modules/nib/node_modules/stylus/lib/functions/match.js
ela-4.1.1 node_modules/stylus/lib/functions/match.js
ela-4.1.1 node_modules/nib/node_modules/stylus/lib/functions/match.js
ela-4.1.0 node_modules/stylus/lib/functions/match.js
ela-4.1.0 node_modules/nib/node_modules/stylus/lib/functions/match.js
ela-4.0.0 node_modules/stylus/lib/functions/match.js
ela-4.0.0 node_modules/nib/node_modules/stylus/lib/functions/match.js
ela-3.4.3 node_modules/stylus/lib/functions/match.js
ela-3.4.3 node_modules/nib/node_modules/stylus/lib/functions/match.js
ela-3.4.2 node_modules/nib/node_modules/stylus/lib/functions/match.js
ela-3.4.2 node_modules/stylus/lib/functions/match.js