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

js-scc

v0.0.12

Published

- npm install with ```npm install js-scc```

Downloads

7

Readme

js-scc (see npm)

Installation

  • npm install with npm install js-scc

Using this library

  • import lib with const Device = require("js-scc");

  • create a class that extends Device, in order to do this, implement the following methods:

    | method | parameters | | returns | |------------------------------|----------------------------------|------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------| | getStatus() | none | | a dictionary of current status of the device, this should include all input and output as defined in the room_config for the backend | | performInstruction(action) | action (a dictionary with keys:) | instruction (string with the name of the instruction) | boolean of whether the instruction could be performed | | | | value (any type with a value specific for this instruction) | | | | | component_id (string with the name of the component for which the instruction is meant, this can be undefined) | | | test() | none | | void | | reset() | none | | void |

  • create a constructor which calls the constructor of Device with super(config, logger) where:

    • config is a dictionary which has keys:

    | key | explanation | |----------|----------------------------------------------------------------------------| | id | string with the id of a device. Write it in camelCase, e.g. "controlBoard" | | host | string with the IP address of the host for the broker | | port | int with the port of the host for the broker | | labels | array of strings with all labels this device should also subscribe to |

    • logger is a function(date, level, message) in which an own logger is implemented where
      • date is an Date object
      • level is one of the following strings: 'debug', 'info', 'warn', 'error', 'fatal'
      • message is a custom string containing more information
  • Now on the instantiation of your class which implements Device, you can call:

    | function | arguments | returns | usecase | |-----------------------|-----------------------------------------------------------------------------------|---------|----------------------------------------------------------------------------------| | start(onStart) | onStart (a function that gets called once the device is connected or reconnected) | void | call this function in order to connect to sciler | | log(level, message) | level (one of the following strings: 'debug', 'info', 'warn', 'error', 'fatal') | void | this method can be used to log in the same logger as the library does | | | message (custom string containing more information) | | | | statusChanged() | none | void | call this function to signal that you updated a status so sciler can be notified |

  • in case of:

    • angular: add js-scc to dependencies in package.json
    • browser javascript: (example nodejs serving web page with javascript which includes this library), Browserify your javascript which includes this library.

Example

Javascript file:

$(document).ready(function() {
  const Device = require("js-scc");
  let display;

  class Display extends Device {
    constructor(config) {
      super(config, timedLogger);
      this.hint = "";
      this.button = false;
    }

    // required method for extending Device
    getStatus() {
      return {
        button: this.button,
        hint: this.hint
      };
    }

    // required method for extending Device
    performInstruction(action) {
      switch (action.instruction) {
        case "hint": {
          this.hint = action.value;
          displayText(this.hint);
          this.statusChanged();
          break;
        }
        default: {
          return false;
        }
      }
      return true;
    }

    // required method for extending Device
    test() {
      this.hint = "test";
      displayText(this.hint);
    }

    // required method for extending Device
    reset() {
      this.hint = "";
      this.button = false;
      displayText(this.hint);
      this.statusChanged();
    }
  }

  // custom logger used in constructor
  function timedLogger(date, level, message) {
    const formatDate = function(date) {
      return (
        date.getDate() +
        "-" +
        date.getMonth() +
        1 +
        "-" +
        date.getFullYear() +
        " " +
        date.getHours() +
        ":" +
        date.getMinutes() +
        ":" +
        date.getSeconds()
      );
    };
    console.log(
      "time=" + formatDate(date) + " level=" + level + " msg=" + message
    ); // call own logger);
  }

  // edit the DOM using JQuery to display text
  function displayText(text) {
    $("#hint").text(text);
  }

  // when the button is click update status and notify sciler
  $("#button").on("click", function() {
    display.button = true;
    display.statusChanged();
  });

  // get config file from server
  $.get("/display_config.json", function(config) {
    display = new Display(JSON.parse(config)); // create new Display object
    // connect
    display.start(() => {
      console.log("connected"); // when connected, do something
    });
  });
});

Where display_config.json is:

{
  "id": "display-node",
  "host": "192.168.178.49",
  "labels": ["hint"],
  "port": 8083
}

And where index.html is:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>Display</title>
    <link rel="icon" type="image/x-icon" href="raccoon.ico">
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="bundle.js"></script>
</head>
<body>
hint: <p id="hint"></p>
<button id="button">button</button>
</body>
</html>

And where the room_config.json looks something like:

{
  "general": { },
  "cameras": [ ],
  "general_events": [ ],
  "button_events": [ ],
  "puzzles": [ ],
  "timers": [ ],
  "devices": [
    { },
    {
      "id": "display-node",
      "description": "displays messages",
      "input": {
        "button": "boolean"
      },
      "output": {
        "display": {
          "type": "string",
          "instructions": {
            "hint": "string"
          }
        }
      }
    },
    { }
  ]
}

Tip reading in config.json in Angular:

When reading in a json file

import * as data from './data.json';

make sure tsconfig.json has resolveJsonModule: true:

{
  "compilerOptions": {
    ...
    "resolveJsonModule": true,
    ...
}

then you can use this object in for example ngOnInit

  ngOnInit(): void {
       this.jsonData = (data  as  any).default
  }

License

GNU GENERAL PUBLIC LICENSE Version 3, see LICENSE.md