How to use the core-util-is.isRegExp function in core-util-is

To help you get started, we’ve selected a few core-util-is examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github basicallydan / interfake / lib / route.js View on Github external
queryKeys.forEach(function (key) {
		var routeQueryValue = route.request.query[key];
		if (util.isRegExp(this.request.query[key])) {
			this.debug('4b. Testing', routeQueryValue, 'matches', this.request.query[key]);
			same = same && this.request.query[key].test(routeQueryValue);
			this.debug('4c. Result is', same);
		} else if (util.isArray(this.request.query[key])) {
			this.debug('4b. Testing', routeQueryValue, 'matches', this.request.query[key]);
			same = same && JSON.stringify(this.request.query[key].sort()) ===  JSON.stringify(routeQueryValue.sort());
			this.debug('4c. Result is', same);
		} else {
			// Not checking type because 1 and '1' are the same in this case
			this.debug('4b. Comparing', this.request.query[key], 'and', routeQueryValue);
			same = same && this.request.query[key] == routeQueryValue;
			this.debug('4c. Result is', same);
		}
	}.bind(this));
github krakenjs / meddleware / index.js View on Github external
function normalize(mountpath, route) {

    if (thing.isRegExp(route)) {
        // we cannot normalize regexes
        return route;
    }

    if (thing.isString(route)) {
        mountpath += mountpath[mountpath.length - 1] !== '/' ? '/' : '';
        mountpath += route[0] === '/' ? route.slice(1) : route;
    }

    return mountpath;
}
github basicallydan / interfake / lib / route.js View on Github external
Route.prototype.compare = function (route) {
	var queryKeys;
	var routeQueryKeys;
	var same = true;

	if (this.hasRegexpURL()) {
		this.debug('1. Testing', route.simpleHash(), 'matches', this.simpleHash());
		return this.request.url.test(route.request.url) && this.request.method.toLowerCase() === route.request.method.toLowerCase();
	} else if (route.simpleHash() !== this.simpleHash()) {
		this.debug('1. Comparing', route.simpleHash(), 'and', this.simpleHash());
		this.debug('No match');
		return false;
	}

	this.debug('2. Testing', route.request.url, 'matches', this.request.url);
	if (util.isRegExp(this.request.url)) {
		if (!this.request.url.test(route.request.url)) {
			this.debug('No match.');
			return false;
		}
	}

	queryKeys = this.queryKeys();
	routeQueryKeys = route.queryKeys();

	this.debug('3. Comparing', queryKeys.length, 'and', routeQueryKeys.length);
	if (queryKeys.length !== routeQueryKeys.length) {
		this.debug('No match');
		return false;
	}

	this.debug('4. Comparing', this.request.query, 'and', route.request.query);
github basicallydan / interfake / lib / route.js View on Github external
echo: false,
			headers: {}
		};
	} else {
		this.response = merge({
			delay: 0,
			code: 200,
			body: {},
			echo: false,
			headers: {}
		}, this.response);
	}

	this.response.query = {};

	if (!util.isRegExp(this.request.url) && util.isObject(this.request.url) && this.request.url.regexp) {
		this.debug('RegExp specified for URL', this.request.url.pattern);
		this.request.url = new RegExp(this.request.url.pattern);
	}

	if (util.isString(this.request.url)) {
		path = url.parse(this.request.url, true);
		this.request.url = path.pathname;
		this.setQueryStrings(path.query);
	}

	if (this.afterResponse && util.isArray(this.afterResponse.endpoints)) {
		this.afterResponse.endpoints = (this.afterResponse.endpoints || []).map(function (descriptor) {
			return new Route(descriptor);
		});
	}
github kaelzhang / skema / packages / basic / src / loose.js View on Github external
set (value) {
      if (isRegExp(value)) {
        return value
      }

      if (isString(value)) {
        return new RegExp(value)
      }

      throw new TypeError('not a regular expression')
    }
  }