@citruslime/utils 1.2.0-beta.0 → 1.3.0-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.
@@ -2,6 +2,13 @@ function p(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("|");
7
+ return t.replace(
8
+ new RegExp(o, "ig"),
9
+ (r) => `<span class="${e}">${r}</span>`
10
+ );
11
+ }
5
12
  String.prototype.similarity = function(t) {
6
13
  let n = 0, e = this.toLowerCase(), o = t.toLowerCase();
7
14
  if (e < o) {
@@ -57,38 +64,44 @@ function g(t, n) {
57
64
  let o;
58
65
  for (let r = 1; r <= n.length; r++) {
59
66
  let i = r;
60
- const l = n[r - 1];
61
- for (let h = 1; h <= t.length; h++) {
62
- if (l === t[h - 1])
63
- o = e[h - 1];
67
+ const h = n[r - 1];
68
+ for (let l = 1; l <= t.length; l++) {
69
+ if (h === t[l - 1])
70
+ o = e[l - 1];
64
71
  else {
65
- const u = i + 1, s = e[h] + 1, c = u - (u - s & s - u >> 7), a = e[h - 1] + 1;
66
- o = c - (c - a & a - c >> 7);
72
+ const c = i + 1, s = e[l] + 1, u = c - (c - s & s - c >> 7), a = e[l - 1] + 1;
73
+ o = u - (u - a & a - u >> 7);
67
74
  }
68
- e[h - 1] = i, i = o;
75
+ e[l - 1] = i, i = o;
69
76
  }
70
77
  e[t.length] = i;
71
78
  }
72
79
  return e[t.length];
73
80
  }
74
- function m() {
81
+ function* f(t, n) {
82
+ for (let e = 0; e < t.length; e += n)
83
+ yield t.slice(e, e + n);
84
+ }
85
+ function y() {
75
86
  return Math.random().toString(36).slice(2, 8);
76
87
  }
77
- function f(t) {
88
+ function x(t) {
78
89
  return t;
79
90
  }
80
- function y(t, n, e) {
91
+ function d(t, n, e) {
81
92
  return t[e] < n[e] ? -1 : t[e] > n[e] ? 1 : 0;
82
93
  }
83
94
  function C(t, n) {
84
95
  let e = "";
85
- const o = decodeURIComponent(t), r = "[\\?&]" + n + "=([^&#]*)", l = new RegExp(r).exec(o);
86
- return l && l[1] && (e = decodeURIComponent(l[1].replace(/\+/g, " "))), e;
96
+ const o = decodeURIComponent(t), r = "[\\?&]" + n + "=([^&#]*)", h = new RegExp(r).exec(o);
97
+ return h && h[1] && (e = decodeURIComponent(h[1].replace(/\+/g, " "))), e;
87
98
  }
88
99
  export {
89
- y as compareByProperty,
90
- m as generateStringId,
100
+ f as chunk,
101
+ d as compareByProperty,
102
+ y as generateStringId,
91
103
  C as getParamsByName,
92
- f as nameOf,
104
+ m as highlightText,
105
+ x as nameOf,
93
106
  p as replacePlaceholders
94
107
  };
@@ -1 +1 @@
1
- (function(o,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(o=typeof globalThis<"u"?globalThis:o||self,u(o.CitrusLimeUtils={}))})(this,function(o){"use strict";function u(e,...n){let t=0;return e.replace(/{\d+}/g,()=>typeof n[t]<"u"?n[t++]:"")}String.prototype.similarity=function(e){let n=0,t=this.toLowerCase(),i=e.toLowerCase();if(t<i){const l=i;i=t,t=l}const r=t.length;return r===0?n=100:n=Math.round((r-m(t,i))/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 u(this,...e)},String.prototype.toDateFromTime=function(){return new Date(`${new Date().toISOString().substr(0,11)}${this}`)};function m(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 i;for(let r=1;r<=n.length;r++){let l=r;const a=n[r-1];for(let h=1;h<=e.length;h++){if(a===e[h-1])i=t[h-1];else{const c=l+1,p=t[h]+1,s=c-(c-p&p-c>>7),g=t[h-1]+1;i=s-(s-g&g-s>>7)}t[h-1]=l,l=i}t[e.length]=l}return t[e.length]}function f(){return Math.random().toString(36).slice(2,8)}function d(e){return e}function y(e,n,t){return e[t]<n[t]?-1:e[t]>n[t]?1:0}function C(e,n){let t="";const i=decodeURIComponent(e),r="[\\?&]"+n+"=([^&#]*)",a=new RegExp(r).exec(i);return a&&a[1]&&(t=decodeURIComponent(a[1].replace(/\+/g," "))),t}o.compareByProperty=y,o.generateStringId=f,o.getParamsByName=C,o.nameOf=d,o.replacePlaceholders=u,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(o,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o.CitrusLimeUtils={}))})(this,function(o){"use strict";function c(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 i=n.map(r=>`(${r})`).join("|");return e.replace(new RegExp(i,"ig"),r=>`<span class="${t}">${r}</span>`)}String.prototype.similarity=function(e){let n=0,t=this.toLowerCase(),i=e.toLowerCase();if(t<i){const l=i;i=t,t=l}const r=t.length;return r===0?n=100:n=Math.round((r-f(t,i))/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 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 i;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])i=t[h-1];else{const a=l+1,g=t[h]+1,s=a-(a-g&g-a>>7),p=t[h-1]+1;i=s-(s-p&p-s>>7)}t[h-1]=l,l=i}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 T(e,n,t){return e[t]<n[t]?-1:e[t]>n[t]?1:0}function b(e,n){let t="";const i=decodeURIComponent(e),r="[\\?&]"+n+"=([^&#]*)",u=new RegExp(r).exec(i);return u&&u[1]&&(t=decodeURIComponent(u[1].replace(/\+/g," "))),t}o.chunk=d,o.compareByProperty=T,o.generateStringId=y,o.getParamsByName=b,o.highlightText=m,o.nameOf=C,o.replacePlaceholders=c,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A generator function which splits a string or array into chunks.
3
+ *
4
+ * @param value The value to split.
5
+ * @param size The size of each chunk.
6
+ * @yields The chunks.
7
+ */
8
+ export declare function chunk<T>(value: string | T[], size: number): Generator<string | T[], any, undefined>;
@@ -1,6 +1,7 @@
1
1
  export {} from './extensions/string';
2
+ export * from './chunk';
2
3
  export * from './id';
3
4
  export * from './name-of';
4
5
  export * from './sort';
5
- export * from './string-functions';
6
+ export * from './strings';
6
7
  export * from './url-params';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Replace placeholders within a string.
3
+ *
4
+ * @param value The string to replace the placeholders for.
5
+ * @param {...any} replacements The replacements.
6
+ * @returns The original value with the replacements replaced.
7
+ */
8
+ export declare function replacePlaceholders(value: string, ...replacements: string[]): string;
9
+ /**
10
+ * Wraps specified search terms, found in the provided text, with a set of highlight classes.
11
+ *
12
+ * @param value The value to highlight the contents of.
13
+ * @param searchTerms The search terms to find in the provided value.
14
+ * @param highlightClasses The classes to be used to highlight the text.
15
+ * @returns The value as a HTML string that highlights the provided terms.
16
+ */
17
+ export declare function highlightText(value: string, searchTerms: string[], highlightClasses?: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citruslime/utils",
3
- "version": "1.2.0-beta.0",
3
+ "version": "1.3.0-beta.0",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Citrus-Lime Ltd",
@@ -1,8 +0,0 @@
1
- /**
2
- * Replace placeholders within a string.
3
- *
4
- * @param value The string to replace the placeholders for.
5
- * @param {...any} replacements The replacements.
6
- * @returns The original value with the replacements replaced.
7
- */
8
- export declare function replacePlaceholders(value: string, ...replacements: string[]): string;