Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var relative = require('./source-relative');
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Codec for relative paths with respect to the source directory.
|
---|
7 | * @type {{name:string, decode: function, encode: function, root: function}}
|
---|
8 | */
|
---|
9 | module.exports = {
|
---|
10 | name : 'sourceRootRelative',
|
---|
11 | decode: decode,
|
---|
12 | encode: encode,
|
---|
13 | root : relative.root
|
---|
14 | };
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Decode the given uri.
|
---|
18 | * Any path with leading slash is tested against source directory.
|
---|
19 | * @this {{options: object}} A loader or compilation
|
---|
20 | * @param {string} uri A source uri to decode
|
---|
21 | * @returns {boolean|string} False where unmatched else the decoded path
|
---|
22 | */
|
---|
23 | function decode(uri) {
|
---|
24 | /* jshint validthis:true */
|
---|
25 | return uri.startsWith('/') && relative.decode.call(this, uri.slice(1));
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Encode the given file path.
|
---|
30 | * @this {{options: object}} A loader or compilation
|
---|
31 | * @param {string} absolute An absolute file path to encode
|
---|
32 | * @returns {string} A uri with leading slash
|
---|
33 | */
|
---|
34 | function encode(absolute) {
|
---|
35 | /* jshint validthis:true */
|
---|
36 | return '/' + relative.encode.call(this, absolute);
|
---|
37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.