GithubHelp home page GithubHelp logo

brunos3d / pupo Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 7 KB

๐Ÿ“ฆ NODE.JS - Simple micro templating based on pupa using object-path.

Home Page: https://www.npmjs.com/package/pupo

License: MIT License

JavaScript 89.99% TypeScript 10.01%
string formatting template object format interpolate placeholders micro transform replace

pupo's Introduction

pupo

npm version npm downloads Build Status object-path Dependency escape-goat Dependency Visitors

๐Ÿ“ฆ 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.

Related

  • pupa - The original package.

pupo's People

Contributors

brunos3d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.