@@ -75,14 +75,15 @@ Utils.empty = function(obj) {
7575}
7676
7777/**
78- * Generates a unique blank node id
78+ * Generates a unique node id
7979 */
80- Utils . genBNID = function ( ) {
80+ Utils . genBNID = function ( base ) {
81+ base = base || ""
8182 const r = Math . random ( )
8283 . toString ( 36 )
8384 . substring ( 7 )
8485 const d = new Date ( )
85- const bnid = `_: ${ r } ${ d . getTime ( ) } `
86+ const bnid = `doc: ${ base } ${ r } ${ d . getTime ( ) } `
8687 return bnid
8788}
8889
@@ -109,18 +110,16 @@ Utils.getShorthand = function(link) {
109110Utils . compareIDs = function ( ida , idb ) {
110111 if ( ida === idb ) return true
111112 if ( this . unshorten ( ida ) === idb ) return true
113+ if ( this . shorten ( ida ) === idb ) return true
112114 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
117115 return false
118116}
119117
120118/**
121119 * Shortens a URL to its compressed format - returns the full URL if not possible
122120 */
123121Utils . shorten = function ( url , prefixes ) {
122+ if ( ! url ) return url
124123 prefixes = prefixes || Utils . standard_urls
125124 for ( const pref in prefixes ) {
126125 if ( prefixes [ pref ] == url . substring ( 0 , prefixes [ pref ] . length ) ) {
@@ -134,6 +133,7 @@ Utils.shorten = function(url, prefixes) {
134133 * Expands a URL to its full URL format - returns the passed string if not possible to expand
135134 */
136135Utils . unshorten = function ( url ) {
136+ if ( ! url ) return url
137137 if ( this . validURL ( url ) ) return url
138138 if ( ! url ) return url
139139 const bits = url . split ( ':' )
@@ -150,6 +150,7 @@ Utils.unshorten = function(url) {
150150 * Valid URLs are those that start with http:// or https://
151151 */
152152Utils . validURL = function ( str ) {
153+ if ( str && typeof str != "string" ) str = "" + str
153154 if ( str && ( str . substring ( 0 , 7 ) === 'http://' || str . substring ( 0 , 8 ) === 'https://' ) )
154155 return true
155156 return false
0 commit comments