@arkyn/shared 3.0.1-beta.115 → 3.0.1-beta.117
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/bundle.js +342 -282
- package/dist/bundle.umd.cjs +6 -6
- package/dist/formats/formatDate.d.ts +43 -15
- package/dist/formats/formatDate.d.ts.map +1 -1
- package/dist/formats/formatDate.js +60 -25
- package/dist/formats/formatJsonObject.d.ts +6 -7
- package/dist/formats/formatJsonObject.d.ts.map +1 -1
- package/dist/formats/formatJsonObject.js +17 -17
- package/dist/formats/formatToCep.d.ts +5 -12
- package/dist/formats/formatToCep.d.ts.map +1 -1
- package/dist/formats/formatToCep.js +11 -16
- package/dist/formats/formatToCnpj.d.ts +3 -13
- package/dist/formats/formatToCnpj.d.ts.map +1 -1
- package/dist/formats/formatToCnpj.js +9 -17
- package/dist/formats/formatToCpf.d.ts +5 -13
- package/dist/formats/formatToCpf.d.ts.map +1 -1
- package/dist/formats/formatToCpf.js +11 -17
- package/dist/formats/formatToCurrency.d.ts +18 -14
- package/dist/formats/formatToCurrency.d.ts.map +1 -1
- package/dist/formats/formatToCurrency.js +21 -14
- package/dist/formats/formatToEllipsis.d.ts +8 -5
- package/dist/formats/formatToEllipsis.d.ts.map +1 -1
- package/dist/formats/formatToEllipsis.js +21 -7
- package/dist/formats/formatToHiddenDigits.d.ts +16 -16
- package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
- package/dist/formats/formatToHiddenDigits.js +19 -19
- package/dist/formats/formatToPhone.d.ts +1 -1
- package/dist/formats/formatToPhone.d.ts.map +1 -1
- package/dist/formats/formatToPhone.js +3 -3
- package/dist/generators/generateColorByString.d.ts +7 -4
- package/dist/generators/generateColorByString.d.ts.map +1 -1
- package/dist/generators/generateColorByString.js +10 -6
- package/dist/generators/generateId.d.ts +3 -3
- package/dist/generators/generateSlug.d.ts +10 -3
- package/dist/generators/generateSlug.d.ts.map +1 -1
- package/dist/generators/generateSlug.js +11 -4
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -10
- package/dist/parsers/parseDate.d.ts +41 -0
- package/dist/parsers/parseDate.d.ts.map +1 -0
- package/dist/parsers/parseDate.js +67 -0
- package/dist/{services/truncateLargeFields.d.ts → parsers/parseLargeFields.d.ts} +9 -11
- package/dist/parsers/parseLargeFields.d.ts.map +1 -0
- package/dist/{services/truncateLargeFields.js → parsers/parseLargeFields.js} +12 -13
- package/dist/parsers/parseSensitiveData.d.ts +23 -0
- package/dist/parsers/parseSensitiveData.d.ts.map +1 -0
- package/dist/{services/maskSensitiveData.js → parsers/parseSensitiveData.js} +10 -12
- package/dist/services/validateDateService.d.ts +9 -0
- package/dist/services/validateDateService.d.ts.map +1 -0
- package/dist/services/validateDateService.js +56 -0
- package/dist/{services → utilities}/calculateCardInstallment.d.ts +16 -18
- package/dist/utilities/calculateCardInstallment.d.ts.map +1 -0
- package/dist/{services → utilities}/calculateCardInstallment.js +12 -15
- package/dist/utilities/ensureQuotes.d.ts +21 -0
- package/dist/utilities/ensureQuotes.d.ts.map +1 -0
- package/dist/{services → utilities}/ensureQuotes.js +12 -4
- package/dist/utilities/isHtml.d.ts +22 -0
- package/dist/utilities/isHtml.d.ts.map +1 -0
- package/dist/utilities/isHtml.js +24 -0
- package/dist/{services → utilities}/removeCurrencySymbols.d.ts +6 -4
- package/dist/utilities/removeCurrencySymbols.d.ts.map +1 -0
- package/dist/{services → utilities}/removeCurrencySymbols.js +8 -7
- package/dist/utilities/removeNonNumeric.d.ts +16 -0
- package/dist/utilities/removeNonNumeric.d.ts.map +1 -0
- package/dist/utilities/removeNonNumeric.js +17 -0
- package/dist/utilities/stripHtmlTags.d.ts +19 -0
- package/dist/utilities/stripHtmlTags.d.ts.map +1 -0
- package/dist/utilities/stripHtmlTags.js +24 -0
- package/package.json +1 -4
- package/dist/formats/formatToCpfCnpj.d.ts +0 -24
- package/dist/formats/formatToCpfCnpj.d.ts.map +0 -1
- package/dist/formats/formatToCpfCnpj.js +0 -33
- package/dist/formats/formatToDate.d.ts +0 -32
- package/dist/formats/formatToDate.d.ts.map +0 -1
- package/dist/formats/formatToDate.js +0 -50
- package/dist/services/calculateCardInstallment.d.ts.map +0 -1
- package/dist/services/ensureQuotes.d.ts +0 -14
- package/dist/services/ensureQuotes.d.ts.map +0 -1
- package/dist/services/isHtml.d.ts +0 -22
- package/dist/services/isHtml.d.ts.map +0 -1
- package/dist/services/isHtml.js +0 -24
- package/dist/services/maskSensitiveData.d.ts +0 -26
- package/dist/services/maskSensitiveData.d.ts.map +0 -1
- package/dist/services/removeCurrencySymbols.d.ts.map +0 -1
- package/dist/services/removeNonNumeric.d.ts +0 -16
- package/dist/services/removeNonNumeric.d.ts.map +0 -1
- package/dist/services/removeNonNumeric.js +0 -16
- package/dist/services/stripHtmlTags.d.ts +0 -16
- package/dist/services/stripHtmlTags.d.ts.map +0 -1
- package/dist/services/stripHtmlTags.js +0 -16
- package/dist/services/truncateLargeFields.d.ts.map +0 -1
|
@@ -24,37 +24,37 @@ const within = (range, value) => value >= range[0] && value <= range[1];
|
|
|
24
24
|
* This function takes a string input and replaces digits within a specified range
|
|
25
25
|
* with a hiding character (e.g., "*"). Non-digit characters remain unchanged.
|
|
26
26
|
*
|
|
27
|
-
* @param value - The input string to be formatted.
|
|
28
|
-
* @param options - Configuration options for formatting.
|
|
29
|
-
* @param options.range - The range of digits to hide. It can be:
|
|
27
|
+
* @param {string} value - The input string to be formatted.
|
|
28
|
+
* @param {FormatToHiddenDigitsOptions} options - Configuration options for formatting.
|
|
29
|
+
* @param {number | [number, number]} options.range - The range of digits to hide. It can be:
|
|
30
30
|
* - A single number (e.g., `3`), which hides the first `n` digits if positive,
|
|
31
31
|
* or the last `n` digits if negative.
|
|
32
32
|
* - A tuple `[start, end]` specifying the range of digits to hide (inclusive).
|
|
33
33
|
* - Defaults to `3`, hiding the first three digits.
|
|
34
|
-
* @param options.hider - The character used to hide digits. Defaults to `"*"`.
|
|
34
|
+
* @param {string} options.hider - The character used to hide digits. Defaults to `"*"`.
|
|
35
35
|
*
|
|
36
|
-
* @returns The formatted string with specified digits hidden.
|
|
36
|
+
* @returns {string} The formatted string with specified digits hidden.
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
39
|
* ```typescript
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* // Output: "***-456-7890"
|
|
40
|
+
* const formatted = formatToHiddenDigits("123-456-7890", { range: 3 });
|
|
41
|
+
* console.log(formatted); // Output: "***-456-7890"
|
|
42
|
+
* ```
|
|
44
43
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const formatted = formatToHiddenDigits("123-456-7890", { range: [4, 6], hider: "#" });
|
|
47
|
+
* console.log(formatted); // Output: "123-###-7890"
|
|
47
48
|
* ```
|
|
48
49
|
*/
|
|
49
|
-
|
|
50
|
+
function formatToHiddenDigits(value, options) {
|
|
50
51
|
const characters = parseToCharacters(value);
|
|
51
|
-
const range = normalizeRange(options
|
|
52
|
-
|
|
53
|
-
.map((node) => {
|
|
52
|
+
const range = normalizeRange(options?.range ?? 3, characters.digits);
|
|
53
|
+
const mappedCharacters = characters.children.map((node) => {
|
|
54
54
|
if (node.kind === "digit" && within(range, node.digit))
|
|
55
|
-
return options
|
|
55
|
+
return options?.hider ?? "*";
|
|
56
56
|
return node.character;
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
}
|
|
57
|
+
});
|
|
58
|
+
return mappedCharacters.join("");
|
|
59
|
+
}
|
|
60
60
|
export { formatToHiddenDigits };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToPhone.d.ts","sourceRoot":"","sources":["../../src/formats/formatToPhone.ts"],"names":[],"mappings":"AAaA,KAAK,qBAAqB,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"formatToPhone.d.ts","sourceRoot":"","sources":["../../src/formats/formatToPhone.ts"],"names":[],"mappings":"AAaA,KAAK,qBAAqB,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;AAmG3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,QAAA,MAAM,aAAa,EAAE,qBAwBpB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { countries } from "@arkyn/templates";
|
|
2
|
-
import { removeNonNumeric } from "../
|
|
2
|
+
import { removeNonNumeric } from "../utilities/removeNonNumeric";
|
|
3
3
|
function getMask(value) {
|
|
4
|
-
const mask = value.length > 10 ? "NINE" : "
|
|
4
|
+
const mask = value.length > 10 ? "NINE" : "EIGHT";
|
|
5
5
|
return mask;
|
|
6
6
|
}
|
|
7
7
|
const TYPES = {
|
|
8
|
-
|
|
8
|
+
EIGHT: "(99) 9999-9999",
|
|
9
9
|
NINE: "(99) 99999-9999",
|
|
10
10
|
};
|
|
11
11
|
const MAX_LENGTH = removeNonNumeric(TYPES.NINE).length;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
type GenerateColorByStringFunction = (prop: string) => string;
|
|
2
1
|
/**
|
|
3
2
|
* Generates a hexadecimal color code based on the input string.
|
|
4
3
|
* The function creates a hash from the string and uses it to calculate
|
|
5
4
|
* RGB values, which are then converted to a hexadecimal color code.
|
|
6
5
|
*
|
|
7
|
-
* @param
|
|
8
|
-
*
|
|
6
|
+
* @param {string} rawString - The input string used to generate the color.
|
|
7
|
+
*
|
|
8
|
+
* @returns {string} A hexadecimal color code (e.g., "#a1b2c3") derived from the input string.
|
|
9
|
+
*
|
|
9
10
|
* @example
|
|
11
|
+
* ```typescript
|
|
10
12
|
* const color = generateColorByString("example");
|
|
11
13
|
* console.log(color); // Outputs a consistent hex color like "#5e8f9a"
|
|
14
|
+
* ```
|
|
12
15
|
*/
|
|
13
|
-
declare
|
|
16
|
+
declare function generateColorByString(rawString: string): string;
|
|
14
17
|
export { generateColorByString };
|
|
15
18
|
//# sourceMappingURL=generateColorByString.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateColorByString.d.ts","sourceRoot":"","sources":["../../src/generators/generateColorByString.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"generateColorByString.d.ts","sourceRoot":"","sources":["../../src/generators/generateColorByString.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,iBAAS,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAgBxD;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -3,16 +3,20 @@
|
|
|
3
3
|
* The function creates a hash from the string and uses it to calculate
|
|
4
4
|
* RGB values, which are then converted to a hexadecimal color code.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
*
|
|
6
|
+
* @param {string} rawString - The input string used to generate the color.
|
|
7
|
+
*
|
|
8
|
+
* @returns {string} A hexadecimal color code (e.g., "#a1b2c3") derived from the input string.
|
|
9
|
+
*
|
|
8
10
|
* @example
|
|
11
|
+
* ```typescript
|
|
9
12
|
* const color = generateColorByString("example");
|
|
10
13
|
* console.log(color); // Outputs a consistent hex color like "#5e8f9a"
|
|
14
|
+
* ```
|
|
11
15
|
*/
|
|
12
|
-
|
|
16
|
+
function generateColorByString(rawString) {
|
|
13
17
|
var hash = 0;
|
|
14
|
-
for (var i = 0; i <
|
|
15
|
-
hash =
|
|
18
|
+
for (var i = 0; i < rawString.length; i++) {
|
|
19
|
+
hash = rawString.charCodeAt(i) + ((hash << 5) - hash);
|
|
16
20
|
}
|
|
17
21
|
var red = (hash & 0xff0000) >> 16;
|
|
18
22
|
var green = (hash & 0x00ff00) >> 8;
|
|
@@ -21,5 +25,5 @@ const generateColorByString = (prop) => {
|
|
|
21
25
|
var greenHex = green.toString(16).padStart(2, "0");
|
|
22
26
|
var blueHex = blue.toString(16).padStart(2, "0");
|
|
23
27
|
return "#" + redHex + greenHex + blueHex;
|
|
24
|
-
}
|
|
28
|
+
}
|
|
25
29
|
export { generateColorByString };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates a unique identifier (UUID) in the specified format and type.
|
|
3
3
|
*
|
|
4
|
-
* @param type - The desired output type of the UUID. Can be:
|
|
4
|
+
* @param {"text" | "binary"} type - The desired output type of the UUID. Can be:
|
|
5
5
|
* - `"text"`: Returns the UUID as a string.
|
|
6
6
|
* - `"binary"`: Returns the UUID as a `Uint8Array` in binary format.
|
|
7
|
-
* @param format - The version of the UUID to generate. Can be:
|
|
7
|
+
* @param {"v4" | "v7"} format - The version of the UUID to generate. Can be:
|
|
8
8
|
* - `"v4"`: Generates a random UUID (version 4).
|
|
9
9
|
* - `"v7"`: Generates a time-ordered UUID (version 7).
|
|
10
|
-
* @returns The generated UUID in the specified type and format.
|
|
10
|
+
* @returns {string | Uint8Array} The generated UUID in the specified type and format.
|
|
11
11
|
* - If `type` is `"text"`, a string representation of the UUID is returned.
|
|
12
12
|
* - If `type` is `"binary"`, a `Uint8Array` representation of the UUID is returned.
|
|
13
13
|
* @throws {Error} If an invalid `type` or `format` is provided.
|
|
@@ -9,9 +9,16 @@
|
|
|
9
9
|
* - Collapses multiple consecutive hyphens into a single hyphen.
|
|
10
10
|
* - Trims leading and trailing hyphens.
|
|
11
11
|
*
|
|
12
|
-
* @param string - The input string to be converted into a slug.
|
|
13
|
-
*
|
|
12
|
+
* @param {string} rawString - The input string to be converted into a slug.
|
|
13
|
+
*
|
|
14
|
+
* @returns {string} A URL-friendly slug derived from the input string.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const slug = generateSlug("Hello, World! This is a Test.");
|
|
19
|
+
* console.log(slug); // Outputs: "hello-world-this-is-a-test"
|
|
20
|
+
* ```
|
|
14
21
|
*/
|
|
15
|
-
declare function generateSlug(
|
|
22
|
+
declare function generateSlug(rawString: string): string;
|
|
16
23
|
export { generateSlug };
|
|
17
24
|
//# sourceMappingURL=generateSlug.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,iBAAS,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAa/C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -9,11 +9,18 @@
|
|
|
9
9
|
* - Collapses multiple consecutive hyphens into a single hyphen.
|
|
10
10
|
* - Trims leading and trailing hyphens.
|
|
11
11
|
*
|
|
12
|
-
* @param string - The input string to be converted into a slug.
|
|
13
|
-
*
|
|
12
|
+
* @param {string} rawString - The input string to be converted into a slug.
|
|
13
|
+
*
|
|
14
|
+
* @returns {string} A URL-friendly slug derived from the input string.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const slug = generateSlug("Hello, World! This is a Test.");
|
|
19
|
+
* console.log(slug); // Outputs: "hello-world-this-is-a-test"
|
|
20
|
+
* ```
|
|
14
21
|
*/
|
|
15
|
-
function generateSlug(
|
|
16
|
-
let slug =
|
|
22
|
+
function generateSlug(rawString) {
|
|
23
|
+
let slug = rawString.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
17
24
|
slug = slug
|
|
18
25
|
.replace(/[^\w\s-]/g, "")
|
|
19
26
|
.replace(/\s+/g, "-")
|
package/dist/index.d.ts
CHANGED
|
@@ -5,21 +5,21 @@ export { formatToCapitalizeFirstWordLetter } from "./formats/formatToCapitalizeF
|
|
|
5
5
|
export { formatToCep } from "./formats/formatToCep";
|
|
6
6
|
export { formatToCnpj } from "./formats/formatToCnpj";
|
|
7
7
|
export { formatToCpf } from "./formats/formatToCpf";
|
|
8
|
-
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
9
8
|
export { formatToCurrency } from "./formats/formatToCurrency";
|
|
10
|
-
export { formatToDate } from "./formats/formatToDate";
|
|
11
9
|
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
12
10
|
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
13
11
|
export { formatToPhone } from "./formats/formatToPhone";
|
|
14
12
|
export { generateColorByString } from "./generators/generateColorByString";
|
|
15
13
|
export { generateId } from "./generators/generateId";
|
|
16
14
|
export { generateSlug } from "./generators/generateSlug";
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
15
|
+
export { parseToDate } from "./parsers/parseDate";
|
|
16
|
+
export { parseLargeFields } from "./parsers/parseLargeFields";
|
|
17
|
+
export { parseSensitiveData } from "./parsers/parseSensitiveData";
|
|
18
|
+
export { ValidateDateService } from "./services/validateDateService";
|
|
19
|
+
export { calculateCardInstallment } from "./utilities/calculateCardInstallment";
|
|
20
|
+
export { ensureQuotes } from "./utilities/ensureQuotes";
|
|
21
|
+
export { isHtml } from "./utilities/isHtml";
|
|
22
|
+
export { removeCurrencySymbols } from "./utilities/removeCurrencySymbols";
|
|
23
|
+
export { removeNonNumeric } from "./utilities/removeNonNumeric";
|
|
24
|
+
export { stripHtmlTags } from "./utilities/stripHtmlTags";
|
|
25
25
|
//# 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,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,
|
|
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,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,9 +6,7 @@ export { formatToCapitalizeFirstWordLetter } from "./formats/formatToCapitalizeF
|
|
|
6
6
|
export { formatToCep } from "./formats/formatToCep";
|
|
7
7
|
export { formatToCnpj } from "./formats/formatToCnpj";
|
|
8
8
|
export { formatToCpf } from "./formats/formatToCpf";
|
|
9
|
-
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
10
9
|
export { formatToCurrency } from "./formats/formatToCurrency";
|
|
11
|
-
export { formatToDate } from "./formats/formatToDate";
|
|
12
10
|
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
13
11
|
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
14
12
|
export { formatToPhone } from "./formats/formatToPhone";
|
|
@@ -16,12 +14,16 @@ export { formatToPhone } from "./formats/formatToPhone";
|
|
|
16
14
|
export { generateColorByString } from "./generators/generateColorByString";
|
|
17
15
|
export { generateId } from "./generators/generateId";
|
|
18
16
|
export { generateSlug } from "./generators/generateSlug";
|
|
17
|
+
// parsers
|
|
18
|
+
export { parseToDate } from "./parsers/parseDate";
|
|
19
|
+
export { parseLargeFields } from "./parsers/parseLargeFields";
|
|
20
|
+
export { parseSensitiveData } from "./parsers/parseSensitiveData";
|
|
19
21
|
// services
|
|
20
|
-
export {
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
22
|
+
export { ValidateDateService } from "./services/validateDateService";
|
|
23
|
+
// utilities
|
|
24
|
+
export { calculateCardInstallment } from "./utilities/calculateCardInstallment";
|
|
25
|
+
export { ensureQuotes } from "./utilities/ensureQuotes";
|
|
26
|
+
export { isHtml } from "./utilities/isHtml";
|
|
27
|
+
export { removeCurrencySymbols } from "./utilities/removeCurrencySymbols";
|
|
28
|
+
export { removeNonNumeric } from "./utilities/removeNonNumeric";
|
|
29
|
+
export { stripHtmlTags } from "./utilities/stripHtmlTags";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a date and time input into a JavaScript `Date` object, formatted according to the specified input format and timezone.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* **Note:** This function works with UTC+0 by default. The returned Date object is not automatically converted to the machine's local timezone.
|
|
6
|
+
* To adjust the timezone, you must manually specify the `timezone` parameter (e.g., -3 for UTC-3).
|
|
7
|
+
*
|
|
8
|
+
* @param {[string, string]} dateTime - An array containing the date and optional time.
|
|
9
|
+
* - The first element is the date string.
|
|
10
|
+
* - The second element is the time string (default is "00:00:00")
|
|
11
|
+
* @param {"brazilianDate" | "isoDate" | "timestamp"} inputFormat - The format of the input date.
|
|
12
|
+
* - "brazilianDate": Expects the date in "DD/MM/YYYY" or "D/M/YYYY" format.
|
|
13
|
+
* - "isoDate": Expects the date in "MM-DD-YYYY" or "M-D-YYYY" format.
|
|
14
|
+
* - "timestamp": Expects the date in "YYYY-MM-DD" or "YYYY-M-D" format.
|
|
15
|
+
* @param {number} [timezone=0] - The timezone offset in hours to apply to the date.
|
|
16
|
+
* - Defaults to 0 (UTC).
|
|
17
|
+
*
|
|
18
|
+
* @returns {Date} A `Date` object representing the parsed date and time, adjusted for the specified timezone.
|
|
19
|
+
*
|
|
20
|
+
* @throws {Error} If the `inputFormat` is invalid.
|
|
21
|
+
* @throws {Error} If the provided date or time is invalid.
|
|
22
|
+
*
|
|
23
|
+
* @example Format a Brazilian date to Date
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const date = parseToDate(["25/12/2023", "15:30:00"], "brazilianDate", -3);
|
|
26
|
+
* console.log(date); // Outputs a Date object for "2023-12-25T12:30:00.000Z" (UTC)
|
|
27
|
+
* ```
|
|
28
|
+
* @example Format an ISO date to Date
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const date = parseToDate(["12-25-2023", "15:30:00"], "isoDate", 2);
|
|
31
|
+
* console.log(date); // Outputs a Date object for "2023-12-25T13:30:00.000Z" (UTC)
|
|
32
|
+
* ```
|
|
33
|
+
* @example Format a timestamp date to Date
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const date = parseToDate(["2023-12-25", "15:30:00"], "timestamp");
|
|
36
|
+
* console.log(date); // Outputs a Date object for "2023-12-25T15:30:00.000Z" (UTC)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function parseToDate([date, time]: [string, string?], inputFormat: "brazilianDate" | "isoDate" | "timestamp", timezone?: number): Date;
|
|
40
|
+
export { parseToDate };
|
|
41
|
+
//# sourceMappingURL=parseDate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseDate.d.ts","sourceRoot":"","sources":["../../src/parsers/parseDate.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,WAAW,CAClB,CAAC,IAAI,EAAE,IAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC5C,WAAW,EAAE,eAAe,GAAG,SAAS,GAAG,WAAW,EACtD,QAAQ,GAAE,MAAU,GACnB,IAAI,CAkCN;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ValidateDateService } from "../services/validateDateService";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a date and time input into a JavaScript `Date` object, formatted according to the specified input format and timezone.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* **Note:** This function works with UTC+0 by default. The returned Date object is not automatically converted to the machine's local timezone.
|
|
7
|
+
* To adjust the timezone, you must manually specify the `timezone` parameter (e.g., -3 for UTC-3).
|
|
8
|
+
*
|
|
9
|
+
* @param {[string, string]} dateTime - An array containing the date and optional time.
|
|
10
|
+
* - The first element is the date string.
|
|
11
|
+
* - The second element is the time string (default is "00:00:00")
|
|
12
|
+
* @param {"brazilianDate" | "isoDate" | "timestamp"} inputFormat - The format of the input date.
|
|
13
|
+
* - "brazilianDate": Expects the date in "DD/MM/YYYY" or "D/M/YYYY" format.
|
|
14
|
+
* - "isoDate": Expects the date in "MM-DD-YYYY" or "M-D-YYYY" format.
|
|
15
|
+
* - "timestamp": Expects the date in "YYYY-MM-DD" or "YYYY-M-D" format.
|
|
16
|
+
* @param {number} [timezone=0] - The timezone offset in hours to apply to the date.
|
|
17
|
+
* - Defaults to 0 (UTC).
|
|
18
|
+
*
|
|
19
|
+
* @returns {Date} A `Date` object representing the parsed date and time, adjusted for the specified timezone.
|
|
20
|
+
*
|
|
21
|
+
* @throws {Error} If the `inputFormat` is invalid.
|
|
22
|
+
* @throws {Error} If the provided date or time is invalid.
|
|
23
|
+
*
|
|
24
|
+
* @example Format a Brazilian date to Date
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const date = parseToDate(["25/12/2023", "15:30:00"], "brazilianDate", -3);
|
|
27
|
+
* console.log(date); // Outputs a Date object for "2023-12-25T12:30:00.000Z" (UTC)
|
|
28
|
+
* ```
|
|
29
|
+
* @example Format an ISO date to Date
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const date = parseToDate(["12-25-2023", "15:30:00"], "isoDate", 2);
|
|
32
|
+
* console.log(date); // Outputs a Date object for "2023-12-25T13:30:00.000Z" (UTC)
|
|
33
|
+
* ```
|
|
34
|
+
* @example Format a timestamp date to Date
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const date = parseToDate(["2023-12-25", "15:30:00"], "timestamp");
|
|
37
|
+
* console.log(date); // Outputs a Date object for "2023-12-25T15:30:00.000Z" (UTC)
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function parseToDate([date, time = "00:00:00"], inputFormat, timezone = 0) {
|
|
41
|
+
const validateDateService = new ValidateDateService();
|
|
42
|
+
validateDateService.validateInputFormat(inputFormat);
|
|
43
|
+
const dateParts = date.split(/[-/]/).map(Number);
|
|
44
|
+
const timeParts = time.split(".")[0].split(":").map(Number);
|
|
45
|
+
let day, month, year;
|
|
46
|
+
const [hours = 0, minutes = 0, seconds = 0] = timeParts;
|
|
47
|
+
switch (inputFormat) {
|
|
48
|
+
case "brazilianDate":
|
|
49
|
+
[day, month, year] = dateParts;
|
|
50
|
+
validateDateService.validateDateParts(year, month, day);
|
|
51
|
+
break;
|
|
52
|
+
case "isoDate":
|
|
53
|
+
[month, day, year] = dateParts;
|
|
54
|
+
validateDateService.validateDateParts(year, month, day);
|
|
55
|
+
break;
|
|
56
|
+
case "timestamp":
|
|
57
|
+
[year, month, day] = dateParts;
|
|
58
|
+
validateDateService.validateDateParts(year, month, day);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
const formattedDate = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds));
|
|
62
|
+
if (isNaN(formattedDate.getTime()))
|
|
63
|
+
throw new Error("Invalid date");
|
|
64
|
+
formattedDate.setUTCHours(formattedDate.getUTCHours() + timezone);
|
|
65
|
+
return formattedDate;
|
|
66
|
+
}
|
|
67
|
+
export { parseToDate };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
type TruncateLargeFieldsFunction = (jsonString: string, maxLength?: number) => string;
|
|
2
1
|
/**
|
|
3
2
|
* Truncates large string fields in a JSON string to a specified maximum length.
|
|
4
3
|
*
|
|
@@ -6,9 +5,10 @@ type TruncateLargeFieldsFunction = (jsonString: string, maxLength?: number) => s
|
|
|
6
5
|
* any string fields that exceed the specified maximum length. If a string field is truncated,
|
|
7
6
|
* it is replaced with a message indicating the original length of the field.
|
|
8
7
|
*
|
|
9
|
-
* @param jsonString - The JSON string to process.
|
|
10
|
-
* @param maxLength - The maximum allowed length for string fields. Defaults to 1000.
|
|
11
|
-
*
|
|
8
|
+
* @param {string} jsonString - The JSON string to process.
|
|
9
|
+
* @param {number} maxLength - The maximum allowed length for string fields. Defaults to 1000.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string} A JSON string with large string fields truncated.
|
|
12
12
|
*
|
|
13
13
|
* @throws {Error} Throws an error if the input is not a valid JSON string.
|
|
14
14
|
*
|
|
@@ -17,16 +17,14 @@ type TruncateLargeFieldsFunction = (jsonString: string, maxLength?: number) => s
|
|
|
17
17
|
* const json = JSON.stringify({
|
|
18
18
|
* name: "John",
|
|
19
19
|
* description: "A very long description that exceeds the maximum length...",
|
|
20
|
-
* nested: {
|
|
21
|
-
* details: "Another long string that needs truncation."
|
|
22
|
-
* }
|
|
20
|
+
* nested: { details: "Another long string that needs truncation." }
|
|
23
21
|
* });
|
|
24
22
|
*
|
|
25
|
-
* const result =
|
|
23
|
+
* const result = parseLargeFields(json, 50);
|
|
26
24
|
* console.log(result);
|
|
27
25
|
* // Output: '{"name":"John","description":"To large information: field as 57 characters","nested":{"details":"To large information: field as 43 characters"}}'
|
|
28
26
|
* ```
|
|
29
27
|
*/
|
|
30
|
-
declare
|
|
31
|
-
export {
|
|
32
|
-
//# sourceMappingURL=
|
|
28
|
+
declare function parseLargeFields(jsonString: string, maxLength?: number): string;
|
|
29
|
+
export { parseLargeFields };
|
|
30
|
+
//# sourceMappingURL=parseLargeFields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseLargeFields.d.ts","sourceRoot":"","sources":["../../src/parsers/parseLargeFields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,iBAAS,gBAAgB,CACvB,UAAU,EAAE,MAAM,EAClB,SAAS,GAAE,MAAa,GACvB,MAAM,CA6BR;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* any string fields that exceed the specified maximum length. If a string field is truncated,
|
|
6
6
|
* it is replaced with a message indicating the original length of the field.
|
|
7
7
|
*
|
|
8
|
-
* @param jsonString - The JSON string to process.
|
|
9
|
-
* @param maxLength - The maximum allowed length for string fields. Defaults to 1000.
|
|
10
|
-
*
|
|
8
|
+
* @param {string} jsonString - The JSON string to process.
|
|
9
|
+
* @param {number} maxLength - The maximum allowed length for string fields. Defaults to 1000.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string} A JSON string with large string fields truncated.
|
|
11
12
|
*
|
|
12
13
|
* @throws {Error} Throws an error if the input is not a valid JSON string.
|
|
13
14
|
*
|
|
@@ -16,17 +17,15 @@
|
|
|
16
17
|
* const json = JSON.stringify({
|
|
17
18
|
* name: "John",
|
|
18
19
|
* description: "A very long description that exceeds the maximum length...",
|
|
19
|
-
* nested: {
|
|
20
|
-
* details: "Another long string that needs truncation."
|
|
21
|
-
* }
|
|
20
|
+
* nested: { details: "Another long string that needs truncation." }
|
|
22
21
|
* });
|
|
23
22
|
*
|
|
24
|
-
* const result =
|
|
23
|
+
* const result = parseLargeFields(json, 50);
|
|
25
24
|
* console.log(result);
|
|
26
25
|
* // Output: '{"name":"John","description":"To large information: field as 57 characters","nested":{"details":"To large information: field as 43 characters"}}'
|
|
27
26
|
* ```
|
|
28
27
|
*/
|
|
29
|
-
|
|
28
|
+
function parseLargeFields(jsonString, maxLength = 1000) {
|
|
30
29
|
function truncateValue(value) {
|
|
31
30
|
if (typeof value === "string" && value.length > maxLength) {
|
|
32
31
|
return `To large information: field as ${value.length} characters`;
|
|
@@ -35,15 +34,15 @@ const truncateLargeFields = (jsonString, maxLength = 1000) => {
|
|
|
35
34
|
}
|
|
36
35
|
function recursiveTruncate(obj) {
|
|
37
36
|
if (Array.isArray(obj)) {
|
|
38
|
-
return obj.map((item) => recursiveTruncate(item));
|
|
37
|
+
return obj.map((item) => recursiveTruncate(item));
|
|
39
38
|
}
|
|
40
39
|
else if (obj !== null && typeof obj === "object") {
|
|
41
40
|
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
|
|
42
41
|
key,
|
|
43
|
-
recursiveTruncate(value),
|
|
42
|
+
recursiveTruncate(value),
|
|
44
43
|
]));
|
|
45
44
|
}
|
|
46
|
-
return truncateValue(obj);
|
|
45
|
+
return truncateValue(obj);
|
|
47
46
|
}
|
|
48
47
|
try {
|
|
49
48
|
const parsedJson = JSON.parse(jsonString);
|
|
@@ -53,5 +52,5 @@ const truncateLargeFields = (jsonString, maxLength = 1000) => {
|
|
|
53
52
|
catch (error) {
|
|
54
53
|
throw new Error("Invalid JSON string");
|
|
55
54
|
}
|
|
56
|
-
}
|
|
57
|
-
export {
|
|
55
|
+
}
|
|
56
|
+
export { parseLargeFields };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
|
|
3
|
+
*
|
|
4
|
+
* @param {string} jsonString - The JSON string to be processed.
|
|
5
|
+
* @param {string[]} sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
|
|
6
|
+
*
|
|
7
|
+
* @returns {string} A JSON string with sensitive data masked. If the input is not a valid JSON string, it returns the original string.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const jsonString = JSON.stringify({
|
|
12
|
+
* username: "user123",
|
|
13
|
+
* password: "secret",
|
|
14
|
+
* profile: { creditCard: "1234-5678-9012-3456" },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const result = parseSensitiveData(jsonString, ["password", "creditCard"]);
|
|
18
|
+
* console.log(result); // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function parseSensitiveData(jsonString: string, sensitiveKeys?: string[]): string;
|
|
22
|
+
export { parseSensitiveData };
|
|
23
|
+
//# sourceMappingURL=parseSensitiveData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseSensitiveData.d.ts","sourceRoot":"","sources":["../../src/parsers/parseSensitiveData.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,iBAAS,kBAAkB,CACzB,UAAU,EAAE,MAAM,EAClB,aAAa,GAAE,MAAM,EAAkD,GACtE,MAAM,CAkCR;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
|
|
3
3
|
*
|
|
4
|
-
* @param jsonString - The JSON string to be processed.
|
|
5
|
-
* @param sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
|
|
6
|
-
*
|
|
4
|
+
* @param {string} jsonString - The JSON string to be processed.
|
|
5
|
+
* @param {string[]} sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
|
|
6
|
+
*
|
|
7
|
+
* @returns {string} A JSON string with sensitive data masked. If the input is not a valid JSON string, it returns the original string.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* ```typescript
|
|
10
11
|
* const jsonString = JSON.stringify({
|
|
11
12
|
* username: "user123",
|
|
12
13
|
* password: "secret",
|
|
13
|
-
* profile: {
|
|
14
|
-
* creditCard: "1234-5678-9012-3456",
|
|
15
|
-
* },
|
|
14
|
+
* profile: { creditCard: "1234-5678-9012-3456" },
|
|
16
15
|
* });
|
|
17
16
|
*
|
|
18
|
-
* const result =
|
|
19
|
-
* console.log(result);
|
|
20
|
-
* // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
|
|
17
|
+
* const result = parseSensitiveData(jsonString, ["password", "creditCard"]);
|
|
18
|
+
* console.log(result); // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
|
|
21
19
|
* ```
|
|
22
20
|
*/
|
|
23
|
-
|
|
21
|
+
function parseSensitiveData(jsonString, sensitiveKeys = ["password", "confirmPassword", "creditCard"]) {
|
|
24
22
|
function maskValue(key, value) {
|
|
25
23
|
if (sensitiveKeys.includes(key))
|
|
26
24
|
return "****";
|
|
@@ -56,5 +54,5 @@ const maskSensitiveData = (jsonString, sensitiveKeys = ["password", "confirmPass
|
|
|
56
54
|
catch (error) {
|
|
57
55
|
return jsonString;
|
|
58
56
|
}
|
|
59
|
-
}
|
|
60
|
-
export {
|
|
57
|
+
}
|
|
58
|
+
export { parseSensitiveData };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare class ValidateDateService {
|
|
2
|
+
private isLeapYear;
|
|
3
|
+
private getDaysInMonth;
|
|
4
|
+
private validateDayInMonth;
|
|
5
|
+
validateDateParts(year: number, month: number, day: number): void;
|
|
6
|
+
validateInputFormat(format: string): void;
|
|
7
|
+
}
|
|
8
|
+
export { ValidateDateService };
|
|
9
|
+
//# sourceMappingURL=validateDateService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateDateService.d.ts","sourceRoot":"","sources":["../../src/services/validateDateService.ts"],"names":[],"mappings":"AAAA,cAAM,mBAAmB;IACvB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,kBAAkB;IA2B1B,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAcjE,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAM1C;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|