Socket
Socket
Sign inDemoInstall

@sensebox/sketch-templater

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sensebox/sketch-templater

nodejs library to create senseBox Arduino Sketches


Version published
Weekly downloads
18
decreased by-78.57%
Maintainers
1
Weekly downloads
 
Created
Source

senseBox sketch-templater

Arduino sketch templates used by the openSenseMap-api

Usage

Install via npm install --save @sensebox/sketch-templater or yarn add @sensebox/sketch-templater


const Sketcher = require('@sensebox/sketch-templater');

const mySketcher = new Sketcher('<your api post domain>');

// generate Sketch
const mySketch = mySketcher.generateSketch(box);

Adding new Templates

To add new templates, just create a new .tpl file in the templates directory. A template consists of two parts. The first line contains a JSON object for configuration. The second line until the end is used as the template text.

Example configuration in first line

Specify a single model:

{ "model": "homeEthernet" }

Specify multiple models:

{ "models": ["homeWifi", "homeWifiFeinstaub"] }

Templating values

The templater uses special transformers to process the templates. The transformers are applied through searching for @@SUB_TEMPLATE_KEY@@ occurrences in the template files. Each replacement starts and ends with a double @. To specify a transformer, append a pipe (|) and the transformer name. When no transformer is specified, it just returns the input variable. For adding new template transformers, see Adding Transformers.

As of writing this, the following replacements can be made:

Template textReplacement
@@SENSEBOX_ID@@the senseBox ID
@@SENSOR_IDS@@sensor IDs
@@NUM_SENSORS@@the number of sensors
@@INGRESS_DOMAIN@@the domain of your ingress server

Additionally, the following transformers are implemented:

Transformer nameDescription
as-isDo nothing.
toHexTransforms a single string to hex tuples. Example: "DEADBEEF" => "0xDE, 0xAD, 0xBE, 0xEF"
toDefineTransform an array of sensors to multiple #define statements.
toHexArrayTransform an array of sensors to a list of hex encoded arrays. Uses toHex internally.

Adding Transformers

In order to add a new transformer, just add a function in src/transformers.js to the module.exports. The function should return a string.

Adding Replacements

Add your additional replacements in src/index.js in the method _cloneBox to the second parameter of the Object.assign call.

License

MIT 2017 Matthias Pfeil, Jan Wirwahn, Gerald Pape

FAQs

Package last updated on 24 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc