@stencitecnologia/utils 0.1.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 +103 -0
- package/dist/index.cjs +1 -0
- package/dist/index.es.js +241 -0
- package/package.json +24 -0
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# @stencitecnologia/utils
|
|
2
|
+
|
|
3
|
+
Funções utilitárias puras: formatação de datas, strings, documentos brasileiros (CPF, CNPJ), telefone, endereço, e validadores. JavaScript framework-agnostic. Única dependência: `dayjs`.
|
|
4
|
+
|
|
5
|
+
## Instalação
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @stencitecnologia/utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`dayjs` é instalado automaticamente como dependência.
|
|
12
|
+
|
|
13
|
+
## Uso
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import {
|
|
17
|
+
formatDate,
|
|
18
|
+
formatPhone,
|
|
19
|
+
onlyNumber,
|
|
20
|
+
isValidCPF,
|
|
21
|
+
addMonths,
|
|
22
|
+
today,
|
|
23
|
+
} from '@stencitecnologia/utils';
|
|
24
|
+
|
|
25
|
+
// Exibição
|
|
26
|
+
formatDate(record.createdAt); // '14/05/2026'
|
|
27
|
+
formatPhone(onlyNumber('+55 (11) 99999-9999')); // '(11) 99999-9999'
|
|
28
|
+
|
|
29
|
+
// Validação (sempre passe o valor já limpo)
|
|
30
|
+
const digits = onlyNumber(rawInput);
|
|
31
|
+
if (isValidCPF(digits)) {
|
|
32
|
+
// CPF válido
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Aritmética de datas
|
|
36
|
+
const proximoMes = addMonths(today(), 1);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Referência — datas
|
|
40
|
+
|
|
41
|
+
Internamente usa `dayjs` configurado com locale `pt-BR` e os plugins `customParseFormat`, `localizedFormat`, `utc`, `timezone`.
|
|
42
|
+
|
|
43
|
+
Tipos aceitos: `Date | string | number | dayjs`. Formatos string aceitos: `YYYY-MM-DD`, `YYYY-MM-DDTHH:mm:ss`, `DD/MM/YYYY`, `DD/MM/YYYY HH:mm`, `DD/MM/YYYY HH:mm:ss`.
|
|
44
|
+
|
|
45
|
+
| Função | Assinatura | Descrição |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `formatDate` | `(date, format?) => string` | Default `'DD/MM/YYYY'`. |
|
|
48
|
+
| `formatDateTime` | `(date, format?) => string` | Default `'DD/MM/YYYY HH:mm'`. |
|
|
49
|
+
| `formatTime` | `(date, format?) => string` | Default `'HH:mm'`. |
|
|
50
|
+
| `formatWeekday` | `(date, format?) => string` | Default `'ddd'` em caixa alta (`'SEG'`). |
|
|
51
|
+
| `formatFullDate` | `(date, format?) => string` | Default `'dddd, DD[ de ]MMMM[ de ]YYYY'`. |
|
|
52
|
+
| `formatDateToApi` | `(date, format?) => string` | Default `'YYYY-MM-DD'`. |
|
|
53
|
+
| `formatDateTimeToApi` | `(date, format?) => string` | Default `'YYYY-MM-DD HH:mm:ss'`. |
|
|
54
|
+
| `toDate` | `(value) => Date \| null` | Converte para `Date` nativo ou retorna `null`. |
|
|
55
|
+
| `startOfDay` | `(date) => Date` | Meia-noite da data informada. |
|
|
56
|
+
| `today` | `() => Date` | Hoje à meia-noite. |
|
|
57
|
+
| `add` | `(date, amount, unit?) => Date` | Unit default: `'day'`. |
|
|
58
|
+
| `addDays` | `(date, days) => Date` | |
|
|
59
|
+
| `addMonths` | `(date, months) => Date` | |
|
|
60
|
+
| `addYears` | `(date, years) => Date` | |
|
|
61
|
+
| `addMinutes` | `(date, minutes) => Date` | |
|
|
62
|
+
|
|
63
|
+
## Referência — strings
|
|
64
|
+
|
|
65
|
+
| Função | Assinatura | Descrição |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `getInitials` | `(name: string) => string` | Primeira letra das duas primeiras palavras, em caixa alta. `'John Doe Smith' → 'JD'`. |
|
|
68
|
+
| `toCamelCaseWords` | `(value: string) => string` | Title-case por palavra. `'hello world' → 'Hello World'`. |
|
|
69
|
+
| `onlyNumber` | `(value: string) => string` | Remove tudo que não for dígito. |
|
|
70
|
+
| `formatDocument` | `(value: string \| null) => string` | Formata como CPF (11 dígitos) ou CNPJ (14 dígitos). Retorna `'-'` para vazio. |
|
|
71
|
+
| `formatNumber` | `(value: number, decimals?) => string` | Locale pt-BR. Default 2 casas. `1234.5 → '1.234,50'`. |
|
|
72
|
+
| `shortCode` | `(objectId: string) => string` | Últimos 8 caracteres em caixa alta. |
|
|
73
|
+
|
|
74
|
+
## Referência — formatadores
|
|
75
|
+
|
|
76
|
+
| Função | Assinatura | Descrição |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| `formatPhone` | `(value: string) => string` | Aceita dígitos crus (com ou sem `55`). 11 dígitos → `(XX) XXXXX-XXXX`, 10 → `(XX) XXXX-XXXX`. |
|
|
79
|
+
| `formatAddress` | `(address) => string` | Recebe `{ postalCode, state, city, neighborhood, addressLine1, addressLine2? }`. CEP renderizado como `XXXXX-XXX`. |
|
|
80
|
+
| `formatCouncil` | `(council) => string` | Recebe `{ name, state, record }`. Retorna `'name state record'`. |
|
|
81
|
+
|
|
82
|
+
## Referência — validadores
|
|
83
|
+
|
|
84
|
+
Predicados puros `(value) => boolean`. **Recebem o valor já limpo** (use `onlyNumber()` antes para documentos/telefones).
|
|
85
|
+
|
|
86
|
+
| Função | Assinatura | Descrição |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `isValidCPF` | `(value: string) => boolean` | 11 dígitos, valida dígitos verificadores. |
|
|
89
|
+
| `isValidCNPJ` | `(value: string) => boolean` | 14 dígitos, valida com pesos. |
|
|
90
|
+
| `isValidCellphone` | `(value: string) => boolean` | Vazio OU exatamente 11 dígitos. |
|
|
91
|
+
| `isValidPhone` | `(value: string) => boolean` | Vazio OU exatamente 10 dígitos. |
|
|
92
|
+
| `isValidPostalCode` | `(value: string) => boolean` | Exatamente 8 dígitos. |
|
|
93
|
+
| `isValidDate` | `(value: Date \| string) => boolean` | |
|
|
94
|
+
| `isFutureDate` | `(value: Date, baseDate?: Date) => boolean` | `baseDate` default: hoje. |
|
|
95
|
+
| `isValidDateRange` | `(value: [Date \| null, Date \| null]) => boolean` | `end >= start`. |
|
|
96
|
+
| `isOnlyNumbers` | `(value: string) => boolean` | |
|
|
97
|
+
| `isValidFullName` | `(value: string) => boolean` | ≥2 tokens, sem caracteres especiais (exceto `'` e `-`), ≥2 chars por token. |
|
|
98
|
+
|
|
99
|
+
## Restrições
|
|
100
|
+
|
|
101
|
+
- Nunca importe `dayjs` diretamente — use as funções deste pacote para garantir locale e plugins corretos.
|
|
102
|
+
- Validadores não fazem stripping. Chame `onlyNumber()` antes de `isValidCPF`, `isValidCellphone` etc.
|
|
103
|
+
- Nada de imports de `vue`, `vue-router`, `pinia`, `primevue`, `@vuelidate/*` ou `axios`.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("dayjs");require("dayjs/locale/pt-br.js");const h=require("dayjs/plugin/customParseFormat.js"),M=require("dayjs/plugin/localizedFormat.js"),y=require("dayjs/plugin/utc.js"),C=require("dayjs/plugin/timezone.js");i.extend(h);i.extend(M);i.extend(y);i.extend(C);i.locale("pt-br");const $=["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(),$,"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 V(){return i().startOf("day").toDate()}function N(t,e="YYYY-MM-DD"){const n=o(t);return n?n.format(e):""}function b(t,e="YYYY-MM-DD HH:mm:ss"){const n=o(t);return n?n.format(e):""}function A(t,e="DD/MM/YYYY"){const n=o(t);return n?n.format(e):""}function T(t,e="DD/MM/YYYY HH:mm"){const n=o(t);return n?n.format(e):""}function F(t,e="HH:mm"){const n=o(t);return n?n.format(e):""}function P(t,e="ddd"){const n=o(t);return n?n.format(e).toUpperCase():""}function H(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 j(t,e){return m(t,e,"day")}function O(t,e){return m(t,e,"month")}function S(t,e){return m(t,e,"year")}function q(t,e){return m(t,e,"minute")}function B(t){return t?t.trim().split(/\s+/).slice(0,2).map(e=>e[0].toUpperCase()).join(""):""}function R(t){return t==null?"":String(t).toLowerCase().trim().split(/\s+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function d(t){return t==null?"":String(t).replace(/\D/g,"")}const W=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},x=(t,e=2)=>t==null?"-":Number(t).toLocaleString("pt-BR",{minimumFractionDigits:e,maximumFractionDigits:e});function z(t){const e=d(t);return e.length!==8?t:e.replace(/(\d{5})(\d{3})/,"$1-$2")}function L(t){if(t==null)return"";const{postalCode:e,state:n,city:r,neighborhood:s,addressLine1:a,addressLine2:c}=t,f=[a,c].filter(Boolean).join(" "),l=[s," - ",r,n].filter(Boolean).join(" "),u=e?z(e):null;return[f," - ",l," - ",u].filter(Boolean).join(" ").replace(/\s-\s$/,"")}function U(t){if(t==null)return"";const{name:e,state:n,record:r}=t;return[e,n,r].filter(Boolean).join(" ")}function w(t){const e=d(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 Z(t){return t?t.toString().slice(-8).toUpperCase():""}function k(t){const e=d(t);if(!e||e.length!==11||/^(\d)\1+$/.test(e))return!1;const n=(a,c)=>{let f=0;for(let u=0;u<a.length;u+=1)f+=Number(a[u])*(c-u);const l=f%11;return l<2?0:11-l},r=n(e.slice(0,9),10),s=n(e.slice(0,10),11);return r===Number(e[9])&&s===Number(e[10])}function E(t){const e=d(t);if(!e||e.length!==14||/^(\d)\1+$/.test(e))return!1;const n=(f,l)=>{let u=0;for(let D=0;D<f.length;D+=1)u+=Number(f[D])*l[D];const g=u%11;return g<2?0:11-g},r=[5,4,3,2,9,8,7,6,5,4,3,2],s=[6,5,4,3,2,9,8,7,6,5,4,3,2],a=n(e.slice(0,12),r),c=n(e.slice(0,13),s);return a===Number(e[12])&&c===Number(e[13])}function J(t,e=new Date){const n=Y(t);if(!n)return!1;const r=p(e);return p(n)>r}function _(t){const e=Y(t);return!!e&&i(e).isValid()}function I(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 G(t){const e=d(t||"");return e?e.length===11:!0}function K(t){const e=d(t||"");return e?e.length===10:!0}function Q(t){return t.replace(/\D/g,"").length===8}function X(t){if(t==null)return!1;const e=String(t).trim();return e?/^\d+$/.test(e):!1}function v(t){return/^[A-Za-zÀ-ÖØ-öø-ÿ\s'-]+$/u.test(t)}function tt(t){return t.endsWith(".")||t.length<2}function et(t){const e=(t||"").trim();if(!e||!v(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||tt(a)?!1:r.test(s)})}exports.add=m;exports.addDays=j;exports.addMinutes=q;exports.addMonths=O;exports.addYears=S;exports.formatAddress=L;exports.formatCouncil=U;exports.formatDate=A;exports.formatDateTime=T;exports.formatDateTimeToApi=b;exports.formatDateToApi=N;exports.formatDocument=W;exports.formatFullDate=H;exports.formatNumber=x;exports.formatPhone=w;exports.formatTime=F;exports.formatWeekday=P;exports.getInitials=B;exports.isFutureDate=J;exports.isOnlyNumbers=X;exports.isValidCNPJ=E;exports.isValidCPF=k;exports.isValidCellphone=G;exports.isValidDate=_;exports.isValidDateRange=I;exports.isValidFullName=et;exports.isValidPhone=K;exports.isValidPostalCode=Q;exports.onlyNumber=d;exports.shortCode=Z;exports.startOfDay=p;exports.toCamelCaseWords=R;exports.toDate=Y;exports.today=V;
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import i from "dayjs";
|
|
2
|
+
import "dayjs/locale/pt-br.js";
|
|
3
|
+
import h from "dayjs/plugin/customParseFormat.js";
|
|
4
|
+
import M from "dayjs/plugin/localizedFormat.js";
|
|
5
|
+
import $ from "dayjs/plugin/utc.js";
|
|
6
|
+
import y from "dayjs/plugin/timezone.js";
|
|
7
|
+
i.extend(h);
|
|
8
|
+
i.extend(M);
|
|
9
|
+
i.extend($);
|
|
10
|
+
i.extend(y);
|
|
11
|
+
i.locale("pt-br");
|
|
12
|
+
const C = [
|
|
13
|
+
"YYYY-MM-DD",
|
|
14
|
+
"YYYY-MM-DDTHH:mm:ss",
|
|
15
|
+
"YYYY-MM-DDTHH:mm:ssZ",
|
|
16
|
+
"YYYY-MM-DDTHH:mm",
|
|
17
|
+
"DD/MM/YYYY",
|
|
18
|
+
"DD/MM/YY"
|
|
19
|
+
], o = (t) => {
|
|
20
|
+
if (t == null || t === "") return null;
|
|
21
|
+
if (t instanceof Date) {
|
|
22
|
+
const r = i(t);
|
|
23
|
+
return r.isValid() ? r : null;
|
|
24
|
+
}
|
|
25
|
+
if (typeof t == "string") {
|
|
26
|
+
const r = i(t.trim(), C, "pt-br", !0);
|
|
27
|
+
return r.isValid() ? r : null;
|
|
28
|
+
}
|
|
29
|
+
const n = i(t);
|
|
30
|
+
return n.isValid() ? n : null;
|
|
31
|
+
};
|
|
32
|
+
function Y(t) {
|
|
33
|
+
const n = o(t);
|
|
34
|
+
return n ? n.startOf("day").toDate() : null;
|
|
35
|
+
}
|
|
36
|
+
function S() {
|
|
37
|
+
return i().startOf("day").toDate();
|
|
38
|
+
}
|
|
39
|
+
function x(t, n = "YYYY-MM-DD") {
|
|
40
|
+
const r = o(t);
|
|
41
|
+
return r ? r.format(n) : "";
|
|
42
|
+
}
|
|
43
|
+
function B(t, n = "YYYY-MM-DD HH:mm:ss") {
|
|
44
|
+
const r = o(t);
|
|
45
|
+
return r ? r.format(n) : "";
|
|
46
|
+
}
|
|
47
|
+
function O(t, n = "DD/MM/YYYY") {
|
|
48
|
+
const r = o(t);
|
|
49
|
+
return r ? r.format(n) : "";
|
|
50
|
+
}
|
|
51
|
+
function z(t, n = "DD/MM/YYYY HH:mm") {
|
|
52
|
+
const r = o(t);
|
|
53
|
+
return r ? r.format(n) : "";
|
|
54
|
+
}
|
|
55
|
+
function L(t, n = "HH:mm") {
|
|
56
|
+
const r = o(t);
|
|
57
|
+
return r ? r.format(n) : "";
|
|
58
|
+
}
|
|
59
|
+
function R(t, n = "ddd") {
|
|
60
|
+
const r = o(t);
|
|
61
|
+
return r ? r.format(n).toUpperCase() : "";
|
|
62
|
+
}
|
|
63
|
+
function U(t, n = "dddd, DD[ de ]MMMM[ de ]YYYY") {
|
|
64
|
+
const r = o(t);
|
|
65
|
+
return r ? r.format(n) : "";
|
|
66
|
+
}
|
|
67
|
+
function g(t) {
|
|
68
|
+
const n = o(t);
|
|
69
|
+
return n ? n.toDate() : null;
|
|
70
|
+
}
|
|
71
|
+
function p(t, n, r = "day") {
|
|
72
|
+
const e = o(t);
|
|
73
|
+
return !e || typeof n != "number" || Number.isNaN(n) ? null : e.add(n, r).toDate();
|
|
74
|
+
}
|
|
75
|
+
function w(t, n) {
|
|
76
|
+
return p(t, n, "day");
|
|
77
|
+
}
|
|
78
|
+
function W(t, n) {
|
|
79
|
+
return p(t, n, "month");
|
|
80
|
+
}
|
|
81
|
+
function Z(t, n) {
|
|
82
|
+
return p(t, n, "year");
|
|
83
|
+
}
|
|
84
|
+
function k(t, n) {
|
|
85
|
+
return p(t, n, "minute");
|
|
86
|
+
}
|
|
87
|
+
function E(t) {
|
|
88
|
+
return t ? t.trim().split(/\s+/).slice(0, 2).map((n) => n[0].toUpperCase()).join("") : "";
|
|
89
|
+
}
|
|
90
|
+
function _(t) {
|
|
91
|
+
return t == null ? "" : String(t).toLowerCase().trim().split(/\s+/).map((n) => n.charAt(0).toUpperCase() + n.slice(1)).join(" ");
|
|
92
|
+
}
|
|
93
|
+
function d(t) {
|
|
94
|
+
return t == null ? "" : String(t).replace(/\D/g, "");
|
|
95
|
+
}
|
|
96
|
+
const J = (t) => {
|
|
97
|
+
if (!t) return "-";
|
|
98
|
+
const n = t.replace(/\D/g, "");
|
|
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
|
+
}, q = (t, n = 2) => t == null ? "-" : Number(t).toLocaleString("pt-BR", {
|
|
101
|
+
minimumFractionDigits: n,
|
|
102
|
+
maximumFractionDigits: n
|
|
103
|
+
});
|
|
104
|
+
function N(t) {
|
|
105
|
+
const n = d(t);
|
|
106
|
+
return n.length !== 8 ? t : n.replace(/(\d{5})(\d{3})/, "$1-$2");
|
|
107
|
+
}
|
|
108
|
+
function G(t) {
|
|
109
|
+
if (t == null) return "";
|
|
110
|
+
const {
|
|
111
|
+
postalCode: n,
|
|
112
|
+
state: r,
|
|
113
|
+
city: e,
|
|
114
|
+
neighborhood: s,
|
|
115
|
+
addressLine1: u,
|
|
116
|
+
addressLine2: l
|
|
117
|
+
} = t, a = [u, l].filter(Boolean).join(" "), c = [s, " - ", e, r].filter(Boolean).join(" "), f = n ? N(n) : null;
|
|
118
|
+
return [a, " - ", c, " - ", f].filter(Boolean).join(" ").replace(/\s-\s$/, "");
|
|
119
|
+
}
|
|
120
|
+
function I(t) {
|
|
121
|
+
if (t == null) return "";
|
|
122
|
+
const { name: n, state: r, record: e } = t;
|
|
123
|
+
return [n, r, e].filter(Boolean).join(" ");
|
|
124
|
+
}
|
|
125
|
+
function K(t) {
|
|
126
|
+
const n = d(t);
|
|
127
|
+
if (!n) return "";
|
|
128
|
+
const r = n.startsWith("55") && n.length > 11 ? n.slice(2) : n;
|
|
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
|
+
}
|
|
131
|
+
function Q(t) {
|
|
132
|
+
return t ? t.toString().slice(-8).toUpperCase() : "";
|
|
133
|
+
}
|
|
134
|
+
function X(t) {
|
|
135
|
+
const n = d(t);
|
|
136
|
+
if (!n || n.length !== 11 || /^(\d)\1+$/.test(n)) return !1;
|
|
137
|
+
const r = (u, l) => {
|
|
138
|
+
let a = 0;
|
|
139
|
+
for (let f = 0; f < u.length; f += 1)
|
|
140
|
+
a += Number(u[f]) * (l - f);
|
|
141
|
+
const c = a % 11;
|
|
142
|
+
return c < 2 ? 0 : 11 - c;
|
|
143
|
+
}, e = r(n.slice(0, 9), 10), s = r(n.slice(0, 10), 11);
|
|
144
|
+
return e === Number(n[9]) && s === Number(n[10]);
|
|
145
|
+
}
|
|
146
|
+
function v(t) {
|
|
147
|
+
const n = d(t);
|
|
148
|
+
if (!n || n.length !== 14 || /^(\d)\1+$/.test(n)) return !1;
|
|
149
|
+
const r = (a, c) => {
|
|
150
|
+
let f = 0;
|
|
151
|
+
for (let m = 0; m < a.length; m += 1)
|
|
152
|
+
f += Number(a[m]) * c[m];
|
|
153
|
+
const D = f % 11;
|
|
154
|
+
return D < 2 ? 0 : 11 - D;
|
|
155
|
+
}, e = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], s = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], u = r(n.slice(0, 12), e), l = r(n.slice(0, 13), s);
|
|
156
|
+
return u === Number(n[12]) && l === Number(n[13]);
|
|
157
|
+
}
|
|
158
|
+
function tt(t, n = /* @__PURE__ */ new Date()) {
|
|
159
|
+
const r = g(t);
|
|
160
|
+
if (!r) return !1;
|
|
161
|
+
const e = Y(n);
|
|
162
|
+
return Y(r) > e;
|
|
163
|
+
}
|
|
164
|
+
function nt(t) {
|
|
165
|
+
const n = g(t);
|
|
166
|
+
return !!n && i(n).isValid();
|
|
167
|
+
}
|
|
168
|
+
function rt(t) {
|
|
169
|
+
if (!Array.isArray(t) || !t[0] || !t[1]) return !1;
|
|
170
|
+
const [n, r] = t;
|
|
171
|
+
return !(n instanceof Date) || !(r instanceof Date) ? !1 : r >= n;
|
|
172
|
+
}
|
|
173
|
+
function et(t) {
|
|
174
|
+
const n = d(t || "");
|
|
175
|
+
return n ? n.length === 11 : !0;
|
|
176
|
+
}
|
|
177
|
+
function it(t) {
|
|
178
|
+
const n = d(t || "");
|
|
179
|
+
return n ? n.length === 10 : !0;
|
|
180
|
+
}
|
|
181
|
+
function ot(t) {
|
|
182
|
+
return t.replace(/\D/g, "").length === 8;
|
|
183
|
+
}
|
|
184
|
+
function st(t) {
|
|
185
|
+
if (t == null) return !1;
|
|
186
|
+
const n = String(t).trim();
|
|
187
|
+
return n ? /^\d+$/.test(n) : !1;
|
|
188
|
+
}
|
|
189
|
+
function b(t) {
|
|
190
|
+
return /^[A-Za-zÀ-ÖØ-öø-ÿ\s'-]+$/u.test(t);
|
|
191
|
+
}
|
|
192
|
+
function A(t) {
|
|
193
|
+
return t.endsWith(".") || t.length < 2;
|
|
194
|
+
}
|
|
195
|
+
function ut(t) {
|
|
196
|
+
const n = (t || "").trim();
|
|
197
|
+
if (!n || !b(n)) return !1;
|
|
198
|
+
const r = n.split(" ").filter(Boolean);
|
|
199
|
+
if (r.length < 2) return !1;
|
|
200
|
+
const e = /^[A-Za-zÀ-ÖØ-öø-ÿ]+(?:[-'][A-Za-zÀ-ÖØ-öø-ÿ]+)*$/u;
|
|
201
|
+
return r.every((s) => {
|
|
202
|
+
const u = s.replace(/^[-']+|[-']+$/g, "");
|
|
203
|
+
return !u || A(u) ? !1 : e.test(s);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
export {
|
|
207
|
+
p as add,
|
|
208
|
+
w as addDays,
|
|
209
|
+
k as addMinutes,
|
|
210
|
+
W as addMonths,
|
|
211
|
+
Z as addYears,
|
|
212
|
+
G as formatAddress,
|
|
213
|
+
I as formatCouncil,
|
|
214
|
+
O as formatDate,
|
|
215
|
+
z as formatDateTime,
|
|
216
|
+
B as formatDateTimeToApi,
|
|
217
|
+
x as formatDateToApi,
|
|
218
|
+
J as formatDocument,
|
|
219
|
+
U as formatFullDate,
|
|
220
|
+
q as formatNumber,
|
|
221
|
+
K as formatPhone,
|
|
222
|
+
L as formatTime,
|
|
223
|
+
R as formatWeekday,
|
|
224
|
+
E as getInitials,
|
|
225
|
+
tt as isFutureDate,
|
|
226
|
+
st as isOnlyNumbers,
|
|
227
|
+
v as isValidCNPJ,
|
|
228
|
+
X as isValidCPF,
|
|
229
|
+
et as isValidCellphone,
|
|
230
|
+
nt as isValidDate,
|
|
231
|
+
rt as isValidDateRange,
|
|
232
|
+
ut as isValidFullName,
|
|
233
|
+
it as isValidPhone,
|
|
234
|
+
ot as isValidPostalCode,
|
|
235
|
+
d as onlyNumber,
|
|
236
|
+
Q as shortCode,
|
|
237
|
+
Y as startOfDay,
|
|
238
|
+
_ as toCamelCaseWords,
|
|
239
|
+
g as toDate,
|
|
240
|
+
S as today
|
|
241
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stencitecnologia/utils",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pure utility functions: validators, formatters, and date helpers. Framework-agnostic.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.es.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.es.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "vite build"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"dayjs": "^1.11.19"
|
|
23
|
+
}
|
|
24
|
+
}
|