@cclr/utils 0.1.0 → 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 +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/type/index.d.ts +14 -2
- package/package.json +7 -5
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
|
|
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)]:[],
|
|
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};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"main": "lib/cjs/index.js",
|
|
9
9
|
"module": "lib/esm/index.js",
|
|
10
10
|
"types": "lib/type/index.d.ts",
|
|
11
|
-
"type": "module",
|
|
12
11
|
"directories": {
|
|
13
12
|
"lib": "lib",
|
|
14
13
|
"test": "__tests__"
|
|
@@ -26,10 +25,13 @@
|
|
|
26
25
|
},
|
|
27
26
|
"scripts": {
|
|
28
27
|
"test": "vitest",
|
|
29
|
-
"relese": "
|
|
28
|
+
"relese": "npm run test && npm publish",
|
|
29
|
+
"build": "ccf build",
|
|
30
|
+
"g:test": "vitest run",
|
|
31
|
+
"g:build": "ccf build"
|
|
30
32
|
},
|
|
31
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "361f93f5ddccff3c90ee52b0698e289dd7c699a2",
|
|
32
34
|
"dependencies": {
|
|
33
|
-
"@cclr/lang": "0.1.
|
|
35
|
+
"@cclr/lang": "^0.1.2"
|
|
34
36
|
}
|
|
35
37
|
}
|