/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/blocks/image-editor/utils.js
24 строки
1 KB
Griffith Chen
Remove lodash `get` in favor of native optional chaining (#112149)
01 июл 2026, 13:04
Не верифицирован
01 июл 2026, 13:04
b455cc9
Код
Авторство
О чём код?
import { AspectRatios, AspectRatiosValues } from 'calypso/state/editor/image-editor/constants'; /** * Returns the default aspect ratio image editor should use. * * If only aspectRatio is specified and is valid, we return it. If only aspectRatios is specified and is valid, * we return its first item. If both aspectRatio and aspectRatios are specified, we return either: * 1. aspectRatio, if it is included in aspectRatios * 2. aspectRatios[ 0 ] if aspectRatio is not included in aspectRatios * * We return AspectRatios.FREE if no specified aspect ratio is valid. * @param {string} aspectRatio an aspect ratio which should be validated and used as default one for image editor * @param {Array} aspectRatios list of aspect ratios to be validated and used in image editor * @returns {string} the default valid aspect ratio image editor should use */ export function getDefaultAspectRatio( aspectRatio = null, aspectRatios = AspectRatiosValues ) { if ( ! aspectRatios?.includes( aspectRatio ) ) { aspectRatio = aspectRatios?.[ 0 ] ?? AspectRatios.FREE; } return AspectRatiosValues.includes( aspectRatio ) ? aspectRatio : getDefaultAspectRatio( aspectRatio ); }