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

@maynoothuniversity/moodle-context-level

v1.0.3

Published

A JavaScript class representing the context levels in Moodle's permissions system.

Downloads

4

Readme

moodle-context-level

A JavaScript class representing the context levels in Moodle's permissions system.

Installation & Importation

NodeJS

Install with:

npm install --save '@maynoothuniversity/moodle-context-level'

Import with:

const MoodleContextLevel = require('@maynoothuniversity/moodle-context-level');

Browser

Import into page with:

<!-- Import MoodleContextLevel from CDN -->
<script src="https://rawcdn.githack.com/bbusschots-mu/moodle-context-level/1aa70e57d14ed7fba107721de9df2dc30806329a/dist/index.js"></script>

Basic Example

// Example assumes module has been imported as MoodleContextLevel

// factory method — 3 ways to create a course context
const cxt1 = MoodleContextLevel.parse('CONTEXT_COURSE'); // by name
const cxt2 = MoodleContextLevel.parse('course'); // by base name or alias
const cxt3 = MoodleContextLevel.parse(50); // by number

// static factory getters - 3 ways to create a category context
const catCxt1 = MoodleContextLevel.CONTEXT_COURSECAT; // by name
const catCxt2 = MoodleContextLevel.coursecat; // by base name
const catCxt3 = MoodleContextLevel.category; // by alias

// properties
console.log(catCxt1.name); // CONTEXT_COURSECAT
console.log(catCxt1.baseName); // courseCat
console.log(catCxt1.aliases); // ['category', 'courseCategory']
console.log(catCxt1.number); // 40

// all existing context names as they appear in the Moodle source code
console.log(MoodleContextLevel.names);
  // [
  //   'CONTEXT_SYSTEM',
  //   'CONTEXT_USER',
  //   'CONTEXT_COURSECAT',
  //   'CONTEXT_COURSE',
  //   'CONTEXT_MODULE',
  //   'CONTEXT_BLOCK'
  // ]
  
// all names understood by the module
console.log(MoodleContextLevel.allNames);
  // [
  //   'CONTEXT_BLOCK',     'CONTEXT_COURSE',
  //   'CONTEXT_COURSECAT', 'CONTEXT_MODULE',
  //   'CONTEXT_SYSTEM',    'CONTEXT_USER',
  //   'block',             'category',
  //   'course',            'courseCategory',
  //   'coursecat',         'module',
  //   'system',            'user'
  // ]

API Documentation

The documentation for the public API can be access at https://bbusschots-mu.github.io/moodle-context-level/.

Development

To contribute to the module, clone it from GitHub and then in the folder execute the following:

npm install

The single source file is ./src/index.html.

Once changes have been made the two distribution files can be generated with:

npm run build

The public API documentation can be updated with:

npm run docs

The generated documentation will be at ./docs/index.html.

The public API documentation does not include private variables. Full developer documentation can be generated with:

npm run docs-dev

The generated develoer documentation will be at ./docs-dev/index.html.

The QUnit test suite is defined in ./test/tests.js.

The tests can be execute in-browser after the code has been built at ./test/index.html, or from the CLI with:

npm run test