/compose-url

Primary LanguageTypeScriptMIT LicenseMIT

Compose url

Replaces Express URL pattern with regular URL.

Install

npm install @economia/compose-url --save

ES6 import

import { composeURL } from '@economia/compose-url'

Common js import

const { composeURL } = require('@economia/compose-url')

Example:

const pattern = '/users/:id'
const params = { id: 42 }

const URL =  composeURL(pattern, params)
// /users/42
const pattern = '/users/:id'
const params = {}

const URL = composeURL(pattern, params)
// error

Optional parameters end with "?" and can be omitted

const pattern = '/users/:id?'
const params = { id: 42 }

const URL = composeURL(pattern, params)
// /users/42
const pattern = '/users/:id?'
const params = {}

const URL = composeURL(pattern, params)
// /users