@cclr/utils 0.1.5 → 0.1.6
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/package.json +2 -2
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=require("@cclr/lang");function t(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=Array(t);e<t;e++)n[e]=r[e];return n}function e(r,t,e){return(t=function(r){var t=function(r,t){if("object"!=typeof r||!r)return r;var e=r[Symbol.toPrimitive];if(void 0!==e){var n=e.call(r,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(r)}(r,"string");return"symbol"==typeof t?t:t+""}(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function n(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function o(r){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){e(r,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(o,t))}))}return r}function u(r,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},u(r,t)}function a(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var e=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=e){var n,o,u,a,c=[],i=!0,l=!1;try{if(u=(e=e.call(r)).next,0===t);else for(;!(i=(n=u.call(e)).done)&&(c.push(n.value),c.length!==t);i=!0);}catch(r){l=!0,o=r}finally{try{if(!i&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(l)throw o}}return c}}(r,e)||function(r,e){if(r){if("string"==typeof r)return t(r,e);var n={}.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(r,e):void 0}}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(){c=function(r,t){return new e(r,void 0,t)};var r=RegExp.prototype,t=new WeakMap;function e(r,n,o){var a=RegExp(r,n);return t.set(a,o||t.get(r)),u(a,e.prototype)}function n(r,e){var n=t.get(e);return Object.keys(n).reduce((function(t,e){var o=n[e];if("number"==typeof o)t[e]=r[o];else{for(var u=0;void 0===r[o[u]]&&u+1<o.length;)u++;t[e]=r[o[u]]}return t}),Object.create(null))}return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),t&&u(r,t)}(e,RegExp),e.prototype.exec=function(t){var e=r.exec.call(this,t);if(e){e.groups=n(e,this);var o=e.indices;o&&(o.groups=n(o,this))}return e},e.prototype[Symbol.replace]=function(e,o){if("string"==typeof o){var u=t.get(this);return r[Symbol.replace].call(this,e,o.replace(/\$<([^>]+)>/g,(function(r,t){var e=u[t];return"$"+(Array.isArray(e)?e.join("$"):e)})))}if("function"==typeof o){var a=this;return r[Symbol.replace].call(this,e,(function(){var r=arguments;return"object"!=typeof r[r.length-1]&&(r=[].slice.call(r)).push(n(r,a)),o.apply(this,r)}))}return r[Symbol.replace].call(this,e,o)},c.apply(this,arguments)}var i=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),l=c(/\?([^#]*)/,{query:1}),p=c(/#(.*)/,{hash:1}),f=c(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),s=function(r){var t=r.protocol,e=r.auth,n=r.host,o=r.hostname,u=r.port,a=r.pathname,c=r.query,i=r.search,l=r.hash,p=t?"".concat(t,"//"):"",f=e?"".concat(e,"@"):"",s=n||"".concat(o||"").concat(u?":".concat(u):""),y=c?"?".concat(c):i||"",h=l?"#".concat(l):"";return"".concat(p).concat(f).concat(s).concat(a).concat(y).concat(h)},y=function(r){if(!r)return"";var t=r.split("?")[1];return t?t.replace(p,""):""},h=function(r){return r?y(r).split("&").reduce((function(r,t){var e=t.indexOf("="),n=(-1!==e?[t.substring(0,e),t.substring(e+1)]:[t]).map((function(r){return decodeURIComponent(r.replace("+"," "))}));return r[n[0]]=n[1],r}),{}):{}};function b(t){var e=t.match(i),n=r.get(e,"groups",{}),o=n.protocol,u=n.auth,c=n.host,l=n.pathname,p=n.query,f=n.hash,s=null,y=null;if(c){var h=a(c.split(":"),2);s=h[0],y=h[1]||null}return{href:t,protocol:o||null,slashes:t.includes("//")||null,auth:u?u.slice(0,-1):null,host:c||null,hostname:s||null,port:y||null,pathname:l||null,search:p?"?".concat(p):null,query:p||null,hash:f||null}}var v=function(t){var e=[];for(var n in t){var o=t[n];r.isUndefinedOrNull(o)?e.push(encodeURIComponent(n)+"="):e.push(encodeURIComponent(n)+"="+encodeURIComponent(o))}return e.join("&")},g=["queryObj"],m=function(r,t){var e=t.queryObj,n=function(r,t){if(null==r)return{};var e,n,o=function(r,t){if(null==r)return{};var e={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(t.includes(n))continue;e[n]=r[n]}return e}(r,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(r);for(n=0;n<u.length;n++)e=u[n],t.includes(e)||{}.propertyIsEnumerable.call(r,e)&&(o[e]=r[e])}return o}(t,g),u=o(o({},b(r)),n),a=o(o({},h(u.search||"")),e);return s(o(o({},u),{},{search:"",query:v(a)}))};function d(r){var t,e=r.match(f);if(e)return(null===(t=e.groups)||void 0===t?void 0:t.pathname)||""}var O={parseUrl:b,getPathArr:function(t){var e=d(t);if(!r.isUndefined(e))return e.split("/").filter(Boolean)},getPathStr:d,getQuery:y,getQueryObj:h,toQueryString:v,change:m,addQuery:function(r,t){return m(r,{queryObj:t})},combine:s};exports.HASH_REGEX=p,exports.PATHNAME_REGEX=f,exports.QUERY_REGEX=l,exports.URL_REGEX=i,exports.deepClone=function(r){return JSON.parse(JSON.stringify(r))},exports.enumToArray=function(t){return r.isPlainObject(t)?[Object.keys(t)]:[]},exports.uri=O,exports.uuid=function(){for(var r=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],t=[],e=0;e<36;e++)t[e]=8===e||13===e||18===e||23===e?"-":r[Math.ceil(Math.random()*r.length-1)];return t.join("")};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isPlainObject as
|
|
1
|
+
import{isPlainObject as r,get as t,isUndefinedOrNull as e,isUndefined as n}from"@cclr/lang";var o=function(r){return JSON.parse(JSON.stringify(r))},u=function(t){return r(t)?[Object.keys(t)]:[]};function a(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=Array(t);e<t;e++)n[e]=r[e];return n}function c(r,t,e){return(t=function(r){var t=function(r,t){if("object"!=typeof r||!r)return r;var e=r[Symbol.toPrimitive];if(void 0!==e){var n=e.call(r,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(r)}(r,"string");return"symbol"==typeof t?t:t+""}(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function i(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function l(r){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{};t%2?i(Object(e),!0).forEach((function(t){c(r,t,e[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(e)):i(Object(e)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(e,t))}))}return r}function f(r,t){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},f(r,t)}function p(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var e=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=e){var n,o,u,a,c=[],i=!0,l=!1;try{if(u=(e=e.call(r)).next,0===t);else for(;!(i=(n=u.call(e)).done)&&(c.push(n.value),c.length!==t);i=!0);}catch(r){l=!0,o=r}finally{try{if(!i&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(l)throw o}}return c}}(r,t)||function(r,t){if(r){if("string"==typeof r)return a(r,t);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?a(r,t):void 0}}(r,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(){s=function(r,t){return new e(r,void 0,t)};var r=RegExp.prototype,t=new WeakMap;function e(r,n,o){var u=RegExp(r,n);return t.set(u,o||t.get(r)),f(u,e.prototype)}function n(r,e){var n=t.get(e);return Object.keys(n).reduce((function(t,e){var o=n[e];if("number"==typeof o)t[e]=r[o];else{for(var u=0;void 0===r[o[u]]&&u+1<o.length;)u++;t[e]=r[o[u]]}return t}),Object.create(null))}return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),t&&f(r,t)}(e,RegExp),e.prototype.exec=function(t){var e=r.exec.call(this,t);if(e){e.groups=n(e,this);var o=e.indices;o&&(o.groups=n(o,this))}return e},e.prototype[Symbol.replace]=function(e,o){if("string"==typeof o){var u=t.get(this);return r[Symbol.replace].call(this,e,o.replace(/\$<([^>]+)>/g,(function(r,t){var e=u[t];return"$"+(Array.isArray(e)?e.join("$"):e)})))}if("function"==typeof o){var a=this;return r[Symbol.replace].call(this,e,(function(){var r=arguments;return"object"!=typeof r[r.length-1]&&(r=[].slice.call(r)).push(n(r,a)),o.apply(this,r)}))}return r[Symbol.replace].call(this,e,o)},s.apply(this,arguments)}var y=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),h=s(/\?([^#]*)/,{query:1}),b=s(/#(.*)/,{hash:1}),v=s(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),m=function(r){var t=r.protocol,e=r.auth,n=r.host,o=r.hostname,u=r.port,a=r.pathname,c=r.query,i=r.search,l=r.hash,f=t?"".concat(t,"//"):"",p=e?"".concat(e,"@"):"",s=n||"".concat(o||"").concat(u?":".concat(u):""),y=c?"?".concat(c):i||"",h=l?"#".concat(l):"";return"".concat(f).concat(p).concat(s).concat(a).concat(y).concat(h)},g=function(r){if(!r)return"";var t=r.split("?")[1];return t?t.replace(b,""):""},O=function(r){return r?g(r).split("&").reduce((function(r,t){var e=t.indexOf("="),n=(-1!==e?[t.substring(0,e),t.substring(e+1)]:[t]).map((function(r){return decodeURIComponent(r.replace("+"," "))}));return r[n[0]]=n[1],r}),{}):{}};function d(r){var e=r.match(y),n=t(e,"groups",{}),o=n.protocol,u=n.auth,a=n.host,c=n.pathname,i=n.query,l=n.hash,f=null,s=null;if(a){var h=p(a.split(":"),2);f=h[0],s=h[1]||null}return{href:r,protocol:o||null,slashes:r.includes("//")||null,auth:u?u.slice(0,-1):null,host:a||null,hostname:f||null,port:s||null,pathname:c||null,search:i?"?".concat(i):null,query:i||null,hash:l||null}}var j=function(r){var t=[];for(var n in r){var o=r[n];e(o)?t.push(encodeURIComponent(n)+"="):t.push(encodeURIComponent(n)+"="+encodeURIComponent(o))}return t.join("&")},w=["queryObj"],S=function(r,t){var e=t.queryObj,n=function(r,t){if(null==r)return{};var e,n,o=function(r,t){if(null==r)return{};var e={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(t.includes(n))continue;e[n]=r[n]}return e}(r,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(r);for(n=0;n<u.length;n++)e=u[n],t.includes(e)||{}.propertyIsEnumerable.call(r,e)&&(o[e]=r[e])}return o}(t,w),o=l(l({},d(r)),n),u=l(l({},O(o.search||"")),e);return m(l(l({},o),{},{search:"",query:j(u)}))};function P(r){var t,e=r.match(v);if(e)return(null===(t=e.groups)||void 0===t?void 0:t.pathname)||""}var A={parseUrl:d,getPathArr:function(r){var t=P(r);if(!n(t))return t.split("/").filter(Boolean)},getPathStr:P,getQuery:g,getQueryObj:O,toQueryString:j,change:S,addQuery:function(r,t){return S(r,{queryObj:t})},combine:m},x=function(){for(var r=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],t=[],e=0;e<36;e++)t[e]=8===e||13===e||18===e||23===e?"-":r[Math.ceil(Math.random()*r.length-1)];return t.join("")};export{b as HASH_REGEX,v as PATHNAME_REGEX,h as QUERY_REGEX,y as URL_REGEX,o as deepClone,u as enumToArray,A as uri,x as uuid};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclr/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
},
|
|
33
33
|
"gitHead": "f7ad5275ae3c07cbf4597b6a38ba41362a27e4e1",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@cclr/lang": "
|
|
35
|
+
"@cclr/lang": "workspace:*"
|
|
36
36
|
}
|
|
37
37
|
}
|