SamVerschueren/string-occurrence · index.js
javascript logo
function (input, search, opts) {
	if (typeof input !== 'string') {
		throw new TypeError('The input should be a string');
	}

	opts = opts || {caseInsensitive: true};

	var flags = 'g';

	if (opts.caseInsensitive === true) {
		flags += 'i';
	}

	return regexOccurrence(input, [].concat(search).map(function (search) {
		return new RegExp(escape(search), flags);
	}));
}
Similar code snippets
1.
angular-translate/translate-compile · prototypes.js
Match rating: 51.66% · See similar code snippets
javascript logo
function(searchStr, isCaseInsensitive) {
	var startIndex = 0,
		searchStrLen = searchStr.length;
	var index, indices = [];
	var str = this;
	if (isCaseInsensitive) {
		str = str.toLowerCase();
		searchStr = searchStr.toLowerCase();
	}
	while ((index = str.indexOf(searchStr, startIndex)) > -1) {
		indices.push(index);
		startIndex = index + searchStrLen;
	}
	return indices;
}
2.
altairstudios/nodeserver · jquery.dataTables.js
Match rating: 51.06% · See similar code snippets
javascript logo
function ( input, regex, smart, caseInsen ) {
		var ctx = this.context;
	
		if ( input === undefined ) {
			// get
			return ctx.length !== 0 ?
				ctx[0].oPreviousSearch.sSearch :
				undefined;
		}
	
		// set
		return this.iterator( 'table', function ( settings ) {
			if ( ! settings.oFeatures.bFilter ) {
				return;
			}
	
			_fnFilterComplete( settings, $.extend( {}, settings.oPreviousSearch, {
				"sSearch": input+"",
				"bRegex":  regex === null ? false : regex,
				"bSmart":  smart === null ? true  : smart,
				"bCaseInsensitive": caseInsen === null ? true : caseInsen
			} ), 1 );
		} );
	}
3.
pbakondy/android-device-list · index.js
Match rating: 47.61% · See similar code snippets
javascript logo
function getDevicesByModel ( model, options ) {
  if ( typeof model !== 'string' ) {
    throw new TypeError( '`model` parameter must be a string' );
  }
  options = options || {};
  let caseInsensitive = !!options.caseInsensitive;
  let contains = !!options.contains;

  return getDevices( model, 'model', caseInsensitive, contains );
}
4.
maxkueng/viewportsizes · index.js
Match rating: 47.26% · See similar code snippets
javascript logo
function list (search) {
	if (!search) {
		return sizes;
	}

	var regex = new RegExp(search, 'i');

	return sizes.filter(function (item) {
		return regex.test(item.fulltext)
	});
}
5.
aheckmann/regexp-clone · index.js
Match rating: 46.73% · See similar code snippets
javascript logo
function (regexp) {
  if (!isRegExp(regexp)) {
    throw new TypeError('Not a RegExp');
  }

  var flags = [];
  if (regexp.global) flags.push('g');
  if (regexp.multiline) flags.push('m');
  if (regexp.ignoreCase) flags.push('i');
  return new RegExp(regexp.source, flags.join(''));
}
6.
eclipse/orion.client · searchUtils.js
Match rating: 46.7% · See similar code snippets
javascript logo
function(searchParams) {
	if(searchParams.rows !== undefined){
		searchParams.rows = parseInt(searchParams.rows, 10);
	}
	if(searchParams.start !== undefined){
		searchParams.start = parseInt(searchParams.start, 10);
	}
	if(typeof searchParams.regEx === "string"){ //$NON-NLS-0$
		searchParams.regEx = (searchParams.regEx.toLowerCase() === "true"); //$NON-NLS-0$
	}
	if(typeof searchParams.caseSensitive === "string"){ //$NON-NLS-0$
		searchParams.caseSensitive = (searchParams.caseSensitive.toLowerCase() === "true"); //$NON-NLS-0$
	}
	if(typeof searchParams.nameSearch === "string"){ //$NON-NLS-0$
		searchParams.nameSearch = (searchParams.nameSearch.toLowerCase() === "true"); //$NON-NLS-0$
	}
	if(searchParams.fileNamePatterns !== undefined){
		searchParams.fileNamePatterns = searchUtils.getFileNamePatternsArray(searchParams.fileNamePatterns);
	}
}
7.
postmanlabs/postman-sandbox · sugar.js
Match rating: 45.82% · See similar code snippets
javascript logo
function(search, fn) {
      var match, i, len;
      if(isFunction(search)) {
        fn = search;
        search = /[\s\S]/g;
      } else if(!search) {
        search = /[\s\S]/g
      } else if(isString(search)) {
        search = regexp(escapeRegExp(search), 'gi');
      } else if(isRegExp(search)) {
        search = regexp(search.source, getRegExpFlags(search, 'g'));
      }
      match = this.match(search) || [];
      if(fn) {
        for(i = 0, len = match.length; i < len; i++) {
          match[i] = fn.call(this, match[i], i, match) || match[i];
        }
      }
      return match;
    }
8.
RallyTools/rally-node · ref.js
Match rating: 45.31% · See similar code snippets
javascript logo
function match(input) {
  input = (input && input._ref) ? input._ref : (input || '');
  const regexMatch = _.find(REF_REGEXES, regex => regex.test(input));
  return (regexMatch && input.match(regexMatch)) || null;
}
9.
joyent/kang · jquery.dataTables.js
Match rating: 45.12% · See similar code snippets
javascript logo
function( sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive )
		{
			var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
			
			if ( !oSettings.oFeatures.bFilter )
			{
				return;
			}
			
			if ( bRegex === undefined || bRegex === null )
			{
				bRegex = false;
			}
			
			if ( bSmart === undefined || bSmart === null )
			{
				bSmart = true;
			}
			
			if ( bShowGlobal === undefined || bShowGlobal === null )
			{
				bShowGlobal = true;
			}
			
			if ( bCaseInsensitive === undefined || bCaseInsensitive === null )
			{
				bCaseInsensitive = true;
			}
			
			if ( iColumn === undefined || iColumn === null )
			{
				/* Global filter */
				_fnFilterComplete( oSettings, {
					"sSearch":sInput+"",
					"bRegex": bRegex,
					"bSmart": bSmart,
					"bCaseInsensitive": bCaseInsensitive
				}, 1 );
				
				if ( bShowGlobal && oSettings.aanFeatures.f )
				{
					var n = oSettings.aanFeatures.f;
					for ( var i=0, iLen=n.length ; i<iLen ; i++ )
					{
						$(n[i]._DT_Input).val( sInput );
					}
				}
			}
			else
			{
				/* Single column filter */
				$.extend( oSettings.aoPreSearchCols[ iColumn ], {
					"sSearch": sInput+"",
					"bRegex": bRegex,
					"bSmart": bSmart,
					"bCaseInsensitive": bCaseInsensitive
				} );
				_fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
			}
		}
10.
kof/node-cjson · index.js
Match rating: 44.72% · See similar code snippets
javascript logo
function(match, search) {
        if (data.hasOwnProperty(search)) {
            // If the variable is an object, stringify it before replacement.
            // The false positive of "null" is fine in this case.
            if (typeof data[search] === 'object') {
                return JSON.stringify(data[search]);
            }
            return data[search];
        }
        return match;
    }