source: imaps-frontend/node_modules/enhanced-resolve/lib/getPaths.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8/**
9 * @param {string} path path
10 * @returns {{paths: string[], segments: string[]}}} paths and segments
11 */
12module.exports = function getPaths(path) {
13 if (path === "/") return { paths: ["/"], segments: [""] };
14 const parts = path.split(/(.*?[\\/]+)/);
15 const paths = [path];
16 const segments = [parts[parts.length - 1]];
17 let part = parts[parts.length - 1];
18 path = path.substring(0, path.length - part.length - 1);
19 for (let i = parts.length - 2; i > 2; i -= 2) {
20 paths.push(path);
21 part = parts[i];
22 path = path.substring(0, path.length - part.length) || "/";
23 segments.push(part.slice(0, -1));
24 }
25 part = parts[1];
26 segments.push(part);
27 paths.push(part);
28 return {
29 paths: paths,
30 segments: segments
31 };
32};
33
34/**
35 * @param {string} path path
36 * @returns {string|null} basename or null
37 */
38module.exports.basename = function basename(path) {
39 const i = path.lastIndexOf("/"),
40 j = path.lastIndexOf("\\");
41 const p = i < 0 ? j : j < 0 ? i : i < j ? j : i;
42 if (p < 0) return null;
43 const s = path.slice(p + 1);
44 return s;
45};
Note: See TracBrowser for help on using the repository browser.