@hzab/data-model 1.7.5 → 1.8.0

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 CHANGED
@@ -1,3 +1,11 @@
1
+ # @hzab/data-model@1.8.0
2
+
3
+ fix: public utils getPublicUrl 多层目录问题修复 isFullPath
4
+
5
+ # @hzab/data-model@1.7.6
6
+
7
+ feat: getPublicUrl 获取 public 文件路径(自动拼接 hash 数据)
8
+
1
9
  # @hzab/data-model@1.7.5
2
10
 
3
11
  fix: array-data-model 数据报错异常处理
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/data-model",
3
- "version": "1.7.5",
3
+ "version": "1.8.0",
4
4
  "description": "data model",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 获取 public 文件路径(自动拼接 hash 数据)
3
+ * @param {*} url 文件路径
4
+ * @param {*} opt
5
+ */
6
+ export function getPublicUrl(url, opt = {}) {
7
+ if (typeof url !== "string") {
8
+ return url;
9
+ }
10
+ const { isFullPath } = opt || {};
11
+ let baseURL = (process.env.WEBPACK_PUBLIC_PATH || ".")?.replace(/^\//, "")?.replace(/\/$/, "");
12
+ if (isFullPath) {
13
+ const fullPathname = (location.origin + location.pathname).replace(/[^\/]+.html\/?$/, "").replace(/\/$/, "");
14
+ return `${fullPathname}/${baseURL?.replace(/^\./, "")}/${url?.replace(/^\//, "")}`;
15
+ }
16
+ return `${baseURL}/${url?.replace(/^\//, "")}`;
17
+ }