New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

route-node

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

route-node - npm Package Compare versions

Comparing version 3.4.2 to 4.0.0

dist/helpers.d.ts

14

CHANGELOG.md

@@ -0,1 +1,15 @@

# [4.0.0](https://github.com/troch/route-node/compare/v3.4.2...v4.0.0) (2020-03-01)
### Features
* Maintain project and dependencies ([#28](https://github.com/troch/route-node/issues/28)) ([7637f06](https://github.com/troch/route-node/commit/7637f062e664b18573e0a727d45a2077636cc0e1))
* New match and build option `urlParamsEncoding` to choose how URL params are encoded and decoded (see README)
### BREAKING CHANGES
* Constructor signature has changed to become: `new RouteNode(nodeName, path, children, options)`. See README.
<a name="3.4.2"></a>

@@ -2,0 +16,0 @@ ## [3.4.2](https://github.com/troch/route-node/compare/v3.4.1...v3.4.2) (2018-10-16)

68

package.json
{
"name": "route-node",
"version": "3.4.2",
"version": "4.0.0",
"description": "A package to create a tree of named routes",
"main": "dist/cjs/route-node.js",
"jsnext:main": "dist/es/route-node.js",
"module": "dist/es/route-node.js",
"main": "dist/index.js",
"module": "dist/route-node.esm.js",
"typings": "dist/index.d.ts",
"sideEffects": false,
"typings": "./typings/RouteNode.d.ts",
"files": [
"dist",
"LICENSE"
],
"scripts": {
"test": "mocha -r ts-node/register 'test/main.js'",
"lint": "tslint modules/*.ts",
"clean": "rimraf dist",
"build": "npm run clean && rollup -c rollup.config.js",
"clog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"precommit": "lint-staged"
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint src test",
"prepare": "tsdx build",
"clog": "conventional-changelog -p angular -i CHANGELOG.md -s"
},
"lint-staged": {
"modules/*.ts": [
"prettier --write",
"tslint",
"git add"
],
"test/*.js": [
"prettier --write",
"git add"
]
},
"repository": {

@@ -39,3 +31,3 @@ "type": "git",

"author": "Thomas Roch",
"license": "ISC",
"license": "MIT",
"bugs": {

@@ -46,22 +38,18 @@ "url": "https://github.com/troch/route-node/issues"

"devDependencies": {
"conventional-changelog-cli": "~2.0.1",
"husky": "~0.14.3",
"lint-staged": "~7.0.0",
"lodash.omit": "~4.5.0",
"mocha": "~5.0.5",
"prettier": "~1.11.1",
"rimraf": "~2.6.2",
"rollup": "~0.57.1",
"rollup-plugin-node-resolve": "~3.3.0",
"rollup-plugin-typescript2": "~0.12.0",
"should": "~13.2.1",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"tslint-config-prettier": "~1.10.0",
"typescript": "~2.7.2"
"conventional-changelog-cli": "2.0.31",
"@types/jest": "^24.0.25",
"husky": "^3.1.0",
"tsdx": "^0.12.1",
"typescript": "^3.7.4"
},
"dependencies": {
"path-parser": "4.2.0",
"search-params": "2.1.3"
"path-parser": "6.1.0",
"search-params": "3.0.0",
"tslib": "^1.10.0"
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint src test"
}
}
}

@@ -5,3 +5,2 @@ [![npm version](https://badge.fury.io/js/route-node.svg)](http://badge.fury.io/js/route-node)

# route-node

@@ -15,3 +14,2 @@

## Creating your tree

@@ -22,28 +20,25 @@

```javascript
import rootNode from 'route-node';
import rootNode from 'route-node'
// Create nodes
const usersNode = new RouteNode('users', '/users', [
new RouteNode('list', '/list'),
new RouteNode('view', '/view/:id')
]);
new RouteNode('list', '/list'),
new RouteNode('view', '/view/:id')
])
// You can also use plain objects
const ordersNode = new RouteNode('orders', '/orders', [
{name: 'pending', path: '/pending'},
{name: 'completed', path: '/completed'},
{name: 'view', path: '/view/:id'}
]);
{ name: 'pending', path: '/pending' },
{ name: 'completed', path: '/completed' },
{ name: 'view', path: '/view/:id' }
])
// Creating a top root node
const rootNode = new RouteNode('', '', [
ordersNode,
usersNode
]);
const rootNode = new RouteNode('', '', [ordersNode, usersNode])
// Add nodes programmatically
rootNode.add(new RouteNode('home', '/home'));
rootNode.add(new RouteNode('home', '/home'))
```
__`/` paths__
**`/` paths (empty paths)**

@@ -54,32 +49,41 @@ When using a deeply nested `/` path, it will automatically be matched when its parent is matched.

const tree = new RouteNode('', '', [
new RouteNode('admin', '/admin', [
new RouteNode('home', '/'),
new RouteNode('users', '/users')
])
]);
new RouteNode('admin', '/admin', [
new RouteNode('home', '/'),
new RouteNode('users', '/users')
])
])
tree.matchPath('/admin'); // => { name: 'admin.home', params: {} }
tree.buildPath('admin.home', {}, { trailingSlashMode: 'never' }); // => '/admin'
tree.matchPath('/admin') // => { name: 'admin.home', params: {} }
tree.buildPath('admin.home', {}, { trailingSlashMode: 'never' }) // => '/admin'
```
__Callbacks__
**Options**
When adding routes (with contructor or `.add`), you can pass a callback which will be executed for each route added successfully to the tree.
```js
const node = new RouteNode('admin', '/admin', [], options)
```
Where options can contain:
- `onAdd`: a callback called when adding routes (with contructor or `.add`), you can pass a callback which will be executed for each route added successfully to the tree.
- `parent`: the node parent
- `finalSort`: to sort children (matching order) after having added all children routes (rather than on each add)
- `sort`: whether to sort on each add or not (default to true, overriden by `finalSort`)
## Building and matching routes
__node.buildPath(routeName: string, params?: object, options?: BuildOptions): string__
**node.buildPath(routeName: string, params?: object, options?: BuildOptions): string**
```javascript
rootNode.buildPath('users.view', {id: 1}) // => "/users/view/1"
rootNode.buildPath('users.view', { id: 1 }) // => "/users/view/1"
```
__Performance__
**Performance**
Node children need to be sorted for matching purposes. By default this operation happens after having added all routes.
__matchPath(path: string, options?: MatchOptions): RouteNodeState | null__
**matchPath(path: string, options?: MatchOptions): RouteNodeState | null**
```js
rootNode.matchPath('/users/view/1');
rootNode.matchPath('/users/view/1')
// => {name: "users.view", params: {id: "1"}}

@@ -91,2 +95,11 @@ ```

Options available:
- `'urlParamsEncoding`, to specify how URL parameters are encoded and decoded:
- `'default'`: `encodeURIComponent` and `decodeURIComponent` are used but some characters to encode and decode URL parameters, but some characters are preserved when encoding (sub-delimiters:`+`,`:`,`'`,`!`,`,`,`;`,`*`).
- `'uriComponent'`: use `encodeURIComponent` and `decodeURIComponent`
for encoding and decoding URL parameters.
- `'uri'`: use `encodeURI` and `decodeURI for encoding amd decoding
URL parameters.
- `'none'`: no encoding or decoding is performed
- `'legacy'`: the approach for version 5.x and below (not recommended)
- `trailingSlashMode`:

@@ -93,0 +106,0 @@ - `'default'`: building follows path definitions

Sorry, the diff of this file is not supported yet

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