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