https://github.com/fuseraft/interpjs
Index-based interpolation implemented in Native JavaScript
https://github.com/fuseraft/interpjs
Last synced: 10 months ago
JSON representation
Index-based interpolation implemented in Native JavaScript
- Host: GitHub
- URL: https://github.com/fuseraft/interpjs
- Owner: fuseraft
- Created: 2015-11-09T17:47:04.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-16T14:30:48.000Z (almost 9 years ago)
- Last Synced: 2025-02-02T17:29:10.450Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## I wanted index-based string interpolation for JavaScript and was bored.
So here's **interp.js**.
And here's a [fiddle](https://jsfiddle.net/29j1v7gy/6/) to see it in action.
InterpJS appends a single function to the String object so that it supports simple index-based interpolation.
You can call `interp()` and pass parameters *like this*:
`'I wish I could write {0} {1}/{2}. :S'.interp('JavaScript', 24, 7);`
*which returns*:
`'I wish I could write JavaScript 24/7. :S'`
Or you can pass an array *like this*:
`'The {0} black {1} jumped over the other {1} {0}ly.'.interp(['quick', 'fox']);`
*which returns*:
`The quick black fox jumped over the other fox quickly.`