@cclr/utils 0.1.1 → 0.1.2

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/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("@cclr/lang");const t=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),r=/#(?<hash>.*)/,n=e=>{if(!e)return"";const t=e.split("?")[1];return t?t.replace(r,""):""};const l={parseUrl:function(r){const n=r.match(t),{protocol:l,auth:s,host:u,pathname:o,query:a,hash:c}=e.get(n,"groups",{});let h=null,p=null;if(u){const[e,t]=u.split(":");h=e,p=t||null}return{href:r,protocol:l||null,slashes:r.includes("//")||null,auth:s?s.slice(0,-1):null,host:u||null,hostname:h||null,port:p||null,pathname:o||null,search:a?`?${a}`:null,query:a||null,hash:c||null}},getQuery:n,getQueryObj:e=>{if(!e)return{};return(n(e)||e).split("&").reduce(((e,t)=>{const r=t.indexOf("=");let n=[];n=-1!==r?[t.substring(0,r),t.substring(r+1)]:[t];const l=n.map((e=>decodeURIComponent(e.replace("+"," "))));return e[l[0]]=l[1],e}),{})}};exports.HASH_REGEX=r,exports.QUERY_REGEX=/\?(?<query>[^#]*)/,exports.URL_REGEX=t,exports.enumToArray=t=>e.isPlainObject(t)?[Object.keys(t)]:[],exports.uri=l,exports.uuid=()=>{const e=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],t=[];for(let r=0;r<36;r++)t[r]=8===r||13===r||18===r||23===r?"-":e[Math.ceil(Math.random()*e.length-1)];return t.join("")};
1
+ "use strict";var e=require("@cclr/lang");const t=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),r=/#(?<hash>.*)/,n=e=>{if(!e)return"";const t=e.split("?")[1];return t?t.replace(r,""):""};const l={parseUrl:function(r){const n=r.match(t),{protocol:l,auth:s,host:u,pathname:o,query:a,hash:c}=e.get(n,"groups",{});let p=null,h=null;if(u){const[e,t]=u.split(":");p=e,h=t||null}return{href:r,protocol:l||null,slashes:r.includes("//")||null,auth:s?s.slice(0,-1):null,host:u||null,hostname:p||null,port:h||null,pathname:o||null,search:a?`?${a}`:null,query:a||null,hash:c||null}},getQuery:n,getQueryObj:e=>{if(!e)return{};return(n(e)||e).split("&").reduce(((e,t)=>{const r=t.indexOf("=");let n=[];n=-1!==r?[t.substring(0,r),t.substring(r+1)]:[t];const l=n.map((e=>decodeURIComponent(e.replace("+"," "))));return e[l[0]]=l[1],e}),{})}};exports.HASH_REGEX=r,exports.QUERY_REGEX=/\?(?<query>[^#]*)/,exports.URL_REGEX=t,exports.deepClone=e=>JSON.parse(JSON.stringify(e)),exports.enumToArray=t=>e.isPlainObject(t)?[Object.keys(t)]:[],exports.uri=l,exports.uuid=()=>{const e=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],t=[];for(let r=0;r<36;r++)t[r]=8===r||13===r||18===r||23===r?"-":e[Math.ceil(Math.random()*e.length-1)];return t.join("")};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{isPlainObject as t,get as e}from"@cclr/lang";const n=e=>t(e)?[Object.keys(e)]:[],l=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),r=/\?(?<query>[^#]*)/,u=/#(?<hash>.*)/,o=t=>{if(!t)return"";const e=t.split("?")[1];return e?e.replace(u,""):""};const s={parseUrl:function(t){const n=t.match(l),{protocol:r,auth:u,host:o,pathname:s,query:a,hash:c}=e(n,"groups",{});let h=null,p=null;if(o){const[t,e]=o.split(":");h=t,p=e||null}return{href:t,protocol:r||null,slashes:t.includes("//")||null,auth:u?u.slice(0,-1):null,host:o||null,hostname:h||null,port:p||null,pathname:s||null,search:a?`?${a}`:null,query:a||null,hash:c||null}},getQuery:o,getQueryObj:t=>{if(!t)return{};return(o(t)||t).split("&").reduce(((t,e)=>{const n=e.indexOf("=");let l=[];l=-1!==n?[e.substring(0,n),e.substring(n+1)]:[e];const r=l.map((t=>decodeURIComponent(t.replace("+"," "))));return t[r[0]]=r[1],t}),{})}},a=()=>{const t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],e=[];for(let n=0;n<36;n++)e[n]=8===n||13===n||18===n||23===n?"-":t[Math.ceil(Math.random()*t.length-1)];return e.join("")};export{u as HASH_REGEX,r as QUERY_REGEX,l as URL_REGEX,n as enumToArray,s as uri,a as uuid};
1
+ import{isPlainObject as t,get as e}from"@cclr/lang";const n=t=>JSON.parse(JSON.stringify(t)),l=e=>t(e)?[Object.keys(e)]:[],r=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),u=/\?(?<query>[^#]*)/,o=/#(?<hash>.*)/,s=t=>{if(!t)return"";const e=t.split("?")[1];return e?e.replace(o,""):""};const a={parseUrl:function(t){const n=t.match(r),{protocol:l,auth:u,host:o,pathname:s,query:a,hash:c}=e(n,"groups",{});let h=null,p=null;if(o){const[t,e]=o.split(":");h=t,p=e||null}return{href:t,protocol:l||null,slashes:t.includes("//")||null,auth:u?u.slice(0,-1):null,host:o||null,hostname:h||null,port:p||null,pathname:s||null,search:a?`?${a}`:null,query:a||null,hash:c||null}},getQuery:s,getQueryObj:t=>{if(!t)return{};return(s(t)||t).split("&").reduce(((t,e)=>{const n=e.indexOf("=");let l=[];l=-1!==n?[e.substring(0,n),e.substring(n+1)]:[e];const r=l.map((t=>decodeURIComponent(t.replace("+"," "))));return t[r[0]]=r[1],t}),{})}},c=()=>{const t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],e=[];for(let n=0;n<36;n++)e[n]=8===n||13===n||18===n||23===n?"-":t[Math.ceil(Math.random()*t.length-1)];return e.join("")};export{o as HASH_REGEX,u as QUERY_REGEX,r as URL_REGEX,n as deepClone,l as enumToArray,a as uri,c as uuid};
@@ -1,5 +1,17 @@
1
- import { TPlainObject } from '@cclr/lang';
1
+ import { TAny, TPlainObject } from '@cclr/lang';
2
2
 
3
+ /**
4
+ * 深拷贝 JSON 方式
5
+ * @param Obj
6
+ * @returns
7
+ */
8
+ declare const deepClone: <T extends object | TAny[]>(Obj: T) => T;
9
+
10
+ /**
11
+ * 枚举key变成数组
12
+ * @param e
13
+ * @returns
14
+ */
3
15
  declare const enumToArray: (e: TPlainObject) => string[][];
4
16
 
5
17
  declare const URL_REGEX: RegExp;
@@ -53,4 +65,4 @@ declare const uri: {
53
65
  */
54
66
  declare const uuid: () => string;
55
67
 
56
- export { HASH_REGEX, QUERY_REGEX, URL_REGEX, enumToArray, uri, uuid };
68
+ export { HASH_REGEX, QUERY_REGEX, URL_REGEX, deepClone, enumToArray, uri, uuid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cclr/utils",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "> TODO: description",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -25,10 +25,13 @@
25
25
  },
26
26
  "scripts": {
27
27
  "test": "vitest",
28
- "relese": "ccf build && npm publish"
28
+ "relese": "npm run test && npm publish",
29
+ "build": "ccf build",
30
+ "g:test": "vitest run",
31
+ "g:build": "ccf build"
29
32
  },
30
- "gitHead": "03fc59004998fb54a36ee04d641d6547bc9abe28",
33
+ "gitHead": "361f93f5ddccff3c90ee52b0698e289dd7c699a2",
31
34
  "dependencies": {
32
- "@cclr/lang": "0.1.1"
35
+ "@cclr/lang": "^0.1.2"
33
36
  }
34
37
  }