3.1.0 • Published 3 years ago

pupa v3.1.0

Weekly downloads
4,495,301
License
MIT
Repository
github
Last release
3 years ago

pupa

Simple micro templating

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

Install

$ npm install pupa

Usage

import pupa from 'pupa';

pupa('The mobile number of {name} is {phone.mobile}', {
	name: 'Sindre',
	phone: {
		mobile: '609 24 363'
	}
});
//=> 'The mobile number of Sindre is 609 24 363'

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

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

API

pupa(template, data, options?)

template

Type: string

Text with placeholders for data properties.

data

Type: object | unknown[]

Data to interpolate into template.

options

Type: object

ignoreMissing

Type: boolean\ Default: false

By default, Pupa throws a MissingValueError when a placeholder resolves to undefined. With this option set to true, it simply ignores it and leaves the placeholder as is.

transform

Type: ((data: {value: unknown; key: string}) => unknown) | undefined (default: ({value}) => value)

Performs arbitrary operation for each interpolation. If the returned value was undefined, it behaves differently depending on the ignoreMissing option. Otherwise, the returned value will be interpolated into a string (and escaped when double-braced) and embedded into the template.

MissingValueError

Exposed for instance checking.

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

update-notifier@loopx/templateeasy-select-rnreact-native-bluetooth2edlairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-moduledeneme323112@codeloop/authorization-casbin@ntt_app/react-native-custom-notificationdiscord-music-botsreact-native-covid-sdk@fsp-fs/electron-dl@saeon/quick-formlog8000v3mysql-formatreact-native-printer-brothersreact-native-shekhar-bridge-testcogoportutilsdyx-reactpolemic@oiti/documentoscopy-react-nativequoc-test@seedcompany/eslint-plugin@infinitebrahmanuniverse/nolb-pupluminos-ui-core@everything-registry/sub-chunk-2494jawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_samplejawwy_library_newjawy_library_v1gamification-jawwy-libraryframework_test_library_sixdee_new_jawwytest_lib_module_aar@hemith/react-native-tnkesbuild-header@erkkah/nomnomd@hbglobal/react-native-actions-shortcutsexpo-renavigatefawaterak-online-paymentfawatrak-online-paymentextract-pr-titles@idas1/ui-component-libserverless-idobata-webhookdriza@frctl/fractal-engine-html@frctl/pages@floross/temp-prisma-nestjs-graphql@geeky-apo/react-native-advanced-clipboardelectron-dlelectron-dl-shuscelectron-file-downloaderelectron-edl@erostools/clireact-native-responsive-helper@enkeledi/react-native-week-month-date-picker@extrieve_technologies/quickcapture_react_native@fe6/qinjs-cli@felipesimmi/react-native-datalogic-module@imrtoy/homebridge-night-light@jliocsar/notiz-clismart_one_connect@kiiid/electron-dlgamification-integration-new@luban-cli/clisvbgenz-native-elementsgithub-organization-bookmarks@platformatic/config@platformatic/create-platformatic-autoupdate-notifier-webpackupdate-notifier-cjsupdate-notifier-gitupdate-notifier-new@praella/localisationist@programmerraj/create@pierred/create-packageuse-config@radarsu/prisma-nestjs-graphql@saad27/react-native-bottom-tab-tour@recalibratedsystems/tron@react-native-ui-design/buttonjsbrain-prisma-nestjs-graphqljrennsoh88-react-native-scroll-indicatorvision-camera-plugin-face-detectorvision-camera-plugin-scan-facesvision-camera-base64-resizedkakao-chatbot-templates@saeon/loggerkhaled-salem-custom-components@samwinslow/edgedbjstransformer-pupaforked-prisma-nestjs-graphql
3.1.0

3 years ago

3.0.0

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.0

7 years ago