Skip to main content

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已替换(参见 其他说明)。
validatesanitize已更新(参见 其他说明)。
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:

    1. 使用 import { arrays, dates, strings, objects } from '@strapi/utils'; 将它们导入到你的代码中。

      ¥Import them in your code with import { arrays, dates, strings, objects } from '@strapi/utils';.

    2. 使用它们,例如 arrays.includesStringstrings.isEqual

      ¥Use them, for instance as arrays.includesString or strings.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();
  • validatesanitize 现在是 strapi.contentAPI 函数的一部分:

    ¥validate and sanitize are now part of the strapi.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();