Skip to content

Commit e60e2fe

Browse files
v1.0.419
[Bot] push changes from Files.com
1 parent 1339796 commit e60e2fe

11 files changed

+651
-6
lines changed

Diff for: README.md

+10
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ You can set the following global properties using static methods on the `Files`
157157
const textContent = await downloadableFile.downloadToString()
158158
}
159159

160+
#### Comparing Case insensitive files and paths
161+
162+
For related documentation see [Case Sensitivity Documentation](https://www.files.com/docs/topics/file-system-semantics#case-sensitivity).
163+
164+
import { pathNormalizer } from 'files.com/lib/utils.js'
165+
166+
if (pathNormalizer.same('Fïłèńämê.Txt', 'filename.txt')) {
167+
// the paths are the same
168+
}
169+
160170
### Additional Object Documentation
161171

162172
Additional docs are available at https://developers.files.com

Diff for: _VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.418
1+
1.0.419

Diff for: lib/Files.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var endpointPrefix = '/api/rest/v1';
1111
var apiKey;
1212
var baseUrl = 'https://app.files.com';
1313
var sessionId = null;
14-
var version = "1.0.418";
14+
var version = "1.0.419";
1515
var userAgent = "Files.com JavaScript SDK v".concat(version);
1616
var logLevel = _Logger.LogLevel.INFO;
1717
var debugRequest = false;

Diff for: lib/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
44
exports.__esModule = true;
55
exports.isString = exports.isObject = exports.isInt = exports.isEmpty = exports.isBrowser = exports.isArray = exports.getType = void 0;
66
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
7+
var _pathNormalizer = _interopRequireDefault(require("./utils/pathNormalizer"));
8+
exports.pathNormalizer = _pathNormalizer.default;
79
var isArray = exports.isArray = function isArray(value) {
810
return Array.isArray(value);
911
};

Diff for: lib/utils/pathNormalizer.js

+261
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
"use strict";
2+
3+
exports.__esModule = true;
4+
exports.default = void 0;
5+
// This implements the algorithm for path normalization described here:
6+
// https://www.files.com/docs/topics/file-system-semantics#exact-algorithm-for-path-normalization
7+
8+
/* eslint-disable sort-keys */
9+
var transliterationMap = {
10+
À: 'A',
11+
Á: 'A',
12+
Â: 'A',
13+
Ã: 'A',
14+
Ä: 'A',
15+
Å: 'A',
16+
Æ: 'AE',
17+
Ç: 'C',
18+
È: 'E',
19+
É: 'E',
20+
Ê: 'E',
21+
Ë: 'E',
22+
Ì: 'I',
23+
Í: 'I',
24+
Î: 'I',
25+
Ï: 'I',
26+
Ð: 'D',
27+
Ñ: 'N',
28+
Ò: 'O',
29+
Ó: 'O',
30+
Ô: 'O',
31+
Õ: 'O',
32+
Ö: 'O',
33+
Ø: 'O',
34+
Ù: 'U',
35+
Ú: 'U',
36+
Û: 'U',
37+
Ü: 'U',
38+
Ý: 'Y',
39+
ß: 'ss',
40+
à: 'a',
41+
á: 'a',
42+
â: 'a',
43+
ã: 'a',
44+
ä: 'a',
45+
å: 'a',
46+
æ: 'ae',
47+
ç: 'c',
48+
è: 'e',
49+
é: 'e',
50+
ê: 'e',
51+
ë: 'e',
52+
ì: 'i',
53+
í: 'i',
54+
î: 'i',
55+
ï: 'i',
56+
ð: 'd',
57+
ñ: 'n',
58+
ò: 'o',
59+
ó: 'o',
60+
ô: 'o',
61+
õ: 'o',
62+
ö: 'o',
63+
ø: 'o',
64+
ù: 'u',
65+
ú: 'u',
66+
û: 'u',
67+
ü: 'u',
68+
ý: 'y',
69+
ÿ: 'y',
70+
Ā: 'A',
71+
ā: 'a',
72+
Ă: 'A',
73+
ă: 'a',
74+
Ą: 'A',
75+
ą: 'a',
76+
Ć: 'C',
77+
ć: 'c',
78+
Ĉ: 'C',
79+
ĉ: 'c',
80+
Ċ: 'C',
81+
ċ: 'c',
82+
Č: 'C',
83+
č: 'c',
84+
Ď: 'D',
85+
ď: 'd',
86+
Đ: 'D',
87+
đ: 'd',
88+
Ē: 'E',
89+
ē: 'e',
90+
Ĕ: 'E',
91+
ĕ: 'e',
92+
Ė: 'E',
93+
ė: 'e',
94+
Ę: 'E',
95+
ę: 'e',
96+
Ě: 'E',
97+
ě: 'e',
98+
Ĝ: 'G',
99+
ĝ: 'g',
100+
Ğ: 'G',
101+
ğ: 'g',
102+
Ġ: 'G',
103+
ġ: 'g',
104+
Ģ: 'G',
105+
ģ: 'g',
106+
Ĥ: 'H',
107+
ĥ: 'h',
108+
Ħ: 'H',
109+
ħ: 'h',
110+
Ĩ: 'I',
111+
ĩ: 'i',
112+
Ī: 'I',
113+
ī: 'i',
114+
Ĭ: 'I',
115+
ĭ: 'i',
116+
Į: 'I',
117+
į: 'i',
118+
İ: 'I',
119+
IJ: 'IJ',
120+
ij: 'ij',
121+
Ĵ: 'J',
122+
ĵ: 'j',
123+
Ķ: 'K',
124+
ķ: 'k',
125+
Ĺ: 'L',
126+
ĺ: 'l',
127+
Ļ: 'L',
128+
ļ: 'l',
129+
Ľ: 'L',
130+
ľ: 'l',
131+
Ł: 'L',
132+
ł: 'l',
133+
Ń: 'N',
134+
ń: 'n',
135+
Ņ: 'N',
136+
ņ: 'n',
137+
Ň: 'N',
138+
ň: 'n',
139+
ʼn: '\'n',
140+
Ō: 'O',
141+
ō: 'o',
142+
Ŏ: 'O',
143+
ŏ: 'o',
144+
Ő: 'O',
145+
ő: 'o',
146+
Œ: 'OE',
147+
œ: 'oe',
148+
Ŕ: 'R',
149+
ŕ: 'r',
150+
Ŗ: 'R',
151+
ŗ: 'r',
152+
Ř: 'R',
153+
ř: 'r',
154+
Ś: 'S',
155+
ś: 's',
156+
Ŝ: 'S',
157+
ŝ: 's',
158+
Ş: 'S',
159+
ş: 's',
160+
Š: 'S',
161+
š: 's',
162+
Ţ: 'T',
163+
ţ: 't',
164+
Ť: 'T',
165+
ť: 't',
166+
Ũ: 'U',
167+
ũ: 'u',
168+
Ū: 'U',
169+
ū: 'u',
170+
Ŭ: 'U',
171+
ŭ: 'u',
172+
Ů: 'U',
173+
ů: 'u',
174+
Ű: 'U',
175+
ű: 'u',
176+
Ų: 'U',
177+
ų: 'u',
178+
Ŵ: 'W',
179+
ŵ: 'w',
180+
Ŷ: 'Y',
181+
ŷ: 'y',
182+
Ÿ: 'Y',
183+
Ź: 'Z',
184+
ź: 'z',
185+
Ż: 'Z',
186+
ż: 'z',
187+
Ž: 'Z',
188+
ž: 'z'
189+
};
190+
/* eslint-enable sort-keys */
191+
192+
var transliterate = function transliterate(str) {
193+
return Array.from(str).map(function (char) {
194+
return transliterationMap[char] || char;
195+
}).join('');
196+
};
197+
198+
// converting the path to UTF-8 is not necessary in JS as it's the default
199+
var normalize = function normalize(path) {
200+
// Remove any characters with byte value of 0
201+
var cleaned = (path || '').replace(/\0/g, '');
202+
203+
// Convert any backslash (\) characters to a forward slash (/)
204+
cleaned = cleaned.replace(/\\/g, '/');
205+
206+
// Remove any trailing or leading slashes
207+
cleaned = cleaned.replace(/^\/+|\/+$/g, '');
208+
209+
// Remove any path parts that are . or ..
210+
cleaned = cleaned.split('/').filter(function (part) {
211+
return part !== '.' && part !== '..';
212+
}).join('/');
213+
214+
// Replace any duplicate forward slashes (such as ///) with a single forward slash (/)
215+
cleaned = cleaned.replace(/\/+/g, '/');
216+
return cleaned;
217+
};
218+
var normalizeForComparisonCache = new Map();
219+
var normalizeForComparison = function normalizeForComparison(path) {
220+
if (normalizeForComparisonCache.has(path)) {
221+
return normalizeForComparisonCache.get(path);
222+
}
223+
224+
// Run the path through the Normalize Algorithm
225+
var normalized = normalize(path);
226+
227+
// Unicode Normalize the Path using Unicode NFKC algorithm
228+
normalized = normalized.normalize('NFKC');
229+
230+
// Transliterate and remove accent marks
231+
normalized = transliterate(normalized);
232+
233+
// Convert the Path to lowercase
234+
normalized = normalized.toLowerCase();
235+
236+
// Remove any trailing whitespace (\r, \n, \t or the space character)
237+
normalized = normalized.replace(/[\r\n\t ]+$/g, '');
238+
normalizeForComparisonCache.set(path, normalized);
239+
return normalized;
240+
};
241+
var same = function same(path1, path2) {
242+
return normalizeForComparison(path1) === normalizeForComparison(path2);
243+
};
244+
var startsWith = function startsWith(path1, path2) {
245+
return normalizeForComparison(path1).startsWith(normalizeForComparison(path2));
246+
};
247+
var keyLookup = function keyLookup(object, path) {
248+
var key = Object.keys(object).find(function (key) {
249+
return same(key, path);
250+
});
251+
return typeof key === 'string' ? object[key] : undefined;
252+
};
253+
var pathNormalizer = {
254+
keyLookup: keyLookup,
255+
normalize: normalize,
256+
same: same,
257+
startsWith: startsWith
258+
};
259+
var _default = exports.default = pathNormalizer;
260+
module.exports = pathNormalizer;
261+
module.exports.default = pathNormalizer;

Diff for: lib/utils/pathNormalizer.test.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"use strict";
2+
3+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
5+
var _pathNormalizer = _interopRequireDefault(require("./pathNormalizer"));
6+
var _normalization_for_comparison_test_data = _interopRequireDefault(require("../../../common/shared/normalization_for_comparison_test_data.json"));
7+
describe('pathNormalizer', function () {
8+
it('normalizes paths for comparison', function () {
9+
_normalization_for_comparison_test_data.default.forEach(function (_ref) {
10+
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
11+
input = _ref2[0],
12+
expected = _ref2[1];
13+
expect(_pathNormalizer.default.same(input, expected)).toBe(true);
14+
var startOfExpected = expected.substring(0, 3);
15+
expect(_pathNormalizer.default.startsWith(input, startOfExpected)).toBe(true);
16+
});
17+
});
18+
it('looks up keys in a map', function () {
19+
var map = {
20+
'': {
21+
list: true
22+
},
23+
foo: {
24+
readonly: true
25+
},
26+
'foo/bar': {
27+
read: false,
28+
write: true
29+
}
30+
};
31+
expect(_pathNormalizer.default.keyLookup(map, 'foo/bar')).toEqual({
32+
read: false,
33+
write: true
34+
});
35+
expect(_pathNormalizer.default.keyLookup(map, '/foo/bar')).toEqual({
36+
read: false,
37+
write: true
38+
});
39+
expect(_pathNormalizer.default.keyLookup(map, '.')).toEqual({
40+
list: true
41+
});
42+
expect(_pathNormalizer.default.keyLookup(map, './..')).toEqual({
43+
list: true
44+
});
45+
expect(_pathNormalizer.default.keyLookup(map, '')).toEqual({
46+
list: true
47+
});
48+
expect(_pathNormalizer.default.keyLookup(map, '/')).toEqual({
49+
list: true
50+
});
51+
expect(_pathNormalizer.default.keyLookup(map, '/ ')).toEqual({
52+
list: true
53+
});
54+
expect(_pathNormalizer.default.keyLookup(map, '// ')).toEqual({
55+
list: true
56+
});
57+
expect(_pathNormalizer.default.keyLookup(map, '////')).toEqual({
58+
list: true
59+
});
60+
expect(_pathNormalizer.default.keyLookup(map, '/foo')).toEqual({
61+
readonly: true
62+
});
63+
expect(_pathNormalizer.default.keyLookup(map, '/////foo')).toEqual({
64+
readonly: true
65+
});
66+
expect(_pathNormalizer.default.keyLookup(map, '/////foo/')).toEqual({
67+
readonly: true
68+
});
69+
});
70+
});

Diff for: package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "files.com",
3-
"version": "1.0.418",
3+
"version": "1.0.419",
44
"description": "Files.com SDK for JavaScript",
55
"keywords": [
66
"files.com",
@@ -32,9 +32,12 @@
3232
"@babel/plugin-proposal-class-properties": "^7.10.1",
3333
"@babel/plugin-transform-modules-commonjs": "^7.10.1",
3434
"@babel/plugin-transform-runtime": "^7.10.3",
35-
"@babel/preset-env": "^7.10.3"
35+
"@babel/preset-env": "^7.10.3",
36+
"jest": "^29.7.0"
3637
},
3738
"scripts": {
38-
"build": "./node_modules/.bin/babel src -d lib"
39+
"build": "./node_modules/.bin/babel src -d lib",
40+
"test": "jest",
41+
"watch": "jest --watch"
3942
}
4043
}

0 commit comments

Comments
 (0)