Skip to content

Commit

Permalink
TESTES + TIPAGENS + USEMASK FUNCIONANDO
Browse files Browse the repository at this point in the history
  • Loading branch information
MauMuller authored Jan 10, 2023
2 parents f00fe8a + d8d2af1 commit 2cc39d9
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/templates/RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v1.0.2
# v1.0.3
- Atualização da Lib

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tempor lobortis massa, nec consectetur lectus ultricies eu.
Expand Down
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@ Aqui estão todos os commits realizados até o momento, acompanhe todos eles na

**Commits:**

- **faa130f3d1080438afd75c88c2cac5e91365fc36**

Link para o commit: [Ver modificações do commit](https://github.com/MauMuller/valisk/commit/faa130f3d1080438afd75c88c2cac5e91365fc36)

Autor: MauMuller - [https://github.com/MauMuller/](https://github.com/MauMuller/)

Data: 10/01/2023

```
♻️ (UseMasks - Hook): Refactor: Realizei uma refatoração ao hook 'useMasks', fazendo o mesmo possuir todas as tipagaens de todos os hooks em um só, algo que ainda está gerando alguns erros, porém atualização das tipgaens nos arquivos foram concluidas com sucesso!

Com essa refatoração, era esperado que o hook voltasse a funcionar, porém não foi o caso, por conta disso será necessário realizar mais teste e verificar qual é a causa de não pode realizar sua utilziação
```

<br />

- **89fa235f254aa00d176e0a909c532b135933e185**

Link para o commit: [Ver modificações do commit](https://github.com/MauMuller/valisk/commit/89fa235f254aa00d176e0a909c532b135933e185)

Autor: MauMuller - [https://github.com/MauMuller/](https://github.com/MauMuller/)

Data: 06/01/2023

```
🐛 (publish_package.yml): Mudança no evento para ativar workflow

Foi incrementado o workflow_dispatch novamente para que seja executado de forma manual essa parte de publicação da biblioteca, já que a API do github não consegue acionar o evento de forma automática
```

<br />

- **0a2266c4b83244257e51f28d088aa824c0a1b11a**

Link para o commit: [Ver modificações do commit](https://github.com/MauMuller/valisk/commit/0a2266c4b83244257e51f28d088aa824c0a1b11a)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@libsdomau/valisk",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT License",
"description": "Validações e máscaras para seus dados, e o melhor, tudo em forma de Hooks!",
"main": "./dist/my-lib.umd.js",
Expand Down Expand Up @@ -40,7 +40,7 @@
"downgrade": "npm version 0.0.0",
"log": "ts-node-esm ./scripts/generateLog.ts",
"release": "ts-node-esm ./scripts/generateRelease.ts",
"update": "ts-node-esm ./scripts/updatePackage.ts && ts-node-esm ./scripts/generateRelease.ts && git add ./.github/templates/RELEASE.md && git commit -m '(RELEASE.md)Docs: Incremento de versão na RELEASE\n\nNova versão disponivel no header'",
"update": "ts-node-esm ./scripts/updatePackage.ts && ts-node-esm ./scripts/generateRelease.ts && git add ./.github/templates/RELEASE.md && git commit -m `(RELEASE.md)Docs:Incremento de versão na RELEASE\n\nNova versão disponivel no header`",
"commit": "ts-node-esm ./scripts/generateLog.ts && git add CHANGELOG.md && gitmoji -c",
"PR": "ts-node-esm ./scripts/generatePR.ts && git add ./.github/PULL_REQUEST_TEMPLATE.md"
},
Expand Down
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const App = () => {
cnpj: { useExplictMask: true },
};

console.log(useMasks({ cep: { useExplictMask: true } }));
const [cpf, setCPF, isCPF, setKeyCPF] = useMaskCPF(configHooks.cpf);
const [cnpj, setCNPJ, isCNPJ, setKeyCNPJ] = useMaskCNPJ(configHooks.cnpj);

Expand Down
21 changes: 2 additions & 19 deletions src/assets/ts/filterByInputMasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
import { getNameFunctions } from "../getNameFunctions";
import { reduceArraysToUniqueArray } from "../reduceArraysToUniqueArray";

import { useMaskCPF } from "../../../hooks/useMaskCPF";
import { useMaskCNPJ } from "../../../hooks/useMaskCNPJ";
import { useMaskCEP } from "../../../hooks/useMaskCEP";
import { useMaskMoney } from "../../../hooks/useMaskMoney";
import { useMaskPhone } from "../../../hooks/useMaskPhone";
import { useMaskPassword } from "../../../hooks/useMaskPassword";

const hooksArray = [
useMaskCPF,
useMaskCNPJ,
useMaskCEP,
useMaskMoney,
useMaskPhone,
useMaskPassword,
];
import hooksArray from "../../../lib/index";

const filterByInputMasks = (masksNames: string[]) => {
const functionsOrdened = masksNames.map((nameMask) =>
hooksArray.filter((hook) => {
let nameHook = getNameFunctions(hook, [7]);
return nameHook === nameMask;
})
hooksArray.filter((hook) => getNameFunctions(hook) === nameMask)
);

return reduceArraysToUniqueArray(functionsOrdened);
Expand Down
25 changes: 15 additions & 10 deletions src/assets/ts/getNameFunctions/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
const getNameFunctions = (
functionValue: Function,
substring?: Array<number>
) => {
const nameFunction = functionValue.name.toLowerCase();
const getNameFunctions = (functionValue: Function) => {
const coreFunction = functionValue.toString();
const findedNameIntoArray = coreFunction.match(
/((?<=const\s\w\s=\s(.+)?")\w+(?="))/g
);
const nameFunction = findedNameIntoArray?.join("") ?? "";
let finalName = "";

const start = substring?.at(0) ?? 0;
const end = substring?.at(1) ?? nameFunction.length;
switch (nameFunction) {
case "phoneMovel":
finalName = nameFunction.replace(/(movel)/im, "");
break;
default:
finalName = nameFunction;
}

const cutName = nameFunction.substring(start, end);

return cutName;
return finalName;
};

export { getNameFunctions };
11 changes: 8 additions & 3 deletions src/assets/ts/modulateObjectToMask/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { TypesMasks } from "../../../types/globalTypes";
import {
TypesMasks,
TypesArrayWithHooks,
TypesArrayWithReturns,
} from "../../../types/globalTypes";

const modulateObjectToMask = (masksObject: TypesMasks) => {
const arrayForResult = [];
const arrayForResult: TypesArrayWithHooks = [];

for (const [key, value] of Object.entries(masksObject)) {
let object = { maskName: key, properties: value };
const valueWithType: TypesArrayWithReturns = value;
let object = { maskName: key, properties: valueWithType };
arrayForResult.push(object);
}

Expand Down
13 changes: 8 additions & 5 deletions src/hooks/useMasks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@ import {
TypesMasks,
TypesHooks,
TypesPasswordValuesReturn,
TypesDigits,
} from "../../types/globalTypes";

const useMasks = (objMasks: TypesMasks) => {
const modulateObjectMask = modulateObjectToMask(objMasks);

const namesMasks = modulateObjectMask.map((obj) =>
obj.maskName.toLowerCase()
);

const hookFiltered = filterByInputMasks(namesMasks);

const values: Array<string | TypesPasswordValuesReturn> = [],
setValues: Function[] = [],
areValidValues: boolean[] = [],
areValidValues: Array<boolean | TypesDigits> = [],
setKeys: Array<Function | undefined> = [];

hookFiltered.forEach((hooks) => {
let nameFunction = getNameFunctions(hooks, [7]);
let maskObjectFiltred = modulateObjectMask.find(
const nameFunction = getNameFunctions(hooks);
const maskObjectFiltred = modulateObjectMask.find(
(obj) => obj.maskName === nameFunction
);

let properties = maskObjectFiltred?.properties ?? {};
let [value, setValue, isValid, setKey]: TypesHooks = hooks(properties);
const properties = maskObjectFiltred?.properties ?? {};
const [value, setValue, isValid, setKey]: TypesHooks = hooks(properties);

values.push(value);
setValues.push(setValue);
Expand Down
9 changes: 9 additions & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import { useMaskMoney } from "../hooks/useMaskMoney";
import { useMaskPassword } from "../hooks/useMaskPassword";
import { useMaskPhone } from "../hooks/useMaskPhone";

export default [
useMaskCPF,
useMaskCNPJ,
useMaskCEP,
useMaskMoney,
useMaskPhone,
useMaskPassword,
];

export {
useMasks,
useMaskCEP,
Expand Down
15 changes: 12 additions & 3 deletions src/types/globalTypes.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
type TypesFunction<K> = (value: K) => void;

type TypesArrayWithReturns = Array<
TypesBasicsProperties | TypesPasswordMask | TypesPhoneMask
>;

type TypesArrayWithHooks = Array<{
maskName: string;
properties: TypesArrayWithReturns;
}>;

type TypesMaskReturn = [
value: string,
setValue: TypesFunction<string>,
Expand Down Expand Up @@ -106,12 +115,10 @@ interface TypesMaskObject {
type TypesHooks = [
value: string | TypesPasswordValuesReturn,
setValue: Function,
isValid: boolean,
isValid: boolean | TypesDigits,
setKey?: Function
];

export {};

export {
TypesChangePasswordState,
TypesFunction,
Expand All @@ -134,4 +141,6 @@ export {
TypesInicialWithoutKey,
TypesChangeBoolean,
TypesChangeObject,
TypesArrayWithHooks,
TypesArrayWithReturns,
};

0 comments on commit 2cc39d9

Please sign in to comment.