function extractPatterns(patterns, type) {
	// Clone and apply the pattern environment.
	const patternsList = patterns.map(pattern =>
		pattern[type].map(applyCondition => {
			const { valid, invalid, ...rest } = pattern; // eslint-disable-line no-unused-vars -- `valid` and `invalid` are used just to exclude properties
			const thisPattern = structuredClone(rest);

			applyCondition(thisPattern);

			if (type === "valid") {
				thisPattern.errors = [];
			} else {
				thisPattern.code += " /* should error */";
			}

			return thisPattern;
		}),
	);

	return patternsList.flat();
}
Extracts patterns each condition for a specified type. The type is `valid` or `invalid`.
@param {Object[]} patterns Original patterns.
@param {string} type One of `"valid"` or `"invalid"`.
@returns {Object[]} Test patterns.