@cclr/utils 0.0.10 → 0.1.1

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("")),l=/#(?<hash>.*)/,r=e=>{if(!e)return"";const t=e.split("?")[1];return t?t.replace(l,""):""};const n={parseUrl:function(l){const r=l.match(t),{protocol:n,auth:u,host:s,pathname:o,query:a,hash:c}=e.get(r,"groups",{});let h=null,p=null;if(s){const[e,t]=s.split(":");h=e,p=t||null}return{href:l,protocol:n||null,slashes:l.includes("//")||null,auth:u?u.slice(0,-1):null,host:s||null,hostname:h||null,port:p||null,pathname:o||null,search:a?`?${a}`:null,query:a||null,hash:c||null}},getQuery:r,getQueryObj:e=>{if(!e)return{};return(r(e)||e).split("&").reduce(((e,t)=>{const l=t.indexOf("=");let r=[];r=-1!==l?[t.substring(0,l),t.substring(l+1)]:[t];const n=r.map((e=>decodeURIComponent(e.replace("+"," "))));return e[n[0]]=n[1],e}),{})}};exports.HASH_REGEX=l,exports.QUERY_REGEX=/\?(?<query>[^#]*)/,exports.URL_REGEX=t,exports.uri=n;
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("")};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{get as l}from"@cclr/lang";const n=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),t=/\?(?<query>[^#]*)/,e=/#(?<hash>.*)/,r=l=>{if(!l)return"";const n=l.split("?")[1];return n?n.replace(e,""):""};const u={parseUrl:function(t){const e=t.match(n),{protocol:r,auth:u,host:o,pathname:s,query:a,hash:h}=l(e,"groups",{});let c=null,p=null;if(o){const[l,n]=o.split(":");c=l,p=n||null}return{href:t,protocol:r||null,slashes:t.includes("//")||null,auth:u?u.slice(0,-1):null,host:o||null,hostname:c||null,port:p||null,pathname:s||null,search:a?`?${a}`:null,query:a||null,hash:h||null}},getQuery:r,getQueryObj:l=>{if(!l)return{};return(r(l)||l).split("&").reduce(((l,n)=>{const t=n.indexOf("=");let e=[];e=-1!==t?[n.substring(0,t),n.substring(t+1)]:[n];const r=e.map((l=>decodeURIComponent(l.replace("+"," "))));return l[r[0]]=r[1],l}),{})}};export{e as HASH_REGEX,t as QUERY_REGEX,n as URL_REGEX,u as uri};
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,3 +1,11 @@
1
+ import { TPlainObject } from '@cclr/lang';
2
+
3
+ declare const enumToArray: (e: TPlainObject) => string[][];
4
+
5
+ declare const URL_REGEX: RegExp;
6
+ declare const QUERY_REGEX: RegExp;
7
+ declare const HASH_REGEX: RegExp;
8
+
1
9
  interface IUrl {
2
10
  /** 完整的 URL 字符串,例如 https://example.com:8080/path?query#fragment */
3
11
  href?: string | null | undefined;
@@ -37,8 +45,12 @@ declare const uri: {
37
45
  getQueryObj: (url: string) => {};
38
46
  };
39
47
 
40
- declare const URL_REGEX: RegExp;
41
- declare const QUERY_REGEX: RegExp;
42
- declare const HASH_REGEX: RegExp;
48
+ /**
49
+ * A function that returns a universally unique identifier (uuid).
50
+ * @example
51
+ * 1b83fd69-abe7-468c-bea1-306a8aa1c81d
52
+ * @returns `string` : 32 character uuid (see example)
53
+ */
54
+ declare const uuid: () => string;
43
55
 
44
- export { HASH_REGEX, QUERY_REGEX, URL_REGEX, uri };
56
+ export { HASH_REGEX, QUERY_REGEX, URL_REGEX, enumToArray, uri, uuid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cclr/utils",
3
- "version": "0.0.10",
3
+ "version": "0.1.1",
4
4
  "description": "> TODO: description",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -24,10 +24,11 @@
24
24
  "url": "git@gitee.com:cclr/toolkit.git"
25
25
  },
26
26
  "scripts": {
27
- "test": "vitest"
27
+ "test": "vitest",
28
+ "relese": "ccf build && npm publish"
28
29
  },
29
- "gitHead": "d58e3b15266c99cfe0938671a0de64bcc19e0b3f",
30
+ "gitHead": "03fc59004998fb54a36ee04d641d6547bc9abe28",
30
31
  "dependencies": {
31
- "@cclr/lang": "0.0.10"
32
+ "@cclr/lang": "0.1.1"
32
33
  }
33
34
  }