@indodev/toolkit 0.3.2 → 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.
- package/dist/{compare-CZadJMGl.d.cts → compare-Ku_8OhuU.d.cts} +25 -1
- package/dist/{compare-CZadJMGl.d.ts → compare-Ku_8OhuU.d.ts} +25 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/text/index.cjs +110 -0
- package/dist/text/index.cjs.map +1 -1
- package/dist/text/index.d.cts +200 -2
- package/dist/text/index.d.ts +200 -2
- package/dist/text/index.js +106 -1
- package/dist/text/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -131,6 +131,30 @@ interface TruncateOptions {
|
|
|
131
131
|
*/
|
|
132
132
|
wordBoundary?: boolean;
|
|
133
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Options for text masking
|
|
136
|
+
*/
|
|
137
|
+
interface MaskOptions {
|
|
138
|
+
/**
|
|
139
|
+
* Masking pattern to apply
|
|
140
|
+
* - `all`: Mask all characters (preserves spaces)
|
|
141
|
+
* - `middle`: Keep start and end visible, mask middle
|
|
142
|
+
* - `email`: Keep first 2 chars of local part and full domain
|
|
143
|
+
*/
|
|
144
|
+
pattern?: 'all' | 'middle' | 'email';
|
|
145
|
+
/**
|
|
146
|
+
* Character to use for masking (default: '*')
|
|
147
|
+
*/
|
|
148
|
+
maskChar?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Number of characters to keep visible at start (for 'middle' pattern, default: 2)
|
|
151
|
+
*/
|
|
152
|
+
visibleStart?: number;
|
|
153
|
+
/**
|
|
154
|
+
* Number of characters to keep visible at end (for 'middle' pattern, default: 2)
|
|
155
|
+
*/
|
|
156
|
+
visibleEnd?: number;
|
|
157
|
+
}
|
|
134
158
|
|
|
135
159
|
/**
|
|
136
160
|
* Capitalize the first letter of a string and lowercase the rest
|
|
@@ -988,4 +1012,4 @@ declare function compareStrings(str1: string, str2: string, options?: CompareOpt
|
|
|
988
1012
|
*/
|
|
989
1013
|
declare function similarity(str1: string, str2: string): number;
|
|
990
1014
|
|
|
991
|
-
export { type CompareOptions as C, type ExtractOptions as E, type SlugifyOptions as S, type TitleCaseOptions as T, toSentenceCase as a, sanitize as b, capitalize as c, contractAbbreviation as d, expandAbbreviation as e, truncate as f, extractWords as g, removeStopwords as h, toFormal as i, isAlay as j, compareStrings as k, similarity as l, type SanitizeOptions as m, normalizeWhitespace as n, type TruncateOptions as o, profanityFilter as p, removeAccents as r, slugify as s, toTitleCase as t };
|
|
1015
|
+
export { type CompareOptions as C, type ExtractOptions as E, type MaskOptions as M, type SlugifyOptions as S, type TitleCaseOptions as T, toSentenceCase as a, sanitize as b, capitalize as c, contractAbbreviation as d, expandAbbreviation as e, truncate as f, extractWords as g, removeStopwords as h, toFormal as i, isAlay as j, compareStrings as k, similarity as l, type SanitizeOptions as m, normalizeWhitespace as n, type TruncateOptions as o, profanityFilter as p, removeAccents as r, slugify as s, toTitleCase as t };
|
|
@@ -131,6 +131,30 @@ interface TruncateOptions {
|
|
|
131
131
|
*/
|
|
132
132
|
wordBoundary?: boolean;
|
|
133
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Options for text masking
|
|
136
|
+
*/
|
|
137
|
+
interface MaskOptions {
|
|
138
|
+
/**
|
|
139
|
+
* Masking pattern to apply
|
|
140
|
+
* - `all`: Mask all characters (preserves spaces)
|
|
141
|
+
* - `middle`: Keep start and end visible, mask middle
|
|
142
|
+
* - `email`: Keep first 2 chars of local part and full domain
|
|
143
|
+
*/
|
|
144
|
+
pattern?: 'all' | 'middle' | 'email';
|
|
145
|
+
/**
|
|
146
|
+
* Character to use for masking (default: '*')
|
|
147
|
+
*/
|
|
148
|
+
maskChar?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Number of characters to keep visible at start (for 'middle' pattern, default: 2)
|
|
151
|
+
*/
|
|
152
|
+
visibleStart?: number;
|
|
153
|
+
/**
|
|
154
|
+
* Number of characters to keep visible at end (for 'middle' pattern, default: 2)
|
|
155
|
+
*/
|
|
156
|
+
visibleEnd?: number;
|
|
157
|
+
}
|
|
134
158
|
|
|
135
159
|
/**
|
|
136
160
|
* Capitalize the first letter of a string and lowercase the rest
|
|
@@ -988,4 +1012,4 @@ declare function compareStrings(str1: string, str2: string, options?: CompareOpt
|
|
|
988
1012
|
*/
|
|
989
1013
|
declare function similarity(str1: string, str2: string): number;
|
|
990
1014
|
|
|
991
|
-
export { type CompareOptions as C, type ExtractOptions as E, type SlugifyOptions as S, type TitleCaseOptions as T, toSentenceCase as a, sanitize as b, capitalize as c, contractAbbreviation as d, expandAbbreviation as e, truncate as f, extractWords as g, removeStopwords as h, toFormal as i, isAlay as j, compareStrings as k, similarity as l, type SanitizeOptions as m, normalizeWhitespace as n, type TruncateOptions as o, profanityFilter as p, removeAccents as r, slugify as s, toTitleCase as t };
|
|
1015
|
+
export { type CompareOptions as C, type ExtractOptions as E, type MaskOptions as M, type SlugifyOptions as S, type TitleCaseOptions as T, toSentenceCase as a, sanitize as b, capitalize as c, contractAbbreviation as d, expandAbbreviation as e, truncate as f, extractWords as g, removeStopwords as h, toFormal as i, isAlay as j, compareStrings as k, similarity as l, type SanitizeOptions as m, normalizeWhitespace as n, type TruncateOptions as o, profanityFilter as p, removeAccents as r, slugify as s, toTitleCase as t };
|
package/dist/index.d.cts
CHANGED
|
@@ -5,4 +5,4 @@ export { f as formatPlate, g as getRegionFromPlate, v as validatePlate } from '.
|
|
|
5
5
|
export { V as VINOptions, a as VINValidationResult, v as validateVIN } from './types-i5e6R0AS.cjs';
|
|
6
6
|
export { c as EmailInfo, b as EmailMaskOptions, E as EmailValidationOptions, a as EmailValidationResult, g as getEmailInfo, m as maskEmail, n as normalizeEmail, v as validateEmail } from './email-validator-R9L5unIw.cjs';
|
|
7
7
|
export { RupiahOptions, WordOptions, addRupiahSymbol, calculateTax, formatAccounting, formatCompact, formatRupiah, parseRupiah, roundToClean, toWords } from './currency/index.cjs';
|
|
8
|
-
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-
|
|
8
|
+
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';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export { f as formatPlate, g as getRegionFromPlate, v as validatePlate } from '.
|
|
|
5
5
|
export { V as VINOptions, a as VINValidationResult, v as validateVIN } from './types-i5e6R0AS.js';
|
|
6
6
|
export { c as EmailInfo, b as EmailMaskOptions, E as EmailValidationOptions, a as EmailValidationResult, g as getEmailInfo, m as maskEmail, n as normalizeEmail, v as validateEmail } from './email-validator-R9L5unIw.js';
|
|
7
7
|
export { RupiahOptions, WordOptions, addRupiahSymbol, calculateTax, formatAccounting, formatCompact, formatRupiah, parseRupiah, roundToClean, toWords } from './currency/index.js';
|
|
8
|
-
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-
|
|
8
|
+
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';
|
package/dist/text/index.cjs
CHANGED
|
@@ -1702,15 +1702,122 @@ function similarity(str1, str2) {
|
|
|
1702
1702
|
return 1 - distance / maxLength;
|
|
1703
1703
|
}
|
|
1704
1704
|
|
|
1705
|
+
// src/text/mask.ts
|
|
1706
|
+
function maskText(text, options) {
|
|
1707
|
+
if (!text) return text;
|
|
1708
|
+
const {
|
|
1709
|
+
pattern = "middle",
|
|
1710
|
+
maskChar = "*",
|
|
1711
|
+
visibleStart = 2,
|
|
1712
|
+
visibleEnd = 2
|
|
1713
|
+
} = options || {};
|
|
1714
|
+
switch (pattern) {
|
|
1715
|
+
case "all":
|
|
1716
|
+
return maskAll(text, maskChar);
|
|
1717
|
+
case "email":
|
|
1718
|
+
return maskEmail(text, maskChar);
|
|
1719
|
+
case "middle":
|
|
1720
|
+
default:
|
|
1721
|
+
return maskMiddle(text, maskChar, visibleStart, visibleEnd);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
function maskAll(text, maskChar) {
|
|
1725
|
+
return text.split("").map((char) => char === " " ? " " : maskChar).join("");
|
|
1726
|
+
}
|
|
1727
|
+
function maskMiddle(text, maskChar, visibleStart, visibleEnd) {
|
|
1728
|
+
const length = text.length;
|
|
1729
|
+
const totalVisible = visibleStart + visibleEnd;
|
|
1730
|
+
if (length < totalVisible) {
|
|
1731
|
+
return maskChar.repeat(length);
|
|
1732
|
+
}
|
|
1733
|
+
const start = text.slice(0, visibleStart);
|
|
1734
|
+
const middle = maskChar.repeat(length - totalVisible);
|
|
1735
|
+
const end = text.slice(length - visibleEnd);
|
|
1736
|
+
return start + middle + end;
|
|
1737
|
+
}
|
|
1738
|
+
function maskEmail(text, maskChar) {
|
|
1739
|
+
const atIndex = text.indexOf("@");
|
|
1740
|
+
if (atIndex === -1) {
|
|
1741
|
+
return maskMiddle(text, maskChar, 2, 0);
|
|
1742
|
+
}
|
|
1743
|
+
const localPart = text.slice(0, atIndex);
|
|
1744
|
+
const domain = text.slice(atIndex);
|
|
1745
|
+
if (localPart.length <= 2) {
|
|
1746
|
+
const maskedLocal2 = localPart + maskChar.repeat(Math.max(0, 2 - localPart.length));
|
|
1747
|
+
return maskedLocal2 + domain;
|
|
1748
|
+
}
|
|
1749
|
+
const visibleLocal = localPart.slice(0, 2);
|
|
1750
|
+
const maskedLocal = visibleLocal + maskChar.repeat(localPart.length - 2);
|
|
1751
|
+
return maskedLocal + domain;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
// src/text/case-converters.ts
|
|
1755
|
+
function toCamelCase(text) {
|
|
1756
|
+
if (!text) return text;
|
|
1757
|
+
const words = extractWords2(text);
|
|
1758
|
+
if (words.length === 0) return "";
|
|
1759
|
+
return words.map((word, index) => {
|
|
1760
|
+
if (index === 0) return word.toLowerCase();
|
|
1761
|
+
return capitalizeFirst(word);
|
|
1762
|
+
}).join("");
|
|
1763
|
+
}
|
|
1764
|
+
function toPascalCase(text) {
|
|
1765
|
+
if (!text) return text;
|
|
1766
|
+
const words = extractWords2(text);
|
|
1767
|
+
return words.map((word) => capitalizeFirst(word)).join("");
|
|
1768
|
+
}
|
|
1769
|
+
function toSnakeCase(text) {
|
|
1770
|
+
if (!text) return text;
|
|
1771
|
+
const words = extractWords2(text);
|
|
1772
|
+
return words.map((word) => word.toLowerCase()).join("_");
|
|
1773
|
+
}
|
|
1774
|
+
function extractWords2(text) {
|
|
1775
|
+
const parts = text.split(/[\s\-_]+/);
|
|
1776
|
+
const words = [];
|
|
1777
|
+
for (const part of parts) {
|
|
1778
|
+
const camelWords = part.split(/(?=[A-Z])/);
|
|
1779
|
+
for (const word of camelWords) {
|
|
1780
|
+
const cleaned = word.replace(/[^a-zA-Z0-9]/g, "");
|
|
1781
|
+
if (cleaned) {
|
|
1782
|
+
words.push(cleaned);
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
return words;
|
|
1787
|
+
}
|
|
1788
|
+
function capitalizeFirst(word) {
|
|
1789
|
+
if (!word) return word;
|
|
1790
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
// src/text/syllable.ts
|
|
1794
|
+
function countSyllables(text) {
|
|
1795
|
+
if (!text) return 0;
|
|
1796
|
+
const cleaned = text.toLowerCase().replace(/[^a-z]/g, "");
|
|
1797
|
+
if (!cleaned) return 0;
|
|
1798
|
+
const withDipthongs = cleaned.replace(/ai/g, "\xE6").replace(/au/g, "\u0153").replace(/oi/g, "\xF8");
|
|
1799
|
+
const vowelGroups = withDipthongs.match(/[aiueoæœø]+/g);
|
|
1800
|
+
if (!vowelGroups) {
|
|
1801
|
+
return cleaned.length > 0 ? 1 : 0;
|
|
1802
|
+
}
|
|
1803
|
+
let count = vowelGroups.length;
|
|
1804
|
+
if (cleaned.endsWith("e") && count > 1) {
|
|
1805
|
+
count -= 1;
|
|
1806
|
+
}
|
|
1807
|
+
return Math.max(1, count);
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1705
1810
|
exports.ABBREVIATIONS = ABBREVIATIONS;
|
|
1706
1811
|
exports.ACRONYMS = ACRONYMS;
|
|
1707
1812
|
exports.LOWERCASE_WORDS = LOWERCASE_WORDS;
|
|
1708
1813
|
exports.capitalize = capitalize;
|
|
1709
1814
|
exports.compareStrings = compareStrings;
|
|
1710
1815
|
exports.contractAbbreviation = contractAbbreviation;
|
|
1816
|
+
exports.countSyllables = countSyllables;
|
|
1711
1817
|
exports.expandAbbreviation = expandAbbreviation;
|
|
1712
1818
|
exports.extractWords = extractWords;
|
|
1713
1819
|
exports.isAlay = isAlay;
|
|
1820
|
+
exports.maskText = maskText;
|
|
1714
1821
|
exports.normalizeWhitespace = normalizeWhitespace;
|
|
1715
1822
|
exports.profanityFilter = profanityFilter;
|
|
1716
1823
|
exports.removeAccents = removeAccents;
|
|
@@ -1718,8 +1825,11 @@ exports.removeStopwords = removeStopwords;
|
|
|
1718
1825
|
exports.sanitize = sanitize;
|
|
1719
1826
|
exports.similarity = similarity;
|
|
1720
1827
|
exports.slugify = slugify;
|
|
1828
|
+
exports.toCamelCase = toCamelCase;
|
|
1721
1829
|
exports.toFormal = toFormal;
|
|
1830
|
+
exports.toPascalCase = toPascalCase;
|
|
1722
1831
|
exports.toSentenceCase = toSentenceCase;
|
|
1832
|
+
exports.toSnakeCase = toSnakeCase;
|
|
1723
1833
|
exports.toTitleCase = toTitleCase;
|
|
1724
1834
|
exports.truncate = truncate;
|
|
1725
1835
|
//# sourceMappingURL=index.cjs.map
|