ndef-lib/ndef-uri.js
function encode(uri) {
    
    var prefix,
        protocolCode,
        encoded;

    // check each protocol, unless we've found a match
    // "urn:" is the one exception where we need to keep checking
    // slice so we don't check ""
    protocols.slice(1).forEach(function(protocol) {                        
        if ((!prefix || prefix === "urn:") && uri.indexOf(protocol) === 0) { 
            prefix = protocol;
        }
    });

    if (!prefix) {
        prefix = "";
    }
    
    encoded = util.stringToBytes(uri.slice(prefix.length));
    protocolCode = protocols.indexOf(prefix);    
    // prepend protocol code
    encoded.unshift(protocolCode);
    
    return encoded; 
}
function encode(uri) {
    
    var prefix,
        protocolCode,
        encoded;

    // check each protocol, unless we've found a match
    // "urn:" is the one exception where we need to keep checking
    // slice so we don't check ""
    protocols.slice(1).forEach(function(protocol) {                        
        if ((!prefix || prefix === "urn:") && uri.indexOf(protocol) === 0) { 
            prefix = protocol;
        }
    });

    if (!prefix) {
        prefix = "";
    }
    
    encoded = util.stringToBytes(uri.slice(prefix.length));
    protocolCode = protocols.indexOf(prefix);    
    // prepend protocol code
    encoded.unshift(protocolCode);
    
    return encoded; 
}
function encode ( uri ) { var prefix , protocolCode , encoded ; // check each protocol, unless we've found a match // "urn:" is the one exception where we need to keep checking // slice so we don't check "" protocols . slice ( 1 ) . forEach ( function ( protocol ) { if ( ( ! prefix || prefix === "urn:" ) && uri . indexOf ( protocol ) === 0 ) { prefix = protocol ; } } ) ; if ( ! prefix ) { prefix = "" ; } encoded = util . stringToBytes ( uri . slice ( prefix . length ) ) ; protocolCode = protocols . indexOf ( prefix ) ; // prepend protocol code encoded . unshift ( protocolCode ) ; return encoded ; }
shorten a URI with standard prefix @returns an array of bytes
shorten a URI with standard prefix