data/import.js
/**
 * If the argument is scalar does nothing. Otherwise (object or array), walks it
 * finds references that begin with "urn:uuid:" and replaces them with the
 * corresponding value from URN_MAP. This is recursive.
 * @throws {Error} If a reference is not found in URN_MAP
 * @returns void
 * @param {*} obj The variable to try to translate
 */
If the argument is scalar does nothing. Otherwise (object or array), walks it
finds references that begin with "urn:uuid:" and replaces them with the
corresponding value from URN_MAP. This is recursive.
@throws {Error} If a reference is not found in URN_MAP
@returns void
@param {*} obj The variable to try to translate
If the argument is scalar does nothing . Otherwise ( object or array ) walks it finds references that begin with " urn : uuid : " and replaces them with the corresponding value from URN_MAP . This is recursive . @throws { Error } If a reference is not found in URN_MAP @returns void @param { * } obj The variable to try to translate
function fixReferences(obj)
{    
    if (Array.isArray(obj)) {
        return obj.every(fixReferences);
    }
    if (obj && typeof obj == "object") {
        for (let key in obj) {
            if (key == "reference") {
                let ref = obj[key];
                if (ref.indexOf("urn:uuid:") === 0) {
                    let newRef = URN_MAP[ref];
                    if (!newRef) {
                        throw new Error(`Cannot find a reference for "${ref}".`);
                    }
                    obj[key] = newRef;
                }
            }
            else {
                fixReferences(obj[key]);
            }
        }
    }
}
function fixReferences ( obj ) { if ( Array . isArray ( obj ) ) { return obj . every ( fixReferences ) ; } if ( obj && typeof obj == "object" ) { for ( let key in obj ) { if ( key == "reference" ) { let ref = obj [ key ] ; if ( ref . indexOf ( "urn:uuid:" ) === 0 ) { let newRef = URN_MAP [ ref ] ; if ( ! newRef ) { throw new Error ( ` ${ ref } ` ) ; } obj [ key ] = newRef ; } } else { fixReferences ( obj [ key ] ) ; } } } }
If the argument is scalar does nothing.
If the argument is scalar does nothing .
// if array just dive into it (it cannot have references anyway)