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

json2iob

v2.6.11

Published

Convert Json to ioBroker States

Downloads

5,239

Readme

Json2iob

This package converts a json objects into ioBroker states. It can handle nested array and obects. It will also generated automaticly the type and roles based on the type of value.

Usage

In a ioBroker Adapter

const Json2iob = require("json2iob");

this.json2iob = new Json2iob(this);

this.json2iob.parse(path, json, { forceIndex: true });

Options:

write //set common write variable to true

forceIndex //instead of trying to find names for array entries, use the index as the name.
Otherweise the value of a key with id, name, label, labelText will use a name. This is key overriden by preferedArrayName

disablePadIndex //disables padding of array index numbers if forceIndex = true

zeroBasedArrayIndex //start array index from 0 if forceIndex = true

preferedArrayName //set key to use this as an array entry name

preferedArrayDec //set key to use this as an array entry description

channelName //set name of the root channel

autoCast (true false) // make JSON.parse on all values to parse numbers correctly

descriptions: //Object of names for state keys

states: // Object of states to create for an id, new entries via json will be added automatically to the states

units: // Object of units to create for an id.

parseBase64: (true false) // parse base64 encoded strings to utf8

parseBase64byIds: //Array of ids to parse base64 encoded strings to utf8

parseBase64byIdsToHex : //Array of ids to parse base64 encoded strings to hex

deleteBeforeUpdate: //Delete channel before update,

removePasswords: // remove the values from password keys

dontSaveCreatedObjects: //create objects but do not save them to alreadyCreatedObjects this leads to recreating at every parsing

excludeStateWithEnding: //Array of strings to exclude states with this ending

makeStateWritableWithEnding: //Array of strings to make states with this ending writable
this.descriptions = {
  1: "POWER",
  2: "PLAY_PAUSE",
  3: "DIRECTION",
  5: "WORK_MODE",
};
this.states = {
  3: {
    FORWARD: "forward",
    BACKWARD: "back",
    LEFT: "left",
    RIGHT: "right",
  },
  5: {
    AUTO: "auto",
    SMALL_ROOM: "SmallRoom",
    SPOT: "Spot",
    EDGE: "Edge",
    NO_SWEEP: "Nosweep",
  },
};

await this.json2iob.parse(path, json, {
  forceIndex: true,
  write: true,
  descriptions: this.descriptions,
  states: this.states,
});

Force recreation after manual deletion

await this.delObjectAsync(id + ".clients", { recursive: true });
for (const key in this.json2iob.alreadyCreatedObjects) {
  if (key.startsWith(id + ".clients")) {
    delete this.json2iob.alreadyCreatedObjects[key];
  }
}

Changelog

2.6.11 Add base64toHex

2.6.8 Add additonal timestamp detection

2.6.6 Add no padding and index start at 0 options

2.6.5 convert to TypeScript and add unit option

2.5.2 add forbidden charackter replacing

2.4.11 Add contidiontal writing with makeStateWritableWithEnding

2.4.9 Add time stamp detection

2.4.8 Add autocast to array elements

2.4.7 Add exclude filter

2.4.2 Fix for numeric id

2.4.0 Add deletePasswords, fix functions and null values

2.3.0 Add deleteBeforeUpdate

2.2.0 Add base64 decoding

2.1.0 Add states definition

2.0.2 Add type check before setState and change type to mixed if its differs from creation type to the current value type