@arkyn/shared 3.0.1-beta.9 → 3.0.1-beta.90

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 (66) hide show
  1. package/README.md +452 -67
  2. package/dist/bundle.js +2337 -0
  3. package/dist/bundle.umd.cjs +6 -0
  4. package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts +35 -0
  5. package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts.map +1 -0
  6. package/dist/formats/formatToCapitalizeFirstWordLetter.js +42 -0
  7. package/dist/index.d.ts +2 -7
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -8
  10. package/dist/services/isHtml.d.ts +22 -0
  11. package/dist/services/isHtml.d.ts.map +1 -0
  12. package/dist/services/isHtml.js +24 -0
  13. package/package.json +26 -6
  14. package/dist/validations/validateCep.d.ts +0 -24
  15. package/dist/validations/validateCep.d.ts.map +0 -1
  16. package/dist/validations/validateCep.js +0 -33
  17. package/dist/validations/validateCnpj.d.ts +0 -22
  18. package/dist/validations/validateCnpj.d.ts.map +0 -1
  19. package/dist/validations/validateCnpj.js +0 -52
  20. package/dist/validations/validateCpf.d.ts +0 -24
  21. package/dist/validations/validateCpf.d.ts.map +0 -1
  22. package/dist/validations/validateCpf.js +0 -54
  23. package/dist/validations/validateDate.d.ts +0 -34
  24. package/dist/validations/validateDate.d.ts.map +0 -1
  25. package/dist/validations/validateDate.js +0 -73
  26. package/dist/validations/validatePassword.d.ts +0 -21
  27. package/dist/validations/validatePassword.d.ts.map +0 -1
  28. package/dist/validations/validatePassword.js +0 -34
  29. package/dist/validations/validatePhone.d.ts +0 -29
  30. package/dist/validations/validatePhone.d.ts.map +0 -1
  31. package/dist/validations/validatePhone.js +0 -44
  32. package/dist/validations/validateRg.d.ts +0 -22
  33. package/dist/validations/validateRg.d.ts.map +0 -1
  34. package/dist/validations/validateRg.js +0 -31
  35. package/src/formats/formatDate.ts +0 -92
  36. package/src/formats/formatJsonObject.ts +0 -90
  37. package/src/formats/formatJsonString.ts +0 -50
  38. package/src/formats/formatToCep.ts +0 -39
  39. package/src/formats/formatToCnpj.ts +0 -40
  40. package/src/formats/formatToCpf.ts +0 -40
  41. package/src/formats/formatToCpfCnpj.ts +0 -38
  42. package/src/formats/formatToCurrency.ts +0 -63
  43. package/src/formats/formatToDate.ts +0 -70
  44. package/src/formats/formatToEllipsis.ts +0 -25
  45. package/src/formats/formatToHiddenDigits.ts +0 -92
  46. package/src/formats/formatToPhone.ts +0 -170
  47. package/src/generators/generateColorByString.ts +0 -33
  48. package/src/generators/generateId.ts +0 -61
  49. package/src/generators/generateSlug.ts +0 -31
  50. package/src/index.ts +0 -36
  51. package/src/services/calculateCardInstallment.ts +0 -73
  52. package/src/services/ensureQuotes.ts +0 -25
  53. package/src/services/maskSensitiveData.ts +0 -68
  54. package/src/services/removeCurrencySymbols.ts +0 -29
  55. package/src/services/removeNonNumeric.ts +0 -20
  56. package/src/services/stripHtmlTags.ts +0 -20
  57. package/src/services/truncateLargeFields.ts +0 -69
  58. package/src/validations/validateCep.ts +0 -41
  59. package/src/validations/validateCnpj.ts +0 -65
  60. package/src/validations/validateCpf.ts +0 -62
  61. package/src/validations/validateDate.ts +0 -86
  62. package/src/validations/validatePassword.ts +0 -41
  63. package/src/validations/validatePhone.ts +0 -50
  64. package/src/validations/validateRg.ts +0 -37
  65. package/tsconfig.json +0 -20
  66. package/vitest.config.ts +0 -5
