Added mocks for all model types, added CollectionDataService

This commit is contained in:
Art Lowel
2017-02-14 14:40:57 +01:00
parent c3214595ef
commit c8fb98760d
30 changed files with 1129 additions and 162 deletions

View File

@@ -0,0 +1,55 @@
import { isEmpty } from "../../shared/empty.util";
/**
* Combines a variable number of strings representing parts
* of a URL in to a single, normalized URL
*/
export class URLCombiner {
private parts: Array<string>;
/**
* Creates a new URLCombiner
*
* @param parts
* a variable number of strings representing parts of a URL
*/
constructor(...parts:Array<string>) {
// can't do this in the constructor signature,
// because of the spread operator
this.parts = parts;
}
/**
* Combines the parts of this URLCombiner in to a single,
* normalized URL
*
* e.g. new URLCombiner('http:/foo.com/', '/bar', 'id', '5').toString()
* returns: http://foo.com/bar/id/5
*
* @return {string}
* The combined URL
*/
toString(): string {
if (isEmpty(this.parts)) {
return '';
}
else {
let url = this.parts.join('/');
// make sure protocol is followed by two slashes
url = url.replace(/:\//g, '://');
// remove consecutive slashes
url = url.replace(/([^:\s])\/+/g, '$1/');
// remove trailing slash before parameters or hash
url = url.replace(/\/(\?|&|#[^!])/g, '$1');
// replace ? in parameters with &
url = url.replace(/(\?.+)\?/g, '$1&');
return url;
}
}
}