Giter Club home page Giter Club logo

pope's Introduction

Pope

Coverage Status

Pope is a fast, minimal and micro template engine for strings only, it plays well where you want to embed micro templates inside your module.

Upgrading from 1.x.x The version 2.0.x has a breaking change, where pope is not the default export, instead exported as a property on the object.

Earlier


const pope = require('pope')

Now


const { pope } = require('pope')

Examples

string interpolation

const { pope } = require('pope')
pope('There are {{count}} emails in your inbox', { count:20 })

nested values

const { pope } = require('pope')
pope('My name is {{profile.name}} and age is {{profile.age}}', { profile: { name:'virk', age: 26 } })

arrays only

const { pope } = require('pope')
pope('There are {{0}} emails in your inbox', [20])

prop

Pulls the nested/flat values from an object. It is similar to lodash.get method.

const { prop } = require('pope')
prop({ count:20 }, 'count') // 20
prop({profile: { name:'virk', age: 26 }}, 'profile.name') // virk
prop([20], '0') // 20
prop({profile: { validate: /^[A-Z][a-z]+/} }, 'profile.validate') //   /^[A-Z][a-z]+/

Options

You can also pass an options object to define the interpolation behavior.

skipUndefined

Do not replace the undefined values with an empty string.

const { pope } = require('pope')
pope('There are {{0}} emails in your inbox', {}, {
  skipUndefined: true
})
// returns - There are {{0}} emails in your inbox

throwOnUndefined

Throw exception when a undefined value is found. throwOnUndefined gets priority over skipUndefined if both are defined.

const { pope } = require('pope')
pope('Hello {{ username }}', {}, {
  throwOnUndefined: true
})

// throws exception
{
  message: 'Missing value for {{ username }}',
  key: 'username',
  code: 'E_MISSING_KEY',
  stack: '.....'
}

pope's People

Contributors

thetutlage avatar damoclark avatar demianalonso avatar

Watchers

James Cloos avatar Khizer Younas 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.