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.
Is this breaking change affecting plugins?Yes
Is this breaking change automatically handled by a codemod?Yes
(see utils-public-interface)更改列表
🌐 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:这在加载旧的 v3 配置文件(JSON 格式)以允 许使用模板时使用。如果插件开发者仍在使用该函数,且确实需要使用模板,应该用真正的模板库来替代它的使用。 -
arrays工具:要使用这些新工具:- 在你的代码中使用
import { arrays, dates, strings, objects } from '@strapi/utils';导入它们。 - 例如,将它们用作
arrays.includesString或strings.isEqual。
- 在你的代码中使用
-
convertQueryParams被替换:// 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功能的一部分:// 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();