UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

69 lines (64 loc) • 2.25 kB
var formatToList = function formatToList2(items) { return Object.entries(items).map(function(param) { var [key, value] = param; return `- ${key} (${value})`; }).join("\n"); }; function validatePathConfig(config) { var root = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true; var validation = { path: "string", initialRouteName: "string", screens: "object", preserveDynamicRoutes: "boolean", preserveGroups: "boolean", ...root ? null : { alias: "array", exact: "boolean", stringify: "object", parse: "object" } }; if (typeof config !== "object" || config === null) { throw new Error(`Expected the configuration to be an object, but got ${JSON.stringify(config)}.`); } var validationErrors = Object.fromEntries(Object.keys(config).map(function(key) { if (key in validation) { var type = validation[key]; var value = config[key]; if (value !== void 0) { if (type === "array") { if (!Array.isArray(value)) { return [key, `expected 'Array', got '${typeof value}'`]; } } else if (typeof value !== type) { return [key, `expected '${type}', got '${typeof value}'`]; } } } else { return [key, "extraneous"]; } return null; }).filter(Boolean)); if (Object.keys(validationErrors).length) { throw new Error(`Found invalid properties in the configuration: ${formatToList(validationErrors)} You can only specify the following properties: ${formatToList(validation)} If you want to specify configuration for screens, you need to specify them under a 'screens' property. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.`); } if (root && "path" in config && typeof config.path === "string" && config.path.includes(":")) { throw new Error(`Found invalid path '${config.path}'. The 'path' in the top-level configuration cannot contain patterns for params.`); } if ("screens" in config && config.screens) { Object.entries(config.screens).forEach(function(param) { var [_, value] = param; if (typeof value !== "string") { validatePathConfig(value, false); } }); } } export { validatePathConfig }; //# sourceMappingURL=validatePathConfig.native.js.map