npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@openactive/skos

v1.4.3

Published

Simple JavaScript library to wrap the OpenActive JSON-LD representation of SKOS.

Downloads

1,599

Readme

npm version Build Status Coverage Status

SKOS.js

Simple JavaScript library to wrap the OpenActive JSON-LD representation of SKOS.

Compatible Platforms and Browsers

SKOS.js will run on any version of Node.js, and is built to use CommonJS so can be built with Webpack and Browserify.

SKOS.js has been tested on IE 9 and above without transpilation or polyfills, and all other major browsers.

Installation

Dependencies

SKOS.js does not have any runtime dependencies. It is written natively in ES5.

As a library

Simply install using npm:

$ npm install @openactive/skos --save

Now you can begin using it on either the client or server side.

var skos = require('@openactive/skos');

// returns an array of the names of all types of Yoga
var response = request('GET', 'https://openactive.io/activity-list', { headers: { accept: 'application/ld+json' } });
if (response && response.statusCode == 200) {
  var activityListJsonObject = JSON.parse(response.getBody('utf8'));

  var scheme = new skos.ConceptScheme(activityListJsonObject);
  return scheme.getConceptByLabel('Yoga').getBroaderTransitive().map(concept => concept.prefLabel);
}

In the browser

See the live demo.

<script src="https://code.jquery.com/jquery-3.3.1.min.js" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/@openactive/skos/dist/skos.min.js" type="text/javascript"></script>
<script type="text/javascript">
  $.getJSON('https://openactive.io/activity-list/activity-list.jsonld', function(activityListJsonObject) {
    var scheme = new skos.ConceptScheme(activityListJsonObject);
    var labels = scheme.getConceptByLabel('Yoga').getNarrowerTransitive();
    $.each(labels, function(index, concept) {
      $('#activity-list').append($('<p>', {
        text: concept.prefLabel
      }));
    });
  });
</script>

API Reference

Note this library is written in ES5 to provide client-side compatibility without requiring transpiling. It has been tested on IE9 upwards.

skos~ConceptScheme

Kind: inner class of skos
Access: public

new ConceptScheme(scheme, [id], [filter])

ConceptScheme constructor.

| Param | Type | Description | | --- | --- | --- | | scheme | Object | Array | Either a JSON ConceptScheme object OR Array of Concepts | | [id] | String | The scheme id, only required if an array is provided for scheme | | [filter] | Object | Array | Filter of ids to be included in the ConceptScheme. Values in the object literal must be true or contain an object of keys which can be assigned on each resulting Concept. Prefer generateSubset() for most use cases. |

Example

// returns Concept for American Football
var activityListJsonObject = JSON.parse(response.getBody('utf8'));
var scheme = new skos.ConceptScheme(activityListJsonObject);
return scheme.getConceptByID('https://openactive.io/activity-list#9caeb442-2834-4859-b660-9172ed61ee71');

Example

// returns ConceptScheme for a provided custom subset of the Activity List
var activityListConceptArray = myApiResult.items;
var scheme = new skos.ConceptScheme(activityListConceptArray, 'https://openactive.io/activity-list');
return scheme;

conceptScheme.getConceptByID(id) ⇒ Concept

Get Concept by ID

Kind: instance method of ConceptScheme
Returns: Concept - the Concept, or null if no matching concept exists

| Param | Type | Description | | --- | --- | --- | | id | String | The id of the Concept |

Example

// returns Concept for American Football
var scheme = new skos.ConceptScheme(activityListJsonObject);
return scheme.getConceptByID('https://openactive.io/activity-list#9caeb442-2834-4859-b660-9172ed61ee71');

conceptScheme.getConceptByLabel(label) ⇒ Concept

Get Concept by prefLabel / altLabel

This will return a case-sensitive exact match based on the prefLabel and altLabel

Kind: instance method of ConceptScheme
Returns: Concept - the Concept, or null if no matching concept exists

| Param | Type | Description | | --- | --- | --- | | label | String | The label of the Concept |

Example

// returns Concept for American Football
var scheme = new skos.ConceptScheme(activityListJsonObject);
return scheme.getConceptByLabel('American Football');

conceptScheme.getAllConcepts() ⇒ Array

Return an array of all concepts in the scheme.

Kind: instance method of ConceptScheme
Returns: Array - an array of Concept

conceptScheme.getAllConceptsByID() ⇒ Array

Return a map of all concepts in the scheme, keyed by ID. This can be useful to power autocomplete dropdowns.

Kind: instance method of ConceptScheme
Returns: Array - an map of Concept by ID

conceptScheme.getAllConceptsByLabel() ⇒ Object

