utilidades-js 0.0.0-stage → 1.0.0
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 +22 -2
- package/index.d.ts +67 -0
- package/main.js +1 -0
- package/modal/modal.js +167 -0
- package/modal/modalStyle.css +120 -0
- package/modules.js +6 -0
- package/notify/notify.js +114 -0
- package/notify/notifyStyle.css +73 -0
- package/package.json +28 -4
- package/utils/gid.js +3 -0
- package/utils/normalize.js +28 -0
- package/utils/numbers.js +17 -0
- package/utils/random.js +46 -0
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# etec-utils
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Biblioteca JavaScript simples para uso direto pela Vercel.
|
|
4
|
+
|
|
5
|
+
## URL pública
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import * as utils from "https://etec-utils.vercel.app/main.js";
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Exemplos
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
utils.createNotify()
|
|
15
|
+
.setText("Olá!")
|
|
16
|
+
.setTime(5)
|
|
17
|
+
.setType("success")
|
|
18
|
+
.show();
|
|
19
|
+
|
|
20
|
+
utils.gid("editor");
|
|
21
|
+
|
|
22
|
+
utils.random(1, 10);
|
|
23
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface RandomIntBuilder {
|
|
2
|
+
setMin(value: number): this;
|
|
3
|
+
setMax(value: number): this;
|
|
4
|
+
value(): number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface RandomFloatBuilder {
|
|
8
|
+
setMin(value: number): this;
|
|
9
|
+
setMax(value: number): this;
|
|
10
|
+
setCases(value: number): this;
|
|
11
|
+
/** Retorna o número decimal como string, pois a implementação usa toFixed(). */
|
|
12
|
+
value(): string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface NormalizeBuilder {
|
|
16
|
+
toLower(): this;
|
|
17
|
+
toUpper(): this;
|
|
18
|
+
firstUpper(): this;
|
|
19
|
+
/** Remove diacríticos e retorna o texto normalizado. */
|
|
20
|
+
get(): string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface NotifyBuilder {
|
|
24
|
+
setText(value: string): this;
|
|
25
|
+
setTime(value: number): this;
|
|
26
|
+
setType(value: "info" | "success" | "warning" | "error" | string): this;
|
|
27
|
+
show(): this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface NotifyContainer {
|
|
31
|
+
setStyle(styles: Partial<CSSStyleDeclaration> & Record<string, string>): this;
|
|
32
|
+
get(): HTMLDivElement;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ModalInput {
|
|
36
|
+
id?: string;
|
|
37
|
+
type?: string;
|
|
38
|
+
placeholder?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ModalBuilder {
|
|
42
|
+
setName(value: string): this;
|
|
43
|
+
setContent(value: string): this;
|
|
44
|
+
setTitle(value: string): this;
|
|
45
|
+
setDescription(value: string): this;
|
|
46
|
+
setCallback(value: (event: MouseEvent) => void): this;
|
|
47
|
+
setButtonText(value: string): this;
|
|
48
|
+
inputs(elements: ModalInput[]): this;
|
|
49
|
+
show(): void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ModalContainer {
|
|
53
|
+
get(): HTMLDivElement;
|
|
54
|
+
getOverlay(): HTMLDivElement;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function gid(id: string): HTMLElement | null;
|
|
58
|
+
export function randomInt(): RandomIntBuilder;
|
|
59
|
+
export function randomFloat(): RandomFloatBuilder;
|
|
60
|
+
export function isPrime(n: number): boolean;
|
|
61
|
+
export function isEven(n: number): boolean;
|
|
62
|
+
export function isOdd(n: number): boolean;
|
|
63
|
+
export function normalize(text?: string): NormalizeBuilder;
|
|
64
|
+
export function notifyContainer(): NotifyContainer;
|
|
65
|
+
export function createNotify(): NotifyBuilder;
|
|
66
|
+
export function modalContainer(): ModalContainer;
|
|
67
|
+
export function createModal(): ModalBuilder;
|
package/main.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./modules.js";
|
package/modal/modal.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export function modalContainer() {
|
|
2
|
+
let container = document.getElementById("modalContainer");
|
|
3
|
+
let overlay = document.getElementById("modalOverlay");
|
|
4
|
+
|
|
5
|
+
if (!container) {
|
|
6
|
+
container = document.createElement("div");
|
|
7
|
+
container.id = "modalContainer";
|
|
8
|
+
|
|
9
|
+
document.body.appendChild(container);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!overlay) {
|
|
13
|
+
overlay = document.createElement("div");
|
|
14
|
+
overlay.id = "modalOverlay";
|
|
15
|
+
|
|
16
|
+
document.body.appendChild(overlay);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
get() {
|
|
21
|
+
return container;
|
|
22
|
+
},
|
|
23
|
+
getOverlay() {
|
|
24
|
+
return overlay;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createModal() {
|
|
30
|
+
const options = {
|
|
31
|
+
name: "Meu Modal",
|
|
32
|
+
title: "Modal sem título",
|
|
33
|
+
content: "Este modal não tem informações",
|
|
34
|
+
description: "Modal criado com utilidades-js",
|
|
35
|
+
buttonText: "Fechar modal",
|
|
36
|
+
callback: () => console.log("botão clicado"),
|
|
37
|
+
inputs: []
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const modal = {
|
|
41
|
+
setName(value) {
|
|
42
|
+
options.name = value;
|
|
43
|
+
return this;
|
|
44
|
+
},
|
|
45
|
+
setContent(value) {
|
|
46
|
+
options.content = value;
|
|
47
|
+
return this;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
setTitle(value) {
|
|
51
|
+
options.title = value;
|
|
52
|
+
return this;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
setDescription(value) {
|
|
56
|
+
options.description = value;
|
|
57
|
+
return this;
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
setCallback(value) {
|
|
61
|
+
options.callback = value;
|
|
62
|
+
return this;
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
setButtonText(value) {
|
|
66
|
+
options.buttonText = value;
|
|
67
|
+
return this;
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
inputs(elements) {
|
|
71
|
+
options.inputs = elements;
|
|
72
|
+
return this;
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
show() {
|
|
76
|
+
const { get, getOverlay } = modalContainer();
|
|
77
|
+
|
|
78
|
+
const container = get();
|
|
79
|
+
const overlay = getOverlay();
|
|
80
|
+
|
|
81
|
+
container.innerHTML = "";
|
|
82
|
+
|
|
83
|
+
const modalElement = document.createElement("div");
|
|
84
|
+
modalElement.classList.add("modal");
|
|
85
|
+
|
|
86
|
+
modalElement.innerHTML = `
|
|
87
|
+
<div class="top">
|
|
88
|
+
<p>${options.title}</p>
|
|
89
|
+
<button id="close-modal">X</button>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<div class="content">
|
|
93
|
+
${options.content}
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
<div class="inputs"></div>
|
|
97
|
+
|
|
98
|
+
<div class="bottom">
|
|
99
|
+
${options.description}
|
|
100
|
+
<button id="modal-action">
|
|
101
|
+
${options.buttonText}
|
|
102
|
+
</button>
|
|
103
|
+
</div>
|
|
104
|
+
`;
|
|
105
|
+
|
|
106
|
+
const inputsContainer = modalElement.querySelector(".inputs");
|
|
107
|
+
|
|
108
|
+
options.inputs.forEach(input => {
|
|
109
|
+
const element = document.createElement("input");
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
element.id = input.id ?? "";
|
|
113
|
+
element.type = input.type ?? "text";
|
|
114
|
+
element.placeholder = input.placeholder ?? "";
|
|
115
|
+
|
|
116
|
+
inputsContainer.appendChild(element);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
container.appendChild(modalElement);
|
|
120
|
+
|
|
121
|
+
overlay.style.display = "block";
|
|
122
|
+
|
|
123
|
+
const closeButton =
|
|
124
|
+
modalElement.querySelector("#close-modal");
|
|
125
|
+
|
|
126
|
+
const actionButton =
|
|
127
|
+
modalElement.querySelector("#modal-action");
|
|
128
|
+
|
|
129
|
+
function closeModal() {
|
|
130
|
+
modalElement.remove();
|
|
131
|
+
overlay.style.display = "none";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
closeButton.addEventListener("click", closeModal);
|
|
135
|
+
|
|
136
|
+
if (typeof options.callback === "function") {
|
|
137
|
+
actionButton.addEventListener(
|
|
138
|
+
"click",
|
|
139
|
+
options.callback
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
actionButton.addEventListener("click", closeModal);
|
|
144
|
+
|
|
145
|
+
overlay.onclick = closeModal;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return modal;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function loadStyle() {
|
|
153
|
+
if (document.getElementById("modalStyle")) return;
|
|
154
|
+
|
|
155
|
+
const style = document.createElement("link");
|
|
156
|
+
|
|
157
|
+
style.id = "modalStyle";
|
|
158
|
+
style.rel = "stylesheet";
|
|
159
|
+
style.href = new URL("./modalStyle.css", import.meta.url).href;
|
|
160
|
+
document.head.appendChild(style);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function init() {
|
|
164
|
+
loadStyle();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
init();
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#modalContainer {
|
|
2
|
+
position: fixed;
|
|
3
|
+
z-index: 100000000000000000000000;
|
|
4
|
+
top: 50%;
|
|
5
|
+
left: 50%;
|
|
6
|
+
transform: translate(-50%, -50%);
|
|
7
|
+
width: min(90%, 500px);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
#modalOverlay {
|
|
11
|
+
position: fixed;
|
|
12
|
+
inset: 0;
|
|
13
|
+
z-index: 1000000000;
|
|
14
|
+
background: rgba(0, 0, 0, 0.55);
|
|
15
|
+
backdrop-filter: blur(3px);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.modal {
|
|
19
|
+
width: 100%;
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
padding: 24px;
|
|
22
|
+
background: #fff;
|
|
23
|
+
border-radius: 16px;
|
|
24
|
+
border: 1px solid #e5e5e5;
|
|
25
|
+
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
|
|
26
|
+
font-family: Arial, sans-serif;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.top {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: space-between;
|
|
33
|
+
gap: 15px;
|
|
34
|
+
margin-bottom: 20px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.top p {
|
|
38
|
+
margin: 0;
|
|
39
|
+
font-size: 22px;
|
|
40
|
+
font-weight: 600;
|
|
41
|
+
color: #222;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.top #close-modal {
|
|
45
|
+
width: 36px;
|
|
46
|
+
height: 36px;
|
|
47
|
+
padding: 0;
|
|
48
|
+
border: none;
|
|
49
|
+
border-radius: 10px;
|
|
50
|
+
background: #f1f1f1;
|
|
51
|
+
color: #555;
|
|
52
|
+
font-size: 18px;
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
transition: 0.2s;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.top #close-modal:hover {
|
|
58
|
+
background: #e5e5e5;
|
|
59
|
+
color: #111;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.content {
|
|
63
|
+
margin-bottom: 20px;
|
|
64
|
+
color: #666;
|
|
65
|
+
line-height: 1.5;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.inputs {
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-direction: column;
|
|
71
|
+
gap: 12px;
|
|
72
|
+
margin-bottom: 24px;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.inputs input {
|
|
76
|
+
width: 100%;
|
|
77
|
+
box-sizing: border-box;
|
|
78
|
+
padding: 12px 14px;
|
|
79
|
+
border: 1px solid #d6d6d6;
|
|
80
|
+
border-radius: 10px;
|
|
81
|
+
outline: none;
|
|
82
|
+
font-size: 15px;
|
|
83
|
+
transition: 0.2s;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.inputs input:focus {
|
|
87
|
+
border-color: #666;
|
|
88
|
+
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.bottom {
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
justify-content: space-between;
|
|
95
|
+
gap: 15px;
|
|
96
|
+
padding-top: 18px;
|
|
97
|
+
border-top: 1px solid #eee;
|
|
98
|
+
color: #777;
|
|
99
|
+
font-size: 14px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.bottom #modal-action {
|
|
103
|
+
width: 100%;
|
|
104
|
+
padding: 10px 18px;
|
|
105
|
+
border: none;
|
|
106
|
+
border-radius: 10px;
|
|
107
|
+
background: #222;
|
|
108
|
+
color: white;
|
|
109
|
+
font-size: 14px;
|
|
110
|
+
cursor: pointer;
|
|
111
|
+
transition: 0.2s;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.bottom #modal-action:hover {
|
|
115
|
+
background: #444;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.bottom #modal-action:active {
|
|
119
|
+
transform: scale(0.97);
|
|
120
|
+
}
|
package/modules.js
ADDED
package/notify/notify.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export function notifyContainer() {
|
|
2
|
+
let container = document.getElementById("notifyContainer");
|
|
3
|
+
|
|
4
|
+
if (!container) {
|
|
5
|
+
container = document.createElement("div");
|
|
6
|
+
container.id = "notifyContainer";
|
|
7
|
+
|
|
8
|
+
document.body.appendChild(container);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
setStyle(styles) {
|
|
13
|
+
for (const property in styles) {
|
|
14
|
+
container.style[property] = styles[property];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return this;
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
get() {
|
|
21
|
+
return container;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function loadStyle() {
|
|
27
|
+
if (document.getElementById("notifyStyle")) return;
|
|
28
|
+
|
|
29
|
+
const style = document.createElement("link");
|
|
30
|
+
|
|
31
|
+
style.id = "notifyStyle";
|
|
32
|
+
style.rel = "stylesheet";
|
|
33
|
+
style.href = new URL("./notifyStyle.css", import.meta.url).href;
|
|
34
|
+
|
|
35
|
+
document.head.appendChild(style);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function createNotify() {
|
|
39
|
+
const options = {
|
|
40
|
+
text: "",
|
|
41
|
+
time: 10,
|
|
42
|
+
type: "success"
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
setText(value) {
|
|
47
|
+
options.text = value;
|
|
48
|
+
return this;
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
setTime(value) {
|
|
52
|
+
options.time = value;
|
|
53
|
+
return this;
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
setType(value) {
|
|
57
|
+
options.type = value;
|
|
58
|
+
return this;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
show() {
|
|
62
|
+
const container = notifyContainer().get();
|
|
63
|
+
|
|
64
|
+
const notify = document.createElement("div");
|
|
65
|
+
|
|
66
|
+
notify.className = `notify ${options.type}`;
|
|
67
|
+
|
|
68
|
+
let displayTime = options.time;
|
|
69
|
+
|
|
70
|
+
notify.innerHTML = `
|
|
71
|
+
<p>${options.text}</p>
|
|
72
|
+
<p>${displayTime}s</p>
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
container.appendChild(notify);
|
|
76
|
+
|
|
77
|
+
const index = container.children.length;
|
|
78
|
+
|
|
79
|
+
setTimeout(() => {
|
|
80
|
+
requestAnimationFrame(() => {
|
|
81
|
+
notify.classList.add("active");
|
|
82
|
+
});
|
|
83
|
+
}, index * 100);
|
|
84
|
+
|
|
85
|
+
const interval = setInterval(() => {
|
|
86
|
+
displayTime--;
|
|
87
|
+
|
|
88
|
+
notify.innerHTML = `
|
|
89
|
+
<p>${options.text}</p>
|
|
90
|
+
<p>${displayTime}s</p>
|
|
91
|
+
`;
|
|
92
|
+
}, 1000);
|
|
93
|
+
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
clearInterval(interval);
|
|
96
|
+
|
|
97
|
+
notify.classList.remove("active");
|
|
98
|
+
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
notify.remove();
|
|
101
|
+
}, 300);
|
|
102
|
+
}, options.time * 1000);
|
|
103
|
+
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function init() {
|
|
110
|
+
loadStyle();
|
|
111
|
+
notifyContainer();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
init();
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#notifyContainer,
|
|
2
|
+
.notify {
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
padding: 0;
|
|
5
|
+
margin: 0;
|
|
6
|
+
overflow-x: hidden;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
#notifyContainer {
|
|
10
|
+
width: 320px;
|
|
11
|
+
max-height: 160px;
|
|
12
|
+
position: fixed;
|
|
13
|
+
top: 20px;
|
|
14
|
+
right: 20px;
|
|
15
|
+
overflow-y: auto;
|
|
16
|
+
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
gap: 12px;
|
|
20
|
+
padding: 5px;
|
|
21
|
+
scrollbar-width: thin;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.notify {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
min-height: 70px;
|
|
29
|
+
width: 100%;
|
|
30
|
+
padding: 16px 18px;
|
|
31
|
+
border-radius: 14px;
|
|
32
|
+
border: 1px solid rgba(0, 0, 0, 0.2);
|
|
33
|
+
background-color: rgb(199, 199, 255);
|
|
34
|
+
color: #202035;
|
|
35
|
+
transform: translateX(120%);
|
|
36
|
+
opacity: 0;
|
|
37
|
+
transition:
|
|
38
|
+
transform 0.35s ease,
|
|
39
|
+
opacity 0.35s ease;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.notify.active {
|
|
43
|
+
transform: translateX(0);
|
|
44
|
+
opacity: 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.notify p {
|
|
48
|
+
margin: 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.notify p:first-child {
|
|
52
|
+
font-size: 15px;
|
|
53
|
+
font-weight: 600;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.notify p:last-child {
|
|
57
|
+
margin-top: 5px;
|
|
58
|
+
|
|
59
|
+
font-size: 12px;
|
|
60
|
+
opacity: 0.65;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.notify.success {
|
|
64
|
+
background-color: rgb(104, 255, 104);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.notify.warning {
|
|
68
|
+
background-color: orange;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.notify.error {
|
|
72
|
+
background-color: rgb(255, 52, 52);
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "utilidades-js",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Biblioteca JavaScript com utilitários para DOM, notificações, modais e números.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./main.js",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"import": "./main.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"main.js",
|
|
16
|
+
"modules.js",
|
|
17
|
+
"index.d.ts",
|
|
18
|
+
"notify/",
|
|
19
|
+
"modal/",
|
|
20
|
+
"utils/"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"javascript",
|
|
24
|
+
"utilities",
|
|
25
|
+
"dom",
|
|
26
|
+
"notifications",
|
|
27
|
+
"modal"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT"
|
|
30
|
+
}
|
package/utils/gid.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function normalize(text = "Nenhum texto informado") {
|
|
2
|
+
|
|
3
|
+
return {
|
|
4
|
+
|
|
5
|
+
toLower() {
|
|
6
|
+
text = text.toLowerCase();
|
|
7
|
+
return this;
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
toUpper() {
|
|
11
|
+
text = text.toUpperCase();
|
|
12
|
+
return this;
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
firstUpper() {
|
|
16
|
+
text = text.charAt(0).toUpperCase() + text.slice(1);
|
|
17
|
+
return this;
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
get() {
|
|
21
|
+
return text
|
|
22
|
+
.normalize("NFD")
|
|
23
|
+
.replace(/[\u0300-\u036f]/g, "");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
}
|
package/utils/numbers.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function isPrime(n) {
|
|
2
|
+
if (n < 2) return false;
|
|
3
|
+
|
|
4
|
+
for (let i = 2; i <= Math.sqrt(n); i++) {
|
|
5
|
+
if (n % i === 0) return false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isEven(n) {
|
|
12
|
+
return n % 2 === 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isOdd(n) {
|
|
16
|
+
return n % 2 !== 0;
|
|
17
|
+
}
|
package/utils/random.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export function randomInt() {
|
|
2
|
+
let min = 0;
|
|
3
|
+
let max = 100;
|
|
4
|
+
|
|
5
|
+
return {
|
|
6
|
+
setMin(value) {
|
|
7
|
+
min = value;
|
|
8
|
+
return this;
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
setMax(value) {
|
|
12
|
+
max = value;
|
|
13
|
+
return this;
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
value() {
|
|
17
|
+
return Math.floor(
|
|
18
|
+
Math.random() * (max - min + 1)
|
|
19
|
+
) + min;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function randomFloat() {
|
|
25
|
+
let min = 0;
|
|
26
|
+
let max = 100;
|
|
27
|
+
let cases = 2
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
setMin(value) {
|
|
31
|
+
min = value;
|
|
32
|
+
return this;
|
|
33
|
+
},
|
|
34
|
+
setMax(value) {
|
|
35
|
+
max = value;
|
|
36
|
+
return this
|
|
37
|
+
},
|
|
38
|
+
setCases(value) {
|
|
39
|
+
cases = value
|
|
40
|
+
return this
|
|
41
|
+
},
|
|
42
|
+
value() {
|
|
43
|
+
return (Math.random() * (max - min) + min).toFixed(cases)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|