@stencitecnologia/utils 0.1.0 → 0.1.1
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/index.cjs +1 -1
- package/dist/index.es.js +107 -106
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("dayjs");require("dayjs/locale/pt-br.js");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("dayjs");require("dayjs/locale/pt-br.js");const g=require("dayjs/plugin/customParseFormat.js"),h=require("dayjs/plugin/localizedFormat.js"),M=require("dayjs/plugin/utc.js"),y=require("dayjs/plugin/timezone.js");i.extend(g);i.extend(h);i.extend(M);i.extend(y);i.locale("pt-br");const C=["YYYY-MM-DD","YYYY-MM-DDTHH:mm:ss","YYYY-MM-DDTHH:mm:ssZ","YYYY-MM-DDTHH:mm","DD/MM/YYYY","DD/MM/YY"],o=t=>{if(t==null||t==="")return null;if(t instanceof Date){const n=i(t);return n.isValid()?n:null}if(typeof t=="string"){const n=i(t.trim(),C,"pt-br",!0);return n.isValid()?n:null}const e=i(t);return e.isValid()?e:null};function p(t){const e=o(t);return e?e.startOf("day").toDate():null}function $(){return i().startOf("day").toDate()}function V(t,e="YYYY-MM-DD"){const n=o(t);return n?n.format(e):""}function A(t,e="YYYY-MM-DD HH:mm:ss"){const n=o(t);return n?n.format(e):""}function b(t,e="DD/MM/YYYY"){const n=o(t);return n?n.format(e):""}function N(t,e="DD/MM/YYYY HH:mm"){const n=o(t);return n?n.format(e):""}function T(t,e="HH:mm"){const n=o(t);return n?n.format(e):""}function F(t,e="ddd"){const n=o(t);return n?n.format(e).toUpperCase():""}function P(t,e="dddd, DD[ de ]MMMM[ de ]YYYY"){const n=o(t);return n?n.format(e):""}function Y(t){const e=o(t);return e?e.toDate():null}function m(t,e,n="day"){const r=o(t);return!r||typeof e!="number"||Number.isNaN(e)?null:r.add(e,n).toDate()}function H(t,e){return m(t,e,"day")}function S(t,e){return m(t,e,"month")}function O(t,e){return m(t,e,"year")}function j(t,e){return m(t,e,"minute")}function q(t){return t?t.trim().split(/\s+/).slice(0,2).map(e=>e[0].toUpperCase()).join(""):""}function z(t){return t==null?"":String(t).toLowerCase().trim().split(/\s+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function c(t){return t==null?"":String(t).replace(/\D/g,"")}const B=t=>{if(!t)return"-";const e=t.replace(/\D/g,"");return e.length===11?e.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/,"$1.$2.$3-$4"):e.length===14?e.replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/,"$1.$2.$3/$4-$5"):t},R=(t,e=2)=>t==null?"-":Number(t).toLocaleString("pt-BR",{minimumFractionDigits:e,maximumFractionDigits:e});function U(t){const e=c(t);return e.length!==8?t:e.replace(/(\d{5})(\d{3})/,"$1-$2")}function W(t){if(t==null)return"";const{postalCode:e,state:n,city:r,neighborhood:s,addressLine1:a,addressLine2:f}=t,l=[a,f].filter(Boolean).join(" "),d=[s," - ",r,n].filter(Boolean).join(" "),u=e?U(e):null;return[l," - ",d," - ",u].filter(Boolean).join(" ").replace(/\s-\s$/,"")}function Z(t){if(t==null)return"";const{name:e,state:n,record:r}=t;return[e,n,r].filter(Boolean).join(" ")}function x(t){const e=c(t);if(!e)return"";const n=e.startsWith("55")&&e.length>11?e.slice(2):e;return n.length===11?n.replace(/(\d{2})(\d{5})(\d{4})/,"($1) $2-$3"):n.length===10?n.replace(/(\d{2})(\d{4})(\d{4})/,"($1) $2-$3"):t}function L(t){return t?t.toString().slice(-8).toUpperCase():""}function w(t){const e=c(t);if(!e||e.length!==11||/^(\d)\1+$/.test(e))return!1;const n=(a,f)=>{let l=0;for(let u=0;u<a.length;u+=1)l+=Number(a[u])*(f-u);const d=l%11;return d<2?0:11-d},r=n(e.slice(0,9),10),s=n(e.slice(0,10),11);return r===Number(e[9])&&s===Number(e[10])}function k(t){if(!t)return!1;const e=String(t).toUpperCase().replace(/[^A-Z0-9]/g,"");if(e.length!==14||/^([A-Z0-9])\1{13}$/.test(e))return!1;const n=f=>f.charCodeAt(0)-48,r=(f,l)=>{let d=0;for(let D=0;D<f;D++)d+=n(e[D])*l[D];const u=d%11;return u<2?0:11-u},s=[5,4,3,2,9,8,7,6,5,4,3,2],a=[6,5,4,3,2,9,8,7,6,5,4,3,2];return r(12,s)===n(e[12])&&r(13,a)===n(e[13])}function E(t,e=new Date){const n=Y(t);if(!n)return!1;const r=p(e);return p(n)>r}function J(t){const e=Y(t);return!!e&&i(e).isValid()}function _(t){if(!Array.isArray(t)||!t[0]||!t[1])return!1;const[e,n]=t;return!(e instanceof Date)||!(n instanceof Date)?!1:n>=e}function I(t){const e=c(t||"");return e?e.length===11:!0}function G(t){const e=c(t||"");return e?e.length===10:!0}function K(t){return t.replace(/\D/g,"").length===8}function Q(t){if(t==null)return!1;const e=String(t).trim();return e?/^\d+$/.test(e):!1}function X(t){return/^[A-Za-zÀ-ÖØ-öø-ÿ\s'-]+$/u.test(t)}function v(t){return t.endsWith(".")||t.length<2}function tt(t){const e=(t||"").trim();if(!e||!X(e))return!1;const n=e.split(" ").filter(Boolean);if(n.length<2)return!1;const r=/^[A-Za-zÀ-ÖØ-öø-ÿ]+(?:[-'][A-Za-zÀ-ÖØ-öø-ÿ]+)*$/u;return n.every(s=>{const a=s.replace(/^[-']+|[-']+$/g,"");return!a||v(a)?!1:r.test(s)})}exports.add=m;exports.addDays=H;exports.addMinutes=j;exports.addMonths=S;exports.addYears=O;exports.formatAddress=W;exports.formatCouncil=Z;exports.formatDate=b;exports.formatDateTime=N;exports.formatDateTimeToApi=A;exports.formatDateToApi=V;exports.formatDocument=B;exports.formatFullDate=P;exports.formatNumber=R;exports.formatPhone=x;exports.formatTime=T;exports.formatWeekday=F;exports.getInitials=q;exports.isFutureDate=E;exports.isOnlyNumbers=Q;exports.isValidCNPJ=k;exports.isValidCPF=w;exports.isValidCellphone=I;exports.isValidDate=J;exports.isValidDateRange=_;exports.isValidFullName=tt;exports.isValidPhone=G;exports.isValidPostalCode=K;exports.onlyNumber=c;exports.shortCode=L;exports.startOfDay=p;exports.toCamelCaseWords=z;exports.toDate=Y;exports.today=$;
|
package/dist/index.es.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import i from "dayjs";
|
|
2
2
|
import "dayjs/locale/pt-br.js";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
3
|
+
import g from "dayjs/plugin/customParseFormat.js";
|
|
4
|
+
import h from "dayjs/plugin/localizedFormat.js";
|
|
5
|
+
import M from "dayjs/plugin/utc.js";
|
|
6
|
+
import $ from "dayjs/plugin/timezone.js";
|
|
7
|
+
i.extend(g);
|
|
7
8
|
i.extend(h);
|
|
8
9
|
i.extend(M);
|
|
9
10
|
i.extend($);
|
|
10
|
-
i.extend(y);
|
|
11
11
|
i.locale("pt-br");
|
|
12
|
-
const
|
|
12
|
+
const y = [
|
|
13
13
|
"YYYY-MM-DD",
|
|
14
14
|
"YYYY-MM-DDTHH:mm:ss",
|
|
15
15
|
"YYYY-MM-DDTHH:mm:ssZ",
|
|
@@ -23,48 +23,48 @@ const C = [
|
|
|
23
23
|
return r.isValid() ? r : null;
|
|
24
24
|
}
|
|
25
25
|
if (typeof t == "string") {
|
|
26
|
-
const r = i(t.trim(),
|
|
26
|
+
const r = i(t.trim(), y, "pt-br", !0);
|
|
27
27
|
return r.isValid() ? r : null;
|
|
28
28
|
}
|
|
29
29
|
const n = i(t);
|
|
30
30
|
return n.isValid() ? n : null;
|
|
31
31
|
};
|
|
32
|
-
function
|
|
32
|
+
function D(t) {
|
|
33
33
|
const n = o(t);
|
|
34
34
|
return n ? n.startOf("day").toDate() : null;
|
|
35
35
|
}
|
|
36
36
|
function S() {
|
|
37
37
|
return i().startOf("day").toDate();
|
|
38
38
|
}
|
|
39
|
-
function
|
|
39
|
+
function j(t, n = "YYYY-MM-DD") {
|
|
40
40
|
const r = o(t);
|
|
41
41
|
return r ? r.format(n) : "";
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function x(t, n = "YYYY-MM-DD HH:mm:ss") {
|
|
44
44
|
const r = o(t);
|
|
45
45
|
return r ? r.format(n) : "";
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function z(t, n = "DD/MM/YYYY") {
|
|
48
48
|
const r = o(t);
|
|
49
49
|
return r ? r.format(n) : "";
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function B(t, n = "DD/MM/YYYY HH:mm") {
|
|
52
52
|
const r = o(t);
|
|
53
53
|
return r ? r.format(n) : "";
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function O(t, n = "HH:mm") {
|
|
56
56
|
const r = o(t);
|
|
57
57
|
return r ? r.format(n) : "";
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function U(t, n = "ddd") {
|
|
60
60
|
const r = o(t);
|
|
61
61
|
return r ? r.format(n).toUpperCase() : "";
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function Z(t, n = "dddd, DD[ de ]MMMM[ de ]YYYY") {
|
|
64
64
|
const r = o(t);
|
|
65
65
|
return r ? r.format(n) : "";
|
|
66
66
|
}
|
|
67
|
-
function
|
|
67
|
+
function Y(t) {
|
|
68
68
|
const n = o(t);
|
|
69
69
|
return n ? n.toDate() : null;
|
|
70
70
|
}
|
|
@@ -72,170 +72,171 @@ function p(t, n, r = "day") {
|
|
|
72
72
|
const e = o(t);
|
|
73
73
|
return !e || typeof n != "number" || Number.isNaN(n) ? null : e.add(n, r).toDate();
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function L(t, n) {
|
|
76
76
|
return p(t, n, "day");
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function R(t, n) {
|
|
79
79
|
return p(t, n, "month");
|
|
80
80
|
}
|
|
81
|
-
function
|
|
81
|
+
function w(t, n) {
|
|
82
82
|
return p(t, n, "year");
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function W(t, n) {
|
|
85
85
|
return p(t, n, "minute");
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function k(t) {
|
|
88
88
|
return t ? t.trim().split(/\s+/).slice(0, 2).map((n) => n[0].toUpperCase()).join("") : "";
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function E(t) {
|
|
91
91
|
return t == null ? "" : String(t).toLowerCase().trim().split(/\s+/).map((n) => n.charAt(0).toUpperCase() + n.slice(1)).join(" ");
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function l(t) {
|
|
94
94
|
return t == null ? "" : String(t).replace(/\D/g, "");
|
|
95
95
|
}
|
|
96
|
-
const
|
|
96
|
+
const _ = (t) => {
|
|
97
97
|
if (!t) return "-";
|
|
98
98
|
const n = t.replace(/\D/g, "");
|
|
99
99
|
return n.length === 11 ? n.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4") : n.length === 14 ? n.replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, "$1.$2.$3/$4-$5") : t;
|
|
100
|
-
},
|
|
100
|
+
}, J = (t, n = 2) => t == null ? "-" : Number(t).toLocaleString("pt-BR", {
|
|
101
101
|
minimumFractionDigits: n,
|
|
102
102
|
maximumFractionDigits: n
|
|
103
103
|
});
|
|
104
|
-
function
|
|
105
|
-
const n =
|
|
104
|
+
function C(t) {
|
|
105
|
+
const n = l(t);
|
|
106
106
|
return n.length !== 8 ? t : n.replace(/(\d{5})(\d{3})/, "$1-$2");
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function q(t) {
|
|
109
109
|
if (t == null) return "";
|
|
110
110
|
const {
|
|
111
111
|
postalCode: n,
|
|
112
112
|
state: r,
|
|
113
113
|
city: e,
|
|
114
114
|
neighborhood: s,
|
|
115
|
-
addressLine1:
|
|
116
|
-
addressLine2:
|
|
117
|
-
} = t,
|
|
118
|
-
return [
|
|
115
|
+
addressLine1: a,
|
|
116
|
+
addressLine2: f
|
|
117
|
+
} = t, d = [a, f].filter(Boolean).join(" "), c = [s, " - ", e, r].filter(Boolean).join(" "), u = n ? C(n) : null;
|
|
118
|
+
return [d, " - ", c, " - ", u].filter(Boolean).join(" ").replace(/\s-\s$/, "");
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function G(t) {
|
|
121
121
|
if (t == null) return "";
|
|
122
122
|
const { name: n, state: r, record: e } = t;
|
|
123
123
|
return [n, r, e].filter(Boolean).join(" ");
|
|
124
124
|
}
|
|
125
|
-
function
|
|
126
|
-
const n =
|
|
125
|
+
function I(t) {
|
|
126
|
+
const n = l(t);
|
|
127
127
|
if (!n) return "";
|
|
128
128
|
const r = n.startsWith("55") && n.length > 11 ? n.slice(2) : n;
|
|
129
129
|
return r.length === 11 ? r.replace(/(\d{2})(\d{5})(\d{4})/, "($1) $2-$3") : r.length === 10 ? r.replace(/(\d{2})(\d{4})(\d{4})/, "($1) $2-$3") : t;
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function K(t) {
|
|
132
132
|
return t ? t.toString().slice(-8).toUpperCase() : "";
|
|
133
133
|
}
|
|
134
|
-
function
|
|
135
|
-
const n =
|
|
134
|
+
function Q(t) {
|
|
135
|
+
const n = l(t);
|
|
136
136
|
if (!n || n.length !== 11 || /^(\d)\1+$/.test(n)) return !1;
|
|
137
|
-
const r = (
|
|
138
|
-
let
|
|
139
|
-
for (let
|
|
140
|
-
|
|
141
|
-
const c =
|
|
137
|
+
const r = (a, f) => {
|
|
138
|
+
let d = 0;
|
|
139
|
+
for (let u = 0; u < a.length; u += 1)
|
|
140
|
+
d += Number(a[u]) * (f - u);
|
|
141
|
+
const c = d % 11;
|
|
142
142
|
return c < 2 ? 0 : 11 - c;
|
|
143
143
|
}, e = r(n.slice(0, 9), 10), s = r(n.slice(0, 10), 11);
|
|
144
144
|
return e === Number(n[9]) && s === Number(n[10]);
|
|
145
145
|
}
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
146
|
+
function X(t) {
|
|
147
|
+
if (!t) return !1;
|
|
148
|
+
const n = String(t).toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
149
|
+
if (n.length !== 14 || /^([A-Z0-9])\1{13}$/.test(n)) return !1;
|
|
150
|
+
const r = (f) => f.charCodeAt(0) - 48, e = (f, d) => {
|
|
151
|
+
let c = 0;
|
|
152
|
+
for (let m = 0; m < f; m++)
|
|
153
|
+
c += r(n[m]) * d[m];
|
|
154
|
+
const u = c % 11;
|
|
155
|
+
return u < 2 ? 0 : 11 - u;
|
|
156
|
+
}, s = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], a = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
157
|
+
return e(12, s) === r(n[12]) && e(13, a) === r(n[13]);
|
|
158
|
+
}
|
|
159
|
+
function v(t, n = /* @__PURE__ */ new Date()) {
|
|
160
|
+
const r = Y(t);
|
|
160
161
|
if (!r) return !1;
|
|
161
|
-
const e =
|
|
162
|
-
return
|
|
162
|
+
const e = D(n);
|
|
163
|
+
return D(r) > e;
|
|
163
164
|
}
|
|
164
|
-
function
|
|
165
|
-
const n =
|
|
165
|
+
function tt(t) {
|
|
166
|
+
const n = Y(t);
|
|
166
167
|
return !!n && i(n).isValid();
|
|
167
168
|
}
|
|
168
|
-
function
|
|
169
|
+
function nt(t) {
|
|
169
170
|
if (!Array.isArray(t) || !t[0] || !t[1]) return !1;
|
|
170
171
|
const [n, r] = t;
|
|
171
172
|
return !(n instanceof Date) || !(r instanceof Date) ? !1 : r >= n;
|
|
172
173
|
}
|
|
173
|
-
function
|
|
174
|
-
const n =
|
|
174
|
+
function rt(t) {
|
|
175
|
+
const n = l(t || "");
|
|
175
176
|
return n ? n.length === 11 : !0;
|
|
176
177
|
}
|
|
177
|
-
function
|
|
178
|
-
const n =
|
|
178
|
+
function et(t) {
|
|
179
|
+
const n = l(t || "");
|
|
179
180
|
return n ? n.length === 10 : !0;
|
|
180
181
|
}
|
|
181
|
-
function
|
|
182
|
+
function it(t) {
|
|
182
183
|
return t.replace(/\D/g, "").length === 8;
|
|
183
184
|
}
|
|
184
|
-
function
|
|
185
|
+
function ot(t) {
|
|
185
186
|
if (t == null) return !1;
|
|
186
187
|
const n = String(t).trim();
|
|
187
188
|
return n ? /^\d+$/.test(n) : !1;
|
|
188
189
|
}
|
|
189
|
-
function
|
|
190
|
+
function A(t) {
|
|
190
191
|
return /^[A-Za-zÀ-ÖØ-öø-ÿ\s'-]+$/u.test(t);
|
|
191
192
|
}
|
|
192
|
-
function
|
|
193
|
+
function V(t) {
|
|
193
194
|
return t.endsWith(".") || t.length < 2;
|
|
194
195
|
}
|
|
195
|
-
function
|
|
196
|
+
function st(t) {
|
|
196
197
|
const n = (t || "").trim();
|
|
197
|
-
if (!n || !
|
|
198
|
+
if (!n || !A(n)) return !1;
|
|
198
199
|
const r = n.split(" ").filter(Boolean);
|
|
199
200
|
if (r.length < 2) return !1;
|
|
200
201
|
const e = /^[A-Za-zÀ-ÖØ-öø-ÿ]+(?:[-'][A-Za-zÀ-ÖØ-öø-ÿ]+)*$/u;
|
|
201
202
|
return r.every((s) => {
|
|
202
|
-
const
|
|
203
|
-
return !
|
|
203
|
+
const a = s.replace(/^[-']+|[-']+$/g, "");
|
|
204
|
+
return !a || V(a) ? !1 : e.test(s);
|
|
204
205
|
});
|
|
205
206
|
}
|
|
206
207
|
export {
|
|
207
208
|
p as add,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
209
|
+
L as addDays,
|
|
210
|
+
W as addMinutes,
|
|
211
|
+
R as addMonths,
|
|
212
|
+
w as addYears,
|
|
213
|
+
q as formatAddress,
|
|
214
|
+
G as formatCouncil,
|
|
215
|
+
z as formatDate,
|
|
216
|
+
B as formatDateTime,
|
|
217
|
+
x as formatDateTimeToApi,
|
|
218
|
+
j as formatDateToApi,
|
|
219
|
+
_ as formatDocument,
|
|
220
|
+
Z as formatFullDate,
|
|
221
|
+
J as formatNumber,
|
|
222
|
+
I as formatPhone,
|
|
223
|
+
O as formatTime,
|
|
224
|
+
U as formatWeekday,
|
|
225
|
+
k as getInitials,
|
|
226
|
+
v as isFutureDate,
|
|
227
|
+
ot as isOnlyNumbers,
|
|
228
|
+
X as isValidCNPJ,
|
|
229
|
+
Q as isValidCPF,
|
|
230
|
+
rt as isValidCellphone,
|
|
231
|
+
tt as isValidDate,
|
|
232
|
+
nt as isValidDateRange,
|
|
233
|
+
st as isValidFullName,
|
|
234
|
+
et as isValidPhone,
|
|
235
|
+
it as isValidPostalCode,
|
|
236
|
+
l as onlyNumber,
|
|
237
|
+
K as shortCode,
|
|
238
|
+
D as startOfDay,
|
|
239
|
+
E as toCamelCaseWords,
|
|
240
|
+
Y as toDate,
|
|
240
241
|
S as today
|
|
241
242
|
};
|