@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.
@@ -0,0 +1,8 @@
1
+ declare const state: {
2
+ cacheKey: string;
3
+ deviceId: string;
4
+ };
5
+ export declare const useIdentity: () => typeof state & {
6
+ makeIdentity: () => string;
7
+ };
8
+ export {};
@@ -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
@@ -6,6 +6,7 @@ export * from './crypto';
6
6
  export * from './date';
7
7
  export * from './dom';
8
8
  export * from './error';
9
+ export * from './identity';
9
10
  export * from './object';
10
11
  export * from './storage';
11
12
  export * from './string';
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,8 @@
1
+ declare const state: {
2
+ cacheKey: string;
3
+ deviceId: string;
4
+ };
5
+ export declare const useIdentity: () => typeof state & {
6
+ makeIdentity: () => string;
7
+ };
8
+ export {};
@@ -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
@@ -6,6 +6,7 @@ export * from './crypto';
6
6
  export * from './date';
7
7
  export * from './dom';
8
8
  export * from './error';
9
+ export * from './identity';
9
10
  export * from './object';
10
11
  export * from './storage';
11
12
  export * from './string';
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"),o=require("./color/index.js"),s=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("./object/index.js"),p=require("./storage/index.js"),x=require("./string/index.js");require("./vue/index.js");const u=require("./dom/style.js"),c=require("./vue/expose.js"),a=require("./vue/func.js"),d=require("./vue/install.js"),j=require("./vue/props.js"),q=require("./vue/slots.js"),E=require("./vue/useRender.js"),U=require("./vue/with.js");exports.base64Util=e.base64Util,exports.clickUtil=r.clickUtil,exports.colorUtil=o.colorUtil,exports.consoleDebug=s.consoleDebug,exports.consoleError=s.consoleError,exports.consoleLog=s.consoleLog,exports.consoleWarn=s.consoleWarn,exports.throwError=s.throwError,exports.cryptoUtil=t.cryptoUtil,exports.dateUtil=i.dateUtil,exports.FastError=n.FastError,exports.objectUtil=l.objectUtil,exports.CACHE_EXPIRE_SUFFIX=p.CACHE_EXPIRE_SUFFIX,exports.CACHE_PREFIX=p.CACHE_PREFIX,exports.Local=p.Local,exports.Session=p.Session,exports.useStorage=p.useStorage,exports.stringUtil=x.stringUtil,exports.addUnit=u.addUnit,exports.useExpose=c.useExpose,exports.execFunction=a.execFunction,exports.withInstall=d.withInstall,exports.withInstallDirective=d.withInstallDirective,exports.withNoopInstall=d.withNoopInstall,exports.definePropType=j.definePropType,exports.useProps=j.useProps,exports.makeSlots=q.makeSlots,exports.useRender=E.useRender,exports.withDefineType=U.withDefineType;
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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fast-china/utils",
3
3
  "author": "小方",
4
- "version": "1.0.3",
4
+ "version": "1.0.4",
5
5
  "description": "Fast 工具库.",
6
6
  "type": "module",
7
7
  "keywords": [