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.2.2
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

.stringify ( name, context )

Build a URL/filepath string from the properties on the given object.

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

.rename ( filepath, options )

Generate a file path using the rename utility.

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 node.js path module.

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

// use the `site` route to parse the filepath
var obj = rte.parse('src/templates/about.hbs', 'site');
// =>
{ basename: 'about',
dirname: 'src/templates',
extname: '.hbs',
name: 'about',
extSegments: [ '.hbs' ],
dest: 'root/about/index.hbs' }
  • 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.

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

// use the `site` route to create a dest filepath
var dest = rte.dest('src/templates/about.hbs', 'site');
// => '_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

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 June 30, 2014.

Keywords

blog entry

FAQs

Package last updated on 30 Jun 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