@cclr/utils 0.1.3 → 0.1.5

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("")),n=/#(?<hash>.*)/,r=/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?(?<pathname>[^?#]*)/,o=e=>{const{protocol:t,auth:n,host:r,hostname:o,port:s,pathname:u,query:l,search:a,hash:c}=e;return`${t?`${t}//`:""}${n?`${n}@`:""}${r||`${o||""}${s?`:${s}`:""}`}${u}${a||(l?`?${l}`:"")}${c?`#${c}`:""}`},s=e=>{if(!e)return"";const t=e.split("?")[1];return t?t.replace(n,""):""},u=e=>{if(!e)return{};return s(e).split("&").reduce(((e,t)=>{const n=t.indexOf("=");let r=[];r=-1!==n?[t.substring(0,n),t.substring(n+1)]:[t];const o=r.map((e=>decodeURIComponent(e.replace("+"," "))));return e[o[0]]=o[1],e}),{})};function l(n){const r=n.match(t),{protocol:o,auth:s,host:u,pathname:l,query:a,hash:c}=e.get(r,"groups",{});let h=null,p=null;if(u){const[e,t]=u.split(":");h=e,p=t||null}return{href:n,protocol:o||null,slashes:n.includes("//")||null,auth:s?s.slice(0,-1):null,host:u||null,hostname:h||null,port:p||null,pathname:l||null,search:a?`?${a}`:null,query:a||null,hash:c||null}}const a=t=>{const n=[];for(const r in t){const o=t[r];e.isUndefinedOrNull(o)?n.push(encodeURIComponent(r)+"="):n.push(encodeURIComponent(r)+"="+encodeURIComponent(o))}return n.join("&")},c=(e,t)=>{const{queryObj:n,...r}=t,s={...l(e),...r},c={...u(s.search||""),...n};return o({...s,search:"",query:a(c)})};function h(e){const t=e.match(r);if(t)return t.groups?.pathname||""}const p={parseUrl:l,getPathArr:function(t){const n=h(t);if(!e.isUndefined(n))return n.split("/").filter(Boolean)},getPathStr:h,getQuery:s,getQueryObj:u,toQueryString:a,change:c,addQuery:(e,t)=>c(e,{queryObj:t}),combine:o};exports.HASH_REGEX=n,exports.PATHNAME_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=p,exports.uuid=()=>{const e=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],t=[];for(let n=0;n<36;n++)t[n]=8===n||13===n||18===n||23===n?"-":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("")),n=/#(?<hash>.*)/,r=/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?(?<pathname>[^?#]*)/,o=e=>{const{protocol:t,auth:n,host:r,hostname:o,port:s,pathname:u,query:l,search:a,hash:c}=e;return`${t?`${t}//`:""}${n?`${n}@`:""}${r||`${o||""}${s?`:${s}`:""}`}${u}${l?`?${l}`:a||""}${c?`#${c}`:""}`},s=e=>{if(!e)return"";const t=e.split("?")[1];return t?t.replace(n,""):""},u=e=>{if(!e)return{};return s(e).split("&").reduce(((e,t)=>{const n=t.indexOf("=");let r=[];r=-1!==n?[t.substring(0,n),t.substring(n+1)]:[t];const o=r.map((e=>decodeURIComponent(e.replace("+"," "))));return e[o[0]]=o[1],e}),{})};function l(n){const r=n.match(t),{protocol:o,auth:s,host:u,pathname:l,query:a,hash:c}=e.get(r,"groups",{});let h=null,p=null;if(u){const[e,t]=u.split(":");h=e,p=t||null}return{href:n,protocol:o||null,slashes:n.includes("//")||null,auth:s?s.slice(0,-1):null,host:u||null,hostname:h||null,port:p||null,pathname:l||null,search:a?`?${a}`:null,query:a||null,hash:c||null}}const a=t=>{const n=[];for(const r in t){const o=t[r];e.isUndefinedOrNull(o)?n.push(encodeURIComponent(r)+"="):n.push(encodeURIComponent(r)+"="+encodeURIComponent(o))}return n.join("&")},c=(e,t)=>{const{queryObj:n,...r}=t,s={...l(e),...r},c={...u(s.search||""),...n};return o({...s,search:"",query:a(c)})};function h(e){const t=e.match(r);if(t)return t.groups?.pathname||""}const p={parseUrl:l,getPathArr:function(t){const n=h(t);if(!e.isUndefined(n))return n.split("/").filter(Boolean)},getPathStr:h,getQuery:s,getQueryObj:u,toQueryString:a,change:c,addQuery:(e,t)=>c(e,{queryObj:t}),combine:o};exports.HASH_REGEX=n,exports.PATHNAME_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=p,exports.uuid=()=>{const e=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],t=[];for(let n=0;n<36;n++)t[n]=8===n||13===n||18===n||23===n?"-":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 n,isUndefinedOrNull as e,isUndefined as r}from"@cclr/lang";const o=t=>JSON.parse(JSON.stringify(t)),s=n=>t(n)?[Object.keys(n)]:[],u=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),a=/\?(?<query>[^#]*)/,l=/#(?<hash>.*)/,c=/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?(?<pathname>[^?#]*)/,h=t=>{const{protocol:n,auth:e,host:r,hostname:o,port:s,pathname:u,query:a,search:l,hash:c}=t;return`${n?`${n}//`:""}${e?`${e}@`:""}${r||`${o||""}${s?`:${s}`:""}`}${u}${l||(a?`?${a}`:"")}${c?`#${c}`:""}`},p=t=>{if(!t)return"";const n=t.split("?")[1];return n?n.replace(l,""):""},i=t=>{if(!t)return{};return p(t).split("&").reduce(((t,n)=>{const e=n.indexOf("=");let r=[];r=-1!==e?[n.substring(0,e),n.substring(e+1)]:[n];const o=r.map((t=>decodeURIComponent(t.replace("+"," "))));return t[o[0]]=o[1],t}),{})};function m(t){const e=t.match(u),{protocol:r,auth:o,host:s,pathname:a,query:l,hash:c}=n(e,"groups",{});let h=null,p=null;if(s){const[t,n]=s.split(":");h=t,p=n||null}return{href:t,protocol:r||null,slashes:t.includes("//")||null,auth:o?o.slice(0,-1):null,host:s||null,hostname:h||null,port:p||null,pathname:a||null,search:l?`?${l}`:null,query:l||null,hash:c||null}}const f=t=>{const n=[];for(const r in t){const o=t[r];e(o)?n.push(encodeURIComponent(r)+"="):n.push(encodeURIComponent(r)+"="+encodeURIComponent(o))}return n.join("&")},d=(t,n)=>{const{queryObj:e,...r}=n,o={...m(t),...r},s={...i(o.search||""),...e};return h({...o,search:"",query:f(s)})};function g(t){const n=t.match(c);if(n)return n.groups?.pathname||""}const y={parseUrl:m,getPathArr:function(t){const n=g(t);if(!r(n))return n.split("/").filter(Boolean)},getPathStr:g,getQuery:p,getQueryObj:i,toQueryString:f,change:d,addQuery:(t,n)=>d(t,{queryObj:n}),combine:h},$=()=>{const t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],n=[];for(let e=0;e<36;e++)n[e]=8===e||13===e||18===e||23===e?"-":t[Math.ceil(Math.random()*t.length-1)];return n.join("")};export{l as HASH_REGEX,c as PATHNAME_REGEX,a as QUERY_REGEX,u as URL_REGEX,o as deepClone,s as enumToArray,y as uri,$ as uuid};
1
+ import{isPlainObject as t,get as n,isUndefinedOrNull as e,isUndefined as r}from"@cclr/lang";const o=t=>JSON.parse(JSON.stringify(t)),s=n=>t(n)?[Object.keys(n)]:[],u=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),a=/\?(?<query>[^#]*)/,l=/#(?<hash>.*)/,c=/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?(?<pathname>[^?#]*)/,h=t=>{const{protocol:n,auth:e,host:r,hostname:o,port:s,pathname:u,query:a,search:l,hash:c}=t;return`${n?`${n}//`:""}${e?`${e}@`:""}${r||`${o||""}${s?`:${s}`:""}`}${u}${a?`?${a}`:l||""}${c?`#${c}`:""}`},p=t=>{if(!t)return"";const n=t.split("?")[1];return n?n.replace(l,""):""},i=t=>{if(!t)return{};return p(t).split("&").reduce(((t,n)=>{const e=n.indexOf("=");let r=[];r=-1!==e?[n.substring(0,e),n.substring(e+1)]:[n];const o=r.map((t=>decodeURIComponent(t.replace("+"," "))));return t[o[0]]=o[1],t}),{})};function m(t){const e=t.match(u),{protocol:r,auth:o,host:s,pathname:a,query:l,hash:c}=n(e,"groups",{});let h=null,p=null;if(s){const[t,n]=s.split(":");h=t,p=n||null}return{href:t,protocol:r||null,slashes:t.includes("//")||null,auth:o?o.slice(0,-1):null,host:s||null,hostname:h||null,port:p||null,pathname:a||null,search:l?`?${l}`:null,query:l||null,hash:c||null}}const f=t=>{const n=[];for(const r in t){const o=t[r];e(o)?n.push(encodeURIComponent(r)+"="):n.push(encodeURIComponent(r)+"="+encodeURIComponent(o))}return n.join("&")},d=(t,n)=>{const{queryObj:e,...r}=n,o={...m(t),...r},s={...i(o.search||""),...e};return h({...o,search:"",query:f(s)})};function g(t){const n=t.match(c);if(n)return n.groups?.pathname||""}const y={parseUrl:m,getPathArr:function(t){const n=g(t);if(!r(n))return n.split("/").filter(Boolean)},getPathStr:g,getQuery:p,getQueryObj:i,toQueryString:f,change:d,addQuery:(t,n)=>d(t,{queryObj:n}),combine:h},$=()=>{const t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],n=[];for(let e=0;e<36;e++)n[e]=8===e||13===e||18===e||23===e?"-":t[Math.ceil(Math.random()*t.length-1)];return n.join("")};export{l as HASH_REGEX,c as PATHNAME_REGEX,a as QUERY_REGEX,u as URL_REGEX,o as deepClone,s as enumToArray,y as uri,$ as uuid};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cclr/utils",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "> TODO: description",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -30,8 +30,8 @@
30
30
  "g:test": "vitest run",
31
31
  "g:build": "ccf build"
32
32
  },
33
- "gitHead": "756346e96b198cbc70acc052058123826f59f5ed",
33
+ "gitHead": "f7ad5275ae3c07cbf4597b6a38ba41362a27e4e1",
34
34
  "dependencies": {
35
- "@cclr/lang": "^0.1.3"
35
+ "@cclr/lang": "0.1.5"
36
36
  }
37
37
  }