Skip to content

chaudhryjunaid/url-placeholders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

url-placeholders

Replace placeholder values in a url path.

Install

Install with npm:

$ npm i 'git+https://github.com/chaudhryjunaid/url-placeholders'

Usage

var placeholders = require('url-placeholders')(options);

placeholders('/users/:userId/books/:bookId', {userId: 1, bookId: 2});
//=> '/users/1/books/2'

Options

Options may be passed to the main function.

var placeholders = require('placeholders')(options);

options.defaults

Pass a defaults object on the main function to use for resolving values in all invocations.

Type: {Object}

Default: undefined

Example

var placeholders = require('placeholders')({
  defaults: {foo: 'one', bar: 'two'}
});

placeholders(':foo/:bar/:baz', {baz: 'three'})
//=> 'one/two/three'

returns a function when no data is passed

This allows you to reuse the same pattern with different data, like a compiled template.

var placeholders = require('placeholders')({
  prefix: '%',
  postfix: '%'
});

var fn = placeholders('foo/%bar%/%baz%');
fn({bar: 'one', baz: 'two'})
//=> 'foo/one/two'
fn({bar: 'a', baz: 'b'})
//=> 'foo/a/b'

About

Related projects

This project aims to provide a useful replacement for placeholders with minimal dependencies.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published