# pinterpolate

> Simple string interpolation

Latest version **0.2.3** (published 2020-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install pinterpolate
pnpm add pinterpolate
yarn add pinterpolate
bun add pinterpolate
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2020-07-08 |
| First published | 2018-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 186.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Pratish Shrestha |
| Maintainers | pratishshr |
| Keywords | format, interpolate, string format, string interpolate, string interpolation |

## Links

- npm: https://www.npmjs.com/package/pinterpolate
- Repository: https://github.com/pratishshr/pinterpolate
- Homepage: https://github.com/pratishshr/pinterpolate#readme
- Issues: https://github.com/pratishshr/pinterpolate/issues
- npm.io page: https://npm.io/package/pinterpolate

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2020-07-08
- 0.2.2 — 2020-04-17
- 0.2.1 — 2018-12-13
- 0.2.0 — 2018-12-13
- 0.1.0 — 2018-12-11
- 0.0.2 — 2018-12-11
- 0.0.1 — 2018-12-11

## README

# pinterpolate

[![npm](https://img.shields.io/npm/v/pinterpolate.svg)](https://www.npmjs.com/package/pinterpolate)
[![Build Status](https://travis-ci.org/pratishshr/pinterpolate.svg?branch=master)](https://travis-ci.org/pratishshr/pinterpolate)
[![npm](https://img.shields.io/npm/dt/pinterpolate.svg)](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 = () => (
  <Router> 
    <Route path={routes.USER} component={UserComponent} />
    <Route path={routes.USERS_RECORD} component={RecordComponent} />
  </Router>
);

// For links
export Component = ({userId, recordId}) => (
  <div>
    <Link to={pinterpolate(routes.USERS_RECORD, {userId, recordId})} />
    <Link to={pinterpolate(routes.USER, {userId})} />
  </div>
);
```

---
_Source: https://npm.io/package/pinterpolate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
