https://github.com/brunos3d/pupo
📦 NODE.JS - Simple micro templating based on pupa using object-path.
https://github.com/brunos3d/pupo
format formatting interpolate intl json micro object object-path placeholders replace simple string template transform
Last synced: 27 days ago
JSON representation
📦 NODE.JS - Simple micro templating based on pupa using object-path.
- Host: GitHub
- URL: https://github.com/brunos3d/pupo
- Owner: brunos3d
- License: mit
- Created: 2020-11-18T03:37:10.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-18T13:24:13.000Z (over 4 years ago)
- Last Synced: 2025-04-20T00:38:34.287Z (about 1 month ago)
- Topics: format, formatting, interpolate, intl, json, micro, object, object-path, placeholders, replace, simple, string, template, transform
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/pupo
- Size: 6.84 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# pupo
[](http://badge.fury.io/js/pupo)
[](http://badge.fury.io/js/pupo)
[](https://travis-ci.org/BrunoS3D/pupo)
[](https://www.npmjs.com/package/object-path)
[](https://www.npmjs.com/package/escape-goat)
[](https://github.com/BrunoS3D/pupo)> 📦 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](https://www.npmjs.com/package/object-path) package to resolve the values of the data object.
## Install
>
```
$ npm install pupo# or
$ yarn add pupo
```## Usage
```js
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}}", ["
🦄", "🐮"]);
//=> 'I like <br>🦄</br> and <i>🐮</i>'// 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](https://github.com/sindresorhus/pupa) - The original package.