UNPKG

mrp-url-generator

Version:

Isomorphic library to generate URLs used across MR PORTER sites

60 lines (43 loc) 1.69 kB
# MR PORTER URL Generator ![Build status](https://circleci.com/gh/NET-A-PORTER/mrp-url-generator.png?circle-token=:circle-token) 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? 1. Harmony has a lot of useful enhancements, especially to `String.prototype` 2. Once io.js has fully merged with Node.js, everything should just work! 3. Native Harmony support is gradually improving ### Tasks * `npm run dist` - compiles the distributable to ECMAScript 5 * `npm test` - runs unit tests