0.4.2 • Published 4 years ago

url-rewrite v0.4.2

Weekly downloads
17
License
MIT
Repository
github
Last release
4 years ago

url-rewrite

A URL rewrite utility.

Install

npm install url-rewrite

Usage

const assert = require('assert')
const Rewriter = require('url-rewrite')

const rewriter = new Rewriter([
  ['https://www.example.com/foo', 'https://example.com/bar'],
  ['https://www.example.com/images/:file(.*)', 'https://images.example.com/:file']
])

rewriter.add('https://ads.example.com/(.*)', '')

assert.strictEqual(
  rewriter.from('https://www.example.com/foo?a=1'),
  'https://example.com/bar?a=1'
)

assert.strictEqual(
  rewriter.from('https://www.example.com/images/a/b.png?v=2&c=3#h'),
  'https://images.example.com/a/b.png?v=2&c=3#h'
)

assert.strictEqual(
  rewriter.from('https://ads.example.com/foo/bar'),
  ''
)

Pattern syntax see url-router#pattern

License

MIT

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.0

5 years ago