0.1.0 • Published 11 years ago

remapper v0.1.0

Weekly downloads
42
License
-
Repository
-
Last release
11 years ago

h1. remapper

Is an URL path remapper. Given an input path, it will rewrite it according to some rules. Similar to a router, but it's okay to have multiple route matches, the first one that satisfies additional criteria will be returned.

An example rule:

    {
      source: '/source/(.*)',
      dest: '/#dest/{whoopsie}/{1}',

      // Everything bellow is optional:
      config: ['test.whatever', 'feature.another'],
      sourceParams: ['whoopsie', 'mobile'],
      destParams: {
        'rest': '{1}',
        'deleteme': null
      },
      forwardParams: true,
      data: { pageKey: 'somethingrather' }
    }

Source is a regexp that, when matched, will be converted to dest. Dest can refer to query params and numbered capture groups from source.

If config is present, it will test for existence of given keys in the passed config hash in order to match the rule.

sourceParams is the list of required query parameters in the source string,

destParams is the list of query parameters output. It also supports referenes. If forwardParams is true, the list of parameters starts from source parameters and adds destParams, otherwise it's just destParams. Setting a param to null deletes it from the original list.

data is whatever data you want returned when this route is matched.

Soo:

    var r = new Router([{ source: ..., dest: ... }, ... ]);
    var result = r.map('http://whatever/source', {
      test: {
        whatever: true
      }
    });
    if (result === null) {
      console.log('Nothing.');
    } else {
      console.log(result.url);
      console.log(result.data);
    }
0.1.0

11 years ago

0.0.9

11 years ago

0.0.8

11 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago