* Creates a stats options. * @param {string | boolean | StatsOptions | undefined} optionsOrPreset stats option value * @param {CreateStatsOptionsContext=} context context * @returns {NormalizedStatsOptions} normalized options
(optionsOrPreset, context = {})
| 1412 | * @returns {NormalizedStatsOptions} normalized options |
| 1413 | */ |
| 1414 | createStatsOptions(optionsOrPreset, context = {}) { |
| 1415 | if (typeof optionsOrPreset === "boolean") { |
| 1416 | optionsOrPreset = { |
| 1417 | preset: optionsOrPreset === false ? "none" : "normal" |
| 1418 | }; |
| 1419 | } else if (typeof optionsOrPreset === "string") { |
| 1420 | optionsOrPreset = { preset: optionsOrPreset }; |
| 1421 | } |
| 1422 | if (typeof optionsOrPreset === "object" && optionsOrPreset !== null) { |
| 1423 | // We use this method of shallow cloning this object to include |
| 1424 | // properties in the prototype chain |
| 1425 | /** @type {Partial<NormalizedStatsOptions>} */ |
| 1426 | const options = {}; |
| 1427 | for (const key in optionsOrPreset) { |
| 1428 | options[key] = optionsOrPreset[/** @type {keyof StatsOptions} */ (key)]; |
| 1429 | } |
| 1430 | if (options.preset !== undefined) { |
| 1431 | this.hooks.statsPreset.for(options.preset).call(options, context); |
| 1432 | } |
| 1433 | this.hooks.statsNormalize.call(options, context); |
| 1434 | return /** @type {NormalizedStatsOptions} */ (options); |
| 1435 | } |
| 1436 | /** @type {Partial<NormalizedStatsOptions>} */ |
| 1437 | const options = {}; |
| 1438 | this.hooks.statsNormalize.call(options, context); |
| 1439 | return /** @type {NormalizedStatsOptions} */ (options); |
| 1440 | } |
| 1441 | |
| 1442 | /** |
| 1443 | * Creates a stats factory. |
no test coverage detected