MCPcopy Create free account
hub / github.com/PrairieLearn/PrairieLearn / trimDots

Function trimDots

public/javascripts/require.js:234–255  ·  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

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