strapi-utils
重构
¥strapi-utils
refactored
在 Strapi 5 中,strapi-utils
核心包已重构。此页面列出了添加、删除和其他更新。
¥In Strapi 5, the strapi-utils
core package has been refactored. This page lists the additions, removals, and other updates.
此页面是 重大变更数据库 的一部分,提供有关重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的其他说明。
¥This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.
\🔌 此重大更改是否会影响插件? | \是 |
---|
\🤖 此重大更改是否由 codemod 自动处理? | \是 |
---|
更改列表
¥List of changes
元素 | 更改说明 | |
---|---|---|
arrays 实用程序 | 已添加并将 stringIncludes 方法移动到其中(参见 其他说明)。 | |
已添加(参见 其他说明)。 | 已添加(参见 其他说明)。 | |
strings.getCommonPath | 已添加 | |
nameToSlug | 移至 strings.nameToSlug | |
nameToCollectionName | 移至 strings.nameToCollectionName | |
stringIncludes | 移至 arrays.includesString | |
stringEquals | 移至 strings.isEqual | |
isCamelCase | 移至 strings.isCamelCase | |
isKebabCase | 移至 strings.isKebabCase | |
toKebabCase | 移至 strings.toKebabCase | |
toRegressedEnumValue | 移至 strings.toRegressedEnumValue | |
startsWithANumber | 移至 strings.startsWithANumber | |
joinBy | 移至 strings.joinBy | |
keysDeep | 移至 objects.keysDeep | |
generateTimestampCode | 移至 dates.timestampCode | |
pipeAsync | 移至 async.pipe | |
mapAsync | 移至 async.map | |
reduceAsync | 移至 async.reduce | |
convertQueryParams | 已替换(参见 其他说明)。 | |
validate 和 sanitize | 已更新(参见 其他说明)。 | |
getCommonBeginning | 已删除 | |
已删除 | ||
forEachAsync | 已删除 | |
removeUndefined | 已删除 | |
templateConfiguration | 已删除(参见 其他说明)。 |
附加说明
¥Additional Notes
templateConfiguration
:这用于在 JSON 中加载旧的 v3 配置文件以允许使用模板。更多信息请参阅贡献者 。¥
templateConfiguration
: This was used when loading the old v3 configuration files in JSON to allow for templates. Plugin developers still using the function should replace its usage by a real template library if they really need to.arrays
实用程序:要使用这些新实用程序:¥
arrays
utils: To use these new utils:使用
import { arrays, dates, strings, objects } from '@strapi/utils';
将它们导入到你的代码中。¥Import them in your code with
import { arrays, dates, strings, objects } from '@strapi/utils';
.使用它们,例如
arrays.includesString
或strings.isEqual
。¥Use them, for instance as
arrays.includesString
orstrings.isEqual
.
convertQueryParams
被替换:¥
convertQueryParams
is replaced:// Strapi v4
import { convertQueryParams } from '@strapi/utils';
convertQueryParams.convertSortQueryParams(...); // now private function to simplify the api
convertQueryParams.convertStartQueryParams(...); // now private function to simplify the api
convertQueryParams.convertLimitQueryParams(...); // now private function to simplify the api
convertQueryParams.convertPopulateQueryParams(...); // now private function to simplify the api
convertQueryParams.convertFiltersQueryParams(...); // now private function to simplify the api
convertQueryParams.convertFieldsQueryParams(...); // now private function to simplify the api
convertQueryParams.convertPublicationStateParams(...); // now private function to simplify the api
convertQueryParams.transformParamsToQuery(...); // becomes the example below
// Strapi 5
// Those utils required the strapi app context, so we decided to expose a strapi service for it
strapi.get('query-params').transform();validate
和sanitize
现在是strapi.contentAPI
函数的一部分:¥
validate
andsanitize
are now part of thestrapi.contentAPI
functions:// Strapi v4
import { validate, sanitize } from '@strapi/utils';
validate.contentAPI.xxx();
sanitize.contentAPI.xxx();
// Strapi 5
// Those methods require the strapi app context
strapi.contentAPI.sanitize.xxx();
strapi.contentAPI.validate.xxx();