Socket
Socket
Sign inDemoInstall

@sanity/state-router

Package Overview
Dependencies
1
Maintainers
6
Versions
702
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0-beta.0 to 0.2.0-beta.1

2

lib/resolvePathFromState.js

@@ -45,3 +45,3 @@ 'use strict';

}
var transform = node.transform && node.transform[segment.name];
var transform = matchNode.transform && matchNode.transform[segment.name];
return transform ? transform.toPath(scopedState[segment.name]) : scopedState[segment.name];

@@ -48,0 +48,0 @@ });

{
"name": "@sanity/state-router",
"version": "0.2.0-beta.0",
"version": "0.2.0-beta.1",
"description": "A path pattern => state object bidirectional mapper",

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

@@ -30,3 +30,3 @@ // @flow

}
const transform = node.transform && node.transform[segment.name]
const transform = matchNode.transform && matchNode.transform[segment.name]
return transform ? transform.toPath(scopedState[segment.name]) : scopedState[segment.name]

@@ -33,0 +33,0 @@ })

// @flow
import test from './_util/test'
import route from '../src/route'
function decodeParams(pathsegment) {
return pathsegment.split(';')
.reduce((params, pair) => {
const [key, value] = pair.split('=')
params[key] = value
return params
}, {})
}
function encodeParams(params) {
return Object.keys(params)
.map(key => `${key}=${params[key]}`)
.join(';')
}
test('route(options)', t => {
test('transform config on regular routes', t => {
const router = route('/some/:section/:settings', {
transform: {
settings: {
toState(settings) {
return settings.split(';')
.reduce((params, pair) => {
const [key, value] = pair.split('=')
params[key] = value
return params
}, {})
},
toPath(params) {
return Object.keys(params)
.map(key => `${key}=${params[key]}`)
.join(';')
}
toState: decodeParams,
toPath: encodeParams
}

@@ -56,1 +58,35 @@ }

})
test('transform config on scoped routes', t => {
const router = route('/some/:section', [
route('/other/:params', {
scope: 'myscope',
transform: {
params: {
toState: decodeParams,
toPath: encodeParams
}
}
})
])
t.same(router.decode('/some/foo/other/width=full;view=details'), {
section: 'foo',
myscope: {
params: {
width: 'full',
view: 'details',
}
}
})
t.same(router.encode({
section: 'foo',
myscope: {
params: {
width: 'full',
view: 'details',
}
}
}), '/some/foo/other/width=full;view=details')
})
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc