MCPcopy Index your code
hub / github.com/Effect-TS/effect / parse

Function parse

packages/platform/src/internal/path.ts:521–598  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

519 },
520
521 parse(path) {
522 const ret = { root: "", dir: "", base: "", ext: "", name: "" }
523 if (path.length === 0) return ret
524 let code = path.charCodeAt(0)
525 const isAbsolute = code === 47 /*/*/
526 let start
527 if (isAbsolute) {
528 ret.root = "/"
529 start = 1
530 } else {
531 start = 0
532 }
533 let startDot = -1
534 let startPart = 0
535 let end = -1
536 let matchedSlash = true
537 let i = path.length - 1
538
539 // Track the state of characters (if any) we see before our first dot and
540 // after any path separator we find
541 let preDotState = 0
542
543 // Get non-dir info
544 for (; i >= start; --i) {
545 code = path.charCodeAt(i)
546 if (code === 47 /*/*/) {
547 // If we reached a path separator that was not part of a set of path
548 // separators at the end of the string, stop now
549 if (!matchedSlash) {
550 startPart = i + 1
551 break
552 }
553 continue
554 }
555 if (end === -1) {
556 // We saw the first non-path separator, mark this as the end of our
557 // extension
558 matchedSlash = false
559 end = i + 1
560 }
561 if (code === 46 /*.*/) {
562 // If this is our first dot, mark it as the start of our extension
563 if (startDot === -1) startDot = i
564 else if (preDotState !== 1) preDotState = 1
565 } else if (startDot !== -1) {
566 // We saw a non-dot and non-path separator before our dot, so we should
567 // have a good chance at having a non-empty extension
568 preDotState = -1
569 }
570 }
571
572 if (
573 startDot === -1 || end === -1 ||
574 // We saw a non-dot character immediately before the dot
575 preDotState === 0 ||
576 // The (right-most) trimmed path component is exactly '..'
577 preDotState === 1 && startDot === end - 1 && startDot === startPart + 1
578 ) {

Callers 11

schemaJsonFunction · 0.70
schemaNoBodyFunction · 0.70
schemaParamsFunction · 0.70
schemaPathParamsFunction · 0.70
schemaJsonFunction · 0.70
schemaNoBodyFunction · 0.70
getFunction · 0.70
schemaCookiesFunction · 0.70
schemaHeadersFunction · 0.50
schemaJsonFunction · 0.50
schemaStructFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected