@strapi/utils 4.2.0-alpha.9 → 4.2.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +2 -0
- package/lib/pagination.js +1 -4
- package/lib/string-formatting.js +15 -0
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -21,6 +21,7 @@ const {
|
|
|
21
21
|
isCamelCase,
|
|
22
22
|
toRegressedEnumValue,
|
|
23
23
|
startsWithANumber,
|
|
24
|
+
joinBy,
|
|
24
25
|
} = require('./string-formatting');
|
|
25
26
|
const { removeUndefined } = require('./object-formatting');
|
|
26
27
|
const { getConfigUrls, getAbsoluteAdminUrl, getAbsoluteServerUrl } = require('./config');
|
|
@@ -51,6 +52,7 @@ module.exports = {
|
|
|
51
52
|
nameToSlug,
|
|
52
53
|
toRegressedEnumValue,
|
|
53
54
|
startsWithANumber,
|
|
55
|
+
joinBy,
|
|
54
56
|
nameToCollectionName,
|
|
55
57
|
getCommonBeginning,
|
|
56
58
|
getConfigUrls,
|
package/lib/pagination.js
CHANGED
|
@@ -47,10 +47,7 @@ const withDefaultPagination = (args, { defaults = {}, maxLimit = -1 } = {}) => {
|
|
|
47
47
|
const usePagePagination = !isNil(args.page) || !isNil(args.pageSize);
|
|
48
48
|
const useOffsetPagination = !isNil(args.start) || !isNil(args.limit);
|
|
49
49
|
|
|
50
|
-
const ensureValidValues = pipe(
|
|
51
|
-
ensureMinValues,
|
|
52
|
-
ensureMaxValues(maxLimit)
|
|
53
|
-
);
|
|
50
|
+
const ensureValidValues = pipe(ensureMinValues, ensureMaxValues(maxLimit));
|
|
54
51
|
|
|
55
52
|
// If there is no pagination attribute, don't modify the payload
|
|
56
53
|
if (!usePagePagination && !useOffsetPagination) {
|
package/lib/string-formatting.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const _ = require('lodash');
|
|
3
|
+
const { trimChars, trimCharsEnd, trimCharsStart } = require('lodash/fp');
|
|
3
4
|
const slugify = require('@sindresorhus/slugify');
|
|
4
5
|
|
|
5
6
|
const nameToSlug = (name, options = { separator: '-' }) => slugify(name, options);
|
|
@@ -44,6 +45,19 @@ const isCamelCase = value => /^[a-z][a-zA-Z0-9]+$/.test(value);
|
|
|
44
45
|
const isKebabCase = value => /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.test(value);
|
|
45
46
|
const startsWithANumber = value => /^[0-9]/.test(value);
|
|
46
47
|
|
|
48
|
+
const joinBy = (joint, ...args) => {
|
|
49
|
+
const trim = trimChars(joint);
|
|
50
|
+
const trimEnd = trimCharsEnd(joint);
|
|
51
|
+
const trimStart = trimCharsStart(joint);
|
|
52
|
+
|
|
53
|
+
return args.reduce((url, path, index) => {
|
|
54
|
+
if (args.length === 1) return path;
|
|
55
|
+
if (index === 0) return trimEnd(path);
|
|
56
|
+
if (index === args.length - 1) return url + joint + trimStart(path);
|
|
57
|
+
return url + joint + trim(path);
|
|
58
|
+
}, '');
|
|
59
|
+
};
|
|
60
|
+
|
|
47
61
|
module.exports = {
|
|
48
62
|
nameToSlug,
|
|
49
63
|
nameToCollectionName,
|
|
@@ -56,4 +70,5 @@ module.exports = {
|
|
|
56
70
|
isKebabCase,
|
|
57
71
|
toRegressedEnumValue,
|
|
58
72
|
startsWithANumber,
|
|
73
|
+
joinBy,
|
|
59
74
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "4.2.0-
|
|
3
|
+
"version": "4.2.0-beta.1",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"node": ">=12.22.0 <=16.x.x",
|
|
46
46
|
"npm": ">=6.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "4fa2804f35e15ed72dfd309fb5bb1c4dba18932f"
|
|
49
49
|
}
|