@fast-china/utils 1.0.3 → 1.0.4
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/dist/index.global.js +169 -142
- package/dist/index.global.js.map +1 -1
- package/dist/index.global.min.js +5 -5
- package/dist/index.global.min.js.map +1 -1
- package/es/identity/index.d.ts +8 -0
- package/es/identity/index.mjs +33 -0
- package/es/identity/index.mjs.map +1 -0
- package/es/index.d.ts +1 -0
- package/es/index.mjs +2 -0
- package/es/index.mjs.map +1 -1
- package/lib/identity/index.d.ts +8 -0
- package/lib/identity/index.js +2 -0
- package/lib/identity/index.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { reactive } from "vue";
|
|
2
|
+
import { Local } from "../storage/index.mjs";
|
|
3
|
+
import { stringUtil } from "../string/index.mjs";
|
|
4
|
+
const state = reactive({
|
|
5
|
+
cacheKey: "__DEVICE_ID",
|
|
6
|
+
deviceId: ""
|
|
7
|
+
});
|
|
8
|
+
const uuidRegExp = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
9
|
+
const makeIdentity = () => {
|
|
10
|
+
if (state.deviceId && uuidRegExp.test(state.deviceId)) {
|
|
11
|
+
Local.set(state.cacheKey, state.deviceId);
|
|
12
|
+
return state.deviceId;
|
|
13
|
+
}
|
|
14
|
+
let deviceID = Local.get(state.cacheKey);
|
|
15
|
+
if (deviceID && uuidRegExp.test(deviceID)) {
|
|
16
|
+
state.deviceId = deviceID;
|
|
17
|
+
return deviceID;
|
|
18
|
+
}
|
|
19
|
+
deviceID = stringUtil.generateUUID();
|
|
20
|
+
Local.set(state.cacheKey, deviceID);
|
|
21
|
+
state.deviceId = deviceID;
|
|
22
|
+
return deviceID;
|
|
23
|
+
};
|
|
24
|
+
const useIdentity = () => {
|
|
25
|
+
return {
|
|
26
|
+
...state,
|
|
27
|
+
makeIdentity
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
useIdentity
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/identity/index.ts"],"sourcesContent":["import { reactive } from \"vue\";\nimport { Local } from \"../storage\";\nimport { stringUtil } from \"../string\";\n\nconst state = reactive({\n\tcacheKey: \"__DEVICE_ID\",\n\tdeviceId: \"\",\n});\n\nconst uuidRegExp = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;\n\n/**\n * 生成设备Id\n */\nconst makeIdentity = (): string => {\n\t// 判断是否存在\n\tif (state.deviceId && uuidRegExp.test(state.deviceId)) {\n\t\tLocal.set(state.cacheKey, state.deviceId);\n\t\treturn state.deviceId;\n\t}\n\t// 生成浏览器唯一 UUID\n\tlet deviceID = Local.get(state.cacheKey);\n\tif (deviceID && uuidRegExp.test(deviceID)) {\n\t\tstate.deviceId = deviceID;\n\t\treturn deviceID;\n\t}\n\tdeviceID = stringUtil.generateUUID();\n\tLocal.set(state.cacheKey, deviceID);\n\tstate.deviceId = deviceID;\n\treturn deviceID;\n};\n\nexport const useIdentity = (): typeof state & { makeIdentity: () => string } => {\n\treturn {\n\t\t...state,\n\t\tmakeIdentity,\n\t};\n};\n"],"names":[],"mappings":";;;AAIA,MAAM,QAAQ,SAAS;AAAA,EACtB,UAAU;AAAA,EACV,UAAU;AACX,CAAC;AAED,MAAM,aAAa;AAKnB,MAAM,eAAe,MAAc;AAElC,MAAI,MAAM,YAAY,WAAW,KAAK,MAAM,QAAQ,GAAG;AACtD,UAAM,IAAI,MAAM,UAAU,MAAM,QAAQ;AACxC,WAAO,MAAM;AAAA,EAAA;AAGd,MAAI,WAAW,MAAM,IAAI,MAAM,QAAQ;AACvC,MAAI,YAAY,WAAW,KAAK,QAAQ,GAAG;AAC1C,UAAM,WAAW;AACV,WAAA;AAAA,EAAA;AAER,aAAW,WAAW,aAAa;AAC7B,QAAA,IAAI,MAAM,UAAU,QAAQ;AAClC,QAAM,WAAW;AACV,SAAA;AACR;AAEO,MAAM,cAAc,MAAqD;AACxE,SAAA;AAAA,IACN,GAAG;AAAA,IACH;AAAA,EACD;AACD;"}
|
package/es/index.d.ts
CHANGED
package/es/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { cryptoUtil } from "./crypto/index.mjs";
|
|
|
6
6
|
import { dateUtil } from "./date/index.mjs";
|
|
7
7
|
import "./dom/index.mjs";
|
|
8
8
|
import { FastError } from "./error/index.mjs";
|
|
9
|
+
import { useIdentity } from "./identity/index.mjs";
|
|
9
10
|
import { objectUtil } from "./object/index.mjs";
|
|
10
11
|
import { CACHE_EXPIRE_SUFFIX, CACHE_PREFIX, Local, Session, useStorage } from "./storage/index.mjs";
|
|
11
12
|
import { stringUtil } from "./string/index.mjs";
|
|
@@ -41,6 +42,7 @@ export {
|
|
|
41
42
|
stringUtil,
|
|
42
43
|
throwError,
|
|
43
44
|
useExpose,
|
|
45
|
+
useIdentity,
|
|
44
46
|
useProps,
|
|
45
47
|
useRender,
|
|
46
48
|
useStorage,
|
package/es/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("../storage/index.js"),c=require("../string/index.js"),i=e.reactive({cacheKey:"__DEVICE_ID",deviceId:""}),r=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,d=()=>{if(i.deviceId&&r.test(i.deviceId))return t.Local.set(i.cacheKey,i.deviceId),i.deviceId;let e=t.Local.get(i.cacheKey);return e&&r.test(e)?(i.deviceId=e,e):(e=c.stringUtil.generateUUID(),t.Local.set(i.cacheKey,e),i.deviceId=e,e)};exports.useIdentity=()=>({...i,makeIdentity:d});
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/identity/index.ts"],"sourcesContent":["import { reactive } from \"vue\";\nimport { Local } from \"../storage\";\nimport { stringUtil } from \"../string\";\n\nconst state = reactive({\n\tcacheKey: \"__DEVICE_ID\",\n\tdeviceId: \"\",\n});\n\nconst uuidRegExp = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;\n\n/**\n * 生成设备Id\n */\nconst makeIdentity = (): string => {\n\t// 判断是否存在\n\tif (state.deviceId && uuidRegExp.test(state.deviceId)) {\n\t\tLocal.set(state.cacheKey, state.deviceId);\n\t\treturn state.deviceId;\n\t}\n\t// 生成浏览器唯一 UUID\n\tlet deviceID = Local.get(state.cacheKey);\n\tif (deviceID && uuidRegExp.test(deviceID)) {\n\t\tstate.deviceId = deviceID;\n\t\treturn deviceID;\n\t}\n\tdeviceID = stringUtil.generateUUID();\n\tLocal.set(state.cacheKey, deviceID);\n\tstate.deviceId = deviceID;\n\treturn deviceID;\n};\n\nexport const useIdentity = (): typeof state & { makeIdentity: () => string } => {\n\treturn {\n\t\t...state,\n\t\tmakeIdentity,\n\t};\n};\n"],"names":["state","reactive","cacheKey","deviceId","uuidRegExp","makeIdentity","test","Local","set","deviceID","get","stringUtil","generateUUID"],"mappings":"wKAIMA,EAAQC,EAAAA,SAAS,CACtBC,SAAU,cACVC,SAAU,KAGLC,EAAa,gFAKbC,EAAe,KAEpB,GAAIL,EAAMG,UAAYC,EAAWE,KAAKN,EAAMG,UAE3C,OADAI,EAAAA,MAAMC,IAAIR,EAAME,SAAUF,EAAMG,UACzBH,EAAMG,SAGd,IAAIM,EAAWF,EAAAA,MAAMG,IAAIV,EAAME,UAC/B,OAAIO,GAAYL,EAAWE,KAAKG,IAC/BT,EAAMG,SAAWM,EACVA,IAEGE,EAAAA,aAAWC,eAChBL,EAAAA,MAAAC,IAAIR,EAAME,SAAUO,GAC1BT,EAAMG,SAAWM,EACVA,EAAA,sBAGmB,KACnB,IACHT,EACHK"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./base64/index.js"),r=require("./click/index.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./base64/index.js"),r=require("./click/index.js"),s=require("./color/index.js"),o=require("./console/index.js"),t=require("./crypto/index.js"),i=require("./date/index.js");require("./dom/index.js");const n=require("./error/index.js"),l=require("./identity/index.js"),p=require("./object/index.js"),x=require("./storage/index.js"),u=require("./string/index.js");require("./vue/index.js");const c=require("./dom/style.js"),d=require("./vue/expose.js"),a=require("./vue/func.js"),j=require("./vue/install.js"),q=require("./vue/props.js"),E=require("./vue/slots.js"),U=require("./vue/useRender.js"),I=require("./vue/with.js");exports.base64Util=e.base64Util,exports.clickUtil=r.clickUtil,exports.colorUtil=s.colorUtil,exports.consoleDebug=o.consoleDebug,exports.consoleError=o.consoleError,exports.consoleLog=o.consoleLog,exports.consoleWarn=o.consoleWarn,exports.throwError=o.throwError,exports.cryptoUtil=t.cryptoUtil,exports.dateUtil=i.dateUtil,exports.FastError=n.FastError,exports.useIdentity=l.useIdentity,exports.objectUtil=p.objectUtil,exports.CACHE_EXPIRE_SUFFIX=x.CACHE_EXPIRE_SUFFIX,exports.CACHE_PREFIX=x.CACHE_PREFIX,exports.Local=x.Local,exports.Session=x.Session,exports.useStorage=x.useStorage,exports.stringUtil=u.stringUtil,exports.addUnit=c.addUnit,exports.useExpose=d.useExpose,exports.execFunction=a.execFunction,exports.withInstall=j.withInstall,exports.withInstallDirective=j.withInstallDirective,exports.withNoopInstall=j.withNoopInstall,exports.definePropType=q.definePropType,exports.useProps=q.useProps,exports.makeSlots=E.makeSlots,exports.useRender=U.useRender,exports.withDefineType=I.withDefineType;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|