Return a map of all concepts in the scheme, keyed by altLabel and prefLabel. This can be useful to power autocomplete dropdowns.

Kind: instance method of ConceptScheme
Returns: Object - a map of Concept by altLabel / prefLabel

conceptScheme.getTopConcepts() ⇒ Array

Return an array of the top concepts in a hierarchical scheme.

Kind: instance method of ConceptScheme
Returns: Array - an array of Concept

conceptScheme.getJSON() ⇒ Object

Return the original JSON object representing the ConceptScheme.

Kind: instance method of ConceptScheme
Returns: Object - a JSON object

conceptScheme.toString() ⇒ String

Return a string rendering the ConceptScheme as Markdown.

Kind: instance method of ConceptScheme
Returns: String - a Markdown string

conceptScheme.generateSubset(filter) ⇒ ConceptScheme

Generate ConceptScheme subset

The subset will be generated to include all broader Concepts of any of those included in the filter, and will have pruned any references to related Concepts that are not included in the resulting subset.

Kind: instance method of ConceptScheme
Returns: ConceptScheme - the ConceptScheme subset

| Param | Type | Description | | --- | --- | --- | | filter | Object | Array | Filter of ids to be included in the ConceptScheme. Values in the object literal must be true or contain an object of keys which can be assigned on each resulting Concept. |

Example

// returns ConceptScheme subset of just Pole Vault and its broader concepts (Athletics)
var scheme = new skos.ConceptScheme(activityListJsonObject);
return scheme.generateSubset(['https://openactive.io/activity-list#5df80216-2af8-4ad3-8120-a34c11ea1a87']);

Example

// returns ConceptScheme subset of just Pole Vault and its broader concepts (Athletics), including metadata attached to Pole Vault.
var scheme = new skos.ConceptScheme(activityListJsonObject);
return scheme.generateSubset({'https://openactive.io/activity-list#5df80216-2af8-4ad3-8120-a34c11ea1a87': {'ext:metadata': 34}});

skos~Concept

Kind: inner class of skos

new Concept(concept)

Concept class.

A wrapper for the SKOS Concept JSON object

| Param | Type | Description | | --- | --- | --- | | concept | Object | A Concept JSON object |

concept.getNarrower() ⇒ Array

Get an array of immediately narrower concepts.

Kind: instance method of Concept
Returns: Array - an array of Concept
Example

// returns only the types of Yoga that are one level below "Yoga"
var scheme = new skos.ConceptScheme(activityListJsonObject);
return scheme.getConceptByLabel('Yoga').getNarrower();

concept.getNarrowerTransitive() ⇒ Array

Get an array of all narrower concepts following transitivity (all children).

Kind: instance method of Concept
Returns: Array - an array of Concept
Example

// returns all type of Yoga
var scheme = new skos.ConceptScheme(activityListJsonObject);
return scheme.getConceptByLabel('Yoga').getNarrowerTransitive();

concept.getBroader() ⇒ Array

Get an array of immediately broader concepts.

Kind: instance method of Concept
Returns: Array - an array of Concept
Example

// returns only the next level up in the hierarchy
var scheme = new skos.ConceptScheme(activityListJsonObject);
return scheme.getConceptByLabel('Yoga').getBroader();

concept.getBroaderTransitive() ⇒ Array

Get an array of all broader concepts following transitivity (all parents).

Kind: instance method of Concept
Returns: Array - an array of Concept
Example

// returns all the higher level categories above Yoga
var scheme = new skos.ConceptScheme(activityListJsonObject);
return scheme.getConceptByLabel('Yoga').getBroaderTransitive();

concept.getRelated() ⇒ Array

Get an array of related concepts.

Kind: instance method of Concept
Returns: Array - an array of Concept

concept.equals(concept) ⇒ boolean

Return true if two Concepts are equal and of the same type. If a raw JSON Concept is supplied it is coerced into a Concept object.

Kind: instance method of Concept
Returns: boolean - representing whether the two Concepts are equal

| Param | Type | Description | | --- | --- | --- | | concept | Concept | Concept to compare |

concept.toString() ⇒ String

Return the prefLabel of the Concept.

Kind: instance method of Concept
Returns: String - a JSON string

concept.getJSON() ⇒ Object

Return the original JSON object representing the Concept.

Kind: instance method of Concept
Returns: Object - a JSON object

Concept.compare(a, b) ⇒ Integer

Compare two Concepts based on prefLabel, for use with native .sort()

Kind: static method of Concept
Returns: Integer - representing which should be sorted above the other

| Param | Type | Description | | --- | --- | --- | | a | Concept | Concept A | | b | Concept | Concept B |

Example

var sortedConcepts = concepts.sort(skos.Concept.compare);