strapi-utils refactored
In Strapi 5, the strapi-utils core package has been refactored. This page lists the additions, removals, and other updates.
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
| Element | Description of the change |
|---|---|
arrays utils | Added, and moved the stringIncludes method inside it (see additional notes). |
| Added (see additional notes). |
strings.getCommonPath | Added |
nameToSlug | Moved to strings.nameToSlug |
nameToCollectionName | Moved to strings.nameToCollectionName |
stringIncludes | Moved to arrays.includesString |
stringEquals | Moved to strings.isEqual |
isCamelCase | Moved to strings.isCamelCase |
isKebabCase | Moved to strings.isKebabCase |
toKebabCase | Moved to strings.toKebabCase |
toRegressedEnumValue | Moved to strings.toRegressedEnumValue |
startsWithANumber | Moved to strings.startsWithANumber |
joinBy | Moved to strings.joinBy |
keysDeep | Moved to objects.keysDeep |
generateTimestampCode | Moved to dates.timestampCode |
pipeAsync | Moved to async.pipe |
mapAsync | Moved to async.map |
reduceAsync | Moved to async.reduce |
convertQueryParams | Replaced (see additional notes). |
validate and sanitize | Updated (see additional notes). |
getCommonBeginning | Removed |
| Removed |
forEachAsync | Removed |
removeUndefined | Removed |
templateConfiguration | Removed (see additional notes). |
Additional Notes
-
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. -
arraysutils: To use these new utils:- Import them in your code with
import { arrays, dates, strings, objects } from '@strapi/utils';. - Use them, for instance as
arrays.includesStringorstrings.isEqual.
- Import them in your code with
-
convertQueryParamsis 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(); -
validateandsanitizeare now part of thestrapi.contentAPIfunctions:// 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();