@citruslime/utils 2.0.6 → 2.0.7-beta.0
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/README.md
CHANGED
|
@@ -9,7 +9,7 @@ A package containing utilities for JavaScript & TypeScript projects. Used by [Ci
|
|
|
9
9
|
- 📖 [Documentation & API](https://uilibrary.citruslime.com)
|
|
10
10
|
- 📌 [Citrus-Lime Ltd](https://www.citruslime.com)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
## Install
|
|
13
13
|
|
|
14
14
|
`pnpm add @citruslime/utils`
|
|
15
15
|
|
|
@@ -3,7 +3,7 @@ function g(t, ...n) {
|
|
|
3
3
|
return t.replace(/{\d+}/g, () => typeof n[e] < "u" ? n[e++] : "");
|
|
4
4
|
}
|
|
5
5
|
function f(t, n, e = "cl:bg-primary-light cl:font-bold") {
|
|
6
|
-
const o = n.map((r) => `(${p(r)})`).join("|");
|
|
6
|
+
const o = n.filter((r) => !!(r != null && r.trim())).map((r) => `(${p(r)})`).join("|");
|
|
7
7
|
return t.replace(
|
|
8
8
|
new RegExp(o, "ig"),
|
|
9
9
|
(r) => `<span class="${e}">${r}</span>`
|
|
@@ -94,19 +94,19 @@ function d(t) {
|
|
|
94
94
|
function C(t, n, e) {
|
|
95
95
|
return t[e] < n[e] ? -1 : t[e] > n[e] ? 1 : 0;
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function w(t, n) {
|
|
98
98
|
let e = "";
|
|
99
99
|
const o = decodeURIComponent(t), r = "[\\?&]" + n + "=([^&#]*)", h = new RegExp(r).exec(o);
|
|
100
100
|
return h && h[1] && (e = decodeURIComponent(h[1].replace(/\+/g, " "))), e;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function T(t, n) {
|
|
103
103
|
const e = Object.keys(t).find((o) => o.toLowerCase() === n.toLowerCase());
|
|
104
104
|
return e ? t[e] : null;
|
|
105
105
|
}
|
|
106
|
-
function
|
|
106
|
+
function $(t) {
|
|
107
107
|
return !!t && /^[^@]+@[^@]+\.[^@]+$/.exec(t) !== null;
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function v() {
|
|
110
110
|
return navigator && "maxTouchPoints" in navigator && navigator.maxTouchPoints > 0;
|
|
111
111
|
}
|
|
112
112
|
export {
|
|
@@ -114,11 +114,11 @@ export {
|
|
|
114
114
|
C as compareByProperty,
|
|
115
115
|
p as escapeStringForRegExp,
|
|
116
116
|
x as generateStringId,
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
T as getCaseInsensitiveQueryParam,
|
|
118
|
+
w as getParamsByName,
|
|
119
119
|
f as highlightText,
|
|
120
|
-
|
|
120
|
+
v as isTouchDevice,
|
|
121
121
|
d as nameOf,
|
|
122
122
|
g as replacePlaceholders,
|
|
123
|
-
|
|
123
|
+
$ as validateEmail
|
|
124
124
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i.CitrusLimeUtils={}))})(this,function(i){"use strict";function c(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"){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 c(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 h=n[r-1];for(let a=1;a<=e.length;a++){if(h===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
|
|
1
|
+
(function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i.CitrusLimeUtils={}))})(this,function(i){"use strict";function c(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"){const o=n.filter(r=>!!(r!=null&&r.trim())).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 c(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 h=n[r-1];for(let a=1;a<=e.length;a++){if(h===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 T(e){return e}function P(e,n,t){return e[t]<n[t]?-1:e[t]>n[t]?1:0}function v(e,n){let t="";const o=decodeURIComponent(e),r="[\\?&]"+n+"=([^&#]*)",h=new RegExp(r).exec(o);return h&&h[1]&&(t=decodeURIComponent(h[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 x(e){return!!e&&/^[^@]+@[^@]+\.[^@]+$/.exec(e)!==null}function S(){return navigator&&"maxTouchPoints"in navigator&&navigator.maxTouchPoints>0}i.chunk=y,i.compareByProperty=P,i.escapeStringForRegExp=g,i.generateStringId=C,i.getCaseInsensitiveQueryParam=w,i.getParamsByName=v,i.highlightText=f,i.isTouchDevice=S,i.nameOf=T,i.replacePlaceholders=c,i.validateEmail=x,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|