MCPcopy Create free account
hub / github.com/Effect-TS/effect / parsePartial

Function parsePartial

packages/effect/src/SemVerRange.ts:137–159  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

135const componentLabels = ["major", "minor", "patch"] as const
136
137const parsePartial = (input: string): PartialVersion => {
138 if (input.length === 0) return invalid("expected a version after the operator")
139 if (input.includes("+")) {
140 return invalid(`build metadata is not allowed in ranges, received ${JSON.stringify(input)}`)
141 }
142 const dash = input.indexOf("-")
143 const parts = (dash === -1 ? input : input.slice(0, dash)).split(".")
144 if (parts.length > 3) return invalid(`expected at most MAJOR.MINOR.PATCH, received ${JSON.stringify(input)}`)
145 const components: Array<number> = []
146 for (let i = 0; i < parts.length; i++) {
147 if (isWildcard(parts[i])) continue
148 // A skipped wildcard leaves `components` shorter than the position reached.
149 if (components.length < i) {
150 return invalid(`a version component cannot follow a wildcard, received ${JSON.stringify(input)}`)
151 }
152 components.push(parseComponent(parts[i], componentLabels[i]))
153 }
154 if (dash === -1) return { components, prerelease: [] }
155 if (components.length < 3) {
156 return invalid(`a pre-release requires MAJOR.MINOR.PATCH, received ${JSON.stringify(input)}`)
157 }
158 return { components, prerelease: input.slice(dash + 1).split(".").map(prereleaseIdentifier) }
159}
160
161const parseComparatorSet = (input: string): ReadonlyArray<Comparator> => {
162 const tokens = input.split(/\s+/).filter((token) => token.length > 0)

Callers 1

parseComparatorSetFunction · 0.85

Calls 7

invalidFunction · 0.90
parseComponentFunction · 0.90
isWildcardFunction · 0.85
sliceMethod · 0.80
pushMethod · 0.65
splitMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected