@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.
- 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/email-validator/index.cjs +83 -0
- package/dist/email-validator/index.cjs.map +1 -0
- package/dist/email-validator/index.d.cts +13 -0
- package/dist/email-validator/index.d.ts +13 -0
- package/dist/email-validator/index.js +76 -0
- package/dist/email-validator/index.js.map +1 -0
- package/dist/email-validator-R9L5unIw.d.cts +120 -0
- package/dist/email-validator-R9L5unIw.d.ts +120 -0
- package/dist/index.cjs +77 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +74 -1
- package/dist/index.js.map +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 +11 -1
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
|