@agnostack/next-shopify 1.15.0-beta.2 → 1.15.0-beta.21
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 +136 -0
- package/dist/lib/handlers/api/auth.js +15 -11
- package/dist/lib/handlers/api/auth.js.map +1 -1
- package/dist/lib/handlers/api/billing.js +13 -9
- package/dist/lib/handlers/api/billing.js.map +1 -1
- package/dist/lib/handlers/api/callback.js +37 -33
- package/dist/lib/handlers/api/callback.js.map +1 -1
- package/dist/lib/handlers/api/index.js +25 -7
- package/dist/lib/handlers/api/index.js.map +1 -1
- package/dist/lib/handlers/api/uninstall.js +12 -8
- package/dist/lib/handlers/api/uninstall.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/appInstallation.js +11 -7
- package/dist/lib/handlers/api/verifiable/appInstallation.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/graph.js +26 -22
- package/dist/lib/handlers/api/verifiable/graph.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/index.js +21 -5
- package/dist/lib/handlers/api/verifiable/index.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/proxy.js +39 -32
- package/dist/lib/handlers/api/verifiable/proxy.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/rest.js +23 -19
- package/dist/lib/handlers/api/verifiable/rest.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/token.js +27 -23
- package/dist/lib/handlers/api/verifiable/token.js.map +1 -1
- package/dist/lib/handlers/api/webhook.js +13 -9
- package/dist/lib/handlers/api/webhook.js.map +1 -1
- package/dist/lib/handlers/index.js +18 -2
- package/dist/lib/handlers/index.js.map +1 -1
- package/dist/lib/handlers/ssr/index.js +18 -2
- package/dist/lib/handlers/ssr/index.js.map +1 -1
- package/dist/lib/handlers/ssr/protect.js +24 -17
- package/dist/lib/handlers/ssr/protect.js.map +1 -1
- package/dist/lib/handlers/ssr/wrap.js +10 -6
- 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 +24 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/utils/billing.js +23 -18
- package/dist/lib/utils/billing.js.map +1 -1
- package/dist/lib/utils/crypto.d.ts +1 -1
- package/dist/lib/utils/crypto.d.ts.map +1 -1
- package/dist/lib/utils/crypto.js +25 -15
- package/dist/lib/utils/crypto.js.map +1 -1
- package/dist/lib/utils/firebase.js +29 -17
- package/dist/lib/utils/firebase.js.map +1 -1
- package/dist/lib/utils/headers.js +13 -6
- package/dist/lib/utils/headers.js.map +1 -1
- package/dist/lib/utils/index.js +24 -8
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/lib/utils/session.js +64 -59
- package/dist/lib/utils/session.js.map +1 -1
- package/dist/lib/utils/shopify-api-js/oauth.js +23 -16
- package/dist/lib/utils/shopify-api-js/oauth.js.map +1 -1
- package/dist/lib/utils/shopify.js +37 -25
- package/dist/lib/utils/shopify.js.map +1 -1
- package/dist/lib/utils/token.js +15 -11
- package/dist/lib/utils/token.js.map +1 -1
- package/dist/plugins/index.d.ts +3 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +19 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/types.d.ts +1 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +1 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/plugins/withShopify.d.ts.map +1 -0
- package/dist/{lib → plugins}/withShopify.js +83 -77
- package/dist/plugins/withShopify.js.map +1 -0
- package/dist/react/hooks/index.js +17 -1
- package/dist/react/hooks/index.js.map +1 -1
- package/dist/react/hooks/useVerification.d.ts +1 -1
- package/dist/react/hooks/useVerification.js +23 -7
- package/dist/react/hooks/useVerification.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +18 -1
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/index.js +17 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/shared/WebCrypto.d.ts +55 -0
- package/dist/shared/WebCrypto.d.ts.map +1 -0
- package/dist/shared/WebCrypto.js +345 -0
- package/dist/shared/WebCrypto.js.map +1 -0
- package/dist/shared/constants.js +15 -11
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/datetime.js +110 -83
- package/dist/shared/datetime.js.map +1 -1
- package/dist/shared/display.d.ts +0 -2
- package/dist/shared/display.d.ts.map +1 -1
- package/dist/shared/display.js +231 -155
- package/dist/shared/display.js.map +1 -1
- package/dist/shared/errors.js +12 -5
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/graph.js +14 -11
- package/dist/shared/graph.js.map +1 -1
- package/dist/shared/index.d.ts +2 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +32 -10
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/match.js +25 -17
- package/dist/shared/match.js.map +1 -1
- package/dist/shared/request.d.ts.map +1 -1
- package/dist/shared/request.js +19 -13
- package/dist/shared/request.js.map +1 -1
- package/dist/shared/shopify.js +31 -21
- package/dist/shared/shopify.js.map +1 -1
- package/dist/shared/uuid.d.ts +3 -0
- package/dist/shared/uuid.d.ts.map +1 -0
- package/dist/shared/uuid.js +10 -0
- package/dist/shared/uuid.js.map +1 -0
- package/dist/shared/verification.d.ts +12 -5
- package/dist/shared/verification.d.ts.map +1 -1
- package/dist/shared/verification.js +34 -23
- package/dist/shared/verification.js.map +1 -1
- package/dist/umd/lib/index.d.ts +1 -1
- package/dist/umd/lib/index.d.ts.map +1 -1
- package/dist/umd/lib/utils/crypto.d.ts +1 -1
- package/dist/umd/lib/utils/crypto.d.ts.map +1 -1
- package/dist/umd/plugins/index.d.ts +3 -0
- package/dist/umd/plugins/index.d.ts.map +1 -0
- package/dist/umd/plugins/types.d.ts +1 -0
- package/dist/umd/plugins/types.d.ts.map +1 -0
- package/dist/umd/plugins/withShopify.d.ts.map +1 -0
- package/dist/umd/react/hooks/useVerification.d.ts +1 -1
- package/dist/umd/react/index.d.ts +1 -0
- package/dist/umd/react/index.d.ts.map +1 -1
- package/dist/umd/shared/WebCrypto.d.ts +55 -0
- package/dist/umd/shared/WebCrypto.d.ts.map +1 -0
- package/dist/umd/shared/display.d.ts +0 -2
- package/dist/umd/shared/display.d.ts.map +1 -1
- package/dist/umd/shared/index.d.ts +2 -1
- package/dist/umd/shared/index.d.ts.map +1 -1
- package/dist/umd/shared/request.d.ts.map +1 -1
- package/dist/umd/shared/uuid.d.ts +3 -0
- package/dist/umd/shared/uuid.d.ts.map +1 -0
- package/dist/umd/shared/verification.d.ts +12 -5
- package/dist/umd/shared/verification.d.ts.map +1 -1
- package/dist/umd/verification/index.d.ts +2 -0
- package/dist/umd/verification/index.d.ts.map +1 -1
- package/dist/umd/verification/utils/errors.d.ts.map +1 -0
- package/dist/umd/verification/utils/index.d.ts +3 -0
- package/dist/umd/verification/utils/index.d.ts.map +1 -0
- package/dist/umd/verification/utils/rawbody.d.ts.map +1 -0
- package/dist/umd/verification/verification.d.ts +3 -1
- package/dist/umd/verification/verification.d.ts.map +1 -1
- package/dist/umd/verification.js +901 -0
- package/dist/umd/verification.js.map +1 -0
- package/dist/verification/index.d.ts +2 -0
- package/dist/verification/index.d.ts.map +1 -1
- package/dist/verification/index.js +19 -1
- package/dist/verification/index.js.map +1 -1
- package/dist/verification/utils/errors.d.ts.map +1 -0
- package/dist/verification/{errors.js → utils/errors.js} +5 -1
- package/dist/verification/utils/errors.js.map +1 -0
- package/dist/verification/utils/index.d.ts +3 -0
- package/dist/verification/utils/index.d.ts.map +1 -0
- package/dist/verification/utils/index.js +19 -0
- package/dist/verification/utils/index.js.map +1 -0
- package/dist/verification/utils/rawbody.d.ts.map +1 -0
- package/dist/verification/utils/rawbody.js +57 -0
- package/dist/verification/utils/rawbody.js.map +1 -0
- package/dist/verification/verification.d.ts +3 -1
- package/dist/verification/verification.d.ts.map +1 -1
- package/dist/verification/verification.js +71 -62
- package/dist/verification/verification.js.map +1 -1
- package/package.json +12 -12
- package/dist/lib/withShopify.d.ts.map +0 -1
- package/dist/lib/withShopify.js.map +0 -1
- package/dist/shared/subtlecrypto.d.ts +0 -41
- package/dist/shared/subtlecrypto.d.ts.map +0 -1
- package/dist/shared/subtlecrypto.js +0 -256
- package/dist/shared/subtlecrypto.js.map +0 -1
- package/dist/umd/lib/withShopify.d.ts.map +0 -1
- package/dist/umd/shared/subtlecrypto.d.ts +0 -41
- package/dist/umd/shared/subtlecrypto.d.ts.map +0 -1
- package/dist/umd/umd-verification.js +0 -968
- package/dist/umd/umd-verification.js.map +0 -1
- package/dist/umd/verification/errors.d.ts.map +0 -1
- package/dist/umd/verification/rawbody.d.ts.map +0 -1
- package/dist/verification/errors.d.ts.map +0 -1
- package/dist/verification/errors.js.map +0 -1
- package/dist/verification/rawbody.d.ts.map +0 -1
- package/dist/verification/rawbody.js +0 -31
- package/dist/verification/rawbody.js.map +0 -1
- package/node_modules/bytes/History.md +0 -97
- package/node_modules/bytes/LICENSE +0 -23
- package/node_modules/bytes/Readme.md +0 -152
- package/node_modules/bytes/index.js +0 -170
- package/node_modules/bytes/package.json +0 -42
- package/node_modules/depd/History.md +0 -103
- package/node_modules/depd/LICENSE +0 -22
- package/node_modules/depd/Readme.md +0 -280
- package/node_modules/depd/index.js +0 -538
- package/node_modules/depd/lib/browser/index.js +0 -77
- package/node_modules/depd/package.json +0 -45
- package/node_modules/http-errors/HISTORY.md +0 -180
- package/node_modules/http-errors/LICENSE +0 -23
- package/node_modules/http-errors/README.md +0 -169
- package/node_modules/http-errors/index.js +0 -289
- package/node_modules/http-errors/package.json +0 -50
- package/node_modules/iconv-lite/Changelog.md +0 -162
- package/node_modules/iconv-lite/LICENSE +0 -21
- package/node_modules/iconv-lite/README.md +0 -156
- package/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -555
- package/node_modules/iconv-lite/encodings/dbcs-data.js +0 -176
- package/node_modules/iconv-lite/encodings/index.js +0 -22
- package/node_modules/iconv-lite/encodings/internal.js +0 -188
- package/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -72
- package/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -451
- package/node_modules/iconv-lite/encodings/sbcs-data.js +0 -174
- package/node_modules/iconv-lite/encodings/tables/big5-added.json +0 -122
- package/node_modules/iconv-lite/encodings/tables/cp936.json +0 -264
- package/node_modules/iconv-lite/encodings/tables/cp949.json +0 -273
- package/node_modules/iconv-lite/encodings/tables/cp950.json +0 -177
- package/node_modules/iconv-lite/encodings/tables/eucjp.json +0 -182
- package/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +0 -1
- package/node_modules/iconv-lite/encodings/tables/gbk-added.json +0 -55
- package/node_modules/iconv-lite/encodings/tables/shiftjis.json +0 -125
- package/node_modules/iconv-lite/encodings/utf16.js +0 -177
- package/node_modules/iconv-lite/encodings/utf7.js +0 -290
- package/node_modules/iconv-lite/lib/bom-handling.js +0 -52
- package/node_modules/iconv-lite/lib/extend-node.js +0 -217
- package/node_modules/iconv-lite/lib/index.d.ts +0 -24
- package/node_modules/iconv-lite/lib/index.js +0 -153
- package/node_modules/iconv-lite/lib/streams.js +0 -121
- package/node_modules/iconv-lite/package.json +0 -46
- package/node_modules/inherits/LICENSE +0 -16
- package/node_modules/inherits/README.md +0 -42
- package/node_modules/inherits/inherits.js +0 -9
- package/node_modules/inherits/inherits_browser.js +0 -27
- package/node_modules/inherits/package.json +0 -29
- package/node_modules/raw-body/HISTORY.md +0 -308
- package/node_modules/raw-body/LICENSE +0 -22
- package/node_modules/raw-body/README.md +0 -223
- package/node_modules/raw-body/SECURITY.md +0 -24
- package/node_modules/raw-body/index.d.ts +0 -87
- package/node_modules/raw-body/index.js +0 -336
- package/node_modules/raw-body/package.json +0 -49
- package/node_modules/safer-buffer/LICENSE +0 -21
- package/node_modules/safer-buffer/Porting-Buffer.md +0 -268
- package/node_modules/safer-buffer/Readme.md +0 -156
- package/node_modules/safer-buffer/dangerous.js +0 -58
- package/node_modules/safer-buffer/package.json +0 -34
- package/node_modules/safer-buffer/safer.js +0 -77
- package/node_modules/safer-buffer/tests.js +0 -406
- package/node_modules/setprototypeof/LICENSE +0 -13
- package/node_modules/setprototypeof/README.md +0 -31
- package/node_modules/setprototypeof/index.d.ts +0 -2
- package/node_modules/setprototypeof/index.js +0 -17
- package/node_modules/setprototypeof/package.json +0 -38
- package/node_modules/setprototypeof/test/index.js +0 -24
- package/node_modules/statuses/HISTORY.md +0 -82
- package/node_modules/statuses/LICENSE +0 -23
- package/node_modules/statuses/README.md +0 -136
- package/node_modules/statuses/codes.json +0 -65
- package/node_modules/statuses/index.js +0 -146
- package/node_modules/statuses/package.json +0 -49
- package/node_modules/toidentifier/HISTORY.md +0 -9
- package/node_modules/toidentifier/LICENSE +0 -21
- package/node_modules/toidentifier/README.md +0 -61
- package/node_modules/toidentifier/index.js +0 -32
- package/node_modules/toidentifier/package.json +0 -38
- package/node_modules/unpipe/HISTORY.md +0 -4
- package/node_modules/unpipe/LICENSE +0 -22
- package/node_modules/unpipe/README.md +0 -43
- package/node_modules/unpipe/index.js +0 -69
- package/node_modules/unpipe/package.json +0 -27
- /package/dist/{lib → plugins}/withShopify.d.ts +0 -0
- /package/dist/umd/{lib → plugins}/withShopify.d.ts +0 -0
- /package/dist/umd/verification/{errors.d.ts → utils/errors.d.ts} +0 -0
- /package/dist/umd/verification/{rawbody.d.ts → utils/rawbody.d.ts} +0 -0
- /package/dist/verification/{errors.d.ts → utils/errors.d.ts} +0 -0
- /package/dist/verification/{rawbody.d.ts → utils/rawbody.d.ts} +0 -0
package/dist/shared/display.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/* eslint-disable no-use-before-define */
|
|
2
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.uppercase = 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 = void 0;
|
|
5
|
+
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 = void 0;
|
|
3
6
|
// #region lib-core
|
|
4
7
|
// TODO!!!: keep in sync between next-shopify and lib-core (and lib-utils-js at bottom)
|
|
5
|
-
|
|
8
|
+
const normalizeShopifyId = (shopifyData) => {
|
|
6
9
|
var _a, _b;
|
|
7
|
-
const isString = isType(shopifyData, 'string');
|
|
10
|
+
const isString = (0, exports.isType)(shopifyData, 'string');
|
|
8
11
|
if (isString && !shopifyData.startsWith('gid:')) {
|
|
9
|
-
if (!isNumericOnly(shopifyData)) {
|
|
12
|
+
if (!(0, exports.isNumericOnly)(shopifyData)) {
|
|
10
13
|
return {};
|
|
11
14
|
}
|
|
12
15
|
return {
|
|
@@ -15,37 +18,40 @@ export const normalizeShopifyId = (shopifyData) => {
|
|
|
15
18
|
}
|
|
16
19
|
const { id: _entityId, legacyResourceId } = isString
|
|
17
20
|
? { id: shopifyData }
|
|
18
|
-
: ensureObject(shopifyData);
|
|
19
|
-
if (stringEmpty(_entityId) && stringEmpty(legacyResourceId)) {
|
|
21
|
+
: (0, exports.ensureObject)(shopifyData);
|
|
22
|
+
if ((0, exports.stringEmpty)(_entityId) && (0, exports.stringEmpty)(legacyResourceId)) {
|
|
20
23
|
return {};
|
|
21
24
|
}
|
|
22
|
-
const entity_id = ensureString(_entityId);
|
|
25
|
+
const entity_id = (0, exports.ensureString)(_entityId);
|
|
23
26
|
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 : {};
|
|
24
|
-
const id = ensureString(parsedId || legacyResourceId);
|
|
25
|
-
const hasEntityId = stringNotEmpty(entity_id);
|
|
26
|
-
const hasEntityType = stringNotEmpty(entity_type);
|
|
27
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({}, stringNotEmpty(id) && { id }), hasEntityId && { entity_id }), hasEntityType && { entity_type }), (hasEntityId && hasEntityType) && {
|
|
27
|
+
const id = (0, exports.ensureString)(parsedId || legacyResourceId);
|
|
28
|
+
const hasEntityId = (0, exports.stringNotEmpty)(entity_id);
|
|
29
|
+
const hasEntityType = (0, exports.stringNotEmpty)(entity_type);
|
|
30
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, (0, exports.stringNotEmpty)(id) && { id }), hasEntityId && { entity_id }), hasEntityType && { entity_type }), (hasEntityId && hasEntityType) && {
|
|
28
31
|
gid: `gid://shopify/${entity_type}/${entity_id}`,
|
|
29
32
|
});
|
|
30
33
|
};
|
|
31
|
-
|
|
34
|
+
exports.normalizeShopifyId = normalizeShopifyId;
|
|
35
|
+
const random = (max = 100, min = 1) => {
|
|
32
36
|
const floor = Math.min(max, min);
|
|
33
37
|
return Math.floor(Math.random() * (max - floor + 1)) + floor;
|
|
34
38
|
};
|
|
35
|
-
|
|
39
|
+
exports.random = random;
|
|
40
|
+
const nextRandom = (max = 100, min = 1) => {
|
|
36
41
|
const maximum = Math.max(max, 0);
|
|
37
42
|
const minimum = Math.max(min, 0);
|
|
38
43
|
let randomNumber = maximum;
|
|
39
44
|
if (maximum > minimum) {
|
|
40
45
|
do {
|
|
41
|
-
randomNumber = random(maximum, minimum);
|
|
42
|
-
} while (randomNumber === nextRandom.last);
|
|
43
|
-
nextRandom.last = randomNumber;
|
|
46
|
+
randomNumber = (0, exports.random)(maximum, minimum);
|
|
47
|
+
} while (randomNumber === exports.nextRandom.last);
|
|
48
|
+
exports.nextRandom.last = randomNumber;
|
|
44
49
|
}
|
|
45
50
|
return randomNumber;
|
|
46
51
|
};
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
exports.nextRandom = nextRandom;
|
|
53
|
+
const arrayRandom = (_values, _max = 1) => {
|
|
54
|
+
const values = (0, exports.ensureArray)(_values);
|
|
49
55
|
const valuesLength = values.length;
|
|
50
56
|
const maxLength = Math.min(_max, valuesLength);
|
|
51
57
|
if (valuesLength <= maxLength) {
|
|
@@ -54,53 +60,60 @@ export const arrayRandom = (_values, _max = 1) => {
|
|
|
54
60
|
const arrayLength = valuesLength - 1;
|
|
55
61
|
const randomValues = [];
|
|
56
62
|
do {
|
|
57
|
-
const newVal = values[nextRandom(arrayLength, 0)];
|
|
63
|
+
const newVal = values[(0, exports.nextRandom)(arrayLength, 0)];
|
|
58
64
|
if (!randomValues.includes(newVal)) {
|
|
59
65
|
randomValues.push(newVal);
|
|
60
66
|
}
|
|
61
67
|
} while (randomValues.length < maxLength);
|
|
62
68
|
return randomValues;
|
|
63
69
|
};
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
exports.arrayRandom = arrayRandom;
|
|
71
|
+
const arrayRandomItem = (_values) => ((0, exports.arrayRandom)(_values)[0]);
|
|
72
|
+
exports.arrayRandomItem = arrayRandomItem;
|
|
73
|
+
const isArray = (value) => (
|
|
66
74
|
// eslint-disable-next-line eqeqeq
|
|
67
75
|
(value != undefined) && Array.isArray(value));
|
|
68
|
-
|
|
76
|
+
exports.isArray = isArray;
|
|
77
|
+
const isSet = (value) => (
|
|
69
78
|
// eslint-disable-next-line eqeqeq
|
|
70
79
|
(value != undefined) && (value instanceof Set));
|
|
71
|
-
|
|
80
|
+
exports.isSet = isSet;
|
|
81
|
+
const isType = (value, type) => (
|
|
72
82
|
// eslint-disable-next-line eqeqeq, valid-typeof
|
|
73
83
|
(value != undefined) && (typeof value === type));
|
|
74
|
-
|
|
84
|
+
exports.isType = isType;
|
|
85
|
+
const isTypeEnhanced = (value, type) => {
|
|
75
86
|
switch (true) {
|
|
76
87
|
case (type === 'set'): {
|
|
77
|
-
return isSet(value);
|
|
88
|
+
return (0, exports.isSet)(value);
|
|
78
89
|
}
|
|
79
90
|
case (type === 'array'): {
|
|
80
|
-
return (isArray(value) &&
|
|
81
|
-
!isSet(value));
|
|
91
|
+
return ((0, exports.isArray)(value) &&
|
|
92
|
+
!(0, exports.isSet)(value));
|
|
82
93
|
}
|
|
83
94
|
case (type === 'object'): {
|
|
84
|
-
return (isType(value, type) &&
|
|
85
|
-
!isArray(value));
|
|
95
|
+
return ((0, exports.isType)(value, type) &&
|
|
96
|
+
!(0, exports.isArray)(value));
|
|
86
97
|
}
|
|
87
98
|
default: {
|
|
88
|
-
return isType(value, type);
|
|
99
|
+
return (0, exports.isType)(value, type);
|
|
89
100
|
}
|
|
90
101
|
}
|
|
91
102
|
};
|
|
92
|
-
|
|
93
|
-
|
|
103
|
+
exports.isTypeEnhanced = isTypeEnhanced;
|
|
104
|
+
const safeTrim = (value) => {
|
|
105
|
+
if ((0, exports.isType)(value, 'string')) {
|
|
94
106
|
// eslint-disable-next-line no-param-reassign
|
|
95
107
|
value = value.trim();
|
|
96
108
|
}
|
|
97
109
|
return value;
|
|
98
110
|
};
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
exports.safeTrim = safeTrim;
|
|
112
|
+
const safeParse = (value, trim) => {
|
|
113
|
+
if ((0, exports.isType)(value, 'string')) {
|
|
101
114
|
if (trim) {
|
|
102
115
|
// eslint-disable-next-line no-param-reassign
|
|
103
|
-
value = safeTrim(value);
|
|
116
|
+
value = (0, exports.safeTrim)(value);
|
|
104
117
|
}
|
|
105
118
|
if (value.startsWith('{') || value.startsWith('[') || value.startsWith('"')) {
|
|
106
119
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -110,65 +123,87 @@ export const safeParse = (value, trim) => {
|
|
|
110
123
|
// TODO: should this be value ?? {}
|
|
111
124
|
return value;
|
|
112
125
|
};
|
|
113
|
-
|
|
126
|
+
exports.safeParse = safeParse;
|
|
127
|
+
const ensureString = (string) => (string ? `${string}` : '');
|
|
128
|
+
exports.ensureString = ensureString;
|
|
114
129
|
// HMMM: what if 'string' is an object?
|
|
115
|
-
|
|
130
|
+
const ensureStringOnly = (string) => (
|
|
116
131
|
// eslint-disable-next-line eqeqeq
|
|
117
132
|
(string != undefined) ? `${string}` : '');
|
|
118
|
-
|
|
133
|
+
exports.ensureStringOnly = ensureStringOnly;
|
|
134
|
+
const ensureStringAscii = (string) => (
|
|
119
135
|
// eslint-disable-next-line no-control-regex
|
|
120
|
-
ensureStringOnly(string).replace(/[^\x00-\x7F]/g, ''));
|
|
121
|
-
|
|
136
|
+
(0, exports.ensureStringOnly)(string).replace(/[^\x00-\x7F]/g, ''));
|
|
137
|
+
exports.ensureStringAscii = ensureStringAscii;
|
|
138
|
+
const ensureStringClean = (string) => (
|
|
122
139
|
// eslint-disable-next-line no-control-regex
|
|
123
|
-
ensureStringOnly(string).replace(/[^a-z0-9_-]/gi, ''));
|
|
124
|
-
|
|
140
|
+
(0, exports.ensureStringOnly)(string).replace(/[^a-z0-9_-]/gi, ''));
|
|
141
|
+
exports.ensureStringClean = ensureStringClean;
|
|
142
|
+
const ensureAlphaNumeric = (string) => (
|
|
125
143
|
// eslint-disable-next-line no-control-regex
|
|
126
|
-
ensureStringOnly(string).replace(/[^a-z0-9]/gi, ''));
|
|
127
|
-
|
|
144
|
+
(0, exports.ensureStringOnly)(string).replace(/[^a-z0-9]/gi, ''));
|
|
145
|
+
exports.ensureAlphaNumeric = ensureAlphaNumeric;
|
|
146
|
+
const isNumericOnly = (value) => {
|
|
128
147
|
var _a;
|
|
129
148
|
const [matched] = (_a = `${value}`.match(/^([0-9]+)$/)) !== null && _a !== void 0 ? _a : [];
|
|
130
149
|
// eslint-disable-next-line eqeqeq
|
|
131
150
|
return (matched != undefined);
|
|
132
151
|
};
|
|
133
|
-
|
|
152
|
+
exports.isNumericOnly = isNumericOnly;
|
|
153
|
+
const isNumericNegatable = (value) => {
|
|
134
154
|
var _a;
|
|
135
155
|
const [matched] = (_a = `${value}`.match(/^(-?[0-9]+(\.[0-9]+)?)?$/)) !== null && _a !== void 0 ? _a : [];
|
|
136
156
|
// eslint-disable-next-line eqeqeq
|
|
137
157
|
return (matched != undefined);
|
|
138
158
|
};
|
|
159
|
+
exports.isNumericNegatable = isNumericNegatable;
|
|
139
160
|
// TODO: explore places using ensureNumeric to move to isNumericNegatable
|
|
140
|
-
|
|
141
|
-
|
|
161
|
+
const ensureNumeric = (string) => (Number((0, exports.ensureString)(string).replace(/[^0-9.]/gi, '')));
|
|
162
|
+
exports.ensureNumeric = ensureNumeric;
|
|
163
|
+
const ensureNumericOnly = (string) => (Number((0, exports.ensureString)(string).replace(/[^0-9]/gi, '')));
|
|
164
|
+
exports.ensureNumericOnly = ensureNumericOnly;
|
|
142
165
|
// TODO: update regex to handle negative number returns negative. Something like (?!\d\.)(-?\d+(\.\d)?)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
166
|
+
const ensureNumericNegatable = (string) => (Number((0, exports.ensureString)(string).replace(/[^0-9.-]/gi, '')));
|
|
167
|
+
exports.ensureNumericNegatable = ensureNumericNegatable;
|
|
168
|
+
const ensureNumericConstrained = (value, { min: _min = 0, max: _max = 100 } = {}) => {
|
|
169
|
+
const min = (0, exports.ensureNumericNegatable)(_min);
|
|
170
|
+
const max = (0, exports.ensureNumericNegatable)(_max);
|
|
171
|
+
return Math.max(min, Math.min((0, exports.ensureNumeric)(value), max));
|
|
148
172
|
};
|
|
149
|
-
|
|
173
|
+
exports.ensureNumericConstrained = ensureNumericConstrained;
|
|
174
|
+
const ensureArray = (array = []) => (
|
|
150
175
|
// eslint-disable-next-line no-nested-ternary
|
|
151
176
|
!array ? [] : Array.isArray(array) ? array : [array]);
|
|
152
|
-
|
|
153
|
-
|
|
177
|
+
exports.ensureArray = ensureArray;
|
|
178
|
+
const ensureArraySet = (arrayOrSet) => ((0, exports.ensureArray)((0, exports.isSet)(arrayOrSet) ? [...arrayOrSet] : arrayOrSet));
|
|
179
|
+
exports.ensureArraySet = ensureArraySet;
|
|
180
|
+
const arrayEmpty = (array, disableEmptyString = false) => (
|
|
154
181
|
// eslint-disable-next-line eqeqeq
|
|
155
|
-
!array || !array.length || (array.length === 1 && (array[0] == undefined || (disableEmptyString && stringEmpty(array[0])))));
|
|
156
|
-
|
|
182
|
+
!array || !array.length || (array.length === 1 && (array[0] == undefined || (disableEmptyString && (0, exports.stringEmpty)(array[0])))));
|
|
183
|
+
exports.arrayEmpty = arrayEmpty;
|
|
184
|
+
const arrayNotEmpty = (array, disableEmptyString = false) => (
|
|
157
185
|
// eslint-disable-next-line eqeqeq
|
|
158
|
-
!arrayEmpty(array) && array[0] != undefined && (!disableEmptyString || stringNotEmpty(array[0])));
|
|
159
|
-
|
|
160
|
-
|
|
186
|
+
!(0, exports.arrayEmpty)(array) && array[0] != undefined && (!disableEmptyString || (0, exports.stringNotEmpty)(array[0])));
|
|
187
|
+
exports.arrayNotEmpty = arrayNotEmpty;
|
|
188
|
+
const findLastMatch = (array, filterCallback = (value) => (value)) => ((0, exports.ensureArray)(array).filter(filterCallback).slice(-1)[0]);
|
|
189
|
+
exports.findLastMatch = findLastMatch;
|
|
190
|
+
const ensureObject = (object) => (object !== null && object !== void 0 ? object : {});
|
|
191
|
+
exports.ensureObject = ensureObject;
|
|
161
192
|
// NOTE: this does not ensure !isType(string)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
193
|
+
const objectEmpty = (object) => (!object || !Object.keys(object).length);
|
|
194
|
+
exports.objectEmpty = objectEmpty;
|
|
195
|
+
const objectNotEmpty = (object) => (!(0, exports.objectEmpty)(object));
|
|
196
|
+
exports.objectNotEmpty = objectNotEmpty;
|
|
197
|
+
const nullable = (object) => ((!object || (object === 'null') || (object === undefined) || (object === null))
|
|
165
198
|
? null // TODO: explore undefined here??
|
|
166
199
|
: object);
|
|
167
|
-
|
|
200
|
+
exports.nullable = nullable;
|
|
201
|
+
const objectContainsAnyValue = (object) => (Object.values((0, exports.ensureObject)(object)).some((value) => (0, exports.nullable)(value)));
|
|
202
|
+
exports.objectContainsAnyValue = objectContainsAnyValue;
|
|
168
203
|
const isUndefined = (value) => (
|
|
169
204
|
// eslint-disable-next-line eqeqeq
|
|
170
205
|
value == undefined);
|
|
171
|
-
|
|
206
|
+
const cleanObject = (object, allowEmptyLeafs, isEmptyCallback) => (Object.entries((0, exports.ensureObject)(object)).reduce((_cleanedObject, [key, _value]) => {
|
|
172
207
|
var _a;
|
|
173
208
|
if (!allowEmptyLeafs && ((_a = isEmptyCallback === null || isEmptyCallback === void 0 ? void 0 : isEmptyCallback(_value)) !== null && _a !== void 0 ? _a : isUndefined(_value))) {
|
|
174
209
|
return _cleanedObject; // skip key if null or undefined
|
|
@@ -181,47 +216,59 @@ export const cleanObject = (object, allowEmptyLeafs, isEmptyCallback) => (Object
|
|
|
181
216
|
]), []);
|
|
182
217
|
return Object.assign(Object.assign({}, _cleanedObject), { [key]: value });
|
|
183
218
|
}, {}));
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
219
|
+
exports.cleanObject = cleanObject;
|
|
220
|
+
const cleanObjectValue = (value, allowEmptyLeafs, isEmptyCallback) => ((0, exports.isType)(value, 'object') ? (0, exports.cleanObject)(value, allowEmptyLeafs, isEmptyCallback) : value);
|
|
221
|
+
const stringNotEmptyOnly = (stringable) => {
|
|
222
|
+
const string = (0, exports.ensureStringOnly)(stringable);
|
|
187
223
|
return ((string.length > 0) && !['null', 'undefined'].includes(string));
|
|
188
224
|
};
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
225
|
+
exports.stringNotEmptyOnly = stringNotEmptyOnly;
|
|
226
|
+
const stringEmptyOnly = (stringable) => (!(0, exports.stringNotEmptyOnly)(stringable));
|
|
227
|
+
exports.stringEmptyOnly = stringEmptyOnly;
|
|
228
|
+
const stringNotEmpty = (stringable) => {
|
|
229
|
+
const string = (0, exports.ensureString)(stringable);
|
|
192
230
|
return ((string.length > 0) && !['null', 'undefined'].includes(string));
|
|
193
231
|
};
|
|
194
|
-
|
|
232
|
+
exports.stringNotEmpty = stringNotEmpty;
|
|
233
|
+
const stringEmpty = (stringable) => (!(0, exports.stringNotEmpty)(stringable));
|
|
234
|
+
exports.stringEmpty = stringEmpty;
|
|
195
235
|
const splitString = (splitting, index = splitting.length) => {
|
|
196
|
-
const string = ensureString(splitting);
|
|
236
|
+
const string = (0, exports.ensureString)(splitting);
|
|
197
237
|
return [string.slice(0, index), string.slice(index)];
|
|
198
238
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
239
|
+
const compareNumber = (number1 = 0, number2 = 0) => (number1 - number2);
|
|
240
|
+
exports.compareNumber = compareNumber;
|
|
241
|
+
const compareString = (string1, string2) => {
|
|
242
|
+
if ((0, exports.stringEmpty)(string1)) {
|
|
202
243
|
return 1;
|
|
203
244
|
}
|
|
204
|
-
if (stringEmpty(string2)) {
|
|
245
|
+
if ((0, exports.stringEmpty)(string2)) {
|
|
205
246
|
return -1;
|
|
206
247
|
}
|
|
207
|
-
return ensureString(string1).localeCompare(string2);
|
|
248
|
+
return (0, exports.ensureString)(string1).localeCompare(string2);
|
|
208
249
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
250
|
+
exports.compareString = compareString;
|
|
251
|
+
const compareEntryKeys = ([string1], [string2]) => ((0, exports.compareString)(string1, string2));
|
|
252
|
+
exports.compareEntryKeys = compareEntryKeys;
|
|
253
|
+
const objectToSortedString = (object, separator = '') => (Object.entries((0, exports.ensureObject)(object))
|
|
254
|
+
.sort(exports.compareEntryKeys)
|
|
212
255
|
.map(([key, value]) => `${key}=${value}`)
|
|
213
256
|
.join(separator));
|
|
214
|
-
|
|
257
|
+
exports.objectToSortedString = objectToSortedString;
|
|
258
|
+
const isHTML = (string) => {
|
|
215
259
|
var _a, _b, _c;
|
|
216
260
|
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);
|
|
217
261
|
};
|
|
218
|
-
|
|
219
|
-
|
|
262
|
+
exports.isHTML = isHTML;
|
|
263
|
+
const freeze = (logMessage, object, type = 'log') => {
|
|
264
|
+
console[type](logMessage, !object ? object : JSON.parse(JSON.stringify((0, exports.ensureObject)(object))));
|
|
220
265
|
};
|
|
221
|
-
|
|
266
|
+
exports.freeze = freeze;
|
|
267
|
+
const replaceSpaces = (string, replacement = '') => (!(0, exports.isType)(string, 'string')
|
|
222
268
|
? ''
|
|
223
269
|
: string.replace(/\s/g, replacement));
|
|
224
|
-
|
|
270
|
+
exports.replaceSpaces = replaceSpaces;
|
|
271
|
+
const recase = (string, replacement = '') => (!(0, exports.isType)(string, 'string')
|
|
225
272
|
? ''
|
|
226
273
|
: string
|
|
227
274
|
.replace(/[^a-zA-Z0-9]+/g, replacement)
|
|
@@ -232,126 +279,152 @@ const recase = (string, replacement = '') => (!isType(string, 'string')
|
|
|
232
279
|
.replace(/[-_]+/g, replacement)
|
|
233
280
|
.replace(new RegExp(`${replacement}$`), '')
|
|
234
281
|
.toLowerCase());
|
|
235
|
-
|
|
282
|
+
const zencase = (string, replacement = '-') => (!(0, exports.isType)(string, 'string')
|
|
236
283
|
? ''
|
|
237
|
-
: replaceSpaces(string, replacement)
|
|
284
|
+
: (0, exports.replaceSpaces)(string, replacement)
|
|
238
285
|
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
239
286
|
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
240
287
|
.replace(new RegExp(`${replacement}$`), '')
|
|
241
288
|
.toLowerCase());
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
289
|
+
exports.zencase = zencase;
|
|
290
|
+
const dashcase = (string) => (recase(string, '-'));
|
|
291
|
+
exports.dashcase = dashcase;
|
|
292
|
+
const undashcase = (string, replacement = ' ') => ((0, exports.ensureString)(string).replace(/-/g, replacement).trim());
|
|
293
|
+
exports.undashcase = undashcase;
|
|
294
|
+
const snakecase = (string) => (recase(string, '_'));
|
|
295
|
+
exports.snakecase = snakecase;
|
|
296
|
+
const unsnakecase = (string, replacement = ' ') => ((0, exports.ensureString)(string).replace(/_/g, replacement).trim());
|
|
297
|
+
exports.unsnakecase = unsnakecase;
|
|
298
|
+
const uppercase = (string) => ((0, exports.ensureString)(string).toUpperCase());
|
|
299
|
+
exports.uppercase = uppercase;
|
|
300
|
+
const lowercase = (string, defaultValue = '') => (!(0, exports.stringNotEmpty)(string)
|
|
248
301
|
? defaultValue
|
|
249
|
-
: ensureString(string).toLowerCase());
|
|
250
|
-
|
|
251
|
-
|
|
302
|
+
: (0, exports.ensureString)(string).toLowerCase());
|
|
303
|
+
exports.lowercase = lowercase;
|
|
304
|
+
const slugify = (string) => ((0, exports.lowercase)((0, exports.dashcase)(string)));
|
|
305
|
+
exports.slugify = slugify;
|
|
306
|
+
const capitalize = (string) => {
|
|
252
307
|
const parts = splitString(string, 1);
|
|
253
|
-
return `${uppercase(parts[0])}${parts[1]}`;
|
|
308
|
+
return `${(0, exports.uppercase)(parts[0])}${parts[1]}`;
|
|
254
309
|
};
|
|
255
|
-
|
|
256
|
-
|
|
310
|
+
exports.capitalize = capitalize;
|
|
311
|
+
const camelCase = (string) => ((0, exports.stringNotEmpty)(string)
|
|
312
|
+
? (0, exports.unsnakecase)((0, exports.undashcase)(string)).replace(/\w\S*/g, (word, charIndex) => {
|
|
257
313
|
if (charIndex === 0) {
|
|
258
|
-
return lowercase(word);
|
|
314
|
+
return (0, exports.lowercase)(word);
|
|
259
315
|
}
|
|
260
|
-
return `${uppercase(word.charAt(0))}${lowercase(word.substr(1))}`;
|
|
316
|
+
return `${(0, exports.uppercase)(word.charAt(0))}${(0, exports.lowercase)(word.substr(1))}`;
|
|
261
317
|
}).split(' ').join('')
|
|
262
318
|
: '');
|
|
263
|
-
|
|
264
|
-
|
|
319
|
+
exports.camelCase = camelCase;
|
|
320
|
+
const titleCase = (string, _overrides) => {
|
|
321
|
+
if (!(0, exports.stringNotEmpty)(string)) {
|
|
265
322
|
return '';
|
|
266
323
|
}
|
|
267
324
|
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);
|
|
268
|
-
const stringParts = lowercase(string)
|
|
325
|
+
const stringParts = (0, exports.lowercase)(string)
|
|
269
326
|
.split(' ')
|
|
270
327
|
.reduce((_stringParts, _stringPart) => {
|
|
271
328
|
var _a;
|
|
272
329
|
const stringPart = (_a = overrides[_stringPart]) !== null && _a !== void 0 ? _a : _stringPart
|
|
273
330
|
.replace(/([A-Z]+)/g, ' $1')
|
|
274
331
|
.replace(/\s\s+/g, ' ')
|
|
275
|
-
.replace(/(\b[a-z](?!\s)*)/g, (firstChar) => uppercase(firstChar));
|
|
332
|
+
.replace(/(\b[a-z](?!\s)*)/g, (firstChar) => (0, exports.uppercase)(firstChar));
|
|
276
333
|
return [
|
|
277
334
|
..._stringParts,
|
|
278
|
-
...stringNotEmpty(stringPart) ? [stringPart] : []
|
|
335
|
+
...(0, exports.stringNotEmpty)(stringPart) ? [stringPart] : []
|
|
279
336
|
];
|
|
280
337
|
}, []);
|
|
281
338
|
return stringParts.join(' ');
|
|
282
339
|
};
|
|
283
|
-
|
|
284
|
-
|
|
340
|
+
exports.titleCase = titleCase;
|
|
341
|
+
const removeLeadingSlash = (string) => ((0, exports.ensureString)(string).replace(/^\//, ''));
|
|
342
|
+
exports.removeLeadingSlash = removeLeadingSlash;
|
|
343
|
+
const removeLeadingTrailingQuotes = (string) => ((0, exports.ensureString)(string).replace(/^"|"$/g, ''));
|
|
344
|
+
exports.removeLeadingTrailingQuotes = removeLeadingTrailingQuotes;
|
|
285
345
|
// TODO: not sure if this should remove multipel at end or just one (as it does now)?
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
346
|
+
const removeTrailingSlash = (string) => ((0, exports.ensureString)(string).replace(/\/$/, ''));
|
|
347
|
+
exports.removeTrailingSlash = removeTrailingSlash;
|
|
348
|
+
const removeLeadingTrailingSlash = (string) => ((0, exports.removeTrailingSlash)((0, exports.removeLeadingSlash)(string)));
|
|
349
|
+
exports.removeLeadingTrailingSlash = removeLeadingTrailingSlash;
|
|
350
|
+
const ensureLeadingSlash = (string) => (`/${(0, exports.removeLeadingSlash)(string)}`);
|
|
351
|
+
exports.ensureLeadingSlash = ensureLeadingSlash;
|
|
352
|
+
const ensureTrailingSlash = (string) => (`${(0, exports.removeTrailingSlash)(string)}/`);
|
|
353
|
+
exports.ensureTrailingSlash = ensureTrailingSlash;
|
|
354
|
+
const ensureExtension = (string, extension) => {
|
|
291
355
|
var _a, _b;
|
|
292
|
-
if (stringEmpty(extension)) {
|
|
356
|
+
if ((0, exports.stringEmpty)(extension)) {
|
|
293
357
|
return string;
|
|
294
358
|
}
|
|
295
359
|
const filePath = (_b = (_a = string.match(/(.*)\..+$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : string;
|
|
296
360
|
return `${filePath}.${extension}`;
|
|
297
361
|
};
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
362
|
+
exports.ensureExtension = ensureExtension;
|
|
363
|
+
const wrappedEncode = (basePath, _wrappingPath) => {
|
|
364
|
+
const wrappingPath = (0, exports.ensureString)(_wrappingPath);
|
|
365
|
+
if ((0, exports.stringEmpty)(basePath)) {
|
|
301
366
|
return wrappingPath;
|
|
302
367
|
}
|
|
303
368
|
return `${basePath}${encodeURIComponent(wrappingPath)}`;
|
|
304
369
|
};
|
|
305
|
-
|
|
370
|
+
exports.wrappedEncode = wrappedEncode;
|
|
371
|
+
const splitCommas = (value) => ((0, exports.ensureString)(value)
|
|
306
372
|
.replace(/, /g, ',')
|
|
307
373
|
.split(',')
|
|
308
374
|
.reduce((_values, _value) => {
|
|
309
|
-
const __value = safeTrim(_value);
|
|
375
|
+
const __value = (0, exports.safeTrim)(_value);
|
|
310
376
|
return [
|
|
311
377
|
..._values,
|
|
312
|
-
...stringNotEmpty(__value) ? [__value] : [] // TODO: explore stringEmptyOnly?
|
|
378
|
+
...(0, exports.stringNotEmpty)(__value) ? [__value] : [] // TODO: explore stringEmptyOnly?
|
|
313
379
|
];
|
|
314
380
|
}, []));
|
|
315
|
-
|
|
381
|
+
exports.splitCommas = splitCommas;
|
|
382
|
+
const combineCommas = (values) => ([...new Set((0, exports.ensureArray)(values).reduce((_combined, value) => ([
|
|
316
383
|
..._combined,
|
|
317
|
-
...splitCommas(value)
|
|
384
|
+
...(0, exports.splitCommas)(value)
|
|
318
385
|
]), []))]);
|
|
319
|
-
|
|
320
|
-
|
|
386
|
+
exports.combineCommas = combineCommas;
|
|
387
|
+
const normalizeArray = (input, separator = ' ') => {
|
|
388
|
+
const inputArray = (0, exports.ensureArray)(input);
|
|
321
389
|
return inputArray.reduce((normalized, _ignore, index) => ([
|
|
322
390
|
...normalized,
|
|
323
391
|
inputArray.slice(0, index + 1).join(separator)
|
|
324
392
|
]), []).reverse();
|
|
325
393
|
};
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
394
|
+
exports.normalizeArray = normalizeArray;
|
|
395
|
+
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 })), {}));
|
|
396
|
+
exports.arrayToObject = arrayToObject;
|
|
397
|
+
const isTrue = (value, falsy) => {
|
|
398
|
+
const string = (0, exports.ensureString)(value);
|
|
399
|
+
return ![...(0, exports.ensureArray)(falsy), '', 'false'].includes(string);
|
|
330
400
|
};
|
|
401
|
+
exports.isTrue = isTrue;
|
|
331
402
|
// TODO: move all uses of parseKeywords to parseKeywordGroups
|
|
332
|
-
|
|
333
|
-
const keywords = splitCommas(keyword);
|
|
403
|
+
const parseKeywords = (keywordGroup, previous) => ([...new Set((0, exports.ensureArray)(keywordGroup).reduce((_parsedKeywords, keyword) => {
|
|
404
|
+
const keywords = (0, exports.splitCommas)(keyword);
|
|
334
405
|
return [
|
|
335
406
|
..._parsedKeywords,
|
|
336
|
-
...keywords.filter((_keyword) => stringNotEmpty(_keyword))
|
|
407
|
+
...keywords.filter((_keyword) => (0, exports.stringNotEmpty)(_keyword))
|
|
337
408
|
];
|
|
338
|
-
}, ensureArray(previous)))].join(', '));
|
|
339
|
-
|
|
340
|
-
|
|
409
|
+
}, (0, exports.ensureArray)(previous)))].join(', '));
|
|
410
|
+
exports.parseKeywords = parseKeywords;
|
|
411
|
+
const parseKeywordGroups = (keywordGroups) => {
|
|
412
|
+
const parsedKeywords = (0, exports.ensureArray)(keywordGroups).reduce((_parsedKeywords, keywordGroup) => ([
|
|
341
413
|
..._parsedKeywords,
|
|
342
|
-
...ensureArray(keywordGroup).reduce((_parsedGroupKeywords, keyword) => {
|
|
343
|
-
const keywords = splitCommas(keyword);
|
|
414
|
+
...(0, exports.ensureArray)(keywordGroup).reduce((_parsedGroupKeywords, keyword) => {
|
|
415
|
+
const keywords = (0, exports.splitCommas)(keyword);
|
|
344
416
|
return [
|
|
345
417
|
..._parsedGroupKeywords,
|
|
346
|
-
...keywords.filter((_keyword) => stringNotEmpty(_keyword))
|
|
418
|
+
...keywords.filter((_keyword) => (0, exports.stringNotEmpty)(_keyword))
|
|
347
419
|
];
|
|
348
420
|
}, [])
|
|
349
421
|
]), []);
|
|
350
422
|
return [...new Set(parsedKeywords)].join(', ');
|
|
351
423
|
};
|
|
352
|
-
|
|
424
|
+
exports.parseKeywordGroups = parseKeywordGroups;
|
|
425
|
+
const parseProjectName = (_name) => {
|
|
353
426
|
var _a;
|
|
354
|
-
const name = ensureString(_name);
|
|
427
|
+
const name = (0, exports.ensureString)(_name);
|
|
355
428
|
const [, organization, ...parts] = (_a = /(@.*)([\\]+|\/)+(.*)/.exec(name)) !== null && _a !== void 0 ? _a : [];
|
|
356
429
|
const projectName = organization ? name.replace(organization, '').replace('/', '') : name;
|
|
357
430
|
return {
|
|
@@ -361,12 +434,13 @@ export const parseProjectName = (_name) => {
|
|
|
361
434
|
projectName,
|
|
362
435
|
};
|
|
363
436
|
};
|
|
364
|
-
|
|
437
|
+
exports.parseProjectName = parseProjectName;
|
|
438
|
+
const parseProject = (packageInfo) => {
|
|
365
439
|
const { shortName, owner: _appOwner, name: _name, appName: _appName, keywords, siteName: _siteName } = packageInfo !== null && packageInfo !== void 0 ? packageInfo : {};
|
|
366
|
-
const { name, organization, projectName } = parseProjectName(_name);
|
|
440
|
+
const { name, organization, projectName } = (0, exports.parseProjectName)(_name);
|
|
367
441
|
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);
|
|
368
442
|
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);
|
|
369
|
-
const companyName = titleCase(organization === null || organization === void 0 ? void 0 : organization.replace('@', ''));
|
|
443
|
+
const companyName = (0, exports.titleCase)(organization === null || organization === void 0 ? void 0 : organization.replace('@', ''));
|
|
370
444
|
const appOwner = _appOwner !== null && _appOwner !== void 0 ? _appOwner : companyName;
|
|
371
445
|
return [{
|
|
372
446
|
keywords,
|
|
@@ -378,28 +452,30 @@ export const parseProject = (packageInfo) => {
|
|
|
378
452
|
projectName,
|
|
379
453
|
}, organization, name];
|
|
380
454
|
};
|
|
455
|
+
exports.parseProject = parseProject;
|
|
381
456
|
// #endregion lib-core
|
|
382
457
|
// #region lib-utils-js
|
|
383
|
-
|
|
384
|
-
if (stringEmpty(queryString)) {
|
|
458
|
+
const querystringToObject = (queryString) => {
|
|
459
|
+
if ((0, exports.stringEmpty)(queryString)) {
|
|
385
460
|
return {};
|
|
386
461
|
}
|
|
387
462
|
const urlParams = new URLSearchParams(queryString);
|
|
388
463
|
return Object.fromEntries(urlParams);
|
|
389
464
|
};
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
465
|
+
exports.querystringToObject = querystringToObject;
|
|
466
|
+
const arrayIncludesAll = (_values, comparison) => {
|
|
467
|
+
const values = (0, exports.ensureArray)(_values);
|
|
468
|
+
return (0, exports.ensureArray)(comparison).every((value) => ((0, exports.stringNotEmpty)(value) && values.includes(value)));
|
|
393
469
|
};
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
470
|
+
exports.arrayIncludesAll = arrayIncludesAll;
|
|
471
|
+
const arraysMatch = (array1, array2) => ((0, exports.arrayIncludesAll)(array1, array2) && (0, exports.arrayIncludesAll)(array2, array1));
|
|
472
|
+
exports.arraysMatch = arraysMatch;
|
|
473
|
+
const appendQuery = (_basePath, queryString) => {
|
|
474
|
+
const basePath = (0, exports.ensureString)(_basePath);
|
|
475
|
+
if ((0, exports.stringEmpty)(queryString)) {
|
|
398
476
|
return basePath;
|
|
399
477
|
}
|
|
400
478
|
return `${basePath}${basePath.includes('?') ? '&' : '?'}${queryString}`;
|
|
401
479
|
};
|
|
402
|
-
|
|
403
|
-
export const getGUID = () => (uuidV4());
|
|
404
|
-
export const getInteger = () => (getGUID().replace(/\D/g, ''));
|
|
480
|
+
exports.appendQuery = appendQuery;
|
|
405
481
|
//# sourceMappingURL=display.js.map
|