From 5d307207d9e2c24eca46882d12f16121dd77c843 Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Tue, 1 Feb 2022 17:09:16 -0300 Subject: [PATCH] Commit Inicial. --- README.md | 29 +++++++---------------------- package.json | 20 ++++++++++++++++++++ src/lhmask.js | 17 +++++++++++++++++ 3 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 package.json create mode 100644 src/lhmask.js diff --git a/README.md b/README.md index 39af52c..dd8fa90 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,14 @@ # README # -This README would normally document whatever steps are necessary to get your application up and running. +Biblioteca com funções para formatação de dados. -### What is this repository for? ### +### Exemplos -* Quick summary -* Version -* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo) +```js +import { formatarCep } from 'lhmask'; -### How do I get set up? ### +console.log(formatarCep('12345000')); -* Summary of set up -* Configuration -* Dependencies -* Database configuration -* How to run tests -* Deployment instructions +// logs: 12.345-000 -### Contribution guidelines ### - -* Writing tests -* Code review -* Other guidelines - -### Who do I talk to? ### - -* Repo owner or admin -* Other community or team contact \ No newline at end of file +``` \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..28bf4a7 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "lhmask", + "version": "1.0.0", + "description": "Biblioteca com funções para formatação de dados.", + "main": "src/lhmask.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+ssh://git@bitbucket.org/leandro_costa/lhmask.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://bitbucket.org/leandro_costa/lhmask/issues" + }, + "homepage": "https://bitbucket.org/leandro_costa/lhmask#readme" +} \ No newline at end of file diff --git a/src/lhmask.js b/src/lhmask.js new file mode 100644 index 0000000..37247ed --- /dev/null +++ b/src/lhmask.js @@ -0,0 +1,17 @@ +module.exports = { + // Entrada: 12345000 Saída: 12.345-000 + formatarCep(txt) { + const soNumeros = e.target.value.replace(/[^\d]/g, '') + if (!soNumeros) onChange(soNumeros); + + let cep = ''; + cep += soNumeros.slice(0, 2); + if (soNumeros.length > 2) + cep += '.' + soNumeros.slice(2, 5); + + if (soNumeros.length > 5) + cep += '-' + soNumeros.slice(5, 8); + + return cep; + } +} \ No newline at end of file