MCPcopy Index your code
hub / github.com/requirejs/requirejs / trimDots

Function trimDots

require.js:236–257  ·  view source on GitHub ↗

* Trims the . and .. from an array of path segments. * It will keep a leading path segment if a .. will become * the first path segment, to help with module name lookups, * which act like paths, but can be remapped. But the end result, * all paths that use this fu

(ary)

Source from the content-addressed store, hash-verified

234 * @param {Array} ary the array of path segments.
235 */
236 function trimDots(ary) {
237 var i, part;
238 for (i = 0; i < ary.length; i++) {
239 part = ary[i];
240 if (part === '.') {
241 ary.splice(i, 1);
242 i -= 1;
243 } else if (part === '..') {
244 // If at the start, or previous value is still ..,
245 // keep them so that when converted to a path it may
246 // still work when converted to a path, even though
247 // as an ID it is less than ideal. In larger point
248 // releases, may be better to just kick out an error.
249 if (i === 0 || (i === 1 && ary[2] === '..') || ary[i - 1] === '..') {
250 continue;
251 } else if (i > 0) {
252 ary.splice(i - 1, 2);
253 i -= 2;
254 }
255 }
256 }
257 }
258
259 /**
260 * Given a relative module name, like ./something, normalize it to

Callers 1

normalizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…