@morui/shared-utils
Advanced tools
Comparing version 2.0.5 to 2.0.8
@@ -10,2 +10,3 @@ export { Dict, __DEV__, __TEST__, dataAttr, isArray, isEmpty, isEmptyArray, isEmptyObject, isFunction, isNumeric, isObject } from './assertion.js'; | ||
export { Timer } from './types.js'; | ||
export { FILE_EXTENSION, HEX_REGEXP, IPFS_PREFIX, URL_PREFIX, buildExternalAssetFilePath, getEnvValue, getExternalAssetFilePath, parseEnvJson, regexp, replaceQuotes } from './env.js'; | ||
import 'react'; |
@@ -23,5 +23,10 @@ "use strict"; | ||
__export(src_exports, { | ||
FILE_EXTENSION: () => FILE_EXTENSION, | ||
HEX_REGEXP: () => HEX_REGEXP, | ||
IPFS_PREFIX: () => IPFS_PREFIX, | ||
URL_PREFIX: () => URL_PREFIX, | ||
__DEV__: () => __DEV__, | ||
__TEST__: () => __TEST__, | ||
arrayToObject: () => arrayToObject, | ||
buildExternalAssetFilePath: () => buildExternalAssetFilePath, | ||
callAll: () => callAll, | ||
@@ -38,2 +43,4 @@ callAllHandlers: () => callAllHandlers, | ||
extractProperty: () => extractProperty, | ||
getEnvValue: () => getEnvValue, | ||
getExternalAssetFilePath: () => getExternalAssetFilePath, | ||
getKeyValue: () => getKeyValue, | ||
@@ -51,5 +58,8 @@ getMargin: () => getMargin, | ||
omitObject: () => omitObject, | ||
parseEnvJson: () => parseEnvJson, | ||
range: () => range, | ||
regexp: () => regexp, | ||
removeEvents: () => removeEvents, | ||
renameProp: () => renameProp, | ||
replaceQuotes: () => replaceQuotes, | ||
safeAriaLabel: () => safeAriaLabel, | ||
@@ -296,7 +306,63 @@ safeText: () => safeText, | ||
} | ||
// src/env.ts | ||
function isBrowser() { | ||
return typeof window !== "undefined"; | ||
} | ||
var URL_PREFIX = /^https?:\/\//i; | ||
var IPFS_PREFIX = /^ipfs:\/\//i; | ||
var HEX_REGEXP = /^(?:0x)?[\da-fA-F]+$/; | ||
var FILE_EXTENSION = /\.([\da-z]+)$/i; | ||
var regexp = { | ||
URL_PREFIX, | ||
IPFS_PREFIX, | ||
HEX_REGEXP, | ||
FILE_EXTENSION | ||
}; | ||
var replaceQuotes = (value) => value == null ? void 0 : value.replaceAll("'", '"'); | ||
var getEnvValue = (envName) => { | ||
const envs = isBrowser() ? window.__envs : process.env; | ||
if (isBrowser() && (envs == null ? void 0 : envs.NEXT_PUBLIC_APP_INSTANCE) === "pw") { | ||
const storageValue = localStorage.getItem(envName); | ||
if (typeof storageValue === "string") { | ||
return storageValue; | ||
} | ||
} | ||
return replaceQuotes(envs == null ? void 0 : envs[envName]); | ||
}; | ||
var parseEnvJson = (env) => { | ||
try { | ||
return JSON.parse(env || "null"); | ||
} catch (error) { | ||
return null; | ||
} | ||
}; | ||
var getExternalAssetFilePath = (envName) => { | ||
const parsedValue = getEnvValue(envName); | ||
if (!parsedValue) { | ||
return; | ||
} | ||
return buildExternalAssetFilePath(envName, parsedValue); | ||
}; | ||
var buildExternalAssetFilePath = (name, value) => { | ||
var _a; | ||
try { | ||
const fileName = name.replace(/^NEXT_PUBLIC_/, "").replace(/_URL$/, "").toLowerCase(); | ||
const url = new URL(value); | ||
const fileExtension = (_a = url.pathname.match(regexp.FILE_EXTENSION)) == null ? void 0 : _a[1]; | ||
return `/assets/${fileName}.${fileExtension}`; | ||
} catch (error) { | ||
return; | ||
} | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
FILE_EXTENSION, | ||
HEX_REGEXP, | ||
IPFS_PREFIX, | ||
URL_PREFIX, | ||
__DEV__, | ||
__TEST__, | ||
arrayToObject, | ||
buildExternalAssetFilePath, | ||
callAll, | ||
@@ -313,2 +379,4 @@ callAllHandlers, | ||
extractProperty, | ||
getEnvValue, | ||
getExternalAssetFilePath, | ||
getKeyValue, | ||
@@ -326,5 +394,8 @@ getMargin, | ||
omitObject, | ||
parseEnvJson, | ||
range, | ||
regexp, | ||
removeEvents, | ||
renameProp, | ||
replaceQuotes, | ||
safeAriaLabel, | ||
@@ -331,0 +402,0 @@ safeText, |
{ | ||
"name": "@morui/shared-utils", | ||
"version": "2.0.5", | ||
"version": "2.0.8", | ||
"description": "A set of MorUI utilities", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48767
46
1690
1