/**
 * If a Promise is resolving too soon, use this to force a wait on it before we advance.
 * Otherwise, if the promise takes as long as the supplied `ms`, then no further delay will be required.
 * @return {Promise<[any]>}
 */
function forcePromiseMinDelay(prom, ms) {
	return Promise.all([prom, getDelay(ms)]).then(valArr => valArr[0]);
}

function getDelay(ms){
	return new Promise(resolve => { setTimeout(()=> resolve(ms), ms); } );
}

/**
 * @param {KeyboardEvent} keyEvent
 */
function isPrintableKey(keyboardEvent) {
	// Test the `key` property is single unicode character: 
	return /^.$/u.test(keyboardEvent.key);
}

/**
 * Create a new Set featuring items in Set A which are not present in Set B.
 * @see {@link https://exploringjs.com/impatient-js/ch_sets.html#difference-a-b} 
 * @param {Set} a
 * @param {Set} b
 */
function setDifference(a, b) {
	return new Set([...a].filter(item => !b.has(item)));
}
function setUnion(a, b) {
	return new Set([...a, ...b]);
}
/**
 * Are the two sets equal?
 * @param {Set} a
 * @param {Set} b
 */
function setEquality(a, b) {
	if (a.size !== b.size) {
		return false;
	}
	// Equal if they are the same size are no further differences.
	return setDifference(a, b).size === 0;
}