@mangos/filepath 0.0.8 → 1.0.0
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 +161 -221
- package/dist/ParsedPath.d.ts +9 -0
- package/dist/ParsedPath.js +17 -0
- package/dist/ParsedPathError.d.ts +9 -0
- package/dist/ParsedPathError.js +20 -0
- package/dist/Token.d.ts +17 -0
- package/dist/Token.js +22 -0
- package/dist/absorbSuccessiveValues.d.ts +4 -0
- package/dist/absorbSuccessiveValues.js +21 -0
- package/dist/absorbers/ddp.d.ts +10 -0
- package/dist/absorbers/ddp.js +46 -0
- package/dist/absorbers/posix.d.ts +2 -0
- package/dist/absorbers/posix.js +33 -0
- package/dist/absorbers/tdp.d.ts +3 -0
- package/dist/absorbers/tdp.js +132 -0
- package/dist/absorbers/unc.d.ts +3 -0
- package/dist/absorbers/unc.js +20 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +17 -0
- package/dist/getCWD.d.ts +1 -0
- package/dist/getCWD.js +12 -0
- package/dist/getDrive.d.ts +1 -0
- package/dist/getDrive.js +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/parser.d.ts +17 -0
- package/dist/parser.js +161 -0
- package/dist/platform.d.ts +1 -0
- package/dist/platform.js +19 -0
- package/dist/togglePathFragment.d.ts +1 -0
- package/dist/togglePathFragment.js +5 -0
- package/dist/types/TokenValueType.d.ts +2 -0
- package/dist/validSep.d.ts +1 -0
- package/dist/validSep.js +6 -0
- package/package.json +61 -49
- package/.eslintrc.js +0 -17
- package/CHANGELOG.md +0 -59
- package/CODE_OF_CONDUCT.md +0 -69
- package/CONTRIBUTING_GUIDELINES.md +0 -9
- package/index.js +0 -23
- package/lib/parser.js +0 -191
- package/lib/tokenizer.js +0 -397
- package/test.js +0 -5
package/CHANGELOG.md
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
## current
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
## "0.0.8"
|
|
5
|
-
### fixes
|
|
6
|
-
- corrected a link in package/filepath/readme.md
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## "0.0.7"
|
|
11
|
-
|
|
12
|
-
### fixes
|
|
13
|
-
- corrected homepage property in package.json, points now to valid readme of the package "filelist" in the mono-repo "mangos".
|
|
14
|
-
|
|
15
|
-
## "0.0.6"
|
|
16
|
-
### changes
|
|
17
|
-
- The functions `inferPathType` and `lexPath` return the same Pathobject.
|
|
18
|
-
- `inferPathType` returns an iterator of PathObject
|
|
19
|
-
- `lextPath` returns a singular PathObject
|
|
20
|
-
- README adjusted
|
|
21
|
-
|
|
22
|
-
## "0.0.5"
|
|
23
|
-
|
|
24
|
-
use globalThis and optional chainging to make platform detection agnostic in node and browser (globalhis.navigator.platform)
|
|
25
|
-
|
|
26
|
-
## "0.0.4"
|
|
27
|
-
|
|
28
|
-
Initial release
|
|
29
|
-
|
|
30
|
-
Added eslint for typechecking
|
|
31
|
-
Zero dependency package
|
|
32
|
-
internals adjusted for use in @mangos/validator package
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
## 1.0.10
|
|
36
|
-
|
|
37
|
-
Released 13 Mar 2020
|
|
38
|
-
Mitiate Circular references by adding an "ignore" argument to the jxpath
|
|
39
|
-
Updated documentation to documentation
|
|
40
|
-
|
|
41
|
-
## 1.0.5
|
|
42
|
-
|
|
43
|
-
Released Feb 7 2020
|
|
44
|
-
Added "internal" sub-module
|
|
45
|
-
|
|
46
|
-
## 1.0.4
|
|
47
|
-
|
|
48
|
-
Released Feb 7 2020
|
|
49
|
-
- Fixed trailing '/' should not cause a exception
|
|
50
|
-
|
|
51
|
-
## 0.0.2
|
|
52
|
-
|
|
53
|
-
Released Jan 15, 2020
|
|
54
|
-
- Development and testing done
|
|
55
|
-
|
|
56
|
-
## 0.0.1
|
|
57
|
-
|
|
58
|
-
Released dec 28, 2019
|
|
59
|
-
- initial release
|
package/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
-
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
|
9
|
-
level of experience, education, socio-economic status, nationality, personal
|
|
10
|
-
appearance, race, religion, or sexual identity and orientation.
|
|
11
|
-
|
|
12
|
-
## Our Standards
|
|
13
|
-
|
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
|
15
|
-
include:
|
|
16
|
-
|
|
17
|
-
* Using welcoming and inclusive language
|
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
|
19
|
-
* Gracefully accepting constructive criticism
|
|
20
|
-
* Focusing on what is best for the community
|
|
21
|
-
* Showing empathy towards other community members
|
|
22
|
-
|
|
23
|
-
Examples of unacceptable behavior by participants include:
|
|
24
|
-
|
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
-
advances
|
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
-
* Public or private harassment
|
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
|
30
|
-
address, without explicit permission
|
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
-
professional setting
|
|
33
|
-
|
|
34
|
-
## Our Responsibilities
|
|
35
|
-
|
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
-
response to any instances of unacceptable behavior.
|
|
39
|
-
|
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
-
that are not aligned to this Code of Conduct, or to block temporarily or
|
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
-
threatening, offensive, or harmful.
|
|
45
|
-
|
|
46
|
-
## Scope
|
|
47
|
-
|
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
-
when an individual is representing the project or its community. Examples of
|
|
50
|
-
representing a project or community include using an official project e-mail
|
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
|
53
|
-
further defined and clarified by project maintainers.
|
|
54
|
-
|
|
55
|
-
## Enforcement
|
|
56
|
-
|
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
-
reported by contacting the project team at info@mail.jacob-bogers.com. All
|
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
|
63
|
-
|
|
64
|
-
## Attribution
|
|
65
|
-
|
|
66
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
67
|
-
version 1.4, available at https://www.contributor-covenant.org/version/1/4/
|
|
68
|
-
|
|
69
|
-
[homepage]: http://contributor-covenant.org
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
Thanks for taking the time to contribute to "@mangos/filepath" Follow these guidelines to make the process smoother:
|
|
2
|
-
|
|
3
|
-
1. One feature per pull request. Each PR should have one focus, and all the code changes should be supporting that one feature or bug fix. Using a [separate branch](https://guides.github.com/introduction/flow/index.html) for each feature should help you manage developing multiple features at once.
|
|
4
|
-
|
|
5
|
-
2. Follow the style of the file when it comes to syntax like curly braces and indents.
|
|
6
|
-
|
|
7
|
-
3. Add a test for the feature or fix, if possible. See the `test` directory for existing tests and README describing how to run these tests.
|
|
8
|
-
|
|
9
|
-
https://r.js.org/
|
package/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const { inferPathType, lexPath, resolve } = require('./lib/parser');
|
|
2
|
-
const { tokens, rootTokens } = require('./lib/tokenizer');
|
|
3
|
-
|
|
4
|
-
function invertObject(o) {
|
|
5
|
-
const rc = {};
|
|
6
|
-
Object.entries(o).reduce((c, [key,value]) => {
|
|
7
|
-
c[value] = key;
|
|
8
|
-
return c;
|
|
9
|
-
}, rc);
|
|
10
|
-
return rc;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
14
|
-
inferPathType,
|
|
15
|
-
lexPath,
|
|
16
|
-
resolve,
|
|
17
|
-
$tokens: {
|
|
18
|
-
root: rootTokens,
|
|
19
|
-
rootValues: invertObject(rootTokens),
|
|
20
|
-
other: tokens,
|
|
21
|
-
values: invertObject(tokens)
|
|
22
|
-
}
|
|
23
|
-
};
|
package/lib/parser.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
posixAbsorber,
|
|
3
|
-
tdpAbsorber,
|
|
4
|
-
uncAbsorber,
|
|
5
|
-
ddpAbsorber,
|
|
6
|
-
tokens,
|
|
7
|
-
rootTokenValues,
|
|
8
|
-
getCWD
|
|
9
|
-
} = require('./tokenizer');
|
|
10
|
-
|
|
11
|
-
const absorberMapping = {
|
|
12
|
-
unc: uncAbsorber,
|
|
13
|
-
dos: tdpAbsorber,
|
|
14
|
-
devicePath: ddpAbsorber,
|
|
15
|
-
posix: posixAbsorber
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// order of importance
|
|
19
|
-
const allNamespaces = ['devicePath', 'unc', 'dos', 'posix'];
|
|
20
|
-
|
|
21
|
-
function lexPath(path = '', options = {}) {
|
|
22
|
-
if (typeof path !== 'string') {
|
|
23
|
-
return path;
|
|
24
|
-
}
|
|
25
|
-
const iterator = inferPathType(path, options);
|
|
26
|
-
const step = iterator.next(); // only get the first one (is also the most likely one)
|
|
27
|
-
if (step.done) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
return step.value;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function filterErr(t) {
|
|
34
|
-
return t.error !== undefined;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function clonePath(path) {
|
|
38
|
-
return Array.from({ length: path.length }, (v, i) => Object.assign({}, path[i]));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function createPathProcessor(path) {
|
|
42
|
-
return function (ns, absorber) {
|
|
43
|
-
// get all path tokens at once
|
|
44
|
-
const _tokens = Array.from(absorber(path));
|
|
45
|
-
if (_tokens.length === 0) return;
|
|
46
|
-
const rc = { type: ns, path: _tokens };
|
|
47
|
-
const firstError = _tokens.find(filterErr);
|
|
48
|
-
if (firstError) {
|
|
49
|
-
rc.firstError = firstError;
|
|
50
|
-
}
|
|
51
|
-
return rc;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function getErrors(path) {
|
|
56
|
-
return path.filter(v => v.error).map(v => v.error).join('|');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function last(arr) {
|
|
60
|
-
return arr[arr.length - 1];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function upp(path) {
|
|
64
|
-
let _last;
|
|
65
|
-
for (_last = last(path); _last.token === tokens.SEP; _last = last(path)) {
|
|
66
|
-
path.pop();
|
|
67
|
-
}
|
|
68
|
-
// there is a root?
|
|
69
|
-
if (!(_last.token in rootTokenValues)) {
|
|
70
|
-
path.pop();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function add(_tokens, token) {
|
|
75
|
-
if (token.token === tokens.SEP) {
|
|
76
|
-
return; // skip this
|
|
77
|
-
}
|
|
78
|
-
let _last = last(_tokens);
|
|
79
|
-
// normalize
|
|
80
|
-
for (; _last === tokens.SEP; _last = last(_tokens).token) {
|
|
81
|
-
tokens.pop();
|
|
82
|
-
}
|
|
83
|
-
_tokens.push({
|
|
84
|
-
token: tokens.SEP,
|
|
85
|
-
start: _last.end + 1,
|
|
86
|
-
end: _last.end + 1,
|
|
87
|
-
value: getSeperator()
|
|
88
|
-
});
|
|
89
|
-
_tokens.push({
|
|
90
|
-
token: token.token,
|
|
91
|
-
start: _last.end + 2,
|
|
92
|
-
end: _last.end + +2 + token.end,
|
|
93
|
-
value: token.value
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function resolve(_from, ..._to) {
|
|
98
|
-
_from = lexPath(_from);
|
|
99
|
-
if (_from && _from.firstError) {
|
|
100
|
-
throw TypeError(`"from" path contains errors: ${getErrors(_from)}`)
|
|
101
|
-
}
|
|
102
|
-
if (_from === undefined) {
|
|
103
|
-
_from = lexPath(getCWD());
|
|
104
|
-
}
|
|
105
|
-
if (!(_from.path[0].token in rootTokenValues)) {
|
|
106
|
-
_to.unshift(_from);
|
|
107
|
-
_from = lexPath(getCWD());
|
|
108
|
-
}
|
|
109
|
-
let to = _to.shift()
|
|
110
|
-
to = lexPath(to);
|
|
111
|
-
if (to && to.firstError) {
|
|
112
|
-
throw TypeError(`"to" path contains errors: ${getErrors(to)}`)
|
|
113
|
-
}
|
|
114
|
-
if (to === undefined) {
|
|
115
|
-
return _from;
|
|
116
|
-
}
|
|
117
|
-
if (to.path && to.path[0].token in rootTokenValues) {
|
|
118
|
-
_from = to;
|
|
119
|
-
if (_to.length === 0) {
|
|
120
|
-
return _from;
|
|
121
|
-
}
|
|
122
|
-
return resolve(to, ..._to);
|
|
123
|
-
}
|
|
124
|
-
// "_from" is guaranteed to me from root and "to" is guaranteed not to be from "root"
|
|
125
|
-
const working = clonePath(_from.path);
|
|
126
|
-
for (const token of to.path) {
|
|
127
|
-
switch (token.token) {
|
|
128
|
-
case tokens.SEP:
|
|
129
|
-
case tokens.CURRENT:
|
|
130
|
-
break;
|
|
131
|
-
case tokens.PARENT:
|
|
132
|
-
upp(working);
|
|
133
|
-
break;
|
|
134
|
-
case tokens.PATHELT:
|
|
135
|
-
add(working, token);
|
|
136
|
-
break;
|
|
137
|
-
default:
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// finished processing all tokens
|
|
141
|
-
const rc = { path: working, type: _from.type };
|
|
142
|
-
if (_to.length === 0) { // efficiency+
|
|
143
|
-
return rc;
|
|
144
|
-
}
|
|
145
|
-
return resolve(rc, ..._to)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function getSeperator() {
|
|
149
|
-
const platform = globalThis?.navigator?.platform || globalThis?.process?.platform || 'posix';
|
|
150
|
-
if (platform === 'win32') {
|
|
151
|
-
return '\\';
|
|
152
|
-
}
|
|
153
|
-
return '/';
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function defaultOptions(options = {}) {
|
|
157
|
-
if (Object.keys(options).filter(f => allNamespaces.includes(f)).length === 0) {
|
|
158
|
-
const platform = globalThis?.navigator?.platform || globalThis?.process?.platform || 'posix';
|
|
159
|
-
Object.assign(options, {
|
|
160
|
-
unc: platform === 'win32',
|
|
161
|
-
dos: platform === 'win32',
|
|
162
|
-
devicePath: platform === 'win32',
|
|
163
|
-
posix: platform !== 'win32'
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return options;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
function* inferPathType(path, options = {}) {
|
|
173
|
-
defaultOptions(options);
|
|
174
|
-
const processor = createPathProcessor(path);
|
|
175
|
-
const filtered = allNamespaces.filter(f => options[f])
|
|
176
|
-
for (const ns of filtered) {
|
|
177
|
-
const result = processor(ns, absorberMapping[ns]);
|
|
178
|
-
if (result) {
|
|
179
|
-
yield result;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
module.exports = {
|
|
188
|
-
inferPathType,
|
|
189
|
-
lexPath,
|
|
190
|
-
resolve
|
|
191
|
-
}
|