@arkyn/shared 3.0.1-beta.21 → 3.0.1-beta.22

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.
Files changed (34) hide show
  1. package/package.json +1 -1
  2. package/src/formats/formatDate.ts +0 -92
  3. package/src/formats/formatJsonObject.ts +0 -90
  4. package/src/formats/formatJsonString.ts +0 -50
  5. package/src/formats/formatToCapitalizeFirstWordLetter.ts +0 -46
  6. package/src/formats/formatToCep.ts +0 -39
  7. package/src/formats/formatToCnpj.ts +0 -40
  8. package/src/formats/formatToCpf.ts +0 -40
  9. package/src/formats/formatToCpfCnpj.ts +0 -38
  10. package/src/formats/formatToCurrency.ts +0 -63
  11. package/src/formats/formatToDate.ts +0 -70
  12. package/src/formats/formatToEllipsis.ts +0 -25
  13. package/src/formats/formatToHiddenDigits.ts +0 -92
  14. package/src/formats/formatToPhone.ts +0 -170
  15. package/src/generators/generateColorByString.ts +0 -33
  16. package/src/generators/generateId.ts +0 -61
  17. package/src/generators/generateSlug.ts +0 -31
  18. package/src/index.ts +0 -37
  19. package/src/services/calculateCardInstallment.ts +0 -73
  20. package/src/services/ensureQuotes.ts +0 -25
  21. package/src/services/maskSensitiveData.ts +0 -68
  22. package/src/services/removeCurrencySymbols.ts +0 -29
  23. package/src/services/removeNonNumeric.ts +0 -20
  24. package/src/services/stripHtmlTags.ts +0 -20
  25. package/src/services/truncateLargeFields.ts +0 -69
  26. package/src/validations/validateCep.ts +0 -41
  27. package/src/validations/validateCnpj.ts +0 -65
  28. package/src/validations/validateCpf.ts +0 -62
  29. package/src/validations/validateDate.ts +0 -86
  30. package/src/validations/validatePassword.ts +0 -41
  31. package/src/validations/validatePhone.ts +0 -50
  32. package/src/validations/validateRg.ts +0 -37
  33. package/tsconfig.json +0 -20
  34. package/vitest.config.ts +0 -5
