@indodev/toolkit 0.3.1 → 0.3.3

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,4 +1,202 @@
1
- export { C as CompareOptions, E as ExtractOptions, m as SanitizeOptions, S as SlugifyOptions, T as TitleCaseOptions, o as TruncateOptions, c as capitalize, k as compareStrings, d as contractAbbreviation, e as expandAbbreviation, g as extractWords, j as isAlay, n as normalizeWhitespace, p as profanityFilter, r as removeAccents, h as removeStopwords, b as sanitize, l as similarity, s as slugify, i as toFormal, a as toSentenceCase, t as toTitleCase, f as truncate } from '../compare-CZadJMGl.cjs';
1
+ import { M as MaskOptions } from '../compare-Ku_8OhuU.cjs';
2
+ export { C as CompareOptions, E as ExtractOptions, m as SanitizeOptions, S as SlugifyOptions, T as TitleCaseOptions, o as TruncateOptions, c as capitalize, k as compareStrings, d as contractAbbreviation, e as expandAbbreviation, g as extractWords, j as isAlay, n as normalizeWhitespace, p as profanityFilter, r as removeAccents, h as removeStopwords, b as sanitize, l as similarity, s as slugify, i as toFormal, a as toSentenceCase, t as toTitleCase, f as truncate } from '../compare-Ku_8OhuU.cjs';
3
+
4
+ /**
5
+ * Mask sensitive text based on predefined patterns or custom configuration
6
+ *
7
+ * This function provides privacy-compliant data display by masking portions
8
+ * of text while keeping certain parts visible. Supports multiple masking
9
+ * patterns for different use cases.
10
+ *
11
+ * **Available Patterns:**
12
+ * - `all`: Masks all characters (preserves spaces)
13
+ * - `middle`: Keeps start and end characters visible, masks the middle
14
+ * - `email`: Keeps first 2 chars of local part and full domain visible
15
+ *
16
+ * @param text - The text to mask
17
+ * @param options - Masking configuration options
18
+ * @returns The masked text
19
+ *
20
+ * @example
21
+ * Mask all characters:
22
+ * ```typescript
23
+ * maskText('Budi Santoso', { pattern: 'all' })
24
+ * // → '**** *******'
25
+ *
26
+ * maskText('123456789', { pattern: 'all', maskChar: '#' })
27
+ * // → '#########'
28
+ * ```
29
+ *
30
+ * @example
31
+ * Mask middle portion:
32
+ * ```typescript
33
+ * maskText('08123456789', { pattern: 'middle', visibleStart: 4, visibleEnd: 3 })
34
+ * // → '0812****789'
35
+ *
36
+ * maskText('ABCDEF', { pattern: 'middle' })
37
+ * // → 'AB**EF' (defaults: visibleStart=2, visibleEnd=2)
38
+ * ```
39
+ *
40
+ * @example
41
+ * Mask email:
42
+ * ```typescript
43
+ * maskText('user@example.com', { pattern: 'email' })
44
+ * // → 'us**@example.com'
45
+ *
46
+ * maskText('a@test.com', { pattern: 'email' })
47
+ * // → 'a*@test.com'
48
+ * ```
49
+ *
50
+ * @example
51
+ * Edge cases:
52
+ * ```typescript
53
+ * maskText('')
54
+ * // → ''
55
+ *
56
+ * maskText('AB', { pattern: 'middle', visibleStart: 2, visibleEnd: 2 })
57
+ * // → '**' (string too short, mask all)
58
+ * ```
59
+ *
60
+ * @public
61
+ */
62
+ declare function maskText(text: string, options?: MaskOptions): string;
63
+
64
+ /**
65
+ * Convert text to camelCase
66
+ *
67
+ * Treats spaces, hyphens, and underscores as word boundaries.
68
+ * Strips all other special characters. First word is lowercase.
69
+ *
70
+ * @param text - The text to convert
71
+ * @returns camelCase string
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * toCamelCase('hello-world')
76
+ * // → 'helloWorld'
77
+ *
78
+ * toCamelCase('hello_world')
79
+ * // → 'helloWorld'
80
+ *
81
+ * toCamelCase('Hello World')
82
+ * // → 'helloWorld'
83
+ *
84
+ * toCamelCase('')
85
+ * // → ''
86
+ * ```
87
+ *
88
+ * @public
89
+ */
90
+ declare function toCamelCase(text: string): string;
91
+ /**
92
+ * Convert text to PascalCase
93
+ *
94
+ * Treats spaces, hyphens, and underscores as word boundaries.
95
+ * Strips all other special characters. Every word is capitalized.
96
+ *
97
+ * @param text - The text to convert
98
+ * @returns PascalCase string
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * toPascalCase('hello_world')
103
+ * // → 'HelloWorld'
104
+ *
105
+ * toPascalCase('hello-world')
106
+ * // → 'HelloWorld'
107
+ *
108
+ * toPascalCase('hello world')
109
+ * // → 'HelloWorld'
110
+ *
111
+ * toPascalCase('')
112
+ * // → ''
113
+ * ```
114
+ *
115
+ * @public
116
+ */
117
+ declare function toPascalCase(text: string): string;
118
+ /**
119
+ * Convert text to snake_case
120
+ *
121
+ * Treats spaces, hyphens, and camelCase boundaries as word separators.
122
+ * Strips all other special characters. All lowercase with underscores.
123
+ *
124
+ * @param text - The text to convert
125
+ * @returns snake_case string
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * toSnakeCase('helloWorld')
130
+ * // → 'hello_world'
131
+ *
132
+ * toSnakeCase('Hello-World')
133
+ * // → 'hello_world'
134
+ *
135
+ * toSnakeCase('Hello World')
136
+ * // → 'hello_world'
137
+ *
138
+ * toSnakeCase('')
139
+ * // → ''
140
+ * ```
141
+ *
142
+ * @public
143
+ */
144
+ declare function toSnakeCase(text: string): string;
145
+
146
+ /**
147
+ * Count the number of syllables in an Indonesian word
148
+ *
149
+ * Uses algorithm-based vowel counting with Indonesian dipthong awareness.
150
+ * Works for both Indonesian and English text.
151
+ *
152
+ * **Syllable Detection Rules:**
153
+ * - Each vowel group (a, i, u, e, o) counts as one syllable
154
+ * - Dipthongs (ai, au, oi) count as a single vowel sound
155
+ * - Silent 'e' at the end is handled
156
+ * - Minimum 1 syllable for any word with letters
157
+ *
158
+ * @param text - The word or text to count syllables in
159
+ * @returns The number of syllables
160
+ *
161
+ * @example
162
+ * Indonesian words:
163
+ * ```typescript
164
+ * countSyllables('buku')
165
+ * // → 2 (bu-ku)
166
+ *
167
+ * countSyllables('matahari')
168
+ * // → 4 (ma-ta-ha-ri)
169
+ *
170
+ * countSyllables('pulau')
171
+ * // → 2 (pu-lau, dipthong 'au' counts as one)
172
+ * ```
173
+ *
174
+ * @example
175
+ * English words:
176
+ * ```typescript
177
+ * countSyllables('hello')
178
+ * // → 2 (hel-lo)
179
+ *
180
+ * countSyllables('beautiful')
181
+ * // → 3 (beau-ti-ful)
182
+ * ```
183
+ *
184
+ * @example
185
+ * Edge cases:
186
+ * ```typescript
187
+ * countSyllables('')
188
+ * // → 0
189
+ *
190
+ * countSyllables('a')
191
+ * // → 1
192
+ *
193
+ * countSyllables('rhythm')
194
+ * // → 1 (no vowels, minimum 1)
195
+ * ```
196
+ *
197
+ * @public
198
+ */
199
+ declare function countSyllables(text: string): number;
2
200
 
