@agnostack/next-shopify 1.13.4 → 1.13.5-beta.2

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/lib/utils/session.d.ts.map +1 -1
  3. package/dist/lib/utils/session.js +2 -2
  4. package/dist/lib/utils/session.js.map +1 -1
  5. package/dist/react/hooks/index.d.ts +2 -0
  6. package/dist/react/hooks/index.d.ts.map +1 -0
  7. package/dist/react/hooks/index.js +5 -0
  8. package/dist/react/hooks/index.js.map +1 -0
  9. package/dist/react/hooks/useVerification.d.ts +9 -0
  10. package/dist/react/hooks/useVerification.d.ts.map +1 -0
  11. package/dist/react/hooks/useVerification.js +63 -0
  12. package/dist/react/hooks/useVerification.js.map +1 -0
  13. package/dist/react/index.d.ts +2 -0
  14. package/dist/react/index.d.ts.map +1 -0
  15. package/dist/react/index.js +5 -0
  16. package/dist/react/index.js.map +1 -0
  17. package/dist/react/types.d.ts +1 -0
  18. package/dist/react/types.d.ts.map +1 -0
  19. package/dist/react/types.js +1 -0
  20. package/dist/react/types.js.map +1 -0
  21. package/dist/shared/datetime.d.ts +96 -0
  22. package/dist/shared/datetime.d.ts.map +1 -0
  23. package/dist/shared/datetime.js +285 -0
  24. package/dist/shared/datetime.js.map +1 -0
  25. package/dist/shared/display.d.ts +88 -23
  26. package/dist/shared/display.d.ts.map +1 -1
  27. package/dist/shared/display.js +409 -104
  28. package/dist/shared/display.js.map +1 -1
  29. package/dist/shared/index.d.ts +1 -0
  30. package/dist/shared/index.d.ts.map +1 -1
  31. package/dist/shared/index.js +1 -0
  32. package/dist/shared/index.js.map +1 -1
  33. package/dist/shared/shopify.d.ts +0 -6
  34. package/dist/shared/shopify.d.ts.map +1 -1
  35. package/dist/shared/shopify.js +1 -28
  36. package/dist/shared/shopify.js.map +1 -1
  37. package/package.json +6 -1
@@ -1,47 +1,154 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
3
+ exports.unsnakecase = exports.snakecase = exports.undashcase = exports.dashcase = exports.zencase = exports.replaceSpaces = exports.freeze = exports.isHTML = exports.objectToSortedString = exports.compareEntryKeys = exports.compareString = exports.compareNumber = exports.stringEmpty = exports.stringNotEmpty = exports.stringEmptyOnly = exports.stringNotEmptyOnly = exports.cleanObject = exports.objectContainsAnyValue = exports.nullable = exports.objectNotEmpty = exports.objectEmpty = exports.ensureObject = exports.findLastMatch = exports.arrayNotEmpty = exports.arrayEmpty = exports.ensureArraySet = exports.ensureArray = exports.ensureNumericConstrained = exports.ensureNumericNegatable = exports.ensureNumericOnly = exports.ensureNumeric = exports.isNumericNegatable = exports.isNumericOnly = exports.ensureAlphaNumeric = exports.ensureStringClean = exports.ensureStringAscii = exports.ensureStringOnly = exports.ensureString = exports.safeParse = exports.safeTrim = exports.isTypeEnhanced = exports.isType = exports.isSet = exports.isArray = exports.arrayRandomItem = exports.arrayRandom = exports.nextRandom = exports.random = exports.normalizeShopifyId = exports.getRequestMethod = void 0;
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;
4
5
  /* eslint-disable no-use-before-define */
5
6
  const uuid_1 = require("uuid");
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;
7
+ // #region lib-core
8
+ // TODO!!!: keep in sync between next-shopify and lib-core (and lib-utils-js at bottom)
28
9
  const getRequestMethod = (body, _method) => {
29
10
  const method = _method !== null && _method !== void 0 ? _method : (body ? 'POST' : 'GET');
30
11
  return (0, exports.uppercase)(method);
31
12
  };
32
13
  exports.getRequestMethod = getRequestMethod;
