1
0
Fork 0

Merge branch 'develop' into i18n3

This commit is contained in:
Joost De Cock 2023-06-17 20:11:44 +02:00 committed by GitHub
commit 1264a07afe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
194 changed files with 2838 additions and 1691 deletions

View file

@ -469,6 +469,29 @@ export function mergeI18n(designs, options) {
return i18n
}
/**
* Helper method to merge passed in options with default options from the pattern config
*
* @param {object} settings - The settings passed to the pattern
* @param {object} optionsConfig - The pattern's options config
* @return {object} result - An object with the merged options and their values
*/
export function mergeOptions(settings, optionsConfig) {
const merged = typeof settings.options === 'undefined' ? {} : { ...settings.option }
for (const [key, option] of Object.entries(optionsConfig)) {
if (typeof option === 'object') {
if (typeof option.pct !== 'undefined') merged[key] = option.pct / 100
else if (typeof option.mm !== 'undefined') merged[key] = option.mm
else if (typeof option.deg !== 'undefined') merged[key] = option.deg
else if (typeof option.count !== 'undefined') merged[key] = option.count
else if (typeof option.bool !== 'undefined') merged[key] = option.bool
else if (typeof option.dflt !== 'undefined') merged[key] = option.dflt
} else merged[key] = option
}
return merged
}
/**
* Helper method to calculate abolute option value based on a measurement
*