@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 +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/type/index.d.ts +16 -4
- package/package.json +5 -4
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("")),
|
|
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
|
|
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};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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.
|
|
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": "
|
|
30
|
+
"gitHead": "03fc59004998fb54a36ee04d641d6547bc9abe28",
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@cclr/lang": "0.
|
|
32
|
+
"@cclr/lang": "0.1.1"
|
|
32
33
|
}
|
|
33
34
|
}
|