@citruslime/utils 2.0.4-beta.0 → 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.
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
function
|
|
1
|
+
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
|
|
6
|
-
|
|
7
|
-
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("|");
|
|
8
7
|
return t.replace(
|
|
9
8
|
new RegExp(o, "ig"),
|
|
10
9
|
(r) => `<span class="${e}">${r}</span>`
|
|
11
10
|
);
|
|
12
11
|
}
|
|
12
|
+
function p(t) {
|
|
13
|
+
return t.replace(/[-[\]{}()*+?.,\\/^$|]/g, "\\$&");
|
|
14
|
+
}
|
|
13
15
|
String.prototype.similarity = function(t) {
|
|
14
16
|
let n = 0, e = this.toLowerCase(), o = t.toLowerCase();
|
|
15
17
|
if (e < o) {
|
|
@@ -17,7 +19,7 @@ String.prototype.similarity = function(t) {
|
|
|
17
19
|
o = e, e = i;
|
|
18
20
|
}
|
|
19
21
|
const r = e.length;
|
|
20
|
-
return r === 0 ? n = 100 : n = Math.round((r -
|
|
22
|
+
return r === 0 ? n = 100 : n = Math.round((r - m(e, o)) / r * 100), n;
|
|
21
23
|
};
|
|
22
24
|
String.prototype.trimChar = function(t) {
|
|
23
25
|
return this.trimStartChar(t).trimEndChar(t);
|
|
@@ -45,12 +47,12 @@ String.prototype.removeNonNumeric = function() {
|
|
|
45
47
|
return this.replace(/[^0-9]/g, "");
|
|
46
48
|
};
|
|
47
49
|
String.prototype.replacePlaceholders = function(...t) {
|
|
48
|
-
return
|
|
50
|
+
return g(this, ...t);
|
|
49
51
|
};
|
|
50
52
|
String.prototype.toDateFromTime = function() {
|
|
51
53
|
return /* @__PURE__ */ new Date(`${(/* @__PURE__ */ new Date()).toISOString().substr(0, 11)}${this}`);
|
|
52
54
|
};
|
|
53
|
-
function
|
|
55
|
+
function m(t, n) {
|
|
54
56
|
if (t.length === 0)
|
|
55
57
|
return n.length;
|
|
56
58
|
if (n.length === 0)
|
|
@@ -70,8 +72,8 @@ function g(t, n) {
|
|
|
70
72
|
if (h === t[l - 1])
|
|
71
73
|
o = e[l - 1];
|
|
72
74
|
else {
|
|
73
|
-
const c = i + 1,
|
|
74
|
-
o = a - (a -
|
|
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);
|
|
75
77
|
}
|
|
76
78
|
e[l - 1] = i, i = o;
|
|
77
79
|
}
|
|
@@ -79,25 +81,25 @@ function g(t, n) {
|
|
|
79
81
|
}
|
|
80
82
|
return e[t.length];
|
|
81
83
|
}
|
|
82
|
-
function*
|
|
84
|
+
function* y(t, n) {
|
|
83
85
|
for (let e = 0; e < t.length; e += n)
|
|
84
86
|
yield t.slice(e, e + n);
|
|
85
87
|
}
|
|
86
|
-
function
|
|
88
|
+
function x() {
|
|
87
89
|
return Math.random().toString(36).slice(2, 8);
|
|
88
90
|
}
|
|
89
|
-
function
|
|
91
|
+
function d(t) {
|
|
90
92
|
return t;
|
|
91
93
|
}
|
|
92
|
-
function
|
|
94
|
+
function C(t, n, e) {
|
|
93
95
|
return t[e] < n[e] ? -1 : t[e] > n[e] ? 1 : 0;
|
|
94
96
|
}
|
|
95
|
-
function
|
|
97
|
+
function w(t, n) {
|
|
96
98
|
let e = "";
|
|
97
99
|
const o = decodeURIComponent(t), r = "[\\?&]" + n + "=([^&#]*)", h = new RegExp(r).exec(o);
|
|
98
100
|
return h && h[1] && (e = decodeURIComponent(h[1].replace(/\+/g, " "))), e;
|
|
99
101
|
}
|
|
100
|
-
function
|
|
102
|
+
function $(t, n) {
|
|
101
103
|
const e = Object.keys(t).find((o) => o.toLowerCase() === n.toLowerCase());
|
|
102
104
|
return e ? t[e] : null;
|
|
103
105
|
}
|
|
@@ -105,13 +107,14 @@ function v(t) {
|
|
|
105
107
|
return !!t && /^[^@]+@[^@]+\.[^@]+$/.exec(t) !== null;
|
|
106
108
|
}
|
|
107
109
|
export {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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,
|
|
118
|
+
g as replacePlaceholders,
|
|
116
119
|
v as validateEmail
|
|
117
120
|
};
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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"})});
|
package/dist/utils/strings.d.ts
CHANGED
|
@@ -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;
|