@@ -1,38 +0,0 @@
1
- import { formatToCnpj } from "./formatToCnpj";
2
- import { formatToCpf } from "./formatToCpf";
3
-
4
- type FormatToCpfCnpjFunction = (value: string) => string;
5
-
6
- /**
7
- * Formats a given string value into either a CPF or CNPJ format based on its length.
8
- *
9
- * - If the input contains 11 numeric characters, it is formatted as a CPF.
10
- * - If the input contains 14 numeric characters, it is formatted as a CNPJ.
11
- * - Throws an error if the input length is neither 11 nor 14 after removing non-numeric characters.
12
- *
13
- * @param value - The string value to be formatted. It may contain non-numeric characters, which will be removed.
14
- * @returns The formatted CPF or CNPJ string.
15
- * @throws {Error} If the input does not have a valid CPF or CNPJ length.
16
- *
17
- * @example
18
- * ```typescript
19
- * formatToCpfCnpj("123.456.789-09"); // Returns "123.456.789-09" (CPF format)
20
- * formatToCpfCnpj("12.345.678/0001-95"); // Returns "12.345.678/0001-95" (CNPJ format)
21
- * formatToCpfCnpj("12345678909"); // Returns "123.456.789-09" (CPF format)
22
- * formatToCpfCnpj("12345678000195"); // Returns "12.345.678/0001-95" (CNPJ format)
23
- * formatToCpfCnpj("123"); // Throws an error: "Invalid CPF or CNPJ length"
24
- * ```
25
- */
26
-
27
- const formatToCpfCnpj: FormatToCpfCnpjFunction = (value) => {
28
- const cleaned = value.replace(/\D/g, "");
29
- if (cleaned.length === 11) {
30
- return formatToCpf(cleaned);
31
- } else if (cleaned.length === 14) {
32
- return formatToCnpj(cleaned);
33
- }
34
-
35
- throw new Error("Invalid CPF or CNPJ length");
36
- };
37
-
38
- export { formatToCpfCnpj };
@@ -1,63 +0,0 @@
1
- import { countryCurrencies } from "@arkyn/templates";
2
- import { removeCurrencySymbols } from "../services/removeCurrencySymbols";
3
-
4
- type Currencies = keyof typeof countryCurrencies;
5
-
6
- type Config = {
7
- showPrefix?: boolean;
8
- };
9
-
10
- type FormatToCurrency = (
11
- value: number,
12
- currency: Currencies,
13
- config?: Config
14
- ) => string;
15
-
16
- /**
17
- * Formats a numeric value into a currency string based on the specified currency and configuration.
18
- *
19
- * @param value - The numeric value to be formatted.
20
- * @param currency - The currency code used to determine the formatting style.
21
- * @param config - Optional configuration object.
22
- * @param config.showPrefix - Determines whether the currency symbol/prefix should be included in the formatted string. Defaults to `true`.
23
- *
24
- * @returns A formatted currency string. If `config.showPrefix` is `false`, the currency symbol is removed.
25
- *
26
- * @example
27
- * ```typescript
28
- * const formatted = formatToCurrency(1234.56, "USD", { showPrefix: true });
29
- * console.log(formatted); // "$1,234.56"
30
- *
31
- * const withoutPrefix = formatToCurrency(1234.56, "USD", { showPrefix: false });
32
- * console.log(withoutPrefix); // "1,234.56"
33
- *
34
- * const formattedBRL = formatToCurrency(1234.56, "BRL", { showPrefix: true });
35
- * console.log(formattedBRL); // "R$ 1.234,56"
36
- *
37
- * const withoutPrefixBRL = formatToCurrency(1234.56, "BRL", { showPrefix: false });
38
- * console.log(withoutPrefixBRL); // "1.234,56"
39
- * ```
40
- */
41
-
42
- const formatToCurrency: FormatToCurrency = (
43
- value,
44
- currency,
45
- config = { showPrefix: true }
46
- ) => {
47
- if (!countryCurrencies[currency]) {
48
- throw new Error("Unsupported currency code");
49
- }
50
-
51
- const { countryCurrency, countryLanguage } = countryCurrencies[currency];
52
-
53
- const format = new Intl.NumberFormat(countryLanguage, {
54
- style: "currency",
55
- currency: countryCurrency,
56
- }).format(value);
57
-
58
- return config.showPrefix
59
- ? format.replace(/\s/g, " ")
60
- : removeCurrencySymbols(format).replace(/\s/g, " ");
61
- };
62
-
63
- export { formatToCurrency };
@@ -1,70 +0,0 @@
1
- type InputFormatTypes = "brazilianDate" | "timestamp" | "isoDate";
2
-
3
- type FormatToDateFunction = (
4
- date: string[], // [date: string, time?: string]
5
- inputFormat: InputFormatTypes,
6
- timezone?: number
7
- ) => Date;
8
-
9
- /**
10
- * Converts a date and time input into a JavaScript `Date` object, formatted according to the specified input format and timezone.
11
- *
12
- * @param param0 - A tuple containing the date string and an optional time string.
13
- * The date string format depends on the `inputFormat` parameter.
14
- * The time string defaults to "00:00:00" if not provided.
15
- * @param inputFormat - The format of the input date string.
16
- * Supported formats are:
17
- * - `"brazilianDate"`: Expects the date in `DD/MM/YYYY` format.
18
- * - `"isoDate"`: Expects the date in `YYYY-MM-DD` format.
19
- * - `"timestamp"`: Expects the date in `YYYY-MM-DD` format (similar to `isoDate`).
20
- * @param timezone - An optional timezone offset in hours. Defaults to `0` (UTC).
21
- *
22
- * @returns A `Date` object representing the parsed date and time, adjusted for the specified timezone.
23
- *
24
- * @throws {Error} If the `inputFormat` is invalid.
25
- * @throws {Error} If the provided date or time is invalid.
26
- *
27
- * @example
28
- * ```typescript
29
- * import { formatToDate } from "./formatToIsoDate";
30
- *
31
- * const date = formatToDate(["25/12/2023", "15:30:00"], "brazilianDate", -3);
32
- * console.log(date); // Outputs a Date object for "2023-12-25T18:30:00.000Z" (UTC)
33
- * ```
34
- */
35
-
36
- const formatToDate: FormatToDateFunction = (
37
- [date, time = "00:00:00"],
38
- inputFormat,
39
- timezone = 0
40
- ) => {
41
- const dateParts = date.split(/[-/]/).map(Number);
42
- const timeParts = time.split(".")[0].split(":").map(Number);
43
-
44
- let day, month, year;
45
- const [hours = 0, minutes = 0, seconds = 0] = timeParts;
46
-
47
- switch (inputFormat) {
48
- case "brazilianDate":
49
- [day, month, year] = dateParts;
50
- break;
51
- case "isoDate":
52
- [year, month, day] = dateParts;
53
- break;
54
- case "timestamp":
55
- [year, month, day] = dateParts.map(Number);
56
- break;
57
- default:
58
- throw new Error("Invalid input format");
59
- }
60
-
61
- const utcDate = new Date(
62
- Date.UTC(year, month - 1, day, hours - timezone, minutes, seconds)
63
- );
64
-
65
- if (isNaN(utcDate.getTime())) throw new Error("Invalid date");
66
-
67
- return utcDate;
68
- };
69
-
70
- export { formatToDate };
@@ -1,25 +0,0 @@
1
- type FormatToEllipsisFunction = (value: string, maxLength: number) => string;
2
-
3
- /**
4
- * Truncates a given text to a specified maximum length and appends an ellipsis ("...")
5
- * if the text exceeds the maximum length.
6
- *
7
- * @param text - The input string to be truncated.
8
- * @param maxLength - The maximum allowed length of the string before truncation.
9
- * @returns The truncated string with an ellipsis if the input exceeds the maximum length,
10
- * or the original string if it does not.
11
- * @example
12
- * const result = formatToEllipsis("Hello, world!", 5);
13
- * console.log(result); // Output: "Hello..."
14
- */
15
-
16
- const formatToEllipsis: FormatToEllipsisFunction = (text, maxLength) => {
17
- if (text.length > maxLength) {
18
- let trimmedText = text.substring(0, maxLength).trimEnd();
19
- trimmedText = trimmedText.replace(/[.,!?;:]$/, "");
20
- return `${trimmedText}...`;
21
- }
22
- return text;
23
- };
24
-
25
- export { formatToEllipsis };
@@ -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,36 +0,0 @@
1
- // formats
2
- export { formatDate } from "./formats/formatDate";
3
- export { formatJsonObject } from "./formats/formatJsonObject";
4
- export { formatJsonString } from "./formats/formatJsonString";
5
- export { formatToCep } from "./formats/formatToCep";
6
- export { formatToCnpj } from "./formats/formatToCnpj";
7
- export { formatToCpf } from "./formats/formatToCpf";
8
- export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
9
- export { formatToCurrency } from "./formats/formatToCurrency";
10
- export { formatToDate } from "./formats/formatToDate";
11
- export { formatToEllipsis } from "./formats/formatToEllipsis";
12
- export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
13
- export { formatToPhone } from "./formats/formatToPhone";
14
-
15
- // generators
16
- export { generateColorByString } from "./generators/generateColorByString";
17
- export { generateId } from "./generators/generateId";
18
- export { generateSlug } from "./generators/generateSlug";
19
-
20
- // services
21
- export { calculateCardInstallment } from "./services/calculateCardInstallment";
22
- export { ensureQuotes } from "./services/ensureQuotes";
23
- export { maskSensitiveData } from "./services/maskSensitiveData";
24
- export { removeCurrencySymbols } from "./services/removeCurrencySymbols";
25
- export { removeNonNumeric } from "./services/removeNonNumeric";
26
- export { stripHtmlTags } from "./services/stripHtmlTags";
27
- export { truncateLargeFields } from "./services/truncateLargeFields";
28
-
29
- // utils
30
- export { validateCep } from "./validations/validateCep";
31
- export { validateCnpj } from "./validations/validateCnpj";
32
- export { validateCpf } from "./validations/validateCpf";
33
- export { validateDate } from "./validations/validateDate";
34
- export { validatePassword } from "./validations/validatePassword";
35
- export { validatePhone } from "./validations/validatePhone";
36
- export { validateRg } from "./validations/validateRg";