@@ -1,92 +0,0 @@
1
- const DIGIT = /^\d$/;
2
-
3
- type DigitCharacterNode = {
4
- kind: "digit";
5
- digit: number;
6
- character: string;
7
- };
8
-
9
- type OtherCharacterNode = {
10
- kind: "other";
11
- character: string;
12
- };
13
-
14
- type RootCharacterNode = {
15
- kind: "root";
16
- digits: number;
17
- children: (DigitCharacterNode | OtherCharacterNode)[];
18
- };
19
-
20
- type FormatToHiddenDigitsFunction = (
21
- value: string,
22
- options: { range?: number | [number, number]; hider?: string }
23
- ) => string;
24
-
25
- const parseToCharacters = (value: string): RootCharacterNode => {
26
- let digits = 0;
27
-
28
- const children = value
29
- .split("")
30
- .map((character: string): DigitCharacterNode | OtherCharacterNode => {
31
- if (DIGIT.test(character))
32
- return { character, kind: "digit", digit: ++digits };
33
- return { character, kind: "other" };
34
- });
35
-
36
- return { digits, children, kind: "root" };
37
- };
38
-
39
- const normalizeRange = (
40
- range: number | [number, number],
41
- limit: number
42
- ): [number, number] => {
43
- if (Array.isArray(range)) return range;
44
- if (range >= 0) return [0, range];
45
- return [limit + 1 - Math.abs(range), limit];
46
- };
47
-
48
- const within = (range: [number, number], value: number): boolean =>
49
- value >= range[0] && value <= range[1];
50
-
51
- /**
52
- * Formats a string by hiding specific digits within a given range.
53
- *
54
- * This function takes a string input and replaces digits within a specified range
55
- * with a hiding character (e.g., "*"). Non-digit characters remain unchanged.
56
- *
57
- * @param value - The input string to be formatted.
58
- * @param options - Configuration options for formatting.
59
- * @param options.range - The range of digits to hide. It can be:
60
- * - A single number (e.g., `3`), which hides the first `n` digits if positive,
61
- * or the last `n` digits if negative.
62
- * - A tuple `[start, end]` specifying the range of digits to hide (inclusive).
63
- * - Defaults to `3`, hiding the first three digits.
64
- * @param options.hider - The character used to hide digits. Defaults to `"*"`.
65
- *
66
- * @returns The formatted string with specified digits hidden.
67
- *
68
- * @example
69
- * ```typescript
70
- * import { formatToHiddenDigits } from "./formatToHiddenDigits";
71
- *
72
- * formatToHiddenDigits("123-456-7890", { range: 3 });
73
- * // Output: "***-456-7890"
74
- *
75
- * formatToHiddenDigits("123-456-7890", { range: [4, 6], hider: "#" });
76
- * // Output: "123-###-7890"
77
- * ```
78
- */
79
-
80
- const formatToHiddenDigits: FormatToHiddenDigitsFunction = (value, options) => {
81
- const characters = parseToCharacters(value);
82
- const range = normalizeRange(options.range ?? 3, characters.digits);
83
- return characters.children
84
- .map((node) => {
85
- if (node.kind === "digit" && within(range, node.digit))
86
- return options.hider ?? "*";
87
- return node.character;
88
- })
89
- .join("");
90
- };
91
-
92
- export { formatToHiddenDigits };
@@ -1,170 +0,0 @@
1
- import { countries } from "@arkyn/templates";
2
-
3
- import { removeNonNumeric } from "../services/removeNonNumeric";
4
-
5
- type CountryType = {
6
- name: string;
7
- code: string;
8
- iso: string;
9
- prefix: null | string;
10
- flag: string;
11
- mask: string;
12
- };
13
-
14
- type FormatToPhoneFunction = (prop: string) => string;
15
-
16
- function getMask(value: string): "NINE" | "EIGTH" {
17
- const mask = value.length > 10 ? "NINE" : "EIGTH";
18
- return mask;
19
- }
20
-
21
- const TYPES = {
22
- EIGTH: "(99) 9999-9999",
23
- NINE: "(99) 99999-9999",
24
- };
25
-
26
- const MAX_LENGTH = removeNonNumeric(TYPES.NINE).length;
27
-
28
- function applyMask(value: string, maskPattern: string) {
29
- let result = "";
30
- let digitIndex = 0;
31
-
32
- for (let i = 0; i < maskPattern.length; i++) {
33
- if (maskPattern[i] === "9") {
34
- if (digitIndex < value.length) {
35
- result += value[digitIndex];
36
- digitIndex++;
37
- } else {
38
- break;
39
- }
40
- } else {
41
- if (digitIndex < value.length) {
42
- result += maskPattern[i];
43
- } else {
44
- break;
45
- }
46
- }
47
- }
48
-
49
- return result;
50
- }
51
-
52
- function formatPhoneNumber(phoneNumber: string, country: CountryType): string {
53
- if (country.code === "+55") {
54
- let value = removeNonNumeric(phoneNumber);
55
- const mask = getMask(value);
56
-
57
- let nextLength = value.length;
58
- if (nextLength > MAX_LENGTH) return value;
59
-
60
- value = applyMask(value, TYPES[mask] as "EIGTH" | "NINE");
61
- return value;
62
- }
63
-
64
- const mask = country.mask;
65
- let formattedNumber = mask;
66
-
67
- if (country.prefix) {
68
- const prefixRegex = /\$+/g;
69
- formattedNumber = formattedNumber.replace(prefixRegex, country.prefix);
70
- }
71
-
72
- for (
73
- let i = 0, j = 0;
74
- i < formattedNumber.length && j < phoneNumber.length;
75
- i++
76
- ) {
77
- if (formattedNumber[i] === "_") {
78
- formattedNumber =
79
- formattedNumber.substring(0, i) +
80
- phoneNumber[j] +
81
- formattedNumber.substring(i + 1);
82
- j++;
83
- }
84
- }
85
-
86
- return formattedNumber;
87
- }
88
-
89
- function getCountryWithPrefixCode(countryCode: string, prefix: string) {
90
- const country = countries.find(
91
- (country) => country.code === countryCode && country.prefix === prefix
92
- );
93
-
94
- if (!country) throw new Error("Invalid country code or prefix");
95
-
96
- if (country.prefix !== prefix) {
97
- throw new Error("Invalid country code or prefix");
98
- }
99
-
100
- if (!country.prefix) {
101
- throw new Error("Invalid country code or prefix");
102
- }
103
- return country;
104
- }
105
-
106
- function getCountryWithoutPrefixCode(countryCode: string) {
107
- const country = countries.find((country) => country.code === countryCode);
108
- if (!country) throw new Error("Invalid country code");
109
- if (country.prefix) throw new Error("Invalid country code");
110
- return country;
111
- }
112
-
113
- /**
114
- * Formats a phone number string based on the provided country code and optional prefix.
115
- *
116
- * The input string should follow the format: `"<countryCode>-<prefix> <phoneNumber>"` or `"<countryCode> <phoneNumber>"`.
117
- * The function determines the appropriate formatting mask based on the country and applies it to the phone number.
118
- *
119
- * @param prop - The phone number string to be formatted. It must include the country code and optionally a prefix.
120
- * Example formats:
121
- * - "+55 32912345678"
122
- * - "+1 1234567890"
123
- *
124
- * @returns The formatted phone number string based on the country's formatting rules.
125
- *
126
- * @throws {Error} If the input phone number does not match the expected format.
127
- * @throws {Error} If the country code or phone number is missing from the input string.
128
- * @throws {Error} If the provided country code and prefix combination is invalid.
129
- * @throws {Error} If the provided country code is invalid.
130
- * @throws {Error} If the provided country code has a prefix but none is supplied in the input.
131
- *
132
- * @example
133
- * ```typescript
134
- * import { formatToPhone } from "./formatToPhone";
135
- *
136
- * const formattedPhone1 = formatToPhone("+55 11912345678");
137
- * console.log(formattedPhone1); // Output: "(11) 91234-5678" (brazilian phone number format)
138
- *
139
- * const formattedPhone2 = formatToPhone("+1-123 4567890");
140
- * console.log(formattedPhone2); // Output: "(123) 456-7890" (us phone number format)
141
- * ```
142
- */
143
-
144
- const formatToPhone: FormatToPhoneFunction = (prop) => {
145
- const phoneRegex = /^\+\d{1,4}(-\d{1,4})? \d+$/;
146
-
147
- if (!phoneRegex.test(prop)) {
148
- throw new Error(
149
- "Invalid phone number format. Expected format: +<countryCode>-<optionalPrefix> <phoneNumber>"
150
- );
151
- }
152
-
153
- const countryCode = prop.split(" ")[0].split("-")[0];
154
- const prefixCode = prop.split(" ")[0].split("-")[1];
155
- const phoneNumber = prop.split(" ")[1];
156
-
157
- if (!countryCode || !phoneNumber) {
158
- throw new Error("Invalid phone number format");
159
- }
160
-
161
- if (prefixCode) {
162
- const country = getCountryWithPrefixCode(countryCode, prefixCode);
163
- return formatPhoneNumber(phoneNumber, country);
164
- }
165
-
166
- const country = getCountryWithoutPrefixCode(countryCode);
167
- return formatPhoneNumber(phoneNumber, country);
168
- };
169
-
170
- export { formatToPhone };
@@ -1,33 +0,0 @@
1
- type GenerateColorByStringFunction = (prop: string) => string;
2
-
3
- /**
4
- * Generates a hexadecimal color code based on the input string.
5
- * The function creates a hash from the string and uses it to calculate
6
- * RGB values, which are then converted to a hexadecimal color code.
7
- *
8
- * @param prop - The input string used to generate the color.
9
- * @returns A hexadecimal color code (e.g., "#a1b2c3") derived from the input string.
10
- * @example
11
- * const color = generateColorByString("example");
12
- * console.log(color); // Outputs a consistent hex color like "#5e8f9a"
13
- */
14
-
15
- const generateColorByString: GenerateColorByStringFunction = (prop) => {
16
- var hash = 0;
17
-
18
- for (var i = 0; i < prop.length; i++) {
19
- hash = prop.charCodeAt(i) + ((hash << 5) - hash);
20
- }
21
-
22
- var red = (hash & 0xff0000) >> 16;
23
- var green = (hash & 0x00ff00) >> 8;
24
- var blue = hash & 0x0000ff;
25
-
26
- var redHex = red.toString(16).padStart(2, "0");
27
- var greenHex = green.toString(16).padStart(2, "0");
28
- var blueHex = blue.toString(16).padStart(2, "0");
29
-
30
- return "#" + redHex + greenHex + blueHex;
31
- };
32
-
33
- export { generateColorByString };
@@ -1,61 +0,0 @@
1
- import { v4, v7 } from "uuid";
2
-
3
- function hexToBin(hex: string) {
4
- hex = hex.replace(/-/g, "");
5
- const buffer = new Uint8Array(hex.length / 2);
6
-
7
- for (let i = 0; i < hex.length; i += 2) {
8
- buffer[i / 2] = parseInt(hex.substring(i, i + 2), 16);
9
- }
10
-
11
- return buffer;
12
- }
13
-
14
- function uuidV4() {
15
- const uuid = v4();
16
- return { text: uuid, binary: hexToBin(uuid) };
17
- }
18
-
19
- function uuidV7() {
20
- const uuid = v7();
21
- return { text: uuid, binary: hexToBin(uuid) };
22
- }
23
-
24
- /**
25
- * Generates a unique identifier (UUID) in the specified format and type.
26
- *
27
- * @param type - The desired output type of the UUID. Can be:
28
- * - `"text"`: Returns the UUID as a string.
29
- * - `"binary"`: Returns the UUID as a `Uint8Array` in binary format.
30
- * @param format - The version of the UUID to generate. Can be:
31
- * - `"v4"`: Generates a random UUID (version 4).
32
- * - `"v7"`: Generates a time-ordered UUID (version 7).
33
- * @returns The generated UUID in the specified type and format.
34
- * - If `type` is `"text"`, a string representation of the UUID is returned.
35
- * - If `type` is `"binary"`, a `Uint8Array` representation of the UUID is returned.
36
- * @throws {Error} If an invalid `type` or `format` is provided.
37
- *
38
- * @example
39
- * // Generate a version 4 UUID as a string
40
- * const idTextV4 = generateId("text", "v4");
41
- * console.log(idTextV4); // e.g., "550e8400-e29b-41d4-a716-446655440000"
42
- *
43
- * @example
44
- * // Generate a version 7 UUID as binary
45
- * const idBinaryV7 = generateId("binary", "v7");
46
- * console.log(idBinaryV7); // Uint8Array([...])
47
- */
48
- function generateId(type: "text", format: "v4" | "v7"): string;
49
- function generateId(type: "binary", format: "v4" | "v7"): Uint8Array;
50
- function generateId(
51
- type: "text" | "binary",
52
- format: "v4" | "v7"
53
- ): string | Uint8Array {
54
- if (type === "text" && format === "v4") return uuidV4().text;
55
- if (type === "binary" && format === "v4") return uuidV4().binary;
56
- if (type === "text" && format === "v7") return uuidV7().text;
57
- if (type === "binary" && format === "v7") return uuidV7().binary;
58
- throw new Error("Invalid type or format");
59
- }
60
-
61
- export { generateId };
@@ -1,31 +0,0 @@
1
- /**
2
- * Generates a URL-friendly slug from a given string.
3
- *
4
- * The function performs the following transformations:
5
- * - Normalizes the string to remove diacritical marks (e.g., accents).
6
- * - Removes non-alphanumeric characters except for spaces and hyphens.
7
- * - Replaces spaces with hyphens.
8
- * - Converts the string to lowercase.
9
- * - Collapses multiple consecutive hyphens into a single hyphen.
10
- * - Trims leading and trailing hyphens.
11
- *
12
- * @param string - The input string to be converted into a slug.
13
- * @returns A URL-friendly slug derived from the input string.
14
- */
15
-
16
- function generateSlug(prop: string) {
17
- let slug = prop.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
18
-
19
- slug = slug
20
- .replace(/[^\w\s-]/g, "")
21
- .replace(/\s+/g, "-")
22
- .toLowerCase();
23
-
24
- slug = slug.replace(/-{2,}/g, "-");
25
-
26
- slug = slug.replace(/^-+|-+$/g, "");
27
-
28
- return slug;
29
- }
30
-
31
- export { generateSlug };
package/src/index.ts DELETED
@@ -1,37 +0,0 @@
1
- // formats
2
- export { formatDate } from "./formats/formatDate";
3
- export { formatJsonObject } from "./formats/formatJsonObject";
4
- export { formatJsonString } from "./formats/formatJsonString";
5
- export { formatToCapitalizeFirstWordLetter } from "./formats/formatToCapitalizeFirstWordLetter";
6
- export { formatToCep } from "./formats/formatToCep";
7
- export { formatToCnpj } from "./formats/formatToCnpj";
8
- export { formatToCpf } from "./formats/formatToCpf";
9
- export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
10
- export { formatToCurrency } from "./formats/formatToCurrency";
11
- export { formatToDate } from "./formats/formatToDate";
12
- export { formatToEllipsis } from "./formats/formatToEllipsis";
13
- export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
14
- export { formatToPhone } from "./formats/formatToPhone";
15
-
16
- // generators
17
- export { generateColorByString } from "./generators/generateColorByString";
18
- export { generateId } from "./generators/generateId";
19
- export { generateSlug } from "./generators/generateSlug";
20
-
21
- // services
22
- export { calculateCardInstallment } from "./services/calculateCardInstallment";
23
- export { ensureQuotes } from "./services/ensureQuotes";
24
- export { maskSensitiveData } from "./services/maskSensitiveData";
25
- export { removeCurrencySymbols } from "./services/removeCurrencySymbols";
26
- export { removeNonNumeric } from "./services/removeNonNumeric";
27
- export { stripHtmlTags } from "./services/stripHtmlTags";
28
- export { truncateLargeFields } from "./services/truncateLargeFields";
29
-
30
- // utils
31
- export { validateCep } from "./validations/validateCep";
32
- export { validateCnpj } from "./validations/validateCnpj";
33
- export { validateCpf } from "./validations/validateCpf";
34
- export { validateDate } from "./validations/validateDate";
35
- export { validatePassword } from "./validations/validatePassword";
36
- export { validatePhone } from "./validations/validatePhone";
37
- export { validateRg } from "./validations/validateRg";
@@ -1,73 +0,0 @@
1
- type CalculateCardInstallmentFunction = (props: {
2
- cashPrice: number;
3
- numberInstallments: number;
4
- fees?: number;
5
- }) => {
6
- totalPrice: number;
7
- installmentPrice: number;
8
- };
9
-
10
- /**
11
- * Calculates the installment price and total price for a card payment plan.
12
- *
13
- * @remarks
14
- * **Important:** When the interest amount (`fees`) is equal to 0 or the number of installments (`numberInstallments`) is equal to 1, no interest will be charged.
15
- *
16
- * @throws Will throw an error if the number of installments is less than or equal to 0.
17
- * @throws Will throw an error if the fees are less than 0.
18
- *
19
- * @param props - The input parameters for the calculation.
20
- * @param props.cashPrice - The total cash price of the product or service.
21
- * @param props.numberInstallments - The number of installments for the payment plan.
22
- * @param props.fees - The interest rate per installment (default is 0.0349).
23
- *
24
- * @returns An object containing:
25
- * - `totalPrice`: The total price to be paid, rounded to two decimal places.
26
- * - `installmentPrice`: The price of each installment, rounded to two decimal places.
27
- *
28
- * @example
29
- * ```typescript
30
- * const result = calculateCardInstallment({
31
- * cashPrice: 1000,
32
- * numberInstallments: 12,
33
- * fees: 0.02,
34
- * });
35
- * console.log(result);
36
- * // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
37
- * ```
38
- */
39
-
40
- const calculateCardInstallment: CalculateCardInstallmentFunction = (props) => {
41
- const { cashPrice, numberInstallments, fees = 0.0349 } = props;
42
-
43
- if (fees === 0 || numberInstallments === 1) {
44
- return {
45
- totalPrice: cashPrice,
46
- installmentPrice: cashPrice / numberInstallments,
47
- };
48
- }
49
-
50
- if (numberInstallments <= 0) {
51
- throw new Error("Number of installments must be greater than 0");
52
- }
53
-
54
- if (fees < 0) {
55
- throw new Error("Fees must be greater than or equal to 0");
56
- }
57
-
58
- let installmentPrice = 0;
59
- let totalPrice = 0;
60
-
61
- let numerator = Math.pow(1 + fees, numberInstallments) * fees;
62
- let denominator = Math.pow(1 + fees, numberInstallments) - 1;
63
-
64
- installmentPrice = cashPrice * (numerator / denominator);
65
- totalPrice = numberInstallments * installmentPrice;
66
-
67
- return {
68
- totalPrice: +totalPrice.toFixed(2),
69
- installmentPrice: +installmentPrice.toFixed(2),
70
- };
71
- };
72
-
73
- export { calculateCardInstallment };
@@ -1,25 +0,0 @@
1
- type EnsureQuotesFunction = (rawValue: string) => string;
2
-
3
- /**
4
- * Ensures that a given rawValue string is enclosed in quotes.
5
- *
6
- * This function checks if the input string is already enclosed in either single
7
- * quotes (`'`) or double quotes (`"`). If the string is already quoted, it is
8
- * returned as-is. Otherwise, the function wraps the string in double quotes.
9
- *
10
- * @param url - The URL string to be checked and potentially quoted.
11
- * @returns The input string, either unchanged if it is already quoted, or wrapped in double quotes.
12
- */
13
-
14
- const ensureQuotes: EnsureQuotesFunction = (rawValue) => {
15
- const hasSingleQuotes = rawValue.startsWith("'") && rawValue.endsWith("'");
16
- const hasDoubleQuotes = rawValue.startsWith('"') && rawValue.endsWith('"');
17
-
18
- if (hasSingleQuotes || hasDoubleQuotes) {
19
- return rawValue;
20
- }
21
-
22
- return `"${rawValue}"`;
23
- };
24
-
25
- export { ensureQuotes };
@@ -1,68 +0,0 @@
1
- type MaskSensitiveDataFunction = (
2
- jsonString: string,
3
- sensitiveKeys?: string[]
4
- ) => string;
5
-
6
- /**
7
- * Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
8
- *
9
- * @param jsonString - The JSON string to be processed.
10
- * @param sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
11
- * @returns A JSON string with sensitive data masked. If the input is not a valid JSON string, it returns the original string.
12
- *
13
- * @example
14
- * ```typescript
15
- * const jsonString = JSON.stringify({
16
- * username: "user123",
17
- * password: "secret",
18
- * profile: {
19
- * creditCard: "1234-5678-9012-3456",
20
- * },
21
- * });
22
- *
23
- * const result = maskSensitiveData(jsonString, ["password", "creditCard"]);
24
- * console.log(result);
25
- * // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
26
- * ```
27
- */
28
-
29
- const maskSensitiveData: MaskSensitiveDataFunction = (
30
- jsonString,
31
- sensitiveKeys = ["password", "confirmPassword", "creditCard"]
32
- ) => {
33
- function maskValue(key: string, value: any): any {
34
- if (sensitiveKeys.includes(key)) return "****";
35
- return value;
36
- }
37
-
38
- function recursiveMask(obj: any): any {
39
- if (Array.isArray(obj)) {
40
- return obj.map((item) => recursiveMask(item));
41
- } else if (obj !== null && typeof obj === "object") {
42
- return Object.keys(obj).reduce((acc, key) => {
43
- let value = obj[key];
44
- if (typeof value === "string") {
45
- try {
46
- const parsedValue = JSON.parse(value);
47
- if (typeof parsedValue === "object") {
48
- value = JSON.stringify(recursiveMask(parsedValue));
49
- }
50
- } catch (e) {}
51
- }
52
- acc[key] = recursiveMask(maskValue(key, value));
53
- return acc;
54
- }, {} as any);
55
- }
56
- return obj;
57
- }
58
-
59
- try {
60
- const jsonObject = JSON.parse(jsonString);
61
- const maskedObject = recursiveMask(jsonObject);
62
- return JSON.stringify(maskedObject);
63
- } catch (error) {
64
- return jsonString;
65
- }
66
- };
67
-
68
- export { maskSensitiveData };
@@ -1,29 +0,0 @@
1
- type RemoveCurrencySymbolsFunction = (formattedValue: string) => string;
2
-
3
- /**
4
- * Removes currency symbols from a given formatted string.
5
- *
6
- * This function takes a string that may contain currency symbols
7
- * and removes them using a regular expression. The resulting string
8
- * is also trimmed of any leading or trailing whitespace.
9
- *
10
- * @param formattedValue - The input string containing currency symbols.
11
- * @returns A string with all currency symbols removed and trimmed of whitespace.
12
- *
13
- * @example
14
- * removeCurrencySymbols("R$13,45"); // "13,45"
15
- * removeCurrencySymbols("$123.45"); // "123.45"
16
- * removeCurrencySymbols("€99.99"); // "99.99"
17
- * removeCurrencySymbols("¥1,000"); // "1,000"
18
- * removeCurrencySymbols("123.45"); // "123.45" (no symbols to remove)
19
- */
20
-
21
- const removeCurrencySymbols: RemoveCurrencySymbolsFunction = (
22
- formattedValue
23
- ) => {
24
- return formattedValue
25
- .replace(/(?:R\$|\p{Sc}|[$€¥£])/gu, "") // Inclui "R$" e outros símbolos comuns
26
- .trim();
27
- };
28
-
29
- export { removeCurrencySymbols };
@@ -1,20 +0,0 @@
1
- type RemoveNonNumericFunction = (formattedValue: string) => string;
2
-
3
- /**
4
- * Removes all non-numeric characters from a given string.
5
- *
6
- * @param prop - The input string from which non-numeric characters will be removed.
7
- * @returns A new string containing only numeric characters from the input.
8
- *
9
- * @example
10
- * ```typescript
11
- * const result = removeNonNumeric("abc123def456");
12
- * console.log(result); // Output: "123456"
13
- * ```
14
- */
15
-
16
- const removeNonNumeric: RemoveNonNumericFunction = (prop) => {
17
- return prop.replace(/[^0-9]/g, "");
18
- };
19
-
20
- export { removeNonNumeric };
@@ -1,20 +0,0 @@
1
- type StripHtmlTagsFunction = (rawHtml: string) => string;
2
-
3
- /**
4
- * Strips HTML tags from a string.
5
- *
6
- * This function removes all HTML tags from the provided string by replacing any content
7
- * that matches the HTML tag pattern with an empty string.
8
- *
9
- * @param rawHtml - The HTML string to be processed
10
- * @returns The input string with all HTML tags removed
11
- *
12
- * @example
13
- * stripHtmlTags("<p>Hello <strong>World</strong></p>"); // "Hello World"
14
- */
15
-
16
- const stripHtmlTags: StripHtmlTagsFunction = (rawHtml) => {
17
- return rawHtml.replace(/<\/?[^>]+(>|$)/g, "");
18
- };
19
-
20
- export { stripHtmlTags };