slicer
A library to parse URI style strings into named segments.
Last updated 14 years ago by antz29 .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install slicer 
SYNC missed versions from official npm registry.

node-slicer - Slice your URIs

Installation

npm install slicer 

What's it do?

It allows you to slice up URIs into named segments. This can be useful for routing requests etc.

Usage

// Create a new slicer (you can have multiple slicer instances that are independant of one another)
var s = require("slicer").create();

// Add a segment identifier for the first URI segment with a default value of 'index'.
s.addSegmentIdentifier('controller','index');

// Add a segment identifier for the second URI segment with a default value of 'index'.
s.addSegmentIdentifier('action','index');

// Slice a URI
var uri = s.slice('/foo');

// Outputs: 
// { 
//     controller: 'foo',
//     action: 'index',
//     uri: [] 
// }

// Note that the action segment is given the default value.

// Slice another URI
var uri = s.slice('/foo/bar/a/b/c');

// Outputs: 
// {   
//     controller: 'foo',
//     action: 'bar',
//     uri: [ 'a', 'b', 'c' ] 
// }

// Note that the uri element contains any non labeled segments.

Bugs

See https://github.com/antz29/node-slicer/issues.

Current Tags

  • 0.3.0                                ...           latest (14 years ago)

4 Versions

  • 0.3.0                                ...           14 years ago
  • 0.2.1                                ...           14 years ago
  • 0.2.0                                ...           14 years ago
  • 0.1.0                                ...           14 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 4
Last Month 0
Dependencies (1)
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |