'use strict';

export interface IDataContractsHelper {
	versionEndpoint(endpoint: string, versionNumber: number): string;
}

class DataContractsHelper implements IDataContractsHelper {
	versionEndpoint(endpoint: string, versionNumber: number): string {
		let endpointFragments: string[] = endpoint.split('api');
		return endpointFragments.join('api/v' + versionNumber);
	}
}

export let helper: IDataContractsHelper = new DataContractsHelper();
'use strict';

export interface IDataContractsHelper {
	versionEndpoint(endpoint: string, versionNumber: number): string;
}

class DataContractsHelper implements IDataContractsHelper {
	versionEndpoint(endpoint: string, versionNumber: number): string {
		let versionExpression: RegEx = /v[0-9]+/;
		let endpointFragments: string[];

		let searchResult = endpoint.search(versionExpression);
		if (searchResult !== -1) {
			endpointFragments = endpoint.split(versionExpression);
		} else {
			endpointFragments = endpoint.split('api');
			endpointFragments[0] += 'api/';
		}

		return endpointFragments.join('v' + versionNumber);
	}
}

export let helper: IDataContractsHelper = new DataContractsHelper();
Use a regular expression to check for a previous version number. If one exists, replace it. Otherwise, add a new version immediately after 'api' in the url.
Use a regular expression to check for a previous version number. If one exists, replace it. Otherwise, add a new version immediately after 'api' in the url.
