How to use the can-connect/helpers/.sub function in can-connect

To help you get started, we’ve selected a few can-connect 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 canjs / can-connect / src / fixture / fixture.js View on Github external
// If the fixture setting is a string, we just change the URL of the
	// AJAX call to the fixture URL.
	if (typeof settings.fixture === "string") {
		var url = settings.fixture;

		// If the URL starts with //, we need to update the URL to become
		// the full path.
		if (/^\/\//.test(url)) {
			// this lets us use rootUrl w/o having steal...
			url = getUrl(settings.fixture.substr(2));
		}

		if (data) {
			// Template static fixture URLs
			url = helpers.sub(url, data);
		}

		delete settings.fixture;

		//!steal-remove-start
		log("looking for fixture in " + url);
		//!steal-remove-end

		// Override the AJAX settings, changing the URL to the fixture file,
		// removing the data, and changing the type to GET.
		settings.url = url;
		settings.data = null;
		settings.type = "GET";
		if (!settings.error) {
			// If no error handling is provided, we provide one and throw an
			// error.