Skip to content

Commit

Permalink
URI to typescript linkeddata#355
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Nov 4, 2019
1 parent 4105764 commit 88e3f83
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 46 deletions.
61 changes: 49 additions & 12 deletions src/uri.js → src/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ var alert = alert || console.log

import NamedNode from './named-node'

export function docpart (uri) {
var i
/**
* Gets the document part of an URI
* @param uri The URI
*/
export function docpart(uri: string): string {
var i: number
i = uri.indexOf('#')
if (i < 0) {
return uri
Expand All @@ -22,11 +26,19 @@ export function docpart (uri) {
}
}

export function document (x) {
return new NamedNode(docpart(x.uri))
/**
* Gets the document part of an URI as a named node
* @param x - The URI
*/
export function document(x: string): NamedNode {
return new NamedNode(docpart(x))
}

export function hostpart (u) {
/**
* Gets the hostname in an URI
* @param u The URI
*/
export function hostpart(u: string): string {
var m = /[^\/]*\/\/([^\/]*)\//.exec(u)
if (m) {
return m[1]
Expand All @@ -35,7 +47,12 @@ export function hostpart (u) {
}
}

export function join (given, base) {
/**
* Joins an URI with a base
* @param given - The relative part
* @param base - The base URI
*/
export function join(given: string, base: string): string {
var baseColon, baseScheme, baseSingle
var colon, lastSlash, path
var baseHash = base.indexOf('#')
Expand Down Expand Up @@ -103,18 +120,38 @@ export function join (given, base) {
return base.slice(0, baseSingle) + path
}

export function protocol (uri) {
var i
i = uri.indexOf(':')
/**
* Gets the protocol part of an URI
* @param uri The URI
*/
export function protocol(uri: string): string | null {
const i = uri.indexOf(':')
if (i < 0) {
return null
} else {
return uri.slice(0, i)
}
}

export function refTo (base, uri) {
var c, i, k, l, len, len1, n, o, p, q, ref, ref1, s
/**
* Gets a relative uri
* @param base The base URI
* @param uri The absolute URI
*/
export function refTo(base: string, uri: string): string {
var c: string,
i: number,
k: number,
l: number,
len: number,
len1: number,
n: number,
o: number,
p: number,
q: number,
ref: string,
ref1: number,
s: string
var commonHost = new RegExp('^[-_a-zA-Z0-9.]+:(//[^/]*)?/[^/]*$')
if (!base) {
return uri
Expand All @@ -123,7 +160,7 @@ export function refTo (base, uri) {
return ''
}
for (i = o = 0, len = uri.length; o < len; i = ++o) {
c = uri[i]
const c = uri[i]
if (c !== base[i]) {
break
}
Expand Down
34 changes: 0 additions & 34 deletions types-temp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,6 @@ import { NamedNode } from './src';
// TypeScript Version: 3.0
// Acknowledgements: This work has been financed by Logilab SA, FRANCE, logilab.fr

export namespace uri {
/**
* Gets the document part of an URI
* @param uri The URI
*/
function docpart(uri: string): string;
/**
* Gets the document part of an URI as a named node
* @param x The URI
*/
function document(x: string): NamedNode;
/**
* Gets the hostname in an URI
* @param u The URI
*/
function hostpart(u: string): string;
/**
* Joins an URI with a base
* @param given The relative part
* @param base The base URI
*/
function join(given: string, base: string): string;
/**
* Gets the protocol part of an URI
* @param uri The URI
*/
function protocol(uri: string): string;
/**
* Gets a relative uri
* @param base The base URI
* @param uri The absolute URI
*/
function refTo(base: string, uri: string): string;
}
export namespace log {
/**
* Logs a debug event
Expand Down

0 comments on commit 88e3f83

Please sign in to comment.