New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

self-templated

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

self-templated

Bring template and graph resolution to your literal objects

  • 0.2.3
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status

Node.js Self Templated project

Self Templated brings the power of templating to your literal object with a graph resolution of the references. It traverses an object recursively and use the same self-referenced object as a context. It is entirely agnostic of the templating engine being used and default to Handlebars.

If this is not clear, imagine a templating engine rendering all the string of an object and inject that same object as a context.

If this is still not clear, imagine a configuration where each value can referenced other values from that same configuration, see the example below.

If you have understood but a more sarrow introduction would have helped, please share your suggestions.

This package features:

  • Agnostic/multi template engines
  • Circular refenrences detection
  • Simple and consise API
  • Full test coverage

Installation

This is OSS and licensed under the new BSD license. The project homepage is located on GitHub and the package is distributed by NPM:

npm install templated-object

Usage

templated(object[,options])

Quite simple, the exported module is a function taking the object to render as first argument and optionally an options object as second argument.

Options includes:

  • array (boolean)
    Proxify array as well, default is false
  • compile (boolean)
    Resolve all the template on creation instead of on-demand, default is false.
  • handlebars (object)
    Options passed to HandleBars.
  • partial (object)
    Filtering the templating to a restricuted list of properties. It is an object where keys can be properties or indexes and values activate or desactivate the template rendering.
  • render (function)
    A user defined function responsible to render a template. Argments are the template and the context, expect to returned the rendered result. Default implementation is using HandleBars.

Examples

templated = require('templated-object');
// Render
config = templated({
  "webapp": {
    "app_name": 'cool_app',
    "db_url": 'mysql://{{db.host}}:{{db.port}}/{{webapp.db_name}}',
    "db_name": 'db_{{webapp.app_name}}'
  },
  "db": {
    "host": 'localhost',
    "port":  '3306'
  }
});
// Assert
console.log(config.webapp.db_url == "mysql://localhost:3306/db_cool_app");

Development

Tests are executed with mocha. To install it, simple run npm install, it will install mocha and its dependencies in your project "node_modules" directory.

To run the tests:

npm test

The tests run against the CoffeeScript source files.

The test suite is run online with Travis.

Contributors

FAQs

Package last updated on 12 Mar 2022

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