From 4c960b46b3a841bccf7c26b3d575ea45cb97172f Mon Sep 17 00:00:00 2001 From: Brian Surowiec Date: Fri, 24 Apr 2015 22:20:21 -0400 Subject: [PATCH 1/5] Move to uri namespace --- urijs/URI-tests.ts | 16 ++ urijs/URI.d.ts | 377 +++++++++++++++++++++++++-------------------- 2 files changed, 222 insertions(+), 171 deletions(-) create mode 100644 urijs/URI-tests.ts diff --git a/urijs/URI-tests.ts b/urijs/URI-tests.ts new file mode 100644 index 000000000..4ab69219e --- /dev/null +++ b/urijs/URI-tests.ts @@ -0,0 +1,16 @@ +/// + +new URI(); +new URI('http://user:pass@example.org:80/foo/bar.html?foo=bar&bar=baz#frag'); +new URI({ + protocol: 'http', + username: 'user', + password: 'pass', + hostname: 'example.org', + port: '80', + path: '/foo/bar.html', + query: 'foo=bar&bar=baz', + fragment: 'frag' +}); + +var uri: uri.URI = $('a').uri(); diff --git a/urijs/URI.d.ts b/urijs/URI.d.ts index 448365762..2f40b1a46 100644 --- a/urijs/URI.d.ts +++ b/urijs/URI.d.ts @@ -1,186 +1,221 @@ // Type definitions for URI.js // Project: https://github.com/medialize/URI.js -// Definitions by: RodneyJT +// Definitions by: RodneyJT , Brian Surowiec // Definitions: https://github.com/borisyankov/DefinitelyTyped /// -interface URIOptions { - protocol?: string; - username?: string; - password?: string; - hostname?: string; - port?: string; - path?: string; - query?: string; - fragment?: string; -} +declare module uri { -declare class URI { - constructor(); - constructor(uri: string); - constructor(options: URIOptions); - clone(): URI; - href(): string; - href(url: string): void; - valueOf(): string; - scheme(): string; - protocol(): string; - scheme(protocol: string): URI; - protocol(protocol: string): URI; - username(): string; - username(uname: string): URI; - password(): string; - password(pw: string): URI; - port(): string; - port(port: string): URI; - hostname(): string; - hostname(hostname: string): URI; - host(): string; - host(host: string): URI; - userinfo(): string; - userinfo(userinfo: string): URI; - authority(): string; - authority(authority: string): URI; - domain(): string; - domain(domain: boolean): string; - domain(domain: string): URI; - subdomain(): string; - subdomain(subdomain: string): URI; - tld(): string; - tld(tld: boolean): string; - tld(tld: string): URI; - path(): string; - path(path: boolean): string; - path(path: string): URI; - pathname(): string; - pathname(path: boolean): string; - pathname(path: string): URI; - directory(): string; - directory(dir: boolean): string; - directory(dir: string): URI; - filename(): string; - filename(file: boolean): string; - filename(file: string): URI; - suffix(): string; - suffix(suffix: boolean): string; - suffix(suffix: string): URI; - segment(): string[]; - segment(segments: string[]): string; - segment(position: number): string; - segment(position: number, level: string): string; - segment(level: string): string; - search(): string; - search(qry: string): URI; - search(qry: boolean): any; - search(qry: Object): URI; - query(): string; - query(qry: string): URI; - query(qry: boolean): Object; - query(qry: Object): URI; - hash(): string; - hash(hash: string): URI; - fragment(): string; - fragment(fragment: string): URI; - resource(): string; - resource(resource: string): URI; - is(qry: string): boolean; - addSearch(qry: string): URI; - addSearch(qry: Object): URI; - addQuery(qry: string): URI; - addQuery(qry: Object): URI; - removeSearch(qry: string): URI; - removeSearch(qry: Object): URI; - removeQuery(qry: string): URI; - removeQuery(qry: Object): URI; - addFragment(fragment: string): URI; - //fragmentPrefix: string; - fragmentPrefix(prefix: string): URI; - normalize(): URI; - normalizeProtocol(): URI; - normalizeHostname(): URI; - normalizePort(): URI; - normalizePathname(): URI; - normalizePath(): URI; - normalizeSearch(): URI; - normalizeQuery(): URI; - normalizeHash(): URI; - normalizeFragment(): URI; - iso8859(): URI; - unicode(): URI; - readable(): string; - relativeTo(path: string): URI; - absoluteTo(path: string): URI; - equals(): boolean; - equals(url: string): boolean; - static parse(url: string): { - protocol: string; - username: string; - password: string; - hostname: string; - port: string; - path: string; - query: string; - fragment: string; - }; - static parseAuthority(url: string, parts: { + interface URI { + absoluteTo(path: string): URI; + addFragment(fragment: string): URI; + addQuery(qry: string): URI; + addQuery(qry: Object): URI; + addSearch(qry: string): URI; + addSearch(qry: Object): URI; + authority(): string; + authority(authority: string): URI; + + clone(): URI; + + directory(): string; + directory(dir: boolean): string; + directory(dir: string): URI; + domain(): string; + domain(domain: boolean): string; + domain(domain: string): URI; + + equals(): boolean; + equals(url: string): boolean; + + filename(): string; + filename(file: boolean): string; + filename(file: string): URI; + fragment(): string; + fragment(fragment: string): URI; + fragmentPrefix(prefix: string): URI; + + hash(): string; + hash(hash: string): URI; + host(): string; + host(host: string): URI; + hostname(): string; + hostname(hostname: string): URI; + href(): string; + href(url: string): void; + + is(qry: string): boolean; + iso8859(): URI; + + normalize(): URI; + normalizeFragment(): URI; + normalizeHash(): URI; + normalizeHostname(): URI; + normalizePath(): URI; + normalizePathname(): URI; + normalizePort(): URI; + normalizeProtocol(): URI; + normalizeQuery(): URI; + normalizeSearch(): URI; + + password(): string; + password(pw: string): URI; + path(): string; + path(path: boolean): string; + path(path: string): URI; + pathname(): string; + pathname(path: boolean): string; + pathname(path: string): URI; + port(): string; + port(port: string): URI; + protocol(): string; + protocol(protocol: string): URI; + + query(): string; + query(qry: string): URI; + query(qry: boolean): Object; + query(qry: Object): URI; + + readable(): string; + relativeTo(path: string): URI; + removeQuery(qry: string): URI; + removeQuery(qry: Object): URI; + removeSearch(qry: string): URI; + removeSearch(qry: Object): URI; + resource(): string; + resource(resource: string): URI; + + scheme(): string; + scheme(protocol: string): URI; + search(): string; + search(qry: string): URI; + search(qry: boolean): any; + search(qry: Object): URI; + segment(): string[]; + segment(segments: string[]): string; + segment(position: number): string; + segment(position: number, level: string): string; + segment(level: string): string; + subdomain(): string; + subdomain(subdomain: string): URI; + suffix(): string; + suffix(suffix: boolean): string; + suffix(suffix: string): URI; + + tld(): string; + tld(tld: boolean): string; + tld(tld: string): URI; + + unicode(): URI; + userinfo(): string; + userinfo(userinfo: string): URI; + username(): string; + username(uname: string): URI; + + valueOf(): string; + } + + interface URIOptions { + protocol?: string; username?: string; password?: string; hostname?: string; port?: string; - }): string; - static parseUserinfo(url: string, parts: { - username?: string; - password?: string; - }): string; - static parseHost(url: string, parts: { - hostname?: string; - port?: string; - }): string; - static parseQuery(url: string): Object; - static build(parts: { - protocol: string; - username: string; - password: string; - hostname: string; - port: string; - path: string; - query: string; - fragment: string; - }): string; - static buildAuthority(parts: { - username?: string; - password?: string; - hostname?: string; - port?: string; - }): string; - static buildUserinfo(parts: { - username?: string; - password?: string; - }): string; - static buildHost(parts: { - hostname?: string; - port?: string; - }): string; - static buildQuery(qry: Object): string; - static buildQuery(qry: Object, duplicates: boolean): string; - static encode(str: string): string; - static decode(str: string): string; - static encodeReserved(str: string): string; - static encodeQuery(qry: string): string; - static decodeQuery(qry: string): string; - static addQuery(data: Object, prop: string, value: string): Object; - static addQuery(data: Object, qryObj: Object): Object; - static removeQuery(data: Object, prop: string, value: string): Object; - static removeQuery(data: Object, props: string[]): Object; - static removeQuery(data: Object, props: Object): Object; - static commonPath(path1: string, path2: string): string; - static withinString(source: string, func: (url: string) => string): string; - static iso8859(): void; - static unicode(): void; - static expand(template: string, vals: Object): URI; + path?: string; + query?: string; + fragment?: string; + } + + interface URIStatic { + new (): URI; + new (value: string | URIOptions): URI; + + addQuery(data: Object, prop: string, value: string): Object; + addQuery(data: Object, qryObj: Object): Object; + + build(parts: { + protocol: string; + username: string; + password: string; + hostname: string; + port: string; + path: string; + query: string; + fragment: string; + }): string; + buildAuthority(parts: { + username?: string; + password?: string; + hostname?: string; + port?: string; + }): string; + buildHost(parts: { + hostname?: string; + port?: string; + }): string; + buildQuery(qry: Object): string; + buildQuery(qry: Object, duplicates: boolean): string; + buildUserinfo(parts: { + username?: string; + password?: string; + }): string; + + commonPath(path1: string, path2: string): string; + + decode(str: string): string; + decodeQuery(qry: string): string; + + encode(str: string): string; + encodeQuery(qry: string): string; + encodeReserved(str: string): string; + expand(template: string, vals: Object): URI; + + iso8859(): void; + + parse(url: string): { + protocol: string; + username: string; + password: string; + hostname: string; + port: string; + path: string; + query: string; + fragment: string; + }; + parseAuthority(url: string, parts: { + username?: string; + password?: string; + hostname?: string; + port?: string; + }): string; + parseHost(url: string, parts: { + hostname?: string; + port?: string; + }): string; + parseQuery(url: string): Object; + parseUserinfo(url: string, parts: { + username?: string; + password?: string; + }): string; + + removeQuery(data: Object, prop: string, value: string): Object; + removeQuery(data: Object, props: string[]): Object; + removeQuery(data: Object, props: Object): Object; + + unicode(): void; + + withinString(source: string, func: (url: string) => string): string; + } + } interface JQuery { - uri(): URI; + uri(): uri.URI; +} + +declare var URI: uri.URIStatic; + +declare module 'URI' { + export = URI; } From 74eeac855c6e93bc6a780700cc06ba0b5059ae0a Mon Sep 17 00:00:00 2001 From: Brian Surowiec Date: Fri, 24 Apr 2015 22:21:50 -0400 Subject: [PATCH 2/5] Add support for URI() --- urijs/URI-tests.ts | 13 +++++++++++++ urijs/URI.d.ts | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/urijs/URI-tests.ts b/urijs/URI-tests.ts index 4ab69219e..75e999140 100644 --- a/urijs/URI-tests.ts +++ b/urijs/URI-tests.ts @@ -1,5 +1,18 @@ /// +URI(); +URI('http://user:pass@example.org:80/foo/bar.html?foo=bar&bar=baz#frag'); +URI({ + protocol: 'http', + username: 'user', + password: 'pass', + hostname: 'example.org', + port: '80', + path: '/foo/bar.html', + query: 'foo=bar&bar=baz', + fragment: 'frag' +}); + new URI(); new URI('http://user:pass@example.org:80/foo/bar.html?foo=bar&bar=baz#frag'); new URI({ diff --git a/urijs/URI.d.ts b/urijs/URI.d.ts index 2f40b1a46..b140df400 100644 --- a/urijs/URI.d.ts +++ b/urijs/URI.d.ts @@ -1,4 +1,4 @@ -// Type definitions for URI.js +// Type definitions for URI.js 1.15.1 // Project: https://github.com/medialize/URI.js // Definitions by: RodneyJT , Brian Surowiec // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -128,6 +128,9 @@ declare module uri { } interface URIStatic { + (): URI; + (value: string | URIOptions): URI; + new (): URI; new (value: string | URIOptions): URI; From e15a4e3df3674496cc08f17cb97b0b8ac9af65aa Mon Sep 17 00:00:00 2001 From: Brian Surowiec Date: Fri, 24 Apr 2015 23:29:27 -0400 Subject: [PATCH 3/5] Add setQuery and setSearch methods --- urijs/URI-tests.ts | 5 +++++ urijs/URI.d.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/urijs/URI-tests.ts b/urijs/URI-tests.ts index 75e999140..0c5efc8c7 100644 --- a/urijs/URI-tests.ts +++ b/urijs/URI-tests.ts @@ -26,4 +26,9 @@ new URI({ fragment: 'frag' }); +URI('').setQuery('foo', 'bar'); +URI('').setQuery({ foo: 'bar' }); +URI('').setSearch('foo', 'bar'); +URI('').setSearch({ foo: 'bar' }); + var uri: uri.URI = $('a').uri(); diff --git a/urijs/URI.d.ts b/urijs/URI.d.ts index b140df400..f745c6164 100644 --- a/urijs/URI.d.ts +++ b/urijs/URI.d.ts @@ -97,6 +97,10 @@ declare module uri { segment(position: number): string; segment(position: number, level: string): string; segment(level: string): string; + setQuery(key: string, value: string): URI; + setQuery(qry: Object): URI; + setSearch(key: string, value: string): URI; + setSearch(qry: Object): URI; subdomain(): string; subdomain(subdomain: string): URI; suffix(): string; From ab3cc6e0e0c362472527c174c2e7c1f6e21968c1 Mon Sep 17 00:00:00 2001 From: Brian Surowiec Date: Fri, 24 Apr 2015 23:30:16 -0400 Subject: [PATCH 4/5] Add html element constructors --- urijs/URI-tests.ts | 2 ++ urijs/URI.d.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/urijs/URI-tests.ts b/urijs/URI-tests.ts index 0c5efc8c7..2ccd29d9c 100644 --- a/urijs/URI-tests.ts +++ b/urijs/URI-tests.ts @@ -12,6 +12,7 @@ URI({ query: 'foo=bar&bar=baz', fragment: 'frag' }); +URI(document.createElement('a')); new URI(); new URI('http://user:pass@example.org:80/foo/bar.html?foo=bar&bar=baz#frag'); @@ -25,6 +26,7 @@ new URI({ query: 'foo=bar&bar=baz', fragment: 'frag' }); +new URI(document.createElement('a')); URI('').setQuery('foo', 'bar'); URI('').setQuery({ foo: 'bar' }); diff --git a/urijs/URI.d.ts b/urijs/URI.d.ts index f745c6164..b59dad6aa 100644 --- a/urijs/URI.d.ts +++ b/urijs/URI.d.ts @@ -133,10 +133,10 @@ declare module uri { interface URIStatic { (): URI; - (value: string | URIOptions): URI; + (value: string | URIOptions | HTMLElement): URI; new (): URI; - new (value: string | URIOptions): URI; + new (value: string | URIOptions | HTMLElement): URI; addQuery(data: Object, prop: string, value: string): Object; addQuery(data: Object, qryObj: Object): Object; From 6c7eba43d4560122032c8504450725645f38832a Mon Sep 17 00:00:00 2001 From: Brian Surowiec Date: Mon, 25 May 2015 15:28:02 -0400 Subject: [PATCH 5/5] Rename files to match project name --- urijs/{URI-tests.ts => URIjs-tests.ts} | 2 +- urijs/{URI.d.ts => URIjs.d.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename urijs/{URI-tests.ts => URIjs-tests.ts} (95%) rename urijs/{URI.d.ts => URIjs.d.ts} (100%) diff --git a/urijs/URI-tests.ts b/urijs/URIjs-tests.ts similarity index 95% rename from urijs/URI-tests.ts rename to urijs/URIjs-tests.ts index 2ccd29d9c..2dfd15618 100644 --- a/urijs/URI-tests.ts +++ b/urijs/URIjs-tests.ts @@ -1,4 +1,4 @@ -/// +/// URI(); URI('http://user:pass@example.org:80/foo/bar.html?foo=bar&bar=baz#frag'); diff --git a/urijs/URI.d.ts b/urijs/URIjs.d.ts similarity index 100% rename from urijs/URI.d.ts rename to urijs/URIjs.d.ts