3
201
  /**
4
202
  * ============================================================================
@@ -281,4 +479,4 @@ declare const ACRONYMS: readonly ["DKI", "DIY", "TNI", "POLRI", "ABRI", "MPR", "
281
479
  */
282
480
  declare const ABBREVIATIONS: Record<string, string>;
283
481
 
284
- export { ABBREVIATIONS, ACRONYMS, LOWERCASE_WORDS };
482
+ export { ABBREVIATIONS, ACRONYMS, LOWERCASE_WORDS, MaskOptions, countSyllables, maskText, toCamelCase, toPascalCase, toSnakeCase };
@@ -1,4 +1,202 @@
1
- export { C as CompareOptions, E as ExtractOptions, m as SanitizeOptions, S as SlugifyOptions, T as TitleCaseOptions, o as TruncateOptions, c as capitalize, k as compareStrings, d as contractAbbreviation, e as expandAbbreviation, g as extractWords, j as isAlay, n as normalizeWhitespace, p as profanityFilter, r as removeAccents, h as removeStopwords, b as sanitize, l as similarity, s as slugify, i as toFormal, a as toSentenceCase, t as toTitleCase, f as truncate } from '../compare-CZadJMGl.js';
1
+ import { M as MaskOptions } from '../compare-Ku_8OhuU.js';
2
+ export { C as CompareOptions, E as ExtractOptions, m as SanitizeOptions, S as SlugifyOptions, T as TitleCaseOptions, o as TruncateOptions, c as capitalize, k as compareStrings, d as contractAbbreviation, e as expandAbbreviation, g as extractWords, j as isAlay, n as normalizeWhitespace, p as profanityFilter, r as removeAccents, h as removeStopwords, b as sanitize, l as similarity, s as slugify, i as toFormal, a as toSentenceCase, t as toTitleCase, f as truncate } from '../compare-Ku_8OhuU.js';
3
+
4
+ /**
5
+ * Mask sensitive text based on predefined patterns or custom configuration
6
+ *
7
+ * This function provides privacy-compliant data display by masking portions
8
+ * of text while keeping certain parts visible. Supports multiple masking
9
+ * patterns for different use cases.
10
+ *
11
+ * **Available Patterns:**
12
+ * - `all`: Masks all characters (preserves spaces)
13
+ * - `middle`: Keeps start and end characters visible, masks the middle
14
+ * - `email`: Keeps first 2 chars of local part and full domain visible
15
+ *
16
+ * @param text - The text to mask
17
+ * @param options - Masking configuration options
18
+ * @returns The masked text
19
+ *
20
+ * @example
21
+ * Mask all characters:
22
+ * ```typescript
23
+ * maskText('Budi Santoso', { pattern: 'all' })
24
+ * // → '**** *******'
25
+ *
26
+ * maskText('123456789', { pattern: 'all', maskChar: '#' })
27
+ * // → '#########'
28
+ * ```
29
+ *
30
+ * @example
31
+ * Mask middle portion:
32
+ * ```typescript
33
+ * maskText('08123456789', { pattern: 'middle', visibleStart: 4, visibleEnd: 3 })
34
+ * // → '0812****789'
35
+ *
36
+ * maskText('ABCDEF', { pattern: 'middle' })
37
+ * // → 'AB**EF' (defaults: visibleStart=2, visibleEnd=2)
38
+ * ```
39
+ *
40
+ * @example
41
+ * Mask email:
42
+ * ```typescript
43
+ * maskText('user@example.com', { pattern: 'email' })
44
+ * // → 'us**@example.com'
45
+ *
46
+ * maskText('a@test.com', { pattern: 'email' })
47
+ * // → 'a*@test.com'
48
+ * ```
49
+ *
50
+ * @example
51
+ * Edge cases:
52
+ * ```typescript
53
+ * maskText('')
54
+ * // → ''
55
+ *
56
+ * maskText('AB', { pattern: 'middle', visibleStart: 2, visibleEnd: 2 })
57
+ * // → '**' (string too short, mask all)
58
+ * ```
59
+ *
60
+ * @public
61
+ */
62
+ declare function maskText(text: string, options?: MaskOptions): string;
63
+
64
+ /**
65
+ * Convert text to camelCase
66
+ *
67
+ * Treats spaces, hyphens, and underscores as word boundaries.
68
+ * Strips all other special characters. First word is lowercase.
69
+ *
70
+ * @param text - The text to convert
71
+ * @returns camelCase string
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * toCamelCase('hello-world')
76
+ * // → 'helloWorld'
77
+ *
78
+ * toCamelCase('hello_world')
79
+ * // → 'helloWorld'
80
+ *
81
+ * toCamelCase('Hello World')
82
+ * // → 'helloWorld'
83
+ *
84
+ * toCamelCase('')
85
+ * // → ''
86
+ * ```
87
+ *
88
+ * @public
89
+ */
90
+ declare function toCamelCase(text: string): string;
91
+ /**
92
+ * Convert text to PascalCase
93
+ *
94
+ * Treats spaces, hyphens, and underscores as word boundaries.
95
+ * Strips all other special characters. Every word is capitalized.
96
+ *
97
+ * @param text - The text to convert
98
+ * @returns PascalCase string
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * toPascalCase('hello_world')
103
+ * // → 'HelloWorld'
104
+ *
105
+ * toPascalCase('hello-world')
106
+ * // → 'HelloWorld'
107
+ *
108
+ * toPascalCase('hello world')
109
+ * // → 'HelloWorld'
110
+ *
111
+ * toPascalCase('')
112
+ * // → ''
113
+ * ```
114
+ *
115
+ * @public
116
+ */
117
+ declare function toPascalCase(text: string): string;
118
+ /**
119
+ * Convert text to snake_case
120
+ *
121
+ * Treats spaces, hyphens, and camelCase boundaries as word separators.
122
+ * Strips all other special characters. All lowercase with underscores.
123
+ *
124
+ * @param text - The text to convert
125
+ * @returns snake_case string
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * toSnakeCase('helloWorld')
130
+ * // → 'hello_world'
131
+ *
132
+ * toSnakeCase('Hello-World')
133
+ * // → 'hello_world'
134
+ *
135
+ * toSnakeCase('Hello World')
136
+ * // → 'hello_world'
137
+ *
138
+ * toSnakeCase('')
139
+ * // → ''
140
+ * ```
141
+ *
142
+ * @public
143
+ */
144
+ declare function toSnakeCase(text: string): string;
145
+
146
+ /**
147
+ * Count the number of syllables in an Indonesian word
148
+ *
149
+ * Uses algorithm-based vowel counting with Indonesian dipthong awareness.
150
+ * Works for both Indonesian and English text.
151
+ *
152
+ * **Syllable Detection Rules:**
153
+ * - Each vowel group (a, i, u, e, o) counts as one syllable
154
+ * - Dipthongs (ai, au, oi) count as a single vowel sound
155
+ * - Silent 'e' at the end is handled
156
+ * - Minimum 1 syllable for any word with letters
157
+ *
158
+ * @param text - The word or text to count syllables in
159
+ * @returns The number of syllables
160
+ *
161
+ * @example
162
+ * Indonesian words:
163
+ * ```typescript
164
+ * countSyllables('buku')
165
+ * // → 2 (bu-ku)
166
+ *
167
+ * countSyllables('matahari')
168
+ * // → 4 (ma-ta-ha-ri)
169
+ *
170
+ * countSyllables('pulau')
171
+ * // → 2 (pu-lau, dipthong 'au' counts as one)
172
+ * ```
173
+ *
174
+ * @example
175
+ * English words:
176
+ * ```typescript
177
+ * countSyllables('hello')
178
+ * // → 2 (hel-lo)
179
+ *
180
+ * countSyllables('beautiful')
181
+ * // → 3 (beau-ti-ful)
182
+ * ```
183
+ *
184
+ * @example
185
+ * Edge cases:
186
+ * ```typescript
187
+ * countSyllables('')
188
+ * // → 0
189
+ *
190
+ * countSyllables('a')
191
+ * // → 1
192
+ *
193
+ * countSyllables('rhythm')
194
+ * // → 1 (no vowels, minimum 1)
195
+ * ```
196
+ *
197
+ * @public
198
+ */
199
+ declare function countSyllables(text: string): number;
2
200
 
