Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

page-path-builder

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

page-path-builder - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

.travis.yml

39

index.js
var parser = require('./path-parser')
var stringifyQuerystring = require('querystring').stringify
module.exports = function(pathStr, parameters) {
var parsed
if (typeof pathStr === 'string') {
parsed = parser(pathStr)
} else {
parsed = pathStr
}
var parsed = typeof pathStr === 'string' ? parser(pathStr) : pathStr
var allTokens = parsed.allTokens

@@ -16,3 +11,3 @@ var regex = parsed.regex

if (parameters) {
var path = allTokens.map(function(bit) {
var path = allTokens.map(function(bit) {
if (bit.string) {

@@ -33,3 +28,3 @@ return bit.string

return path
return buildPathWithQuerystring(path, parameters, allTokens)
} else {

@@ -39,1 +34,27 @@ return parsed

}
function buildPathWithQuerystring(path, parameters, tokenArray) {
var parametersInQuerystring = getParametersWithoutMatchingToken(parameters, tokenArray)
if (Object.keys(parametersInQuerystring).length === 0) {
return path
}
return path + '?' + stringifyQuerystring(parametersInQuerystring)
}
function getParametersWithoutMatchingToken(parameters, tokenArray) {
var tokenHash = tokenArray.reduce(function(memo, bit) {
if (!bit.string) {
memo[bit.name] = bit
}
return memo
}, {})
return Object.keys(parameters).filter(function(param) {
return !tokenHash[param]
}).reduce(function(newParameters, param) {
newParameters[param] = parameters[param]
return newParameters
}, {})
}
{
"name": "page-path-builder",
"version": "1.0.1",
"version": "1.0.2",
"description": "Uses a page.js-style routing string to build up a path you can link to",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -0,1 +1,2 @@

[![Build Status](https://travis-ci.org/TehShrike/page-path-builder.svg)](https://travis-ci.org/TehShrike/page-path-builder)

@@ -2,0 +3,0 @@ For those times when you want to programmatically generate a link to page.js route.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc