@citruslime/utils 2.0.3 → 2.0.4-beta.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.
@@ -2,13 +2,16 @@ function g(t, ...n) {
2
2
  let e = 0;
3
3
  return t.replace(/{\d+}/g, () => typeof n[e] < "u" ? n[e++] : "");
4
4
  }
5
- function m(t, n, e = "cl-bg-primary-light cl-font-bold cl-px-0.5") {
6
- const o = n.map((r) => `(${r})`).join("|");
5
+ function f(t, n, e = "cl-bg-primary-light cl-font-bold cl-px-0.5") {
6
+ const o = n.map((r) => `(${p(r)})`).join("|");
7
7
  return t.replace(
8
8
  new RegExp(o, "ig"),
9
9
  (r) => `<span class="${e}">${r}</span>`
10
10
  );
11
11
  }
12
+ function p(t) {
13
+ return t.replace(/[-[\]{}()*+?.,\\/^$|]/g, "\\$&");
14
+ }
12
15
  String.prototype.similarity = function(t) {
13
16
  let n = 0, e = this.toLowerCase(), o = t.toLowerCase();
14
17
  if (e < o) {
@@ -16,7 +19,7 @@ String.prototype.similarity = function(t) {
16
19
  o = e, e = i;
17
20
  }
18
21
  const r = e.length;
19
- return r === 0 ? n = 100 : n = Math.round((r - p(e, o)) / r * 100), n;
22
+ return r === 0 ? n = 100 : n = Math.round((r - m(e, o)) / r * 100), n;
20
23
  };
21
24
  String.prototype.trimChar = function(t) {
22
25
  return this.trimStartChar(t).trimEndChar(t);
@@ -49,7 +52,7 @@ String.prototype.replacePlaceholders = function(...t) {
49
52
  String.prototype.toDateFromTime = function() {
50
53
  return /* @__PURE__ */ new Date(`${(/* @__PURE__ */ new Date()).toISOString().substr(0, 11)}${this}`);
51
54
  };
52
- function p(t, n) {
55
+ function m(t, n) {
53
56
  if (t.length === 0)
54
57
  return n.length;
55
58
  if (n.length === 0)
@@ -69,8 +72,8 @@ function p(t, n) {
69
72
  if (h === t[l - 1])
70
73
  o = e[l - 1];
71
74
  else {
72
- const c = i + 1, a = e[l] + 1, s = c - (c - a & a - c >> 7), u = e[l - 1] + 1;
73
- o = s - (s - u & u - s >> 7);
75
+ const c = i + 1, s = e[l] + 1, a = c - (c - s & s - c >> 7), u = e[l - 1] + 1;
76
+ o = a - (a - u & u - a >> 7);
74
77
  }
75
78
  e[l - 1] = i, i = o;
76
79
  }
@@ -78,25 +81,25 @@ function p(t, n) {
78
81
  }
79
82
  return e[t.length];
80
83
  }
81
- function* f(t, n) {
84
+ function* y(t, n) {
82
85
  for (let e = 0; e < t.length; e += n)
83
86
  yield t.slice(e, e + n);
84
87
  }
85
- function y() {
88
+ function x() {
86
89
  return Math.random().toString(36).slice(2, 8);
87
90
  }
88
- function x(t) {
91
+ function d(t) {
89
92
  return t;
90
93
  }
91
- function d(t, n, e) {
94
+ function C(t, n, e) {
92
95
  return t[e] < n[e] ? -1 : t[e] > n[e] ? 1 : 0;
93
96
  }
94
- function C(t, n) {
97
+ function w(t, n) {
95
98
  let e = "";
96
99
  const o = decodeURIComponent(t), r = "[\\?&]" + n + "=([^&#]*)", h = new RegExp(r).exec(o);
97
100
  return h && h[1] && (e = decodeURIComponent(h[1].replace(/\+/g, " "))), e;
98
101
  }
99
- function w(t, n) {
102
+ function $(t, n) {
100
103
  const e = Object.keys(t).find((o) => o.toLowerCase() === n.toLowerCase());
101
104
  return e ? t[e] : null;
102
105
  }
@@ -104,13 +107,14 @@ function v(t) {
104
107
  return !!t && /^[^@]+@[^@]+\.[^@]+$/.exec(t) !== null;
105
108
  }
106
109
  export {
107
- f as chunk,
108
- d as compareByProperty,
109
- y as generateStringId,
110
- w as getCaseInsensitiveQueryParam,
111
- C as getParamsByName,
112
- m as highlightText,
113
- x as nameOf,
110
+ y as chunk,
111
+ C as compareByProperty,
112
+ p as escapeStringForRegExp,
113
+ x as generateStringId,
114
+ $ as getCaseInsensitiveQueryParam,
115
+ w as getParamsByName,
116
+ f as highlightText,
117
+ d as nameOf,
114
118
  g as replacePlaceholders,
115
119
  v as validateEmail
116
120
  };
@@ -1 +1 @@
1
- (function(i,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(i=typeof globalThis<"u"?globalThis:i||self,a(i.CitrusLimeUtils={}))})(this,function(i){"use strict";function a(e,...n){let t=0;return e.replace(/{\d+}/g,()=>typeof n[t]<"u"?n[t++]:"")}function m(e,n,t="cl-bg-primary-light cl-font-bold cl-px-0.5"){const o=n.map(r=>`(${r})`).join("|");return e.replace(new RegExp(o,"ig"),r=>`<span class="${t}">${r}</span>`)}String.prototype.similarity=function(e){let n=0,t=this.toLowerCase(),o=e.toLowerCase();if(t<o){const l=o;o=t,t=l}const r=t.length;return r===0?n=100:n=Math.round((r-f(t,o))/r*100),n},String.prototype.trimChar=function(e){return this.trimStartChar(e).trimEndChar(e)},String.prototype.trimStartChar=function(e){return e!==""&&this.startsWith(e)?this.slice(1):this},String.prototype.trimEndChar=function(e){return e!==""&&this.endsWith(e)?this.slice(0,-1):this},String.prototype.trimToLength=function(e,n=!1){const t=this.length<e?this.length:e;return n&&t>=4&&t<this.length?`${this.slice(0,Math.max(t-3,1))}...`:this.slice(0,Math.max(t,1))},String.prototype.removeWhitespace=function(){return this.replace(/\s/g,"")},String.prototype.removeNonAlphanumeric=function(){return this.replace(/[^a-zA-Z0-9]/g,"")},String.prototype.removeNonAlphabetic=function(){return this.replace(/[^a-zA-Z]/g,"")},String.prototype.removeNonNumeric=function(){return this.replace(/[^0-9]/g,"")},String.prototype.replacePlaceholders=function(...e){return a(this,...e)},String.prototype.toDateFromTime=function(){return new Date(`${new Date().toISOString().substr(0,11)}${this}`)};function f(e,n){if(e.length===0)return n.length;if(n.length===0)return e.length;if(e.length>n.length){const r=e;e=n,n=r}const t=new Int8Array(e.length+1);for(let r=0;r<=e.length;r++)t[r]=r;let o;for(let r=1;r<=n.length;r++){let l=r;const u=n[r-1];for(let h=1;h<=e.length;h++){if(u===e[h-1])o=t[h-1];else{const c=l+1,g=t[h]+1,s=c-(c-g&g-c>>7),p=t[h-1]+1;o=s-(s-p&p-s>>7)}t[h-1]=l,l=o}t[e.length]=l}return t[e.length]}function*d(e,n){for(let t=0;t<e.length;t+=n)yield e.slice(t,t+n)}function y(){return Math.random().toString(36).slice(2,8)}function C(e){return e}function v(e,n,t){return e[t]<n[t]?-1:e[t]>n[t]?1:0}function P(e,n){let t="";const o=decodeURIComponent(e),r="[\\?&]"+n+"=([^&#]*)",u=new RegExp(r).exec(o);return u&&u[1]&&(t=decodeURIComponent(u[1].replace(/\+/g," "))),t}function w(e,n){const t=Object.keys(e).find(o=>o.toLowerCase()===n.toLowerCase());return t?e[t]:null}function T(e){return!!e&&/^[^@]+@[^@]+\.[^@]+$/.exec(e)!==null}i.chunk=d,i.compareByProperty=v,i.generateStringId=y,i.getCaseInsensitiveQueryParam=w,i.getParamsByName=P,i.highlightText=m,i.nameOf=C,i.replacePlaceholders=a,i.validateEmail=T,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(i,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(i=typeof globalThis<"u"?globalThis:i||self,h(i.CitrusLimeUtils={}))})(this,function(i){"use strict";function h(e,...n){let t=0;return e.replace(/{\d+}/g,()=>typeof n[t]<"u"?n[t++]:"")}function f(e,n,t="cl-bg-primary-light cl-font-bold cl-px-0.5"){const o=n.map(r=>`(${g(r)})`).join("|");return e.replace(new RegExp(o,"ig"),r=>`<span class="${t}">${r}</span>`)}function g(e){return e.replace(/[-[\]{}()*+?.,\\/^$|]/g,"\\$&")}String.prototype.similarity=function(e){let n=0,t=this.toLowerCase(),o=e.toLowerCase();if(t<o){const l=o;o=t,t=l}const r=t.length;return r===0?n=100:n=Math.round((r-d(t,o))/r*100),n},String.prototype.trimChar=function(e){return this.trimStartChar(e).trimEndChar(e)},String.prototype.trimStartChar=function(e){return e!==""&&this.startsWith(e)?this.slice(1):this},String.prototype.trimEndChar=function(e){return e!==""&&this.endsWith(e)?this.slice(0,-1):this},String.prototype.trimToLength=function(e,n=!1){const t=this.length<e?this.length:e;return n&&t>=4&&t<this.length?`${this.slice(0,Math.max(t-3,1))}...`:this.slice(0,Math.max(t,1))},String.prototype.removeWhitespace=function(){return this.replace(/\s/g,"")},String.prototype.removeNonAlphanumeric=function(){return this.replace(/[^a-zA-Z0-9]/g,"")},String.prototype.removeNonAlphabetic=function(){return this.replace(/[^a-zA-Z]/g,"")},String.prototype.removeNonNumeric=function(){return this.replace(/[^0-9]/g,"")},String.prototype.replacePlaceholders=function(...e){return h(this,...e)},String.prototype.toDateFromTime=function(){return new Date(`${new Date().toISOString().substr(0,11)}${this}`)};function d(e,n){if(e.length===0)return n.length;if(n.length===0)return e.length;if(e.length>n.length){const r=e;e=n,n=r}const t=new Int8Array(e.length+1);for(let r=0;r<=e.length;r++)t[r]=r;let o;for(let r=1;r<=n.length;r++){let l=r;const c=n[r-1];for(let a=1;a<=e.length;a++){if(c===e[a-1])o=t[a-1];else{const u=l+1,p=t[a]+1,s=u-(u-p&p-u>>7),m=t[a-1]+1;o=s-(s-m&m-s>>7)}t[a-1]=l,l=o}t[e.length]=l}return t[e.length]}function*y(e,n){for(let t=0;t<e.length;t+=n)yield e.slice(t,t+n)}function C(){return Math.random().toString(36).slice(2,8)}function v(e){return e}function P(e,n,t){return e[t]<n[t]?-1:e[t]>n[t]?1:0}function w(e,n){let t="";const o=decodeURIComponent(e),r="[\\?&]"+n+"=([^&#]*)",c=new RegExp(r).exec(o);return c&&c[1]&&(t=decodeURIComponent(c[1].replace(/\+/g," "))),t}function x(e,n){const t=Object.keys(e).find(o=>o.toLowerCase()===n.toLowerCase());return t?e[t]:null}function S(e){return!!e&&/^[^@]+@[^@]+\.[^@]+$/.exec(e)!==null}i.chunk=y,i.compareByProperty=P,i.escapeStringForRegExp=g,i.generateStringId=C,i.getCaseInsensitiveQueryParam=x,i.getParamsByName=w,i.highlightText=f,i.nameOf=v,i.replacePlaceholders=h,i.validateEmail=S,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
@@ -15,3 +15,10 @@ export declare function replacePlaceholders(value: string, ...replacements: stri
15
15
  * @returns The value as a HTML string that highlights the provided terms.
16
16
  */
17
17
  export declare function highlightText(value: string, searchTerms: string[], highlightClasses?: string): string;
18
+ /**
19
+ * Escapes a string to be used inside a RegExp expression.
20
+ *
21
+ * @param regexp The string that will be used as the body of a RegExp object and needs to be escaped.
22
+ * @returns The escaped RegExp body string.
23
+ */
24
+ export declare function escapeStringForRegExp(regexp: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citruslime/utils",
3
- "version": "2.0.3",
3
+ "version": "2.0.4-beta.1",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Citrus-Lime Ltd",