@citruslime/utils 1.1.0 → 1.1.1-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.
@@ -1,16 +1,6 @@
1
- function g() {
2
- return Math.random().toString(36).slice(2, 8);
3
- }
4
- function m(t) {
5
- return t;
6
- }
7
- function f(t, n, e) {
8
- return t[e] < n[e] ? -1 : t[e] > n[e] ? 1 : 0;
9
- }
10
- function y(t, n) {
11
- let e = "";
12
- const o = decodeURIComponent(t), r = "[\\?&]" + n + "=([^&#]*)", l = new RegExp(r).exec(o);
13
- return l && l[1] && (e = decodeURIComponent(l[1].replace(/\+/g, " "))), e;
1
+ function p(t, ...n) {
2
+ let e = 0;
3
+ return t.replace(/{\d+}/g, () => typeof n[e] < "u" ? n[e++] : "");
14
4
  }
15
5
  String.prototype.similarity = function(t) {
16
6
  let n = 0, e = this.toLowerCase(), o = t.toLowerCase();
@@ -19,7 +9,7 @@ String.prototype.similarity = function(t) {
19
9
  o = e, e = i;
20
10
  }
21
11
  const r = e.length;
22
- return r === 0 ? n = 100 : n = Math.round((r - p(e, o)) / r * 100), n;
12
+ return r === 0 ? n = 100 : n = Math.round((r - g(e, o)) / r * 100), n;
23
13
  };
24
14
  String.prototype.trimChar = function(t) {
25
15
  return this.trimStartChar(t).trimEndChar(t);
@@ -47,13 +37,12 @@ String.prototype.removeNonNumeric = function() {
47
37
  return this.replace(/[^0-9]/g, "");
48
38
  };
49
39
  String.prototype.replacePlaceholders = function(...t) {
50
- let n = 0;
51
- return this.replace(/{\d+}/g, () => typeof t[n] < "u" ? t[n++] : "");
40
+ return p(this, ...t);
52
41
  };
53
42
  String.prototype.toDateFromTime = function() {
54
43
  return new Date(`${new Date().toISOString().substr(0, 11)}${this}`);
55
44
  };
56
- function p(t, n) {
45
+ function g(t, n) {
57
46
  if (t.length === 0)
58
47
  return n.length;
59
48
  if (n.length === 0)
@@ -82,9 +71,24 @@ function p(t, n) {
82
71
  }
83
72
  return e[t.length];
84
73
  }
74
+ function m() {
75
+ return Math.random().toString(36).slice(2, 8);
76
+ }
77
+ function f(t) {
78
+ return t;
79
+ }
80
+ function y(t, n, e) {
81
+ return t[e] < n[e] ? -1 : t[e] > n[e] ? 1 : 0;
82
+ }
83
+ function C(t, n) {
84
+ 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;
87
+ }
85
88
  export {
86
- f as compareByProperty,
87
- g as generateStringId,
88
- y as getParamsByName,
89
- m as nameOf
89
+ y as compareByProperty,
90
+ m as generateStringId,
91
+ C as getParamsByName,
92
+ f as nameOf,
93
+ p as replacePlaceholders
90
94
  };
@@ -1 +1 @@
1
- (function(i,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(i=typeof globalThis<"u"?globalThis:i||self,u(i.CitrusLimeUtils={}))})(this,function(i){"use strict";function u(){return Math.random().toString(36).slice(2,8)}function g(e){return e}function f(e,n,t){return e[t]<n[t]?-1:e[t]>n[t]?1:0}function y(e,n){let t="";const o=decodeURIComponent(e),r="[\\?&]"+n+"=([^&#]*)",s=new RegExp(r).exec(o);return s&&s[1]&&(t=decodeURIComponent(s[1].replace(/\+/g," "))),t}String.prototype.similarity=function(e){let n=0,t=this.toLowerCase(),o=e.toLowerCase();if(t<o){const h=o;o=t,t=h}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){let n=0;return this.replace(/{\d+}/g,()=>typeof e[n]<"u"?e[n++]:"")},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 h=r;const s=n[r-1];for(let l=1;l<=e.length;l++){if(s===e[l-1])o=t[l-1];else{const a=h+1,p=t[l]+1,c=a-(a-p&p-a>>7),m=t[l-1]+1;o=c-(c-m&m-c>>7)}t[l-1]=h,h=o}t[e.length]=h}return t[e.length]}i.compareByProperty=f,i.generateStringId=u,i.getParamsByName=y,i.nameOf=g,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
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,5 +1,6 @@
1
+ export {} from './extensions/string';
1
2
  export * from './id';
2
3
  export * from './name-of';
3
4
  export * from './sort';
5
+ export * from './string-functions';
4
6
  export * from './url-params';
5
- export {} from './extensions/string';
@@ -0,0 +1,8 @@
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citruslime/utils",
3
- "version": "1.1.0",
3
+ "version": "1.1.1-beta.0",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Citrus-Lime Ltd",