Show contrast ratios in contrast pair tables

This commit is contained in:
Lea Verou
2025-01-16 12:47:06 -05:00
parent fba0b11343
commit df51149d0a
7 changed files with 139 additions and 56 deletions

View File

@@ -105,6 +105,23 @@ export function deepValue(obj, key) {
return key.reduce((subObj, property) => subObj?.[property], obj);
}
export function number(value, options) {
if (typeof value !== 'number' && isNaN(value)) {
return value;
}
let lang = options?.lang ?? 'en';
if (options?.lang) {
delete options.lang;
}
if (!options || Object.keys(options).length === 0) {
options = { maximumSignificantDigits: 3 };
}
return Number(value).toLocaleString(lang, options);
}
export function isNumeric(value) {
return typeof value === 'number' || (typeof value === 'string' && !isNaN(value));
}