33
- const querystringToObject = (queryString) => {
34
- if ((0, exports.stringEmpty)(queryString)) {
14
+ const normalizeShopifyId = (shopifyData) => {
15
+ var _a, _b;
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)) {
35
29
  return {};
36
30
  }
37
- const urlParams = new URLSearchParams(queryString);
38
- return Object.fromEntries(urlParams);
31
+ const entity_id = (0, exports.ensureString)(_entityId);
32
+ const { entity_type, parsedId } = (_b = (_a = entity_id.match(/^gid:\/\/shopify\/(?<entity_type>.*)\/(?<parsedId>[0-9]+).*$/)) === null || _a === void 0 ? void 0 : _a.groups) !== null && _b !== void 0 ? _b : {};
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
39
  };
40
- exports.querystringToObject = querystringToObject;
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;
75
+ };
76
+ exports.arrayRandom = arrayRandom;
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;
41
87
  const isType = (value, type) => (
42
88
  // eslint-disable-next-line eqeqeq, valid-typeof
43
89
  (value != undefined) && (typeof value === type));
44
90
  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;
45
152
  const isNumericOnly = (value) => {
46
153
  var _a;
47
154
  const [matched] = (_a = `${value}`.match(/^([0-9]+)$/)) !== null && _a !== void 0 ? _a : [];
@@ -49,24 +156,33 @@ const isNumericOnly = (value) => {
49
156
  return (matched != undefined);
50
157
  };
51
158
  exports.isNumericOnly = isNumericOnly;
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));
159
+ const isNumericNegatable = (value) => {
160
+ var _a;
161
+ const [matched] = (_a = `${value}`.match(/^(-?[0-9]+(\.[0-9]+)?)?$/)) !== null && _a !== void 0 ? _a : [];
162
+ // eslint-disable-next-line eqeqeq
163
+ return (matched != undefined);
59
164
  };
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));
165
+ exports.isNumericNegatable = isNumericNegatable;
166
+ // TODO: explore places using ensureNumeric to move to isNumericNegatable
167
+ const ensureNumeric = (string) => (Number((0, exports.ensureString)(string).replace(/[^0-9.]/gi, '')));
168
+ exports.ensureNumeric = ensureNumeric;
169
+ const ensureNumericOnly = (string) => (Number((0, exports.ensureString)(string).replace(/[^0-9]/gi, '')));
170
+ exports.ensureNumericOnly = ensureNumericOnly;
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));
66
178
  };
