lib/object-types.js
function guessObjectType(obj, shortname=false) {
  var type
  if (typeof obj === "string" && obj) {
    if (obj in objectTypeUris) {
      // given by URI
      type = objectTypeUris[obj]
    } else {
      // given by name
      obj = obj.toLowerCase().replace(/s$/,"")
      type = Object.keys(objectTypes).find(name => {
        const lowercase = name.toLowerCase()
        if (lowercase === obj || lowercase === "concept" + obj) {
          return true
        }
      })
    }
  } else if (typeof obj === "object") {
    if (obj.type) {
      let types = Array.isArray(obj.type) ? obj.type : [obj.type]
      for (let uri of types) {
        if (uri in objectTypeUris) {
          type = objectTypeUris[uri]
          break
        }
      }
    }
  }
  return (shortname && type) ? type.toLowerCase().replace(/^concept(.+)/, "$1") : type
}
function guessObjectType(obj, shortname=false) {
  var type
  if (typeof obj === "string" && obj) {
    if (obj in objectTypeUris) {
      // given by URI
      type = objectTypeUris[obj]
    } else {
      // given by name
      obj = obj.toLowerCase().replace(/s$/,"")
      type = Object.keys(objectTypes).find(name => {
        const lowercase = name.toLowerCase()
        if (lowercase === obj || lowercase === "concept" + obj) {
          return true
        }
      })
    }
  } else if (typeof obj === "object") {
    if (obj.type) {
      let types = Array.isArray(obj.type) ? obj.type : [obj.type]
      for (let uri of types) {
        if (uri in objectTypeUris) {
          type = objectTypeUris[uri]
          break
        }
      }
    }
  }
  return (shortname && type) ? type.toLowerCase().replace(/^concept(.+)/, "$1") : type
}
function guessObjectType ( obj , shortname = false ) { var type if ( typeof obj === "string" && obj ) { if ( obj in objectTypeUris ) { // given by URI type = objectTypeUris [ obj ] } else { // given by name obj = obj . toLowerCase ( ) . replace ( / s$ / , "" ) type = Object . keys ( objectTypes ) . find ( name => { const lowercase = name . toLowerCase ( ) if ( lowercase === obj || lowercase === "concept" + obj ) { return true } } ) } } else if ( typeof obj === "object" ) { if ( obj . type ) { let types = Array . isArray ( obj . type ) ? obj . type : [ obj . type ] for ( let uri of types ) { if ( uri in objectTypeUris ) { type = objectTypeUris [ uri ] break } } } } return ( shortname && type ) ? type . toLowerCase ( ) . replace ( / ^concept(.+) / , "$1" ) : type }
Guess the JSKOS Concept Type name from an object or name.
@memberof module:jskos-tools
@param {object|string} jskos|name|uri object or string to guess from
@param {boolean} shortname return short name if enabled (false by default)
Guess the JSKOS Concept Type name from an object or name .