3
201
  /**
4
202
  * ============================================================================
@@ -281,4 +479,4 @@ declare const ACRONYMS: readonly ["DKI", "DIY", "TNI", "POLRI", "ABRI", "MPR", "
281
479
  */
282
480
  declare const ABBREVIATIONS: Record<string, string>;
283
481
 
284
- export { ABBREVIATIONS, ACRONYMS, LOWERCASE_WORDS };
482
+ export { ABBREVIATIONS, ACRONYMS, LOWERCASE_WORDS, MaskOptions, countSyllables, maskText, toCamelCase, toPascalCase, toSnakeCase };
@@ -1700,6 +1700,111 @@ function similarity(str1, str2) {
1700
1700
  return 1 - distance / maxLength;
1701
1701
  }
1702
1702
 
1703
- export { ABBREVIATIONS, ACRONYMS, LOWERCASE_WORDS, capitalize, compareStrings, contractAbbreviation, expandAbbreviation, extractWords, isAlay, normalizeWhitespace, profanityFilter, removeAccents, removeStopwords, sanitize, similarity, slugify, toFormal, toSentenceCase, toTitleCase, truncate };
1703
+ // src/text/mask.ts
1704
+ function maskText(text, options) {
1705
+ if (!text) return text;
1706
+ const {
1707
+ pattern = "middle",
1708
+ maskChar = "*",
1709
+ visibleStart = 2,
1710
+ visibleEnd = 2
1711
+ } = options || {};
1712
+ switch (pattern) {
1713
+ case "all":
1714
+ return maskAll(text, maskChar);
1715
+ case "email":
1716
+ return maskEmail(text, maskChar);
1717
+ case "middle":
1718
+ default:
1719
+ return maskMiddle(text, maskChar, visibleStart, visibleEnd);
1720
+ }
1721
+ }
1722
+ function maskAll(text, maskChar) {
1723
+ return text.split("").map((char) => char === " " ? " " : maskChar).join("");
1724
+ }
1725
+ function maskMiddle(text, maskChar, visibleStart, visibleEnd) {
1726
+ const length = text.length;
1727
+ const totalVisible = visibleStart + visibleEnd;
1728
+ if (length < totalVisible) {
1729
+ return maskChar.repeat(length);
1730
+ }
1731
+ const start = text.slice(0, visibleStart);
1732
+ const middle = maskChar.repeat(length - totalVisible);
1733
+ const end = text.slice(length - visibleEnd);
1734
+ return start + middle + end;
1735
+ }
1736
+ function maskEmail(text, maskChar) {
1737
+ const atIndex = text.indexOf("@");
1738
+ if (atIndex === -1) {
1739
+ return maskMiddle(text, maskChar, 2, 0);
1740
+ }
1741
+ const localPart = text.slice(0, atIndex);
1742
+ const domain = text.slice(atIndex);
1743
+ if (localPart.length <= 2) {
1744
+ const maskedLocal2 = localPart + maskChar.repeat(Math.max(0, 2 - localPart.length));
1745
+ return maskedLocal2 + domain;
1746
+ }
1747
+ const visibleLocal = localPart.slice(0, 2);
1748
+ const maskedLocal = visibleLocal + maskChar.repeat(localPart.length - 2);
1749
+ return maskedLocal + domain;
1750
+ }
1751
+
1752
+ // src/text/case-converters.ts
1753
+ function toCamelCase(text) {
1754
+ if (!text) return text;
1755
+ const words = extractWords2(text);
1756
+ if (words.length === 0) return "";
1757
+ return words.map((word, index) => {
1758
+ if (index === 0) return word.toLowerCase();
1759
+ return capitalizeFirst(word);
1760
+ }).join("");
1761
+ }
1762
+ function toPascalCase(text) {
1763
+ if (!text) return text;
1764
+ const words = extractWords2(text);
1765
+ return words.map((word) => capitalizeFirst(word)).join("");
1766
+ }
1767
+ function toSnakeCase(text) {
1768
+ if (!text) return text;
1769
+ const words = extractWords2(text);
1770
+ return words.map((word) => word.toLowerCase()).join("_");
1771
+ }
1772
+ function extractWords2(text) {
1773
+ const parts = text.split(/[\s\-_]+/);
1774
+ const words = [];
1775
+ for (const part of parts) {
1776
+ const camelWords = part.split(/(?=[A-Z])/);
1777
+ for (const word of camelWords) {
1778
+ const cleaned = word.replace(/[^a-zA-Z0-9]/g, "");
1779
+ if (cleaned) {
1780
+ words.push(cleaned);
1781
+ }
1782
+ }
1783
+ }
1784
+ return words;
1785
+ }
1786
+ function capitalizeFirst(word) {
1787
+ if (!word) return word;
1788
+ return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
1789
+ }
1790
+
1791
+ // src/text/syllable.ts
1792
+ function countSyllables(text) {
1793
+ if (!text) return 0;
1794
+ const cleaned = text.toLowerCase().replace(/[^a-z]/g, "");
1795
+ if (!cleaned) return 0;
1796
+ const withDipthongs = cleaned.replace(/ai/g, "\xE6").replace(/au/g, "\u0153").replace(/oi/g, "\xF8");
1797
+ const vowelGroups = withDipthongs.match(/[aiueoæœø]+/g);
1798
+ if (!vowelGroups) {
1799
+ return cleaned.length > 0 ? 1 : 0;
1800
+ }
1801
+ let count = vowelGroups.length;
1802
+ if (cleaned.endsWith("e") && count > 1) {
1803
+ count -= 1;
1804
+ }
1805
+ return Math.max(1, count);
1806
+ }
1807
+
1808
+ export { ABBREVIATIONS, ACRONYMS, LOWERCASE_WORDS, capitalize, compareStrings, contractAbbreviation, countSyllables, expandAbbreviation, extractWords, isAlay, maskText, normalizeWhitespace, profanityFilter, removeAccents, removeStopwords, sanitize, similarity, slugify, toCamelCase, toFormal, toPascalCase, toSentenceCase, toSnakeCase, toTitleCase, truncate };
1704
1809
  //# sourceMappingURL=index.js.map
1705
1810
  //# sourceMappingURL=index.js.map