@mangos/filepath 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,11 +61,11 @@ There are 4 exported functions:
|
|
|
61
61
|
import { allPath, firstPath, resolve, resolvePathObject } from '@mangos/filepath';
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
Most of the time you will be using
|
|
64
|
+
Most of the time you will be using <a href="#fn-resolve"><code>resolve</code></a>, <a href="#fn-first-path"><code>firstPath</code></a>.
|
|
65
65
|
|
|
66
66
|
<h3 id="infer-path-options">Type <code>InferPathOptions</code></h3>
|
|
67
67
|
|
|
68
|
-
The functions
|
|
68
|
+
The functions <a href="fn-all-path"><code>allPath</code></a> and <a href="fn-first-path"><code>firstPath</code></a> will try to tokenize a path string based on options object specified as the second argument.
|
|
69
69
|
|
|
70
70
|
```typescript
|
|
71
71
|
type InferPathOptions = {
|
|
@@ -76,17 +76,17 @@ type InferPathOptions = {
|
|
|
76
76
|
}
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
Multiple path types
|
|
79
|
+
Multiple path types <i>can</i> be tokenized from the same path string.
|
|
80
80
|
|
|
81
|
-
The response of
|
|
81
|
+
The response of <a href="#fn-all-path"><code>allPath</code></a> will be an <b>array</b> of `ParsedPath` <b>or/and</b> <a href="#parsed-path-error"><code>ParsedPathError</code></a> class instance, representing parsing for multiple OS path types.
|
|
82
82
|
|
|
83
83
|
<h4 id="infer-path-options-defaults">defaults:</h4>
|
|
84
84
|
|
|
85
|
-
If <
|
|
85
|
+
If <a href="#infer-path-options"><code>InferpathOptions</code></a> argument is left empty in <a href="#fn-all-path"><code>allPath</code></a> and <a href="#fn-first-path"><code>firstPath</code></a> the default will be used based on OS:
|
|
86
86
|
|
|
87
87
|
|
|
88
|
-
- The default for windos:
|
|
89
|
-
- The default for unix:
|
|
88
|
+
- The default for windos: <code>{ dos: true, devicePath: true, unc: true, posix: false }</code>
|
|
89
|
+
- The default for unix: <code>{ posix: true }</code>
|
|
90
90
|
|
|
91
91
|
<h3 id="parsed-path"><code>ParsedPath</code> object</h3>
|
|
92
92
|
|
|
@@ -95,21 +95,21 @@ The response of a successfull path tokenization will be an ADT: `ParsedPath`.
|
|
|
95
95
|
An instance of `ParsedPath` has the following fields/members
|
|
96
96
|
|
|
97
97
|
- members:
|
|
98
|
-
-
|
|
99
|
-
-
|
|
98
|
+
- <code>toString(): <i>string</i></code>: return the original path string
|
|
99
|
+
- <code>isRelative(): <i>boolean</i></codes>: is the a path a relative one?
|
|
100
100
|
- fields:
|
|
101
|
-
-
|
|
102
|
-
-
|
|
101
|
+
- <code>type: <i>string</i></code>: one of the value `devicePath`, `unc`, `dos`, `posix`.
|
|
102
|
+
- <code>path: <i>Token[]</i></code>: the path tokenized (see source).
|
|
103
103
|
|
|
104
104
|
<h3 id="parsed-path-error"><code>ParsedPathError</code> object</h3>
|
|
105
105
|
|
|
106
|
-
If a path has illigal characters or is invalid the result of a tokenization will be an ADT:
|
|
106
|
+
If a path has illigal characters or is invalid the result of a tokenization will be an ADT: <code>ParsedPathError</code>
|
|
107
107
|
|
|
108
108
|
- members:
|
|
109
|
-
-
|
|
109
|
+
- <code>toString(): <i>string</i></code>: algamation of all errors found during parsing.
|
|
110
110
|
- attributes:
|
|
111
|
-
-
|
|
112
|
-
-
|
|
111
|
+
- <code>type: <i>string</i></code>: one of the values `devicePath`, `unc`, `dos`, `posix`.
|
|
112
|
+
- <code>path: <i>Token[]</i></code>: the path tokenized.
|
|
113
113
|
|
|
114
114
|
|
|
115
115
|
<h3 id="path-type-order-of-evaluation">Path type order of evaluation</h4>
|
|
@@ -131,8 +131,8 @@ function allPath(path = '', options: InferPathOptions = {}): (ParsedPath | Parse
|
|
|
131
131
|
|
|
132
132
|
<h5 id="fn-all-path-arguments">Arguments:</h5>
|
|
133
133
|
|
|
134
|
-
- <code>path: <i>string</i> optional</code>: (<b>Default</b> is current working directory). Relative or absolute <code>path</code> conforming to one of the <a href="#supported-path">supported path types</a>.
|
|
135
|
-
- <code>options: <
|
|
134
|
+
- <code>path: <i>string</i> optional</code>: (<b>Default</b> is current working directory). Relative or absolute <code>path</code> conforming to one of the <a href="#supported-path">supported path types</a>.
|
|
135
|
+
- <code>options: <i>InferPathOptions</i> optional</code>: Parsing limited to flags set to <code>true</code> in <a href="#infer-path-options">options</a>.
|
|
136
136
|
|
|
137
137
|
<h5 id="fn-all-path-return">Return:</h5>
|
|
138
138
|
|
|
@@ -165,52 +165,50 @@ function firstPath(path = '', options: InferPathOptions = {}): ParsedPath | Pars
|
|
|
165
165
|
|
|
166
166
|
<h5 id="fn-first-path-arguments">Arguments:</h5>
|
|
167
167
|
|
|
168
|
-
- <code>path: <i>string</i> optional</code>: (<b>Default</b> is current working directory). Relative or absolute <code>path</code> conforming to one of the <a href="#supported-path">supported path types</a>.
|
|
169
|
-
- <code>options: <
|
|
168
|
+
- <code>path: <i>string</i> optional</code>: (<b>Default</b> is current working directory). Relative or absolute <code>path</code> conforming to one of the <a href="#supported-path">supported path types</a>.
|
|
169
|
+
- <code>options: <i>InferPathOptions</i> optional</code>: Parsing limited to flags set to <code>true</code> in <a href="#infer-path-options">options</a>.
|
|
170
170
|
|
|
171
171
|
<h5 id="fn-all-path-return">Return:</h5>
|
|
172
172
|
|
|
173
173
|
- <code>undefined</code>: The path was not confirm to any of the types listed in <a href="#supported-path">path types</a>
|
|
174
174
|
|
|
175
175
|
- <a href="#parsed-path"><code>ParsedPath</code></a>: In case of successfull parse.
|
|
176
|
-
|
|
177
176
|
- <a href="#parsed-path-error"><code>ParsedPathError</code></a>: In case of legal structure but illegal characters in the path.
|
|
178
177
|
|
|
179
178
|
|
|
180
|
-
<h4 id="fn-resolve-path-
|
|
179
|
+
<h4 id="fn-resolve-path-object">function: <code>resolvePathObject</code></h4>
|
|
181
180
|
|
|
182
181
|
```typescript
|
|
183
182
|
function resolvePathObject(from: ParsedPath, ...toFragments: string[]): ParsedPath | ParsedPathError;
|
|
184
183
|
```
|
|
185
184
|
|
|
186
|
-
<h5 id="fn-resolve-path-
|
|
185
|
+
<h5 id="fn-resolve-path-object-arguments">Arguments:</h5>
|
|
187
186
|
|
|
188
|
-
- <code>from: <
|
|
187
|
+
- <code>from: <i>ParsedPath</i></code>: A previously created <code><a href="#parsed-path">ParsedPath</a></code> object via <a href="#fn-first-path"><code>firstPath</code></a> function.
|
|
189
188
|
- <code>toFragments: <i>string[]</i></code>: A sequence of paths or path segments.
|
|
190
189
|
|
|
191
|
-
<h5 id="fn-resolve-path-
|
|
190
|
+
<h5 id="fn-resolve-path-object-return">Return:</h5>
|
|
192
191
|
|
|
193
192
|
- <a href="#parsed-path"><code>ParsedPath</code></a>: In case of successfull resolve.
|
|
194
193
|
- <a href="#parsed-path-error"><code>ParsedPathError</code></a>: In case of legal structure but illegal characters in the `from` or `toFragments`.
|
|
195
194
|
|
|
196
|
-
<h5 id="fn-resolve-path-
|
|
195
|
+
<h5 id="fn-resolve-path-object-throws">throws:</h5>
|
|
197
196
|
|
|
198
197
|
If <code>from</code> is a <a href="#parsed-path-error"><code>ParsedPathError</code></a> an `Error` will be thrown.
|
|
199
198
|
|
|
200
199
|
<h4 id="fn-resolve">function: <code>resolve</code></h4>
|
|
201
200
|
|
|
202
201
|
```typescript
|
|
203
|
-
function resolve(fromStr
|
|
202
|
+
function resolve(fromStr: string, ...toFragments: string[]): ParsedPath | ParsedPathError;
|
|
204
203
|
```
|
|
205
204
|
|
|
206
205
|
<h5 id="fn-resolve-arguments">Arguments:</h5>
|
|
207
206
|
|
|
208
|
-
- <code>fromStr: <i>string</i
|
|
207
|
+
- <code>fromStr: <i>string</i> optional</code>: A path according to a <a href="#supperted-path">path type</a>. Defaults to current working directory if absent/undefined.
|
|
209
208
|
- <code>toFragments: <i>string[]</i></code>: A sequence of paths or path segments.
|
|
210
209
|
|
|
211
210
|
<h5 id="fn-resolve-return">Return:</h5>
|
|
212
211
|
|
|
213
|
-
|
|
214
212
|
- <a href="#parsed-path"><code>ParsedPath</code></a>: In case of successfull resolve.
|
|
215
213
|
- <a href="#parsed-path-error"><code>ParsedPathError</code></a>: In case of legal structure but illegal characters in the `from` or `toFragments`.
|
|
216
214
|
|