67
- exports.stringNotEmptyOnly = stringNotEmptyOnly;
68
- const stringEmptyOnly = (stringable) => (!(0, exports.stringNotEmptyOnly)(stringable));
69
- exports.stringEmptyOnly = stringEmptyOnly;
179
+ exports.ensureNumericConstrained = ensureNumericConstrained;
180
+ const ensureArray = (array = []) => (
181
+ // eslint-disable-next-line no-nested-ternary
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;
70
186
  const arrayEmpty = (array, disableEmptyString = false) => (
71
187
  // eslint-disable-next-line eqeqeq
72
188
  !array || !array.length || (array.length === 1 && (array[0] == undefined || (disableEmptyString && (0, exports.stringEmpty)(array[0])))));
@@ -75,31 +191,24 @@ const arrayNotEmpty = (array, disableEmptyString = false) => (
75
191
  // eslint-disable-next-line eqeqeq
76
192
  !(0, exports.arrayEmpty)(array) && array[0] != undefined && (!disableEmptyString || (0, exports.stringNotEmpty)(array[0])));
77
193
  exports.arrayNotEmpty = arrayNotEmpty;
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;
194
+ const findLastMatch = (array, filterCallback = (value) => (value)) => ((0, exports.ensureArray)(array).filter(filterCallback).slice(-1)[0]);
195
+ exports.findLastMatch = findLastMatch;
196
+ const ensureObject = (object) => (object !== null && object !== void 0 ? object : {});
197
+ exports.ensureObject = ensureObject;
198
+ // NOTE: this does not ensure !isType(string)
199
+ const objectEmpty = (object) => (!object || !Object.keys(object).length);
200
+ exports.objectEmpty = objectEmpty;
201
+ const objectNotEmpty = (object) => (!(0, exports.objectEmpty)(object));
202
+ exports.objectNotEmpty = objectNotEmpty;
203
+ const nullable = (object) => ((!object || (object === 'null') || (object === undefined) || (object === null))
204
+ ? null // TODO: explore undefined here??
205
+ : object);
206
+ exports.nullable = nullable;
207
+ const objectContainsAnyValue = (object) => (Object.values((0, exports.ensureObject)(object)).some((value) => (0, exports.nullable)(value)));
208
+ exports.objectContainsAnyValue = objectContainsAnyValue;
99
209
  const isUndefined = (value) => (
100
210
  // eslint-disable-next-line eqeqeq
101
211
  value == undefined);
102
- const cleanObjectValue = (value, allowEmptyLeafs, isEmptyCallback) => ((0, exports.isType)(value, 'object') ? (0, exports.cleanObject)(value, allowEmptyLeafs, isEmptyCallback) : value);
103
212
  const cleanObject = (object, allowEmptyLeafs, isEmptyCallback) => (Object.entries((0, exports.ensureObject)(object)).reduce((_cleanedObject, [key, _value]) => {
104
213
  var _a;
105
214
  if (!allowEmptyLeafs && ((_a = isEmptyCallback === null || isEmptyCallback === void 0 ? void 0 : isEmptyCallback(_value)) !== null && _a !== void 0 ? _a : isUndefined(_value))) {
@@ -114,47 +223,27 @@ const cleanObject = (object, allowEmptyLeafs, isEmptyCallback) => (Object.entrie
114
223
  return Object.assign(Object.assign({}, _cleanedObject), { [key]: value });
115
224
  }, {}));
116
225
  exports.cleanObject = cleanObject;
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;
226
+ const cleanObjectValue = (value, allowEmptyLeafs, isEmptyCallback) => ((0, exports.isType)(value, 'object') ? (0, exports.cleanObject)(value, allowEmptyLeafs, isEmptyCallback) : value);
227
+ const stringNotEmptyOnly = (stringable) => {
228
+ const string = (0, exports.ensureStringOnly)(stringable);
229
+ return ((string.length > 0) && !['null', 'undefined'].includes(string));
123
230
  };
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;
231
+ exports.stringNotEmptyOnly = stringNotEmptyOnly;
232
+ const stringEmptyOnly = (stringable) => (!(0, exports.stringNotEmptyOnly)(stringable));
233
+ exports.stringEmptyOnly = stringEmptyOnly;
234
+ const stringNotEmpty = (stringable) => {
235
+ const string = (0, exports.ensureString)(stringable);
236
+ return ((string.length > 0) && !['null', 'undefined'].includes(string));
138
237
  };
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)));
238
+ exports.stringNotEmpty = stringNotEmpty;
239
+ const stringEmpty = (stringable) => (!(0, exports.stringNotEmpty)(stringable));
240
+ exports.stringEmpty = stringEmpty;
241
+ const splitString = (splitting, index = splitting.length) => {
242
+ const string = (0, exports.ensureString)(splitting);
243
+ return [string.slice(0, index), string.slice(index)];
154
244
  };
155
- exports.arrayIncludesAll = arrayIncludesAll;
156
- const arraysMatch = (array1, array2) => ((0, exports.arrayIncludesAll)(array1, array2) && (0, exports.arrayIncludesAll)(array2, array1));
157
- exports.arraysMatch = arraysMatch;
245
+ const compareNumber = (number1 = 0, number2 = 0) => (number1 - number2);
246
+ exports.compareNumber = compareNumber;
158
247
  const compareString = (string1, string2) => {
159
248
  if ((0, exports.stringEmpty)(string1)) {
160
249
  return 1;
@@ -172,10 +261,221 @@ const objectToSortedString = (object, separator = '') => (Object.entries((0, exp
172
261
  .map(([key, value]) => `${key}=${value}`)
173
262
  .join(separator));
174
263
  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;
175
347
  const removeLeadingSlash = (string) => ((0, exports.ensureString)(string).replace(/^\//, ''));
176
348
  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;
177
356
  const ensureLeadingSlash = (string) => (`/${(0, exports.removeLeadingSlash)(string)}`);
178
357
  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;
179
479
  const appendQuery = (_basePath, queryString) => {
180
480
  const basePath = (0, exports.ensureString)(_basePath);
181
481
  if ((0, exports.stringEmpty)(queryString)) {
@@ -184,4 +484,9 @@ const appendQuery = (_basePath, queryString) => {
184
484
  return `${basePath}${basePath.includes('?') ? '&' : '?'}${queryString}`;
185
485
  };
186
486
  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;
187
492
  //# sourceMappingURL=display.js.map