MCPcopy
hub / github.com/originjs/vite-plugin-federation / parseOptions

Function parseOptions

packages/lib/src/utils/index.ts:130–169  ·  view source on GitHub ↗
(
  options: Exposes | Remotes | Shared | undefined,
  normalizeSimple: (value: any, key: any) => ConfigTypeSet,
  normalizeOptions: (value: any, key: any) => ConfigTypeSet
)

Source from the content-addressed store, hash-verified

128}
129
130export function parseOptions(
131 options: Exposes | Remotes | Shared | undefined,
132 normalizeSimple: (value: any, key: any) => ConfigTypeSet,
133 normalizeOptions: (value: any, key: any) => ConfigTypeSet
134): (string | ConfigTypeSet)[] {
135 if (!options) {
136 return []
137 }
138 const list: {
139 [index: number]: string | ConfigTypeSet
140 }[] = []
141 const array = (items: (string | ConfigTypeSet)[]) => {
142 for (const item of items) {
143 if (typeof item === 'string') {
144 list.push([item, normalizeSimple(item, item)])
145 } else if (item && typeof item === 'object') {
146 object(item)
147 } else {
148 throw new Error('Unexpected options format')
149 }
150 }
151 }
152 const object = (obj) => {
153 for (const [key, value] of Object.entries(obj)) {
154 if (typeof value === 'string' || Array.isArray(value)) {
155 list.push([key, normalizeSimple(value, key)])
156 } else {
157 list.push([key, normalizeOptions(value, key)])
158 }
159 }
160 }
161 if (Array.isArray(options)) {
162 array(options)
163 } else if (typeof options === 'object') {
164 object(options)
165 } else {
166 throw new Error('Unexpected options format')
167 }
168 return list
169}
170
171const letterReg = new RegExp('[0-9a-zA-Z]+')
172

Callers 4

utils.spec.tsFile · 0.90
parseSharedOptionsFunction · 0.85
parseExposeOptionsFunction · 0.85
parseRemoteOptionsFunction · 0.85

Calls 2

arrayFunction · 0.85
objectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…