https://github.com/pratishshr/pinterpolate
String interpolation utility.
https://github.com/pratishshr/pinterpolate
formatter interpolation string-fomatting string-formatter string-interpolation
Last synced: 3 months ago
JSON representation
String interpolation utility.
- Host: GitHub
- URL: https://github.com/pratishshr/pinterpolate
- Owner: pratishshr
- License: mit
- Created: 2018-12-11T14:30:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T01:59:15.000Z (about 3 years ago)
- Last Synced: 2025-12-06T13:05:34.060Z (4 months ago)
- Topics: formatter, interpolation, string-fomatting, string-formatter, string-interpolation
- Language: JavaScript
- Homepage:
- Size: 947 KB
- Stars: 10
- Watchers: 1
- Forks: 5
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pinterpolate
[](https://www.npmjs.com/package/pinterpolate)
[](https://travis-ci.org/pratishshr/pinterpolate)
[](https://www.npmjs.com/package/pinterpolate)
> Simple string formatting.
## Installation
```sh
$ npm install --save pinterpolate
```
```sh
$ yarn add pinterpolate
```
Build supplied string by interpolating properties after delimiter ':' with the given parameters.
Useful for formatting strings.
## Usage
```js
import pinterpolate from 'pinterpolate';
pinterpolate('/users/:id', { id: 1 });
// => '/users/1'
pinterpolate(':name is here.', { name: 'Barbara' });
// => 'Barbaba is here.'
```
## Use Case
I mostly use this utility in conjuction with my API endpoints and React Router routes.
#### For APIs
```js
const USERS_IMAGE = '/users/:userId/images/:imageId'
export function fetchUsersImage(userId, imageId) {
return http.get(pinterpolate(USERS_IMAGE, {
userId,
imageId
})
}
```
#### For React Router routes
```js
// constants/routes.js
const USER = '/users/:userId'
const USERS_RECORD = '/users/:userId/records/:recordId';
// Router.js
export Router = () => (
);
// For links
export Component = ({userId, recordId}) => (
);
```