@@ -75,14 +75,15 @@ Utils.empty = function(obj) {
75
75
}
76
76
77
77
/**
78
- * Generates a unique blank node id
78
+ * Generates a unique node id
79
79
*/
80
- Utils . genBNID = function ( ) {
80
+ Utils . genBNID = function ( base ) {
81
+ base = base || ""
81
82
const r = Math . random ( )
82
83
. toString ( 36 )
83
84
. substring ( 7 )
84
85
const d = new Date ( )
85
- const bnid = `_: ${ r } ${ d . getTime ( ) } `
86
+ const bnid = `doc: ${ base } ${ r } ${ d . getTime ( ) } `
86
87
return bnid
87
88
}
88
89
@@ -109,18 +110,16 @@ Utils.getShorthand = function(link) {
109
110
Utils . compareIDs = function ( ida , idb ) {
110
111
if ( ida === idb ) return true
111
112
if ( this . unshorten ( ida ) === idb ) return true
113
+ if ( this . shorten ( ida ) === idb ) return true
112
114
if ( this . unshorten ( ida ) === this . unshorten ( idb ) ) return true
113
- const sha = this . getShorthand ( ida )
114
- const shb = this . getShorthand ( idb )
115
- if ( sha && ( sha === idb || sha === shb ) ) return true
116
- if ( shb && shb === ida ) return true
117
115
return false
118
116
}
119
117
120
118
/**
121
119
* Shortens a URL to its compressed format - returns the full URL if not possible
122
120
*/
123
121
Utils . shorten = function ( url , prefixes ) {
122
+ if ( ! url ) return url
124
123
prefixes = prefixes || Utils . standard_urls
125
124
for ( const pref in prefixes ) {
126
125
if ( prefixes [ pref ] == url . substring ( 0 , prefixes [ pref ] . length ) ) {
@@ -134,6 +133,7 @@ Utils.shorten = function(url, prefixes) {
134
133
* Expands a URL to its full URL format - returns the passed string if not possible to expand
135
134
*/
136
135
Utils . unshorten = function ( url ) {
136
+ if ( ! url ) return url
137
137
if ( this . validURL ( url ) ) return url
138
138
if ( ! url ) return url
139
139
const bits = url . split ( ':' )
@@ -150,6 +150,7 @@ Utils.unshorten = function(url) {
150
150
* Valid URLs are those that start with http:// or https://
151
151
*/
152
152
Utils . validURL = function ( str ) {
153
+ if ( str && typeof str != "string" ) str = "" + str
153
154
if ( str && ( str . substring ( 0 , 7 ) === 'http://' || str . substring ( 0 , 8 ) === 'https://' ) )
154
155
return true
155
156
return false
0 commit comments