@citruslime/utils 1.0.0-beta.1 → 1.0.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Citrus-Lime Utils
2
2
 
3
- A TypeScript package containing utilities for any JavaScript or TypeScript project. Used by the [Citrus-Lime UI](https://www.npmjs.com/package/@citruslime/ui) package.
3
+ A TypeScript package containing utilities for any JavaScript or TypeScript project. Used by [Citrus-Lime UI](https://www.npmjs.com/package/@citruslime/ui).
4
4
 
5
5
  ![version](https://img.shields.io/npm/v/@citruslime/utils/latest)
6
6
  ![version next](https://img.shields.io/npm/v/@citruslime/utils/next)
@@ -1,52 +1,38 @@
1
- function generateStringId() {
1
+ function g() {
2
2
  return Math.random().toString(36).slice(2, 8);
3
3
  }
4
- function nameOf(name) {
5
- return name;
4
+ function m(t) {
5
+ return t;
6
6
  }
7
- function compareByProperty(firstValue, secondValue, property) {
8
- return firstValue[property] < secondValue[property] ? -1 : firstValue[property] > secondValue[property] ? 1 : 0;
7
+ function f(t, n, e) {
8
+ return t[e] < n[e] ? -1 : t[e] > n[e] ? 1 : 0;
9
9
  }
10
- function getParamsByName(stringToSearch, paramToFind) {
11
- let valueToReturn = "";
12
- const urlToSearch = decodeURIComponent(stringToSearch);
13
- const regexS = "[\\?&]" + paramToFind + "=([^&#]*)";
14
- const regex = new RegExp(regexS);
15
- const results = regex.exec(urlToSearch);
16
- if (results && results[1]) {
17
- valueToReturn = decodeURIComponent(results[1].replace(/\+/g, " "));
18
- }
19
- return valueToReturn;
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;
20
14
  }
21
- String.prototype.similarity = function(comparisonString) {
22
- let similarityToReturn = 0;
23
- let longerString = this.toLowerCase();
24
- let shorterString = comparisonString.toLowerCase();
25
- if (longerString < shorterString) {
26
- const temp = shorterString;
27
- shorterString = longerString;
28
- longerString = temp;
29
- }
30
- const longerLength = longerString.length;
31
- if (longerLength === 0) {
32
- similarityToReturn = 100;
33
- } else {
34
- similarityToReturn = Math.round((longerLength - levenshtein(longerString, shorterString)) / longerLength * 100);
15
+ String.prototype.similarity = function(t) {
16
+ let n = 0, e = this.toLowerCase(), o = t.toLowerCase();
17
+ if (e < o) {
18
+ const i = o;
19
+ o = e, e = i;
35
20
  }
36
- return similarityToReturn;
21
+ const r = e.length;
22
+ return r === 0 ? n = 100 : n = Math.round((r - p(e, o)) / r * 100), n;
37
23
  };
38
- String.prototype.trimChar = function(character) {
39
- return this.trimStartChar(character).trimEndChar(character);
24
+ String.prototype.trimChar = function(t) {
25
+ return this.trimStartChar(t).trimEndChar(t);
40
26
  };
41
- String.prototype.trimStartChar = function(character) {
42
- return character !== "" && this.startsWith(character) ? this.slice(1) : this;
27
+ String.prototype.trimStartChar = function(t) {
28
+ return t !== "" && this.startsWith(t) ? this.slice(1) : this;
43
29
  };
44
- String.prototype.trimEndChar = function(character) {
45
- return character !== "" && this.endsWith(character) ? this.slice(0, -1) : this;
30
+ String.prototype.trimEndChar = function(t) {
31
+ return t !== "" && this.endsWith(t) ? this.slice(0, -1) : this;
46
32
  };
47
- String.prototype.trimToLength = function(length, addEllipsis = false) {
48
- const trimLength = this.length < length ? this.length : length;
49
- return addEllipsis && trimLength >= 4 && trimLength < this.length ? `${this.slice(0, Math.max(trimLength - 3, 1))}...` : this.slice(0, Math.max(trimLength, 1));
33
+ String.prototype.trimToLength = function(t, n = !1) {
34
+ const e = this.length < t ? this.length : t;
35
+ return n && e >= 4 && e < this.length ? `${this.slice(0, Math.max(e - 3, 1))}...` : this.slice(0, Math.max(e, 1));
50
36
  };
51
37
  String.prototype.removeWhitespace = function() {
52
38
  return this.replace(/\s/g, "");
@@ -60,48 +46,45 @@ String.prototype.removeNonAlphabetic = function() {
60
46
  String.prototype.removeNonNumeric = function() {
61
47
  return this.replace(/[^0-9]/g, "");
62
48
  };
63
- String.prototype.replacePlaceholders = function(...args) {
64
- let i = 0;
65
- return this.replace(/{\d+}/g, () => typeof args[i] !== "undefined" ? args[i++] : "");
49
+ String.prototype.replacePlaceholders = function(...t) {
50
+ let n = 0;
51
+ return this.replace(/{\d+}/g, () => typeof t[n] < "u" ? t[n++] : "");
66
52
  };
67
53
  String.prototype.toDateFromTime = function() {
68
54
  return new Date(`${new Date().toISOString().substr(0, 11)}${this}`);
69
55
  };
70
- function levenshtein(firstString, secondString) {
71
- if (firstString.length === 0) {
72
- return secondString.length;
73
- }
74
- if (secondString.length === 0) {
75
- return firstString.length;
56
+ function p(t, n) {
57
+ if (t.length === 0)
58
+ return n.length;
59
+ if (n.length === 0)
60
+ return t.length;
61
+ if (t.length > n.length) {
62
+ const r = t;
63
+ t = n, n = r;
76
64
  }
77
- if (firstString.length > secondString.length) {
78
- const tmp = firstString;
79
- firstString = secondString;
80
- secondString = tmp;
81
- }
82
- const row = new Int8Array(firstString.length + 1);
83
- for (let i = 0; i <= firstString.length; i++) {
84
- row[i] = i;
85
- }
86
- let temp;
87
- for (let i = 1; i <= secondString.length; i++) {
88
- let prev = i;
89
- const previousChar = secondString[i - 1];
90
- for (let j = 1; j <= firstString.length; j++) {
91
- if (previousChar === firstString[j - 1]) {
92
- temp = row[j - 1];
93
- } else {
94
- const a = prev + 1;
95
- const b = row[j] + 1;
96
- const c = a - (a - b & b - a >> 7);
97
- const d = row[j - 1] + 1;
98
- temp = c - (c - d & d - c >> 7);
65
+ const e = new Int8Array(t.length + 1);
66
+ for (let r = 0; r <= t.length; r++)
67
+ e[r] = r;
68
+ let o;
69
+ for (let r = 1; r <= n.length; r++) {
70
+ let i = r;
71
+ const l = n[r - 1];
72
+ for (let h = 1; h <= t.length; h++) {
73
+ if (l === t[h - 1])
74
+ o = e[h - 1];
75
+ else {
76
+ const u = i + 1, s = e[h] + 1, c = u - (u - s & s - u >> 7), a = e[h - 1] + 1;
77
+ o = c - (c - a & a - c >> 7);
99
78
  }
100
- row[j - 1] = prev;
101
- prev = temp;
79
+ e[h - 1] = i, i = o;
102
80
  }
103
- row[firstString.length] = prev;
81
+ e[t.length] = i;
104
82
  }
105
- return row[firstString.length];
83
+ return e[t.length];
106
84
  }
107
- export { compareByProperty, generateStringId, getParamsByName, nameOf };
85
+ export {
86
+ f as compareByProperty,
87
+ g as generateStringId,
88
+ y as getParamsByName,
89
+ m as nameOf
90
+ };
@@ -1 +1 @@
1
- (function(i,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(i=typeof globalThis!="undefined"?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 d(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 l=o;o=t,t=l}const r=t.length;return r===0?n=100:n=Math.round((r-y(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]!="undefined"?e[n++]:"")},String.prototype.toDateFromTime=function(){return new Date(`${new Date().toISOString().substr(0,11)}${this}`)};function y(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 s=n[r-1];for(let h=1;h<=e.length;h++){if(s===e[h-1])o=t[h-1];else{const a=l+1,p=t[h]+1,c=a-(a-p&p-a>>7),m=t[h-1]+1;o=c-(c-m&m-c>>7)}t[h-1]=l,l=o}t[e.length]=l}return t[e.length]}i.compareByProperty=f,i.generateStringId=u,i.getParamsByName=d,i.nameOf=g,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
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 d(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 l=o;o=t,t=l}const r=t.length;return r===0?n=100:n=Math.round((r-y(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 y(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 s=n[r-1];for(let h=1;h<=e.length;h++){if(s===e[h-1])o=t[h-1];else{const a=l+1,p=t[h]+1,c=a-(a-p&p-a>>7),m=t[h-1]+1;o=c-(c-m&m-c>>7)}t[h-1]=l,l=o}t[e.length]=l}return t[e.length]}i.compareByProperty=f,i.generateStringId=u,i.getParamsByName=d,i.nameOf=g,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/dist/env.d.ts ADDED
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@citruslime/utils",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.1-beta.0",
4
+ "type": "module",
4
5
  "author": {
5
6
  "name": "Citrus-Lime Ltd",
6
7
  "url": "https://citruslime.com"
@@ -13,6 +14,9 @@
13
14
  "files": [
14
15
  "dist"
15
16
  ],
17
+ "maintainers": [
18
+ "Citrus-Lime"
19
+ ],
16
20
  "main": "dist/citrus-lime-utils.umd.js",
17
21
  "module": "dist/citrus-lime-utils.es.js",
18
22
  "types": "dist/main.d.ts",
@@ -24,10 +28,5 @@
24
28
  },
25
29
  "scripts": {
26
30
  "build": "vite build && copyfiles -u 2 \"dist/src/**/*\" dist && del-cli dist/src"
27
- },
28
- "devDependencies": {
29
- "copyfiles": "^2.4.1",
30
- "del-cli": "^4.0.1",
31
- "vite-plugin-dts": "^0.9.10"
32
31
  }
33
32
  }