JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7027
  • Score
    100M100P100Q132955F
  • License MIT

Zero dependency micro templating engine for strings only.

Package Exports

  • pope

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pope) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.

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 pope = require('pope')
pope.prop({ count:20 }, 'count') // 20
pope.prop({profile: { name:'virk', age: 26 }}, 'profile.name') // virk
pope.prop([20], '0') // 20
pope.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: '.....'
}