Socket
Socket
Sign inDemoInstall

@sanity/state-router

Package Overview
Dependencies
Maintainers
6
Versions
702
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/state-router - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0-beta.0

lib/components/IntentLink.js

3

lib/components/RouterProvider.js

@@ -49,2 +49,4 @@ 'use strict';

return _this.props.router.encode(state);
}, _this.resolveIntentLink = function (intent, params) {
return _this.props.router.encode({ intent: intent, params: params });
}, _temp), _possibleConstructorReturn(_this, _ret);

@@ -61,2 +63,3 @@ }

resolvePathFromState: this.resolvePathFromState,
resolveIntentLink: this.resolveIntentLink,
navigateUrl: this.navigateUrl

@@ -63,0 +66,0 @@ },

@@ -46,2 +46,3 @@ 'use strict';

},
resolveIntentLink: __internalRouter.resolveIntentLink,
navigateUrl: __internalRouter.navigateUrl

@@ -48,0 +49,0 @@ },

@@ -25,2 +25,4 @@ 'use strict';

var _paramsEncoding = require('./utils/paramsEncoding');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -70,2 +72,24 @@

function normalize() {
for (var _len2 = arguments.length, paths = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
paths[_key2] = arguments[_key2];
}
return paths.reduce(function (acc, path) {
return acc.concat(path.split('/'));
}, []).filter(Boolean);
}
route.intents = function intents(base) {
var basePath = normalize(base).join('/');
return route(basePath + '/:intent', [route(':params', {
transform: {
params: {
toState: _paramsEncoding.decodeParams,
toPath: _paramsEncoding.encodeParams
}
}
})]);
};
var EMPTY_STATE = {};

@@ -72,0 +96,0 @@ function isRoot(pathname) {

2

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

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

@@ -24,2 +24,6 @@ import React, {PropTypes} from 'react'

resolveIntentLink = (intent, params) => {
return this.props.router.encode({intent, params})
}
getChildContext() {

@@ -30,2 +34,3 @@ const {state} = this.props

resolvePathFromState: this.resolvePathFromState,
resolveIntentLink: this.resolveIntentLink,
navigateUrl: this.navigateUrl

@@ -32,0 +37,0 @@ },

@@ -23,2 +23,3 @@ import React, {PropTypes} from 'react'

},
resolveIntentLink: __internalRouter.resolveIntentLink,
navigateUrl: __internalRouter.navigateUrl

@@ -25,0 +26,0 @@ },

@@ -7,2 +7,3 @@ // @flow

import resolvePathFromState from './resolvePathFromState'
import {decodeParams, encodeParams} from './utils/paramsEncoding'

@@ -62,2 +63,20 @@ type NodeOptions = {

function normalize(...paths) {
return paths
.reduce((acc, path) => acc.concat(path.split('/')), [])
.filter(Boolean)
}
route.intents = function intents(base) {
const basePath = normalize(base).join('/')
return route(`${basePath}/:intent`, [route(':params', {
transform: {
params: {
toState: decodeParams,
toPath: encodeParams
}
}
})])
}
const EMPTY_STATE = {}

@@ -64,0 +83,0 @@ function isRoot(pathname: string): boolean {

// @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(';')
}
import {decodeParams, encodeParams} from '../src/utils/paramsEncoding'

@@ -18,0 +6,0 @@ test('transform config on regular routes', t => {

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