@arkyn/shared 2.2.1 → 2.2.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/README.md +4 -1
- package/dist/formats/formatDate.js +1 -1
- package/dist/formats/formatToDate.js +1 -1
- package/dist/formats/formatToPhone.d.ts +1 -1
- package/dist/formats/formatToPhone.js +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/services/stripHtmlTags.d.ts +16 -0
- package/dist/services/stripHtmlTags.d.ts.map +1 -0
- package/dist/services/stripHtmlTags.js +16 -0
- package/package.json +1 -1
- package/src/formats/formatToPhone.ts +1 -1
- package/src/index.ts +5 -1
- package/src/services/stripHtmlTags.ts +20 -0
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npm install @arkyn/shared
|
|
|
16
16
|
|
|
17
17
|
### Formatting
|
|
18
18
|
|
|
19
|
-
- **`formatDate(date:
|
|
19
|
+
- **`formatDate(date: dateString[], inputFormat: "brazilianDate" | "isoDate" | "timestamp", outputFormat: string, timezone?: number): string`**
|
|
20
20
|
Formats a date into a readable string.
|
|
21
21
|
|
|
22
22
|
- **`formatJsonObject(obj: object): string`**
|
|
@@ -40,6 +40,9 @@ npm install @arkyn/shared
|
|
|
40
40
|
- **`formatToCurrency(value: number): string`**
|
|
41
41
|
Converts a number into a currency format.
|
|
42
42
|
|
|
43
|
+
- **`formatToDate(date: dateString[], inputFormat: "brazilianDate" | "isoDate" | "timestamp", timezone?: number): Date`**
|
|
44
|
+
Formats a date into a Date class.
|
|
45
|
+
|
|
43
46
|
- **`formatToEllipsis(value: string, maxLength: number): string`**
|
|
44
47
|
Truncates a string and appends an ellipsis if it exceeds the maximum length.
|
|
45
48
|
|
|
@@ -41,7 +41,7 @@ function formatDateString(date, format) {
|
|
|
41
41
|
*/
|
|
42
42
|
const formatDate = ([date, time = "00:00:00"], inputFormat, outputFormat, timezone = 0) => {
|
|
43
43
|
const dateParts = date.split(/[-/]/).map(Number);
|
|
44
|
-
const timeParts = time.split(":").map(Number);
|
|
44
|
+
const timeParts = time.split(".")[0].split(":").map(Number);
|
|
45
45
|
let day, month, year;
|
|
46
46
|
const [hours = 0, minutes = 0, seconds = 0] = timeParts;
|
|
47
47
|
switch (inputFormat) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const formatToDate = ([date, time = "00:00:00"], inputFormat, timezone = 0) => {
|
|
2
2
|
const dateParts = date.split(/[-/]/).map(Number);
|
|
3
|
-
const timeParts = time.split(":").map(Number);
|
|
3
|
+
const timeParts = time.split(".")[0].split(":").map(Number);
|
|
4
4
|
let day, month, year;
|
|
5
5
|
const [hours = 0, minutes = 0, seconds = 0] = timeParts;
|
|
6
6
|
switch (inputFormat) {
|
|
@@ -7,7 +7,7 @@ import type { FormatToPhoneFunction } from "@arkyn/types";
|
|
|
7
7
|
*
|
|
8
8
|
* @param prop - The phone number string to be formatted. It must include the country code and optionally a prefix.
|
|
9
9
|
* Example formats:
|
|
10
|
-
* - "+55
|
|
10
|
+
* - "+55 32912345678"
|
|
11
11
|
* - "+1 1234567890"
|
|
12
12
|
*
|
|
13
13
|
* @returns The formatted phone number string based on the country's formatting rules.
|
|
@@ -88,7 +88,7 @@ function getCountryWithoutPrefixCode(countryCode) {
|
|
|
88
88
|
*
|
|
89
89
|
* @param prop - The phone number string to be formatted. It must include the country code and optionally a prefix.
|
|
90
90
|
* Example formats:
|
|
91
|
-
* - "+55
|
|
91
|
+
* - "+55 32912345678"
|
|
92
92
|
* - "+1 1234567890"
|
|
93
93
|
*
|
|
94
94
|
* @returns The formatted phone number string based on the country's formatting rules.
|
package/dist/index.d.ts
CHANGED
|
@@ -6,21 +6,25 @@ export { formatToCnpj } from "./formats/formatToCnpj";
|
|
|
6
6
|
export { formatToCpf } from "./formats/formatToCpf";
|
|
7
7
|
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
8
8
|
export { formatToCurrency } from "./formats/formatToCurrency";
|
|
9
|
+
export { formatToDate } from "./formats/formatToDate";
|
|
9
10
|
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
10
11
|
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
11
12
|
export { formatToPhone } from "./formats/formatToPhone";
|
|
12
|
-
export { formatToDate } from "./formats/formatToDate";
|
|
13
13
|
export { generateColorByString } from "./generators/generateColorByString";
|
|
14
14
|
export { generateId } from "./generators/generateId";
|
|
15
15
|
export { generateSlug } from "./generators/generateSlug";
|
|
16
16
|
export { calculateCardInstallment } from "./services/calculateCardInstallment";
|
|
17
|
+
export { ensureQuotes } from "./services/ensureQuotes";
|
|
17
18
|
export { maskSensitiveData } from "./services/maskSensitiveData";
|
|
19
|
+
export { removeCurrencySymbols } from "./services/removeCurrencySymbols";
|
|
18
20
|
export { removeNonNumeric } from "./services/removeNonNumeric";
|
|
21
|
+
export { stripHtmlTags } from "./services/stripHtmlTags";
|
|
19
22
|
export { truncateLargeFields } from "./services/truncateLargeFields";
|
|
20
23
|
export { validateCep } from "./validations/validateCep";
|
|
21
24
|
export { validateCnpj } from "./validations/validateCnpj";
|
|
22
25
|
export { validateCpf } from "./validations/validateCpf";
|
|
23
26
|
export { validateDate } from "./validations/validateDate";
|
|
27
|
+
export { validatePassword } from "./validations/validatePassword";
|
|
24
28
|
export { validatePhone } from "./validations/validatePhone";
|
|
25
29
|
export { validateRg } from "./validations/validateRg";
|
|
26
30
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE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EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,23 +7,27 @@ export { formatToCnpj } from "./formats/formatToCnpj";
|
|
|
7
7
|
export { formatToCpf } from "./formats/formatToCpf";
|
|
8
8
|
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
9
9
|
export { formatToCurrency } from "./formats/formatToCurrency";
|
|
10
|
+
export { formatToDate } from "./formats/formatToDate";
|
|
10
11
|
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
11
12
|
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
12
13
|
export { formatToPhone } from "./formats/formatToPhone";
|
|
13
|
-
export { formatToDate } from "./formats/formatToDate";
|
|
14
14
|
// generators
|
|
15
15
|
export { generateColorByString } from "./generators/generateColorByString";
|
|
16
16
|
export { generateId } from "./generators/generateId";
|
|
17
17
|
export { generateSlug } from "./generators/generateSlug";
|
|
18
18
|
// services
|
|
19
19
|
export { calculateCardInstallment } from "./services/calculateCardInstallment";
|
|
20
|
+
export { ensureQuotes } from "./services/ensureQuotes";
|
|
20
21
|
export { maskSensitiveData } from "./services/maskSensitiveData";
|
|
22
|
+
export { removeCurrencySymbols } from "./services/removeCurrencySymbols";
|
|
21
23
|
export { removeNonNumeric } from "./services/removeNonNumeric";
|
|
24
|
+
export { stripHtmlTags } from "./services/stripHtmlTags";
|
|
22
25
|
export { truncateLargeFields } from "./services/truncateLargeFields";
|
|
23
26
|
// utils
|
|
24
27
|
export { validateCep } from "./validations/validateCep";
|
|
25
28
|
export { validateCnpj } from "./validations/validateCnpj";
|
|
26
29
|
export { validateCpf } from "./validations/validateCpf";
|
|
27
30
|
export { validateDate } from "./validations/validateDate";
|
|
31
|
+
export { validatePassword } from "./validations/validatePassword";
|
|
28
32
|
export { validatePhone } from "./validations/validatePhone";
|
|
29
33
|
export { validateRg } from "./validations/validateRg";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { StripHtmlTagsFunction } from "@arkyn/types";
|
|
2
|
+
/**
|
|
3
|
+
* Strips HTML tags from a string.
|
|
4
|
+
*
|
|
5
|
+
* This function removes all HTML tags from the provided string by replacing any content
|
|
6
|
+
* that matches the HTML tag pattern with an empty string.
|
|
7
|
+
*
|
|
8
|
+
* @param rawHtml - The HTML string to be processed
|
|
9
|
+
* @returns The input string with all HTML tags removed
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* stripHtmlTags("<p>Hello <strong>World</strong></p>"); // "Hello World"
|
|
13
|
+
*/
|
|
14
|
+
declare const stripHtmlTags: StripHtmlTagsFunction;
|
|
15
|
+
export { stripHtmlTags };
|
|
16
|
+
//# sourceMappingURL=stripHtmlTags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripHtmlTags.d.ts","sourceRoot":"","sources":["../../src/services/stripHtmlTags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D;;;;;;;;;;;GAWG;AAEH,QAAA,MAAM,aAAa,EAAE,qBAEpB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips HTML tags from a string.
|
|
3
|
+
*
|
|
4
|
+
* This function removes all HTML tags from the provided string by replacing any content
|
|
5
|
+
* that matches the HTML tag pattern with an empty string.
|
|
6
|
+
*
|
|
7
|
+
* @param rawHtml - The HTML string to be processed
|
|
8
|
+
* @returns The input string with all HTML tags removed
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* stripHtmlTags("<p>Hello <strong>World</strong></p>"); // "Hello World"
|
|
12
|
+
*/
|
|
13
|
+
const stripHtmlTags = (rawHtml) => {
|
|
14
|
+
return rawHtml.replace(/<\/?[^>]+(>|$)/g, "");
|
|
15
|
+
};
|
|
16
|
+
export { stripHtmlTags };
|
package/package.json
CHANGED
|
@@ -108,7 +108,7 @@ function getCountryWithoutPrefixCode(countryCode: string) {
|
|
|
108
108
|
*
|
|
109
109
|
* @param prop - The phone number string to be formatted. It must include the country code and optionally a prefix.
|
|
110
110
|
* Example formats:
|
|
111
|
-
* - "+55
|
|
111
|
+
* - "+55 32912345678"
|
|
112
112
|
* - "+1 1234567890"
|
|
113
113
|
*
|
|
114
114
|
* @returns The formatted phone number string based on the country's formatting rules.
|
package/src/index.ts
CHANGED
|
@@ -7,10 +7,10 @@ export { formatToCnpj } from "./formats/formatToCnpj";
|
|
|
7
7
|
export { formatToCpf } from "./formats/formatToCpf";
|
|
8
8
|
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
9
9
|
export { formatToCurrency } from "./formats/formatToCurrency";
|
|
10
|
+
export { formatToDate } from "./formats/formatToDate";
|
|
10
11
|
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
11
12
|
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
12
13
|
export { formatToPhone } from "./formats/formatToPhone";
|
|
13
|
-
export { formatToDate } from "./formats/formatToDate";
|
|
14
14
|
|
|
15
15
|
// generators
|
|
16
16
|
export { generateColorByString } from "./generators/generateColorByString";
|
|
@@ -19,8 +19,11 @@ export { generateSlug } from "./generators/generateSlug";
|
|
|
19
19
|
|
|
20
20
|
// services
|
|
21
21
|
export { calculateCardInstallment } from "./services/calculateCardInstallment";
|
|
22
|
+
export { ensureQuotes } from "./services/ensureQuotes";
|
|
22
23
|
export { maskSensitiveData } from "./services/maskSensitiveData";
|
|
24
|
+
export { removeCurrencySymbols } from "./services/removeCurrencySymbols";
|
|
23
25
|
export { removeNonNumeric } from "./services/removeNonNumeric";
|
|
26
|
+
export { stripHtmlTags } from "./services/stripHtmlTags";
|
|
24
27
|
export { truncateLargeFields } from "./services/truncateLargeFields";
|
|
25
28
|
|
|
26
29
|
// utils
|
|
@@ -28,5 +31,6 @@ export { validateCep } from "./validations/validateCep";
|
|
|
28
31
|
export { validateCnpj } from "./validations/validateCnpj";
|
|
29
32
|
export { validateCpf } from "./validations/validateCpf";
|
|
30
33
|
export { validateDate } from "./validations/validateDate";
|
|
34
|
+
export { validatePassword } from "./validations/validatePassword";
|
|
31
35
|
export { validatePhone } from "./validations/validatePhone";
|
|
32
36
|
export { validateRg } from "./validations/validateRg";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { StripHtmlTagsFunction } from "@arkyn/types";
|
|
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 };
|