Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jskos-tools

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jskos-tools - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

61

lib/object-types.js

@@ -18,11 +18,19 @@ const mappingTypes = require("./mapping-types.json")

ConceptOccurrence: {
type: ["http://purl.org/cld/cdtype/CatalogueOrIndex"]
type: [
"http://purl.org/cld/cdtype/CatalogueOrIndex"
]
},
Registry: {
Registry: {
type: [
"http://www.w3.org/ns/dcat#Catalog"
]
},
Distribution: {
type: [
"http://www.w3.org/ns/dcat#Distribution"
]
},
Concordance: {
type: [
"http://rdfs.org/ns/void#Linkset",
"http://rdfs.org/ns/void#Linkset",
"http://rdf-vocabulary.ddialliance.org/xkos#Correspondence"

@@ -32,3 +40,9 @@ ]

Resource: {},
Item: {}
Item: {},
Annotation: {
type: [
"Annotation",
"http://www.w3.org/ns/oa#Annotation"
]
}
}

@@ -40,3 +54,3 @@

map[uri] = name
}
}
return map

@@ -49,29 +63,34 @@ }, {})

* @param {object|string} jskos|name|uri object or string to guess from
* @param {boolean} shortname return short name if enabled (false by default)
*/
function guessObjectType(obj) {
function guessObjectType(obj, shortname=false) {
var type
if (typeof obj === "string" && obj) {
// given by URI
if (obj in objectTypeUris) {
return objectTypeUris[obj]
// 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
}
})
}
// given by name
obj = obj.toLowerCase().replace(/s$/,"")
return Object.keys(objectTypes).find(name => {
const lowercase = name.toLowerCase()
if (lowercase === obj || lowercase === "concept" + obj) {
return true
}
})
} else if (typeof obj === "object") {
const type = obj.type
if (type && Array.isArray(type)) {
for (let uri of type) {
if (obj.type) {
let types = Array.isArray(obj.type) ? obj.type : [obj.type]
for (let uri of types) {
if (uri in objectTypeUris) {
return objectTypeUris[uri]
type = objectTypeUris[uri]
break
}
}
}
}
}
return shortname ? type.toLowerCase().replace(/^concept(.+)/, "$1") : type
}
module.exports = { objectTypes, guessObjectType }
{
"name": "jskos-tools",
"version": "0.2.0",
"version": "0.2.1",
"description": "Tools for working with the JSKOS data format.",

@@ -17,4 +17,4 @@ "homepage": "https://github.com/gbv/jskos-tools",

"test": "mocha",
"lint": "eslint ./*.js ./**/*.js ./bin/*",
"fix": "eslint --fix ./*.js ./**/*.js ./bin/*",
"lint": "eslint ./*.js ./test/*.js ./lib/*.js ./bin/*",
"fix": "eslint --fix ./*.js ./test/*.js ./lib/*.js ./bin/*",
"lint-staged": "lint-staged",

@@ -46,2 +46,4 @@ "docs": "jsdoc --configure jsdoc.json && cp -r jsdoc/assets/* jsdoc/build"

"pre-commit": "^1.2.2",
"request": "^2.88.0",
"request-promise-core": "^1.1.2",
"request-promise-native": "^1.0.5",

@@ -48,0 +50,0 @@ "wikidata-sdk": "^5.15.10"

@@ -280,4 +280,9 @@ # JSKOS Tools

Guess the JSKOS object type of an object or string and return its name.
Guess the JSKOS object type of an object, URI or name and return its canonical name.
```js
type = guessObjectType(objectOrString) // get full name such as `ConceptScheme`
type = guessObjectType(objectOrString, true) // get short name such as `scheme`
```
## Build

@@ -284,0 +289,0 @@

@@ -6,9 +6,16 @@ const assert = require("assert")

it("objectTypes", () => {
assert.ok("ConceptScheme" in objectTypes)
assert.ok("ConceptScheme" in objectTypes)
})
it("guessObjectType (shortname)", () => {
for (let name in objectTypes) {
let shortName = name.toLowerCase().replace(/^concept(.+)/, "$1")
assert.equal(guessObjectType(name, true), shortName)
}
})
it("guessObjectType (string)", () => {
for (let name in objectTypes) {
assert.equal(guessObjectType(name), name)
assert.equal(guessObjectType(name.toLowerCase()), name)
assert.equal(guessObjectType(name), name)
assert.equal(guessObjectType(name.toLowerCase()), name)
}

@@ -24,4 +31,4 @@ assert.equal(guessObjectType("scheme"), "ConceptScheme")

const { type } = objectTypes[name]
for (let uri of (type || [])) {
let obj = { type: [uri] }
for (let uri of (type || [])) {
let obj = { type: name === "Annotation" ? uri : [uri] }
assert.equal(guessObjectType(obj), name)

@@ -28,0 +35,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc