page-path-builder
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -16,7 +16,8 @@ var parser = require('./path-parser') | ||
if (!bit.optional && !parameters[bit.name]) { | ||
var defined = typeof parameters[bit.name] !== 'undefined' | ||
if (!bit.optional && !defined) { | ||
throw new Error('Must supply argument ' + bit.name + ' for path ' + pathStr) | ||
} | ||
return parameters[bit.name] ? (bit.delimiter + encodeURIComponent(parameters[bit.name])) : '' | ||
return defined ? (bit.delimiter + encodeURIComponent(parameters[bit.name])) : '' | ||
}).join('') | ||
@@ -23,0 +24,0 @@ |
{ | ||
"name": "page-path-builder", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Uses a page.js-style routing string to build up a path you can link to", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "node test.js && jsmd readme.md" | ||
}, | ||
@@ -20,2 +20,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"jsmd": "^0.3.0", | ||
"tape": "^3.0.0" | ||
@@ -22,0 +23,0 @@ }, |
[![Build Status](https://travis-ci.org/TehShrike/page-path-builder.svg)](https://travis-ci.org/TehShrike/page-path-builder) | ||
For those times when you want to programmatically generate a link to page.js route. | ||
For those times when you want to programmatically generate a link to a [page.js](https://github.com/visionmedia/page.js) route. | ||
@@ -8,19 +8,16 @@ Usage | ||
var buildPath = require('page-path-builder') | ||
```js | ||
var buildPath = require('./') | ||
var path = buildPath('/wat/:huh/yeah', { huh: 'go figure' }) | ||
buildPath('/wat/:huh/yeah', { huh: 'go figure' }) // => '/wat/go%20figure/yeah' | ||
``` | ||
console.log(path) // => /wat/go%20figure/yeah | ||
Or parse a path once for more efficient url construction later: | ||
var parsedPath = buildPath('/page/:id') | ||
```js | ||
var parsedPath = buildPath('/page/:id') | ||
var path = buildPath(parsedPath, { id: 13 }) | ||
buildPath(parsedPath, { id: 13 }) // => '/page/13' | ||
console.log(path) // => /page/13 | ||
var anotherPath = buildPath(parsedPath, { id: 1337 }) | ||
console.log(anotherPath) // => /page/1337 | ||
buildPath(parsedPath, { id: 1337 }) // => '/page/1337' | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3519
60
2
23