@agnostack/next-shopify 1.13.9-beta.2 → 1.13.9
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/CHANGELOG.md +40 -61
- package/dist/lib/handlers/api/graph.d.ts.map +1 -1
- package/dist/lib/handlers/api/graph.js +79 -84
- package/dist/lib/handlers/api/graph.js.map +1 -1
- package/dist/lib/handlers/api/proxy.d.ts.map +1 -1
- package/dist/lib/handlers/api/proxy.js +156 -115
- package/dist/lib/handlers/api/proxy.js.map +1 -1
- package/dist/lib/handlers/api/rest.d.ts.map +1 -1
- package/dist/lib/handlers/api/rest.js +65 -70
- package/dist/lib/handlers/api/rest.js.map +1 -1
- package/dist/lib/handlers/api/token.js +3 -2
- package/dist/lib/handlers/api/token.js.map +1 -1
- package/dist/lib/handlers/ssr/wrap.d.ts.map +1 -1
- package/dist/lib/handlers/ssr/wrap.js +3 -1
- package/dist/lib/handlers/ssr/wrap.js.map +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +4 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/utils/index.d.ts +0 -1
- package/dist/lib/utils/index.js +0 -1
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/lib/utils/session.d.ts.map +1 -1
- package/dist/lib/utils/session.js +2 -2
- package/dist/lib/utils/session.js.map +1 -1
- package/dist/shared/display.d.ts +23 -88
- package/dist/shared/display.d.ts.map +1 -1
- package/dist/shared/display.js +104 -409
- package/dist/shared/display.js.map +1 -1
- package/dist/shared/index.d.ts +0 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +0 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/shopify.d.ts +6 -0
- package/dist/shared/shopify.d.ts.map +1 -1
- package/dist/shared/shopify.js +28 -1
- package/dist/shared/shopify.js.map +1 -1
- package/package.json +1 -6
- package/dist/lib/utils/verification.d.ts +0 -2
- package/dist/lib/utils/verification.d.ts.map +0 -1
- package/dist/lib/utils/verification.js +0 -69
- package/dist/lib/utils/verification.js.map +0 -1
- package/dist/react/hooks/index.d.ts +0 -2
- package/dist/react/hooks/index.d.ts.map +0 -1
- package/dist/react/hooks/index.js +0 -5
- package/dist/react/hooks/index.js.map +0 -1
- package/dist/react/hooks/useVerification.d.ts +0 -9
- package/dist/react/hooks/useVerification.d.ts.map +0 -1
- package/dist/react/hooks/useVerification.js +0 -63
- package/dist/react/hooks/useVerification.js.map +0 -1
- package/dist/react/index.d.ts +0 -2
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -5
- package/dist/react/index.js.map +0 -1
- package/dist/react/types.d.ts +0 -1
- package/dist/react/types.d.ts.map +0 -1
- package/dist/react/types.js +0 -1
- package/dist/react/types.js.map +0 -1
- package/dist/shared/datetime.d.ts +0 -96
- package/dist/shared/datetime.d.ts.map +0 -1
- package/dist/shared/datetime.js +0 -285
- package/dist/shared/datetime.js.map +0 -1
package/dist/shared/display.js
CHANGED
|
@@ -1,154 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.getInteger = exports.getGUID = exports.appendQuery = exports.arraysMatch = exports.arrayIncludesAll = exports.querystringToObject = exports.parseProject = exports.parseProjectName = exports.parseKeywordGroups = exports.parseKeywords = exports.isTrue = exports.arrayToObject = exports.normalizeArray = exports.combineCommas = exports.splitCommas = exports.wrappedEncode = exports.ensureExtension = exports.ensureTrailingSlash = exports.ensureLeadingSlash = exports.removeLeadingTrailingSlash = exports.removeTrailingSlash = exports.removeLeadingTrailingQuotes = exports.removeLeadingSlash = exports.titleCase = exports.camelCase = exports.capitalize = exports.slugify = exports.lowercase = exports.uppercase = void 0;
|
|
3
|
+
exports.appendQuery = exports.ensureLeadingSlash = exports.removeLeadingSlash = exports.objectToSortedString = exports.compareEntryKeys = exports.compareString = exports.arraysMatch = exports.arrayIncludesAll = exports.splitCommas = exports.safeParse = exports.safeTrim = exports.cleanObject = exports.isTrue = exports.unsnakecase = exports.snakecase = exports.arrayNotEmpty = exports.arrayEmpty = exports.stringEmptyOnly = exports.stringNotEmptyOnly = exports.stringEmpty = exports.stringNotEmpty = exports.objectNotEmpty = exports.objectEmpty = exports.isNumericOnly = exports.isType = exports.querystringToObject = exports.getRequestMethod = exports.uppercase = exports.ensureNumeric = exports.ensureArray = exports.ensureStringOnly = exports.ensureString = exports.ensureObject = exports.getInteger = exports.getGUID = void 0;
|
|
5
4
|
/* eslint-disable no-use-before-define */
|
|
6
5
|
const uuid_1 = require("uuid");
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const getGUID = () => ((0, uuid_1.v4)());
|
|
7
|
+
exports.getGUID = getGUID;
|
|
8
|
+
const getInteger = () => ((0, exports.getGUID)().replace(/\D/g, ''));
|
|
9
|
+
exports.getInteger = getInteger;
|
|
10
|
+
// TODO: keep in sync w/ lib-core
|
|
11
|
+
const ensureObject = (object) => (object !== null && object !== void 0 ? object : {});
|
|
12
|
+
exports.ensureObject = ensureObject;
|
|
13
|
+
const ensureString = (string) => (string ? `${string}` : '');
|
|
14
|
+
exports.ensureString = ensureString;
|
|
15
|
+
// HMMM: what if 'string' is an object?
|
|
16
|
+
const ensureStringOnly = (string) => (
|
|
17
|
+
// eslint-disable-next-line eqeqeq
|
|
18
|
+
(string != undefined) ? `${string}` : '');
|
|
19
|
+
exports.ensureStringOnly = ensureStringOnly;
|
|
20
|
+
const ensureArray = (array = []) => (
|
|
21
|
+
// eslint-disable-next-line no-nested-ternary
|
|
22
|
+
!array ? [] : Array.isArray(array) ? array : [array]);
|
|
23
|
+
exports.ensureArray = ensureArray;
|
|
24
|
+
const ensureNumeric = (string) => (Number((0, exports.ensureString)(string).replace(/[^0-9.]/gi, '')));
|
|
25
|
+
exports.ensureNumeric = ensureNumeric;
|
|
26
|
+
const uppercase = (string) => ((0, exports.ensureString)(string).toUpperCase());
|
|
27
|
+
exports.uppercase = uppercase;
|
|
9
28
|
const getRequestMethod = (body, _method) => {
|
|
10
29
|
const method = _method !== null && _method !== void 0 ? _method : (body ? 'POST' : 'GET');
|
|
11
30
|
return (0, exports.uppercase)(method);
|
|
12
31
|
};
|
|
13
32
|
exports.getRequestMethod = getRequestMethod;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const isString = (0, exports.isType)(shopifyData, 'string');
|
|
17
|
-
if (isString && !shopifyData.startsWith('gid:')) {
|
|
18
|
-
if (!(0, exports.isNumericOnly)(shopifyData)) {
|
|
19
|
-
return {};
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
id: `${shopifyData}`,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const { id: _entityId, legacyResourceId } = isString
|
|
26
|
-
? { id: shopifyData }
|
|
27
|
-
: (0, exports.ensureObject)(shopifyData);
|
|
28
|
-
if ((0, exports.stringEmpty)(_entityId) && (0, exports.stringEmpty)(legacyResourceId)) {
|
|
33
|
+
const querystringToObject = (queryString) => {
|
|
34
|
+
if ((0, exports.stringEmpty)(queryString)) {
|
|
29
35
|
return {};
|
|
30
36
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const id = (0, exports.ensureString)(parsedId || legacyResourceId);
|
|
34
|
-
const hasEntityId = (0, exports.stringNotEmpty)(entity_id);
|
|
35
|
-
const hasEntityType = (0, exports.stringNotEmpty)(entity_type);
|
|
36
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({}, (0, exports.stringNotEmpty)(id) && { id }), hasEntityId && { entity_id }), hasEntityType && { entity_type }), (hasEntityId && hasEntityType) && {
|
|
37
|
-
gid: `gid://shopify/${entity_type}/${entity_id}`,
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
exports.normalizeShopifyId = normalizeShopifyId;
|
|
41
|
-
const random = (max = 100, min = 1) => {
|
|
42
|
-
const floor = Math.min(max, min);
|
|
43
|
-
return Math.floor(Math.random() * (max - floor + 1)) + floor;
|
|
44
|
-
};
|
|
45
|
-
exports.random = random;
|
|
46
|
-
const nextRandom = (max = 100, min = 1) => {
|
|
47
|
-
const maximum = Math.max(max, 0);
|
|
48
|
-
const minimum = Math.max(min, 0);
|
|
49
|
-
let randomNumber = maximum;
|
|
50
|
-
if (maximum > minimum) {
|
|
51
|
-
do {
|
|
52
|
-
randomNumber = (0, exports.random)(maximum, minimum);
|
|
53
|
-
} while (randomNumber === exports.nextRandom.last);
|
|
54
|
-
exports.nextRandom.last = randomNumber;
|
|
55
|
-
}
|
|
56
|
-
return randomNumber;
|
|
57
|
-
};
|
|
58
|
-
exports.nextRandom = nextRandom;
|
|
59
|
-
const arrayRandom = (_values, _max = 1) => {
|
|
60
|
-
const values = (0, exports.ensureArray)(_values);
|
|
61
|
-
const valuesLength = values.length;
|
|
62
|
-
const maxLength = Math.min(_max, valuesLength);
|
|
63
|
-
if (valuesLength <= maxLength) {
|
|
64
|
-
return values;
|
|
65
|
-
}
|
|
66
|
-
const arrayLength = valuesLength - 1;
|
|
67
|
-
const randomValues = [];
|
|
68
|
-
do {
|
|
69
|
-
const newVal = values[(0, exports.nextRandom)(arrayLength, 0)];
|
|
70
|
-
if (!randomValues.includes(newVal)) {
|
|
71
|
-
randomValues.push(newVal);
|
|
72
|
-
}
|
|
73
|
-
} while (randomValues.length < maxLength);
|
|
74
|
-
return randomValues;
|
|
37
|
+
const urlParams = new URLSearchParams(queryString);
|
|
38
|
+
return Object.fromEntries(urlParams);
|
|
75
39
|
};
|
|
76
|
-
exports.
|
|
77
|
-
const arrayRandomItem = (_values) => ((0, exports.arrayRandom)(_values)[0]);
|
|
78
|
-
exports.arrayRandomItem = arrayRandomItem;
|
|
79
|
-
const isArray = (value) => (
|
|
80
|
-
// eslint-disable-next-line eqeqeq
|
|
81
|
-
(value != undefined) && Array.isArray(value));
|
|
82
|
-
exports.isArray = isArray;
|
|
83
|
-
const isSet = (value) => (
|
|
84
|
-
// eslint-disable-next-line eqeqeq
|
|
85
|
-
(value != undefined) && (value instanceof Set));
|
|
86
|
-
exports.isSet = isSet;
|
|
40
|
+
exports.querystringToObject = querystringToObject;
|
|
87
41
|
const isType = (value, type) => (
|
|
88
42
|
// eslint-disable-next-line eqeqeq, valid-typeof
|
|
89
43
|
(value != undefined) && (typeof value === type));
|
|
90
44
|
exports.isType = isType;
|
|
91
|
-
const isTypeEnhanced = (value, type) => {
|
|
92
|
-
switch (true) {
|
|
93
|
-
case (type === 'set'): {
|
|
94
|
-
return (0, exports.isSet)(value);
|
|
95
|
-
}
|
|
96
|
-
case (type === 'array'): {
|
|
97
|
-
return ((0, exports.isArray)(value) &&
|
|
98
|
-
!(0, exports.isSet)(value));
|
|
99
|
-
}
|
|
100
|
-
case (type === 'object'): {
|
|
101
|
-
return ((0, exports.isType)(value, type) &&
|
|
102
|
-
!(0, exports.isArray)(value));
|
|
103
|
-
}
|
|
104
|
-
default: {
|
|
105
|
-
return (0, exports.isType)(value, type);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
exports.isTypeEnhanced = isTypeEnhanced;
|
|
110
|
-
const safeTrim = (value) => {
|
|
111
|
-
if ((0, exports.isType)(value, 'string')) {
|
|
112
|
-
// eslint-disable-next-line no-param-reassign
|
|
113
|
-
value = value.trim();
|
|
114
|
-
}
|
|
115
|
-
return value;
|
|
116
|
-
};
|
|
117
|
-
exports.safeTrim = safeTrim;
|
|
118
|
-
const safeParse = (value, trim) => {
|
|
119
|
-
if ((0, exports.isType)(value, 'string')) {
|
|
120
|
-
if (trim) {
|
|
121
|
-
// eslint-disable-next-line no-param-reassign
|
|
122
|
-
value = (0, exports.safeTrim)(value);
|
|
123
|
-
}
|
|
124
|
-
if (value.startsWith('{') || value.startsWith('[')) {
|
|
125
|
-
// eslint-disable-next-line no-param-reassign
|
|
126
|
-
value = JSON.parse(value);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// TODO: should this be value ?? {}
|
|
130
|
-
return value;
|
|
131
|
-
};
|
|
132
|
-
exports.safeParse = safeParse;
|
|
133
|
-
const ensureString = (string) => (string ? `${string}` : '');
|
|
134
|
-
exports.ensureString = ensureString;
|
|
135
|
-
// HMMM: what if 'string' is an object?
|
|
136
|
-
const ensureStringOnly = (string) => (
|
|
137
|
-
// eslint-disable-next-line eqeqeq
|
|
138
|
-
(string != undefined) ? `${string}` : '');
|
|
139
|
-
exports.ensureStringOnly = ensureStringOnly;
|
|
140
|
-
const ensureStringAscii = (string) => (
|
|
141
|
-
// eslint-disable-next-line no-control-regex
|
|
142
|
-
(0, exports.ensureStringOnly)(string).replace(/[^\x00-\x7F]/g, ''));
|
|
143
|
-
exports.ensureStringAscii = ensureStringAscii;
|
|
144
|
-
const ensureStringClean = (string) => (
|
|
145
|
-
// eslint-disable-next-line no-control-regex
|
|
146
|
-
(0, exports.ensureStringOnly)(string).replace(/[^a-z0-9_-]/gi, ''));
|
|
147
|
-
exports.ensureStringClean = ensureStringClean;
|
|
148
|
-
const ensureAlphaNumeric = (string) => (
|
|
149
|
-
// eslint-disable-next-line no-control-regex
|
|
150
|
-
(0, exports.ensureStringOnly)(string).replace(/[^a-z0-9]/gi, ''));
|
|
151
|
-
exports.ensureAlphaNumeric = ensureAlphaNumeric;
|
|
152
45
|
const isNumericOnly = (value) => {
|
|
153
46
|
var _a;
|
|
154
47
|
const [matched] = (_a = `${value}`.match(/^([0-9]+)$/)) !== null && _a !== void 0 ? _a : [];
|
|
@@ -156,33 +49,24 @@ const isNumericOnly = (value) => {
|
|
|
156
49
|
return (matched != undefined);
|
|
157
50
|
};
|
|
158
51
|
exports.isNumericOnly = isNumericOnly;
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
52
|
+
const objectEmpty = (object) => (!object || !Object.keys(object).length);
|
|
53
|
+
exports.objectEmpty = objectEmpty;
|
|
54
|
+
const objectNotEmpty = (object) => (!(0, exports.objectEmpty)(object));
|
|
55
|
+
exports.objectNotEmpty = objectNotEmpty;
|
|
56
|
+
const stringNotEmpty = (stringable) => {
|
|
57
|
+
const string = (0, exports.ensureString)(stringable);
|
|
58
|
+
return ((string.length > 0) && !['null', 'undefined'].includes(string));
|
|
164
59
|
};
|
|
165
|
-
exports.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
// TODO: update regex to handle negative number returns negative. Something like (?!\d\.)(-?\d+(\.\d)?)
|
|
172
|
-
const ensureNumericNegatable = (string) => (Number((0, exports.ensureString)(string).replace(/[^0-9.-]/gi, '')));
|
|
173
|
-
exports.ensureNumericNegatable = ensureNumericNegatable;
|
|
174
|
-
const ensureNumericConstrained = (value, { min: _min = 0, max: _max = 100 } = {}) => {
|
|
175
|
-
const min = (0, exports.ensureNumericNegatable)(_min);
|
|
176
|
-
const max = (0, exports.ensureNumericNegatable)(_max);
|
|
177
|
-
return Math.max(min, Math.min((0, exports.ensureNumeric)(value), max));
|
|
60
|
+
exports.stringNotEmpty = stringNotEmpty;
|
|
61
|
+
const stringEmpty = (stringable) => (!(0, exports.stringNotEmpty)(stringable));
|
|
62
|
+
exports.stringEmpty = stringEmpty;
|
|
63
|
+
const stringNotEmptyOnly = (stringable) => {
|
|
64
|
+
const string = (0, exports.ensureStringOnly)(stringable);
|
|
65
|
+
return ((string.length > 0) && !['null', 'undefined'].includes(string));
|
|
178
66
|
};
|
|
179
|
-
exports.
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
!array ? [] : Array.isArray(array) ? array : [array]);
|
|
183
|
-
exports.ensureArray = ensureArray;
|
|
184
|
-
const ensureArraySet = (arrayOrSet) => ((0, exports.ensureArray)((0, exports.isSet)(arrayOrSet) ? [...arrayOrSet] : arrayOrSet));
|
|
185
|
-
exports.ensureArraySet = ensureArraySet;
|
|
67
|
+
exports.stringNotEmptyOnly = stringNotEmptyOnly;
|
|
68
|
+
const stringEmptyOnly = (stringable) => (!(0, exports.stringNotEmptyOnly)(stringable));
|
|
69
|
+
exports.stringEmptyOnly = stringEmptyOnly;
|
|
186
70
|
const arrayEmpty = (array, disableEmptyString = false) => (
|
|
187
71
|
// eslint-disable-next-line eqeqeq
|
|
188
72
|
!array || !array.length || (array.length === 1 && (array[0] == undefined || (disableEmptyString && (0, exports.stringEmpty)(array[0])))));
|
|
@@ -191,24 +75,31 @@ const arrayNotEmpty = (array, disableEmptyString = false) => (
|
|
|
191
75
|
// eslint-disable-next-line eqeqeq
|
|
192
76
|
!(0, exports.arrayEmpty)(array) && array[0] != undefined && (!disableEmptyString || (0, exports.stringNotEmpty)(array[0])));
|
|
193
77
|
exports.arrayNotEmpty = arrayNotEmpty;
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
exports.
|
|
207
|
-
const
|
|
208
|
-
exports.
|
|
78
|
+
const recase = (string, replacement = '') => (!(0, exports.isType)(string, 'string')
|
|
79
|
+
? ''
|
|
80
|
+
: string
|
|
81
|
+
.replace(/[^a-zA-Z0-9]+/g, replacement)
|
|
82
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
83
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
84
|
+
.replace(/([0-9])([^0-9])/g, '$1-$2')
|
|
85
|
+
.replace(/([^0-9])([0-9])/g, '$1-$2')
|
|
86
|
+
.replace(/[-_]+/g, replacement)
|
|
87
|
+
.replace(new RegExp(`${replacement}$`), '')
|
|
88
|
+
.toLowerCase());
|
|
89
|
+
const snakecase = (string) => (recase(string, '_'));
|
|
90
|
+
exports.snakecase = snakecase;
|
|
91
|
+
const unsnakecase = (string, replacement = ' ') => ((0, exports.ensureString)(string).replace(/_/g, replacement).trim());
|
|
92
|
+
exports.unsnakecase = unsnakecase;
|
|
93
|
+
// TODO should we include 'undefined' into the default array?
|
|
94
|
+
const isTrue = (value, falsy) => {
|
|
95
|
+
const string = (0, exports.ensureString)(value);
|
|
96
|
+
return ![...(0, exports.ensureArray)(falsy), '', 'false'].includes(string);
|
|
97
|
+
};
|
|
98
|
+
exports.isTrue = isTrue;
|
|
209
99
|
const isUndefined = (value) => (
|
|
210
100
|
// eslint-disable-next-line eqeqeq
|
|
211
101
|
value == undefined);
|
|
102
|
+
const cleanObjectValue = (value, allowEmptyLeafs, isEmptyCallback) => ((0, exports.isType)(value, 'object') ? (0, exports.cleanObject)(value, allowEmptyLeafs, isEmptyCallback) : value);
|
|
212
103
|
const cleanObject = (object, allowEmptyLeafs, isEmptyCallback) => (Object.entries((0, exports.ensureObject)(object)).reduce((_cleanedObject, [key, _value]) => {
|
|
213
104
|
var _a;
|
|
214
105
|
if (!allowEmptyLeafs && ((_a = isEmptyCallback === null || isEmptyCallback === void 0 ? void 0 : isEmptyCallback(_value)) !== null && _a !== void 0 ? _a : isUndefined(_value))) {
|
|
@@ -223,27 +114,47 @@ const cleanObject = (object, allowEmptyLeafs, isEmptyCallback) => (Object.entrie
|
|
|
223
114
|
return Object.assign(Object.assign({}, _cleanedObject), { [key]: value });
|
|
224
115
|
}, {}));
|
|
225
116
|
exports.cleanObject = cleanObject;
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
117
|
+
const safeTrim = (value) => {
|
|
118
|
+
if ((0, exports.isType)(value, 'string')) {
|
|
119
|
+
// eslint-disable-next-line no-param-reassign
|
|
120
|
+
value = value.trim();
|
|
121
|
+
}
|
|
122
|
+
return value;
|
|
230
123
|
};
|
|
231
|
-
exports.
|
|
232
|
-
const
|
|
233
|
-
exports.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
124
|
+
exports.safeTrim = safeTrim;
|
|
125
|
+
const safeParse = (value, trim) => {
|
|
126
|
+
if ((0, exports.isType)(value, 'string')) {
|
|
127
|
+
if (trim) {
|
|
128
|
+
// eslint-disable-next-line no-param-reassign
|
|
129
|
+
value = (0, exports.safeTrim)(value);
|
|
130
|
+
}
|
|
131
|
+
if (value.startsWith('{') || value.startsWith('[')) {
|
|
132
|
+
// eslint-disable-next-line no-param-reassign
|
|
133
|
+
value = JSON.parse(value);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// TODO: should this be value ?? {}
|
|
137
|
+
return value;
|
|
237
138
|
};
|
|
238
|
-
exports.
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
139
|
+
exports.safeParse = safeParse;
|
|
140
|
+
const splitCommas = (value) => ((0, exports.ensureString)(value)
|
|
141
|
+
.replace(/, /g, ',')
|
|
142
|
+
.split(',')
|
|
143
|
+
.reduce((_values, _value) => {
|
|
144
|
+
const __value = (0, exports.safeTrim)(_value);
|
|
145
|
+
return [
|
|
146
|
+
..._values,
|
|
147
|
+
...(0, exports.stringNotEmpty)(__value) ? [__value] : []
|
|
148
|
+
];
|
|
149
|
+
}, []));
|
|
150
|
+
exports.splitCommas = splitCommas;
|
|
151
|
+
const arrayIncludesAll = (_values, comparison) => {
|
|
152
|
+
const values = (0, exports.ensureArray)(_values);
|
|
153
|
+
return (0, exports.ensureArray)(comparison).every((value) => ((0, exports.stringNotEmpty)(value) && values.includes(value)));
|
|
244
154
|
};
|
|
245
|
-
|
|
246
|
-
exports.
|
|
155
|
+
exports.arrayIncludesAll = arrayIncludesAll;
|
|
156
|
+
const arraysMatch = (array1, array2) => ((0, exports.arrayIncludesAll)(array1, array2) && (0, exports.arrayIncludesAll)(array2, array1));
|
|
157
|
+
exports.arraysMatch = arraysMatch;
|
|
247
158
|
const compareString = (string1, string2) => {
|
|
248
159
|
if ((0, exports.stringEmpty)(string1)) {
|
|
249
160
|
return 1;
|
|
@@ -261,221 +172,10 @@ const objectToSortedString = (object, separator = '') => (Object.entries((0, exp
|
|
|
261
172
|
.map(([key, value]) => `${key}=${value}`)
|
|
262
173
|
.join(separator));
|
|
263
174
|
exports.objectToSortedString = objectToSortedString;
|
|
264
|
-
const isHTML = (string) => {
|
|
265
|
-
var _a, _b, _c;
|
|
266
|
-
return ((_c = (((_a = string === null || string === void 0 ? void 0 : string.startsWith) === null || _a === void 0 ? void 0 : _a.call(string, '<')) || ((_b = string === null || string === void 0 ? void 0 : string.startsWith) === null || _b === void 0 ? void 0 : _b.call(string, '\n<')))) !== null && _c !== void 0 ? _c : false);
|
|
267
|
-
};
|
|
268
|
-
exports.isHTML = isHTML;
|
|
269
|
-
const freeze = (logMessage, object, type = 'log') => {
|
|
270
|
-
console[type](logMessage, !object ? object : JSON.parse(JSON.stringify((0, exports.ensureObject)(object))));
|
|
271
|
-
};
|
|
272
|
-
exports.freeze = freeze;
|
|
273
|
-
const replaceSpaces = (string, replacement = '') => (!(0, exports.isType)(string, 'string')
|
|
274
|
-
? ''
|
|
275
|
-
: string.replace(/\s/g, replacement));
|
|
276
|
-
exports.replaceSpaces = replaceSpaces;
|
|
277
|
-
const recase = (string, replacement = '') => (!(0, exports.isType)(string, 'string')
|
|
278
|
-
? ''
|
|
279
|
-
: string
|
|
280
|
-
.replace(/[^a-zA-Z0-9]+/g, replacement)
|
|
281
|
-
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
282
|
-
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
283
|
-
.replace(/([0-9])([^0-9])/g, '$1-$2')
|
|
284
|
-
.replace(/([^0-9])([0-9])/g, '$1-$2')
|
|
285
|
-
.replace(/[-_]+/g, replacement)
|
|
286
|
-
.replace(new RegExp(`${replacement}$`), '')
|
|
287
|
-
.toLowerCase());
|
|
288
|
-
const zencase = (string, replacement = '-') => (!(0, exports.isType)(string, 'string')
|
|
289
|
-
? ''
|
|
290
|
-
: (0, exports.replaceSpaces)(string, replacement)
|
|
291
|
-
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
292
|
-
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
293
|
-
.replace(new RegExp(`${replacement}$`), '')
|
|
294
|
-
.toLowerCase());
|
|
295
|
-
exports.zencase = zencase;
|
|
296
|
-
const dashcase = (string) => (recase(string, '-'));
|
|
297
|
-
exports.dashcase = dashcase;
|
|
298
|
-
const undashcase = (string, replacement = ' ') => ((0, exports.ensureString)(string).replace(/-/g, replacement).trim());
|
|
299
|
-
exports.undashcase = undashcase;
|
|
300
|
-
const snakecase = (string) => (recase(string, '_'));
|
|
301
|
-
exports.snakecase = snakecase;
|
|
302
|
-
const unsnakecase = (string, replacement = ' ') => ((0, exports.ensureString)(string).replace(/_/g, replacement).trim());
|
|
303
|
-
exports.unsnakecase = unsnakecase;
|
|
304
|
-
const uppercase = (string) => ((0, exports.ensureString)(string).toUpperCase());
|
|
305
|
-
exports.uppercase = uppercase;
|
|
306
|
-
const lowercase = (string, defaultValue = '') => (!(0, exports.stringNotEmpty)(string)
|
|
307
|
-
? defaultValue
|
|
308
|
-
: (0, exports.ensureString)(string).toLowerCase());
|
|
309
|
-
exports.lowercase = lowercase;
|
|
310
|
-
const slugify = (string) => ((0, exports.lowercase)((0, exports.dashcase)(string)));
|
|
311
|
-
exports.slugify = slugify;
|
|
312
|
-
const capitalize = (string) => {
|
|
313
|
-
const parts = splitString(string, 1);
|
|
314
|
-
return `${(0, exports.uppercase)(parts[0])}${parts[1]}`;
|
|
315
|
-
};
|
|
316
|
-
exports.capitalize = capitalize;
|
|
317
|
-
const camelCase = (string) => ((0, exports.stringNotEmpty)(string)
|
|
318
|
-
? (0, exports.unsnakecase)((0, exports.undashcase)(string)).replace(/\w\S*/g, (word, charIndex) => {
|
|
319
|
-
if (charIndex === 0) {
|
|
320
|
-
return (0, exports.lowercase)(word);
|
|
321
|
-
}
|
|
322
|
-
return `${(0, exports.uppercase)(word.charAt(0))}${(0, exports.lowercase)(word.substr(1))}`;
|
|
323
|
-
}).split(' ').join('')
|
|
324
|
-
: '');
|
|
325
|
-
exports.camelCase = camelCase;
|
|
326
|
-
const titleCase = (string, _overrides) => {
|
|
327
|
-
if (!(0, exports.stringNotEmpty)(string)) {
|
|
328
|
-
return '';
|
|
329
|
-
}
|
|
330
|
-
const overrides = Object.assign({ 'add-ons': 'Add-Ons', agnostack: 'agnoStack', ai: 'AI', b2b: 'B2B', b2c: 'B2C', cartcollab: 'CartCollab', 'cartcollab(sm)': 'CartCollab(SM)', chatgpt: 'ChatGPT', covid: 'COVID', covid19: 'COVID-19', 'covid-19': 'COVID-19', crm: 'CRM', elasticpath: 'Elastic Path', ecommerce: 'eCommerce', 'e-commerce': 'eCommerce', faqs: 'FAQs', gpt: 'GPT', 'smile.io': 'Smile.io', 'stamped.io': 'Stamped.io', 'judge.me': 'Judge.me', 'influence.io': 'Influence.io', keepsmallstrong: 'KeepSmallStrong', loyaltylion: 'LoyaltyLion', openai: 'OpenAI', paypal: 'PayPal', 'postscript.io': 'Postscript.io', recharge: 'ReCharge', 'stay.ai': 'Stay.ai', 'stay ai': 'Stay Ai', shipengine: 'ShipEngine', shipperhq: 'ShipperHQ', shipstation: 'ShipStation', taxjar: 'TaxJar', yotpo: 'YotPo' }, _overrides);
|
|
331
|
-
const stringParts = (0, exports.lowercase)(string)
|
|
332
|
-
.split(' ')
|
|
333
|
-
.reduce((_stringParts, _stringPart) => {
|
|
334
|
-
var _a;
|
|
335
|
-
const stringPart = (_a = overrides[_stringPart]) !== null && _a !== void 0 ? _a : _stringPart
|
|
336
|
-
.replace(/([A-Z]+)/g, ' $1')
|
|
337
|
-
.replace(/\s\s+/g, ' ')
|
|
338
|
-
.replace(/(\b[a-z](?!\s)*)/g, (firstChar) => (0, exports.uppercase)(firstChar));
|
|
339
|
-
return [
|
|
340
|
-
..._stringParts,
|
|
341
|
-
...(0, exports.stringNotEmpty)(stringPart) ? [stringPart] : []
|
|
342
|
-
];
|
|
343
|
-
}, []);
|
|
344
|
-
return stringParts.join(' ');
|
|
345
|
-
};
|
|
346
|
-
exports.titleCase = titleCase;
|
|
347
175
|
const removeLeadingSlash = (string) => ((0, exports.ensureString)(string).replace(/^\//, ''));
|
|
348
176
|
exports.removeLeadingSlash = removeLeadingSlash;
|
|
349
|
-
const removeLeadingTrailingQuotes = (string) => ((0, exports.ensureString)(string).replace(/^"|"$/g, ''));
|
|
350
|
-
exports.removeLeadingTrailingQuotes = removeLeadingTrailingQuotes;
|
|
351
|
-
// TODO: not sure if this should remove multipel at end or just one (as it does now)?
|
|
352
|
-
const removeTrailingSlash = (string) => ((0, exports.ensureString)(string).replace(/\/$/, ''));
|
|
353
|
-
exports.removeTrailingSlash = removeTrailingSlash;
|
|
354
|
-
const removeLeadingTrailingSlash = (string) => ((0, exports.removeTrailingSlash)((0, exports.removeLeadingSlash)(string)));
|
|
355
|
-
exports.removeLeadingTrailingSlash = removeLeadingTrailingSlash;
|
|
356
177
|
const ensureLeadingSlash = (string) => (`/${(0, exports.removeLeadingSlash)(string)}`);
|
|
357
178
|
exports.ensureLeadingSlash = ensureLeadingSlash;
|
|
358
|
-
const ensureTrailingSlash = (string) => (`${(0, exports.removeTrailingSlash)(string)}/`);
|
|
359
|
-
exports.ensureTrailingSlash = ensureTrailingSlash;
|
|
360
|
-
const ensureExtension = (string, extension) => {
|
|
361
|
-
var _a, _b;
|
|
362
|
-
if ((0, exports.stringEmpty)(extension)) {
|
|
363
|
-
return string;
|
|
364
|
-
}
|
|
365
|
-
const filePath = (_b = (_a = string.match(/(.*)\..+$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : string;
|
|
366
|
-
return `${filePath}.${extension}`;
|
|
367
|
-
};
|
|
368
|
-
exports.ensureExtension = ensureExtension;
|
|
369
|
-
const wrappedEncode = (basePath, _wrappingPath) => {
|
|
370
|
-
const wrappingPath = (0, exports.ensureString)(_wrappingPath);
|
|
371
|
-
if ((0, exports.stringEmpty)(basePath)) {
|
|
372
|
-
return wrappingPath;
|
|
373
|
-
}
|
|
374
|
-
return `${basePath}${encodeURIComponent(wrappingPath)}`;
|
|
375
|
-
};
|
|
376
|
-
exports.wrappedEncode = wrappedEncode;
|
|
377
|
-
const splitCommas = (value) => ((0, exports.ensureString)(value)
|
|
378
|
-
.replace(/, /g, ',')
|
|
379
|
-
.split(',')
|
|
380
|
-
.reduce((_values, _value) => {
|
|
381
|
-
const __value = (0, exports.safeTrim)(_value);
|
|
382
|
-
return [
|
|
383
|
-
..._values,
|
|
384
|
-
...(0, exports.stringNotEmpty)(__value) ? [__value] : [] // TODO: explore stringEmptyOnly?
|
|
385
|
-
];
|
|
386
|
-
}, []));
|
|
387
|
-
exports.splitCommas = splitCommas;
|
|
388
|
-
const combineCommas = (values) => ([...new Set((0, exports.ensureArray)(values).reduce((_combined, value) => ([
|
|
389
|
-
..._combined,
|
|
390
|
-
...(0, exports.splitCommas)(value)
|
|
391
|
-
]), []))]);
|
|
392
|
-
exports.combineCommas = combineCommas;
|
|
393
|
-
const normalizeArray = (input, separator = ' ') => {
|
|
394
|
-
const inputArray = (0, exports.ensureArray)(input);
|
|
395
|
-
return inputArray.reduce((normalized, _ignore, index) => ([
|
|
396
|
-
...normalized,
|
|
397
|
-
inputArray.slice(0, index + 1).join(separator)
|
|
398
|
-
]), []).reverse();
|
|
399
|
-
};
|
|
400
|
-
exports.normalizeArray = normalizeArray;
|
|
401
|
-
const arrayToObject = (arrayable, key) => ((0, exports.ensureArray)(arrayable).reduce((_object, item) => (Object.assign(Object.assign({}, _object), { [item === null || item === void 0 ? void 0 : item[key]]: item })), {}));
|
|
402
|
-
exports.arrayToObject = arrayToObject;
|
|
403
|
-
const isTrue = (value, falsy) => {
|
|
404
|
-
const string = (0, exports.ensureString)(value);
|
|
405
|
-
return ![...(0, exports.ensureArray)(falsy), '', 'false'].includes(string);
|
|
406
|
-
};
|
|
407
|
-
exports.isTrue = isTrue;
|
|
408
|
-
// TODO: move all uses of parseKeywords to parseKeywordGroups
|
|
409
|
-
const parseKeywords = (keywordGroup, previous) => ([...new Set((0, exports.ensureArray)(keywordGroup).reduce((_parsedKeywords, keyword) => {
|
|
410
|
-
const keywords = (0, exports.splitCommas)(keyword);
|
|
411
|
-
return [
|
|
412
|
-
..._parsedKeywords,
|
|
413
|
-
...keywords.filter((_keyword) => (0, exports.stringNotEmpty)(_keyword))
|
|
414
|
-
];
|
|
415
|
-
}, (0, exports.ensureArray)(previous)))].join(', '));
|
|
416
|
-
exports.parseKeywords = parseKeywords;
|
|
417
|
-
const parseKeywordGroups = (keywordGroups) => {
|
|
418
|
-
const parsedKeywords = (0, exports.ensureArray)(keywordGroups).reduce((_parsedKeywords, keywordGroup) => ([
|
|
419
|
-
..._parsedKeywords,
|
|
420
|
-
...(0, exports.ensureArray)(keywordGroup).reduce((_parsedGroupKeywords, keyword) => {
|
|
421
|
-
const keywords = (0, exports.splitCommas)(keyword);
|
|
422
|
-
return [
|
|
423
|
-
..._parsedGroupKeywords,
|
|
424
|
-
...keywords.filter((_keyword) => (0, exports.stringNotEmpty)(_keyword))
|
|
425
|
-
];
|
|
426
|
-
}, [])
|
|
427
|
-
]), []);
|
|
428
|
-
return [...new Set(parsedKeywords)].join(', ');
|
|
429
|
-
};
|
|
430
|
-
exports.parseKeywordGroups = parseKeywordGroups;
|
|
431
|
-
const parseProjectName = (_name) => {
|
|
432
|
-
var _a;
|
|
433
|
-
const name = (0, exports.ensureString)(_name);
|
|
434
|
-
const [, organization, ...parts] = (_a = /(@.*)([\\]+|\/)+(.*)/.exec(name)) !== null && _a !== void 0 ? _a : [];
|
|
435
|
-
const projectName = organization ? name.replace(organization, '').replace('/', '') : name;
|
|
436
|
-
return {
|
|
437
|
-
name,
|
|
438
|
-
parts,
|
|
439
|
-
organization,
|
|
440
|
-
projectName,
|
|
441
|
-
};
|
|
442
|
-
};
|
|
443
|
-
exports.parseProjectName = parseProjectName;
|
|
444
|
-
const parseProject = (packageInfo) => {
|
|
445
|
-
const { shortName, owner: _appOwner, name: _name, appName: _appName, keywords, siteName: _siteName } = packageInfo !== null && packageInfo !== void 0 ? packageInfo : {};
|
|
446
|
-
const { name, organization, projectName } = (0, exports.parseProjectName)(_name);
|
|
447
|
-
const appName = _appName !== null && _appName !== void 0 ? _appName : projectName === null || projectName === void 0 ? void 0 : projectName.slice((projectName === null || projectName === void 0 ? void 0 : projectName.indexOf('-')) + 1);
|
|
448
|
-
const siteName = _siteName !== null && _siteName !== void 0 ? _siteName : projectName === null || projectName === void 0 ? void 0 : projectName.slice((projectName === null || projectName === void 0 ? void 0 : projectName.indexOf('-')) + 1);
|
|
449
|
-
const companyName = (0, exports.titleCase)(organization === null || organization === void 0 ? void 0 : organization.replace('@', ''));
|
|
450
|
-
const appOwner = _appOwner !== null && _appOwner !== void 0 ? _appOwner : companyName;
|
|
451
|
-
return [{
|
|
452
|
-
keywords,
|
|
453
|
-
appOwner,
|
|
454
|
-
appName,
|
|
455
|
-
siteName,
|
|
456
|
-
shortName,
|
|
457
|
-
companyName,
|
|
458
|
-
projectName,
|
|
459
|
-
}, organization, name];
|
|
460
|
-
};
|
|
461
|
-
exports.parseProject = parseProject;
|
|
462
|
-
// #endregion lib-core
|
|
463
|
-
// #region lib-utils-js
|
|
464
|
-
const querystringToObject = (queryString) => {
|
|
465
|
-
if ((0, exports.stringEmpty)(queryString)) {
|
|
466
|
-
return {};
|
|
467
|
-
}
|
|
468
|
-
const urlParams = new URLSearchParams(queryString);
|
|
469
|
-
return Object.fromEntries(urlParams);
|
|
470
|
-
};
|
|
471
|
-
exports.querystringToObject = querystringToObject;
|
|
472
|
-
const arrayIncludesAll = (_values, comparison) => {
|
|
473
|
-
const values = (0, exports.ensureArray)(_values);
|
|
474
|
-
return (0, exports.ensureArray)(comparison).every((value) => ((0, exports.stringNotEmpty)(value) && values.includes(value)));
|
|
475
|
-
};
|
|
476
|
-
exports.arrayIncludesAll = arrayIncludesAll;
|
|
477
|
-
const arraysMatch = (array1, array2) => ((0, exports.arrayIncludesAll)(array1, array2) && (0, exports.arrayIncludesAll)(array2, array1));
|
|
478
|
-
exports.arraysMatch = arraysMatch;
|
|
479
179
|
const appendQuery = (_basePath, queryString) => {
|
|
480
180
|
const basePath = (0, exports.ensureString)(_basePath);
|
|
481
181
|
if ((0, exports.stringEmpty)(queryString)) {
|
|
@@ -484,9 +184,4 @@ const appendQuery = (_basePath, queryString) => {
|
|
|
484
184
|
return `${basePath}${basePath.includes('?') ? '&' : '?'}${queryString}`;
|
|
485
185
|
};
|
|
486
186
|
exports.appendQuery = appendQuery;
|
|
487
|
-
// #endregion lib-utils-js
|
|
488
|
-
const getGUID = () => ((0, uuid_1.v4)());
|
|
489
|
-
exports.getGUID = getGUID;
|
|
490
|
-
const getInteger = () => ((0, exports.getGUID)().replace(/\D/g, ''));
|
|
491
|
-
exports.getInteger = getInteger;
|
|
492
187
|
//# sourceMappingURL=display.js.map
|