mrp-url-generator
v1.0.6
Published
Isomorphic library to generate URLs used across MR PORTER sites
Downloads
29
Maintainers
Readme
MR PORTER URL Generator
An isomorphic JavaScript library to generate URLs used across the MR PORTER sites, following our agreed formatting conventions.
Usage
npm i mrp-url-generator --save
ECMAScript 6
import { buildProductDetailsUrl } from 'mrp-url-generator';
/* alternatively, one can import the entire library with:
* import urlGen from 'mrp-url-generator'; */
ECMAScript 5
var buildProductDetailsUrl = require('mrp-url-generator').buildProductDetailsUrl;
Browser
This is confirmed to work with Browserify and Webpack.
If, unfortunately, script
tag includes are the only option, one must build the distributable manually with a tool such as Browserify:
browserify dist/index.js --outfile mrp-url-generator.js
API
All methods return String
s representing relative URLs
buildProductDetailsUrl(brandUrlKey, productName, productId, locale)
Returns a product details page link e.g:
//returns '/en-gb/mens/mario_super_designer/my-3456-woouuuuderful-trou-ers-are-great/12345'
buildProductDetailsUrl('Mario_Super_Designer', 'My 3456 Ẅöőuúüűderful Trou$ers! Are great', 12345, 'en-gb');
Contributing
Setup
npm i -g babel
npm i
Babel?! Why does this project use ECMAScript 6?
- Harmony has a lot of useful enhancements, especially to
String.prototype
- Once io.js has fully merged with Node.js, everything should just work!
- Native Harmony support is gradually improving
Tasks
npm run dist
- compiles the distributable to ECMAScript 5npm test
- runs unit tests