Socket
Socket
Sign inDemoInstall

pupo

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pupo

📦 NODE.JS - Simple micro templating based on pupa using object-path.


Version published
Weekly downloads
6
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

pupo Build Status

📦 NODE.JS - Simple micro templating based on pupa using object-path.

Useful when all you need is to fill in some placeholders.

Pupo implements the object-path package to resolve the values of the data object.

Install

$ npm install pupo

# or

$ yarn add pupo

Usage

const pupo = require("pupo");

pupo("The mobile number of {name} is {phone.mobile}", {
    name: "Foo",
    phone: {
        mobile: "100 20 300",
    },
});
//=> 'The mobile number of Foo is 100 20 300'

pupo("I like {0} and {1}", ["🦄", "🐮"]);
//=> 'I like 🦄 and 🐮'

// Double braces encodes the HTML entities to avoid code injection
pupo("I like {{0}} and {{1}}", ["<br>🦄</br>", "<i>🐮</i>"]);
//=> 'I like &lt;br&gt;🦄&lt;/br&gt; and &lt;i&gt;🐮&lt;/i&gt;'

// Deep object value
pupo("{deep.obj.value-foo}", {
    deep: {
        obj: {
            "value-foo": "Hello, World!",
        },
    },
});
//=> 'This is a deep object value: Hello, World!'

// Format using object with special key names
pupo("{foo bar} {12 345} {value-foo}", {
    "foo bar": "Foo Bar",
    "12 345": "12345",
    "value-foo": "Hello, World!",
});
//=> 'Foo Bar 12345 Hello, World!'

API

pupo(template, data)

template

Type: string

Text with placeholders for data properties.

data

Type: object | unknown[]

Data to interpolate into template.

FAQ

What about template literals?

Template literals expand on creation. This module expands the template on execution, which can be useful if either or both template and data are lazily created or user-supplied.

  • pupa - The original package.

Keywords

FAQs

Package last updated on 18 Nov 2020

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