@appartmint/mint 0.15.4 → 0.15.6

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,25 +2,64 @@
2
2
  * Functions for analyzing and manipulating text.
3
3
  */
4
4
  export abstract class mintText {
5
- /*static fitContainer () {
6
- let $warning: JQuery<HTMLElement> = $(warningSelector);
7
- $warning.css({
8
- overflow: 'scroll',
9
- fontSize: ''
10
- });
11
- while (($warning?.[0].scrollHeight ?? Number.MIN_SAFE_INTEGER) > ($warning?.innerHeight() ?? Number.MAX_SAFE_INTEGER)) {
12
- let fontSize: number = parseInt($warning.css('font-size')) - 1;
13
- $warning.css('font-size', fontSize + 'px');
14
- }
15
- }*/
16
5
 
17
6
  /**
18
7
  * Generate a slug from a string
19
- * @param str - The string to slugify
8
+ * @param text - The string to slugify
20
9
  * @returns The slugified string
21
10
  */
22
- static slug (str: string): string {
23
- return str.toLowerCase().replace(/\W+/g, '-').replace(/^-+|-+$/g, '');
11
+ static slug (text?: string): string {
12
+ return text?.toLowerCase().replace(/\W+/g, '-').replace(/^-+|-+$/g, '') ?? '';
13
+ }
14
+
15
+ /**
16
+ * Format a phone number
17
+ * @param phone - The phone number to format
18
+ * @returns The formatted phone number
19
+ */
20
+ static phone (phone?: string | number): string {
21
+ const given = phone?.toString().trim() ?? '';
22
+ if (given === '(' || given === '') {
23
+ return given;
24
+ }
25
+
26
+ let numbers = given.replace(/\D/g, '') ?? '',
27
+ formatted = '';
28
+
29
+ if (numbers.length > 10) {
30
+ formatted += `+${numbers.slice(0, numbers.length - 10)} `;
31
+ numbers = numbers.slice(numbers.length - 10);
32
+ }
33
+
34
+ for (var i = 0; i < numbers.length; i++) {
35
+ switch (i) {
36
+ case 0:
37
+ formatted += '(';
38
+ break;
39
+ case 3:
40
+ formatted += ') ';
41
+ break;
42
+ case 6:
43
+ formatted += '-';
44
+ break;
45
+ }
46
+ formatted += numbers[i];
47
+ }
48
+
49
+ switch (given[given.length - 1]) {
50
+ case ')':
51
+ if (i === 3) {
52
+ formatted += ') ';
53
+ }
54
+ break;
55
+ case '-':
56
+ if (i === 6) {
57
+ formatted += '-';
58
+ }
59
+ break;
60
+ }
61
+
62
+ return formatted;
24
63
  }
25
64
 
26
65
  /**