source: imaps-frontend/node_modules/common-path-prefix/README.md@ 79a0317

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[79a0317]1# common-path-prefix
2
3Computes the longest prefix string that is common to each path, excluding the base component. Tested with Node.js 8 and above.
4
5## Installation
6
7```console
8npm install common-path-prefix
9```
10
11## Usage
12
13The module has one default export, the `commonPathPrefix` function:
14
15```js
16const commonPathPrefix = require('common-path-prefix')
17```
18
19Call `commonPathPrefix()` with an array of paths (strings) and an optional separator character:
20
21```js
22const paths = ['templates/main.handlebars', 'templates/_partial.handlebars']
23
24commonPathPrefix(paths, '/') // returns 'templates/'
25```
26
27If the separator is not provided the first `/` or `\` found in any of the paths is used. Otherwise the platform-default value is used:
28
29```js
30commonPathPrefix(['templates/main.handlebars', 'templates/_partial.handlebars']) // returns 'templates/'
31commonPathPrefix(['templates\\main.handlebars', 'templates\\_partial.handlebars']) // returns 'templates\\'
32```
33
34You can provide any separator, for example:
35
36```js
37commonPathPrefix(['foo$bar', 'foo$baz'], '$') // returns 'foo$''
38```
39
40An empty string is returned if no common prefix exists:
41
42```js
43commonPathPrefix(['foo/bar', 'baz/qux']) // returns ''
44commonPathPrefix(['foo/bar']) // returns ''
45```
46
47Note that the following *does* have a common prefix:
48
49```js
50commonPathPrefix(['/foo/bar', '/baz/qux']) // returns '/'
51```
Note: See TracBrowser for help on using the repository browser.