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

terms2js

v0.3.5

Published

This a basic and lightweight JavaScript and JSON version of Metadata Reference Data & Classification Schemes. Stores the vocabularies as JSON objects, accesible as node modules or by browser javascript interpreter. Generated vocabulariy files have no dependencies. The package is completely generic and may be used to generate your own hierarchical reference vocabularies such as the ones expressed with the TV-Anytime XML Schema.

Downloads

3

Readme

terms2js

This a basic and lightweight JavaScript and JSON version of Metadata Reference Data & Classification Schemes.

Stores the vocabularies as JSON objects, accesible as node modules or by browser javascript interpreter. Generated vocabulariy files have no dependencies and can be used stand-alone.

The package is completely generic and may be used to generate your own hierarchical reference vocabularies such as the ones expressed with the TV-Anytime XML Schema.

Command line

To built a new version of vocabularies in refdata or transform your own you can use the 'terms2js' command.

Note: In order to run the 'terms2js' command you need to install these node modules:

npm install -g optimist
npm install -g uglify-js

For example

terms2js test/*.xml --output-dir test

Generated Vocabularies usage

From javascript the JSON object is not accesible directly. You must use this public functions:

  • .isValid (term): Return boolean value, true if term (termId or termUri) is supported.
  • .getTermId (term): Return a string containing the termId given the fully qualified term URI. If term isn't matching return null.
  • .getTermUri (termId): Return a string containing the fully qualified term URI.
  • .isDeprecated (termId): Return boolean value, true if termId is deprecated.
  • .getAllTermId (): Return an array with all the termId codes supported.
  • .getAllTermIdMatching (string): Return an array with all the termId matching string.
  • .getTermInfo (termId): Return object {"Name"}. If termId isn't supported return {}.
  • .isTermUri (term): Return true if term is the fully qualified term URI, false otherwise.
  • .getUri (): Return a string containing the vocabulary namespace URI.
  • .getVersionDate (): Return a string containing the vocabulary namespace version date.
  • .getLang(): Return a string containing the vocabulary language.
  • .stringify(): JSON stringify the vocabulary.
  • .getEquivalent(): Return an array of fully qualified URIs containing equivalent terms in other classification schemas.
  • .getMappings(): Return an array of mappings to equivalent terms in external controlled vocabularies.

See the test folder for more usage examples:

From nodejs

// From node the module is accesible with a simple require
var roles = require ('../test/en/ebu_RoleCodeCS.min.js').Vocabulary;
var num_roles = 0;

// roles.getAllTermId () return an array of all EBU Role terms supported
var rolecodes = roles.getAllTermId ();
// iterate this array
for (num_roles=0; num_roles<rolecodes.length; num_roles++) {
  // show a string representation of the object return by roles.getTermInfo(termId)
        console.log (rolecodes[num_roles]);
        console.log ("   "+JSON.stringify(roles.getTermInfo(rolecodes[num_roles])));
}
// show the number of roles supported
console.log ("Roles supported: "+num_roles);
// test roles.isValid (termId) function
console.log("Is '4.2' a role code? "+roles.isValid ('4.2'));
console.log("What is the URI of role code '4.2'? "+roles.getTermUri ('4.2'));
console.log("What is the role code for 'Actor'? "+roles.getAllTermIdMatching ('Actor'));

From browser

<!doctype html>
<html>
<head>
    <title>Test EBU roles module</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
    <!--<script src="../test/en/ebu_RoleCodeCS.min.js"></script>-->
    <script src="../test/en/ebu_RoleCodeCS.js"></script>
    <style>
    body {
        background-color: #eee;
    }
    .center {
        width:700px;
        margin:10px auto;
        border:1px solid #ccc;
        padding:20px;
        background-color:#fff;
    }
    </style>
</head>
<body>
    <div class="center">
        <h1>Test EBU roles module (Browser client side)</h1>
        <hr />
        <div id="test"></div>
    </div>
    <script>
        var num_roles = 0,
        text = '';

        // terms2js.en.ebu_RoleCodeCS.Vocabulary.getAllTermId() return an array of all EBU Role terms supported
        var rolecodes = terms2js.en.ebu_RoleCodeCS.Vocabulary.getAllTermId();
        // iterate this array
        for (num_roles=0; num_roles<rolecodes.length; num_roles++) {
            // save in text variable a string representation of the object return by terms2js.en.ebu_RoleCodeCS.Vocabulary.getTermInfo(termId)
            var termId = rolecodes[num_roles];
            text+='<b>'+termId+'</b> '+JSON.stringify(terms2js.en.ebu_RoleCodeCS.Vocabulary.getTermInfo(termId))+'<br />';
        }
        // save the number of roles supported
        text = '<h2>Roles supported: '+num_roles+'</h2>'+text;
        // write the test result in DOM element with id='test'
        document.getElementById('test').innerHTML = text;
    </script>
</body>
</html>

See Also

  • EBU Metadata Reference Data & Classification Schemes - http://tech.ebu.ch/MetadataReferenceData
  • EBU Reference Data & Classification Schemes Tech 3336 - http://tech.ebu.ch/docs/tech/tech3336v1_1.pdf
  • ETSI TS 102 822-3-1 V1.7.1 (2011-11) - http://www.etsi.org/deliver/etsi_ts/102800_102899/1028220301/01.07.01_60/ts_1028220301v010701p.pdf

Aknowledgments

This package is inspired to languages4translatewiki.js.