Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

rte

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rte

Simple, server-side routing to complement the node.js path module.

Source
npmnpm
Version
0.3.0
Version published
Weekly downloads
9
-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

rte NPM version

Simple, server-side routing to complement the node.js path module.

Table of Contents

Install

Install with npm:

npm i rte --save-dev

Tests

Run mocha or npm test to run the tests. Visit the tests to learn how this works.

Getting started

Create a new instance:

// optionally pass a default `context`
var rte = new Route({root: '_gh_pages', ext: '.html'});

Next, define some routes to use:

rte.set('site', ':root/:basename/index:ext');
rte.set('blog', ':root/blog/:basename/index:ext');

Last, generate your destination paths:

// use the `site` route to create the dest filepath
var dest = rte.dest('src/templates/about.hbs', 'site');
// => '_gh_pages/about/index.html'

// use the `blog` route to create the dest filepath
var dest = rte.dest('src/templates/about.hbs', 'site');
// => '_gh_pages/blog/about/index.html'

Override the default context:

var dest = rte.dest('src/templates/about.hbs', 'site', {root: 'dist'});
// => 'dist/blog/about/index.html'

API

Route

Define a new instance of Route, optionally passing a default context object.

Example

var route = new Route({base: 'dist'});
  • type {String}:
  • return

.set ( name, route )

Set or get a route by name.

route.set('dest', ':base/:dirname/:basename/index.html');
  • name {String}:
  • route {String}:
  • return

.get ( name )

Get a route by name.

route.get('dest');
// ':base/:dirname/:basename/index.html'
  • name {String}:
  • return

.rename ( filepath, options )

Rename parts of a file path using rename-path.

route.rename ('a/b/c.hbs', {ext: '.html'});
//=> 'a/b/c.html'
  • filepath {String}:
  • options {Object}:
  • return

.parse ( filepath, name, context )

Parse the filepath into an object using the named route and the methods on the node.js path module. The purpose of this method is to simplify the process of renaming parts of file paths.

Example:

Given this route:

rte.set('foo', ':a/:b/:basename/index:ext');

We can parse a filepath and create an object that consists of properties that are created using the foo route, e.g.

var obj = rte.parse('src/templates/about.hbs', 'foo', {
  a: 'one',
  b: 'two',
  ext: '.html'
});
console.log(obj);

which results in:

{
  dirname: 'src/templates',
  basename: 'about',
  name: 'about',
  extname: '.hbs',
  extSegments: ['.hbs'],
  ext: '.html',
  a: 'one',
  b: 'two',
  dest: 'one/two/about/index.html' // based on the `foo` propstring
}
  • filepath {String}:
  • name {String}: The name of the route to use
  • context {Object}: Optionally pass a context with custom properties.
  • return

.dest ( filepath, name, context )

Facade for .parse(), returning only the dest value.

Example:

rte.set('blog', ':foo/:basename/index:ext');

// use the `blog` route to create a dest filepath
var dest = rte.dest('src/templates/about.hbs', 'blog');
// => '_gh_pages/about/index.html'
  • filepath {String}:
  • name {String}: The name of the route to use
  • context {Object}: Optionally pass a context with custom properties.
  • return

.process ( name, context )

Resolve a named route using the properties on the given object.

route.process (name, context)

Example:

route.process(':a/:b/:c', {a: 'one', b: 'two', c: 'three'});
//=> 'one/two/three'
  • key {String}:
  • context {Object}:
  • return

.resolve

Resolve a named route using the properties on the given object.

route.resolve (name, context)

Example:

route.set('dist', ':foo/:basename/index.html');
route.resolve('dist', {foo: '_gh_pages', basename: 'foo'});
//=> '_gh_pages/foo/index.html'
  • key {String}:
  • context {Object}:
  • return

Expose Route

  • return

Contributing

Find a bug? Have a feature request? Please create an Issue.

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality, and run docs in the command line to build the docs with Verb.

Pull requests are also encouraged, and if you find this project useful please consider "starring" it to show your support! Thanks!

Authors

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license

This file was generated by verb-cli on July 10, 2014.

Keywords

blog entry

FAQs

Package last updated on 10 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts