MCPcopy
hub / github.com/webpack/webpack / process

Function process

lib/container/options.js:30–68  ·  view source on GitHub ↗
(options, normalizeSimple, normalizeOptions, fn)

Source from the content-addressed store, hash-verified

28 * @returns {void}
29 */
30const process = (options, normalizeSimple, normalizeOptions, fn) => {
31 /**
32 * Processes the provided item.
33 * @param {(string | Item<T>)[]} items items
34 */
35 const array = (items) => {
36 for (const item of items) {
37 if (typeof item === "string") {
38 fn(item, normalizeSimple(item, item));
39 } else if (item && typeof item === "object") {
40 object(item);
41 } else {
42 throw new Error("Unexpected options format");
43 }
44 }
45 };
46 /**
47 * Processes the provided obj.
48 * @param {Item<T>} obj an object
49 */
50 const object = (obj) => {
51 for (const [key, value] of Object.entries(obj)) {
52 if (typeof value === "string" || Array.isArray(value)) {
53 fn(key, normalizeSimple(value, key));
54 } else {
55 fn(key, normalizeOptions(value, key));
56 }
57 }
58 };
59 if (!options) {
60 // Do nothing
61 } else if (Array.isArray(options)) {
62 array(options);
63 } else if (typeof options === "object") {
64 object(options);
65 } else {
66 throw new Error("Unexpected options format");
67 }
68};
69
70/**
71 * Returns parsed options.

Callers 2

parseOptionsFunction · 0.70
scopeFunction · 0.70

Calls 3

arrayFunction · 0.85
objectFunction · 0.85
isArrayMethod · 0.80

Tested by

no test coverage detected