<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Carlos Azuaje</title>
    <description>The latest articles on DEV Community by Carlos Azuaje (@charlyjazz).</description>
    <link>https://dev.to/charlyjazz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F171186%2Fe30d379a-dea4-4edd-a2d1-927a57a42b9c.jpeg</url>
      <title>DEV Community: Carlos Azuaje</title>
      <link>https://dev.to/charlyjazz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/charlyjazz"/>
    <language>en</language>
    <item>
      <title>I created a Monorepo Chat architecture solution</title>
      <dc:creator>Carlos Azuaje</dc:creator>
      <pubDate>Sun, 26 Nov 2023 16:00:11 +0000</pubDate>
      <link>https://dev.to/charlyjazz/i-created-a-monorepo-chat-architecture-solution-1dn</link>
      <guid>https://dev.to/charlyjazz/i-created-a-monorepo-chat-architecture-solution-1dn</guid>
      <description>&lt;h1&gt;
  
  
  Realtime Chat using Apache Camel, Cassandra and Firestore
&lt;/h1&gt;

&lt;p&gt;Source Code: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/CharlyJazz/Chat-Firebase-Apache-Camel"&gt;https://github.com/CharlyJazz/Chat-Firebase-Apache-Camel&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you one learn about Python, Microservices, Next JS, GCP, Kubernetes you are welcome to check it out the code&lt;/p&gt;

&lt;p&gt;Chat system architecture leveraging Apache Camel's aggregation pattern. This architecture incorporates a mechanism to buffer incoming messages for a specific timeout duration, measured in seconds. Subsequently, the system aggregates these buffered messages based on their unique chat IDs. The purpose of this aggregation step is to optimize Firestore usage by reducing the number of write operations. The aggregated message data is then efficiently dispatched to Firestore, with the primary goal of minimizing Firestore billing costs.&lt;/p&gt;

&lt;p&gt;The chat pagination utilize Cassandra instead of Firestore. This strategic decision serves a dual purpose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It alleviates the load on Firestore's read operations&lt;/li&gt;
&lt;li&gt;Harnesses the inherent advantages of Cassandra for optimizing the partitioning using the &lt;code&gt;chat_id&lt;/code&gt; as the partition key.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://user-images.githubusercontent.com/12489333/273462854-31d8e470-4169-4ac7-a397-327987f885f3.mov"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MU2m33pw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/CharlyJazz/Chat-Firebase-Apache-Camel/assets/12489333/79618746-367e-474c-bc16-07b2da7693dc" alt="Demo Video" width="800" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next content of this paper explain the sistem using a Architectural Map Features approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Create a chat that makes spam difficult, optimizes availability, and manages reading and writing operations in Firestore to reduce expenses.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Features are:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create User&lt;/li&gt;
&lt;li&gt;Login&lt;/li&gt;
&lt;li&gt;Get the list of users&lt;/li&gt;
&lt;li&gt;User send messages to other user&lt;/li&gt;
&lt;li&gt;Create a new chat room between to users: The user A will find the user B and start a chat.&lt;/li&gt;
&lt;li&gt;User get realtime message updating&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Mapping Features to Architectural Components
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Feature Mapping 1: The users management and authentication (features 1, 2 and 3) will be handle by a microservice called &lt;strong&gt;Auth Microservice&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;The microservice will have a store.&lt;/li&gt;
&lt;li&gt;The microservice will use JWT for the Authentication.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Feature Mapping 2. Chat creation and Message creation/retrieving (features 4 and 5) will be handle by a microservice called &lt;strong&gt;Chat Microservice&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;The microservice will have a store.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Feature Mapping 3. &lt;strong&gt;Chat Microservice&lt;/strong&gt; will take care of sending the messages to a queue proccesing in other to satisfy the feature 6&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Realtime solution to satisfy feature 6
&lt;/h2&gt;

&lt;p&gt;Instead of using Firestore or another cloud-based solution for a complete chat solution, we are going to use Firestore only to update the UI with the &lt;code&gt;aggregated news messages&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;aggregated news messages&lt;/code&gt; refers to a set of messages sent by a user. Instead of displaying each message one by one, there will be a server that will group all the related messages sent by a user into a list. This list will then be retrieved for the chat..&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sDzqr7PE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/12489333/166072172-482250b2-93f7-4787-9652-3826054cc817.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sDzqr7PE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/12489333/166072172-482250b2-93f7-4787-9652-3826054cc817.png" alt="Architecture diagram" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how it looks like in Firestore:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yMaWhdUb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/12489333/269821581-987ba838-92c0-493a-bc08-5352205597cf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yMaWhdUb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://user-images.githubusercontent.com/12489333/269821581-987ba838-92c0-493a-bc08-5352205597cf.png" alt="Firestore Image of the messages" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Architectural Components to explicit implementation details
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The auth and chat microservices will be written in Python using FastAPI.&lt;/li&gt;
&lt;li&gt;The message aggregating process will be handled by Apache Camel using SpringBoot on Java.&lt;/li&gt;
&lt;li&gt;User databases will be Postgres.&lt;/li&gt;
&lt;li&gt;Chat database will be Cassandra to create a fast partition for each chat and fast pagination based on Time UUID.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;aggregated news messages&lt;/code&gt; will be saved into Firestore and only will retrieve for realtime&lt;/li&gt;
&lt;li&gt;Chat messages queue processing will be handle by Kafka using a Python Kafka Consumer.&lt;/li&gt;
&lt;li&gt;Auth validation in Python microservices will be handled by a Python shared library called &lt;code&gt;auth-validator&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Chat messages pagination and retrieving of the first page
&lt;/h2&gt;

&lt;p&gt;The Chat will send a HTTP request to the Chat Microserver &lt;code&gt;/chat/&amp;lt;id&amp;gt;?time=&amp;lt;time-uuid&amp;gt;&amp;amp;quantity&lt;/code&gt; to retrieve a set of messages&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Query parameter &lt;strong&gt;quatity&lt;/strong&gt; will be a integer to know the max size of messages to get&lt;/li&gt;
&lt;li&gt;Query parameter &lt;strong&gt;time&lt;/strong&gt; will be the UUID time of the last message that the chat have to get messages before that time&lt;/li&gt;
&lt;li&gt;Both query parameter are optional. When there are not quantity you get 10. When there are not time you get the latest messages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Development Enviroment Details
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We going to use &lt;a href="https://tilt.dev/"&gt;tilt&lt;/a&gt; in order to run the infraestructure on Kubernetes for development purposes.&lt;/li&gt;
&lt;li&gt;There is a Docker Compose for development purposes.&lt;/li&gt;
&lt;li&gt;For Python you need Pipenv and version 3.9.7&lt;/li&gt;
&lt;li&gt;For Java you need:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java 17.0.2 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running the project using Docker Compose:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-svf&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; docker-compose up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should create 9 containers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1.) chat-firebase-apache-camel_zookeeper_1
2.) chat-firebase-apache-camel_cassandra_1
3.) chat-firebase-apache-camel_auth_db_1
4.) chat-firebase-apache-camel_kafka_1
5.) chat-firebase-apache-camel_consumer_1
6.) chat-firebase-apache-camel_auth_microservice_1
7.) chat-firebase-apache-camel_apache_camel_microservices_1
8.) chat-firebase-apache-camel_chat_microservices_1
9.) front_end_next_js_1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you can open &lt;code&gt;http://localhost:3000/&lt;/code&gt; and start using the chat.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run tests in Apache Camel
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mvn &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;-X&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to run the microservices manually?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Chat Microservice:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;chat-microservice &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; pipenv run server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Auth Microservice:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;auth-microservice &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; pipenv run server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You will need Maven to run the Apache Camel Spring Boot server
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;apache-camel-service-bus &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; mvn package &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; mvn spring-boot:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Docker Development Worflow
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Main command to run docker-compose
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-svf&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; docker-compose up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Migrate using Alembic in the Auth Microservice
&lt;/h3&gt;

&lt;p&gt;In order to use the auth microservice you must migrate using alembic to create the user table. Access to the container and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pipenv shell
alembic upgrade &lt;span class="nb"&gt;head&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should print something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dict_keys&lt;span class="o"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt;
INFO  &lt;span class="o"&gt;[&lt;/span&gt;alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  &lt;span class="o"&gt;[&lt;/span&gt;alembic.runtime.migration] Will assume transactional DDL.
INFO  &lt;span class="o"&gt;[&lt;/span&gt;alembic.runtime.migration] Running upgrade  -&amp;gt; fe1a63894533, create user table
INFO  &lt;span class="o"&gt;[&lt;/span&gt;alembic.runtime.migration] Running upgrade fe1a63894533 -&amp;gt; d3c6204b9f3c, username unique
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Run Kafka CLI:
&lt;/h3&gt;

&lt;p&gt;Create a topic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; CONTAINER_ID kafka-topics.sh &lt;span class="nt"&gt;--create&lt;/span&gt; &lt;span class="nt"&gt;--bootstrap-server&lt;/span&gt; localhost:9092 &lt;span class="nt"&gt;--replication-factor&lt;/span&gt; 1 &lt;span class="nt"&gt;--partitions&lt;/span&gt; 3 &lt;span class="nt"&gt;--topic&lt;/span&gt; charlytest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List of topics:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; CONTAINER_ID kafka-topics.sh &lt;span class="nt"&gt;--bootstrap-server&lt;/span&gt; localhost:9092 &lt;span class="nt"&gt;--list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get topics information&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; CONTAINER_ID kafka-topics.sh &lt;span class="nt"&gt;--bootstrap-server&lt;/span&gt; localhost:9092 &lt;span class="nt"&gt;--describe&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Console Producer using key and acks&lt;/p&gt;

&lt;p&gt;In this case 12345 is the key and hello de message content (Useful to put all the messages in the same partition using the user_id)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; CONTAINER_ID kafka-console-producer.sh  &lt;span class="nt"&gt;--bootstrap-server&lt;/span&gt; localhost:9092 &lt;span class="nt"&gt;--topic&lt;/span&gt; charlytest &lt;span class="nt"&gt;--producer-property&lt;/span&gt; &lt;span class="nv"&gt;acks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;all &lt;span class="nt"&gt;--property&lt;/span&gt; parse.key&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt; &lt;span class="nt"&gt;--property&lt;/span&gt; key.separator&lt;span class="o"&gt;=&lt;/span&gt;:

&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; 12345:hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Access to Cassandra:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; CONTAINER_ID cqlsh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get the network information
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network &lt;span class="nb"&gt;ls&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="s2"&gt;"camel"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Firebase integration for Firestore.
&lt;/h3&gt;

&lt;p&gt;You need to download the &lt;code&gt;service_account_key.json&lt;/code&gt; from your Firebase project add it to the &lt;code&gt;aggregated-messages-consumer&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;Also you need to update the .env file in the &lt;code&gt;frontend-dev&lt;/code&gt; folder to looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# MICROSERVICES&lt;/span&gt;
NEXT_PUBLIC_AUTH_MICROSERVICE &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'http://0.0.0.0:8000'&lt;/span&gt;
NEXT_PUBLIC_CHAT_MICROSERVICE &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'http://0.0.0.0:9000'&lt;/span&gt;
&lt;span class="c"&gt;# FIREBASE&lt;/span&gt;
&lt;span class="nv"&gt;NEXT_PUBLIC_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;span class="nv"&gt;NEXT_PUBLIC_AUTH_DOMAIN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;span class="nv"&gt;NEXT_PUBLIC_PROJECT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;span class="nv"&gt;NEXT_PUBLIC_STORAGE_BUCKET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;span class="nv"&gt;NEXT_PUBLIC_MESSAGING_SENDER_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;span class="nv"&gt;NEXT_PUBLIC_APP_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  License
&lt;/h3&gt;

&lt;p&gt;Apache License 2.0&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>kubernetes</category>
      <category>restapi</category>
      <category>react</category>
    </item>
    <item>
      <title>I wrote a super hexagon clone game in python pygame</title>
      <dc:creator>Carlos Azuaje</dc:creator>
      <pubDate>Sun, 25 Oct 2020 23:51:23 +0000</pubDate>
      <link>https://dev.to/charlyjazz/i-wrote-a-super-hexagon-clone-game-in-python-pygame-2g5k</link>
      <guid>https://dev.to/charlyjazz/i-wrote-a-super-hexagon-clone-game-in-python-pygame-2g5k</guid>
      <description>&lt;p&gt;If someone want learn how it work check the code: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/CharlyJazz/Hexagonal-Game"&gt;https://github.com/CharlyJazz/Hexagonal-Game&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feedback welcome!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Answer: Decimal or numeric values in regular expression validation</title>
      <dc:creator>Carlos Azuaje</dc:creator>
      <pubDate>Sat, 06 Jun 2020 00:52:44 +0000</pubDate>
      <link>https://dev.to/charlyjazz/answer-decimal-or-numeric-values-in-regular-expression-validation-2n7g</link>
      <guid>https://dev.to/charlyjazz/answer-decimal-or-numeric-values-in-regular-expression-validation-2n7g</guid>
      <description>&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;h1&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pTF_nE4a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
            &lt;a href="https://stackoverflow.com/questions/2811031/decimal-or-numeric-values-in-regular-expression-validation/39399503#39399503" rel="noopener noreferrer"&gt;
              &lt;span class="title-flare"&gt;answer&lt;/span&gt; re:  Decimal or numeric values in regular expression validation
            &lt;/a&gt;
        &lt;/h1&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Sep  8 '16&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/2811031/decimal-or-numeric-values-in-regular-expression-validation/39399503#39399503" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5MiFESHx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          92
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rk_a5QFN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;Actually, none of the given answers are fully cover the request.&lt;br&gt;
As the OP didn't provided a specific use case or types of numbers, I will try to cover all possible cases and permutations.&lt;/p&gt;
&lt;h1&gt;Regular Numbers&lt;/h1&gt;

&lt;h3&gt;Whole Positive&lt;/h3&gt;

&lt;p&gt;This number is usually called &lt;em&gt;unsigned integer&lt;/em&gt;, but you can also…&lt;/p&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    
      &lt;a href="https://stackoverflow.com/questions/2811031/decimal-or-numeric-values-in-regular-expression-validation/39399503#39399503" rel="noopener noreferrer"&gt;Open Full Answer&lt;/a&gt;
    
  &lt;/div&gt;
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Experience building a package from react to svelte</title>
      <dc:creator>Carlos Azuaje</dc:creator>
      <pubDate>Fri, 15 May 2020 21:44:15 +0000</pubDate>
      <link>https://dev.to/charlyjazz/experience-building-a-package-from-react-to-svelte-4n9n</link>
      <guid>https://dev.to/charlyjazz/experience-building-a-package-from-react-to-svelte-4n9n</guid>
      <description>&lt;p&gt;The svelte ecosystem grows more and more. New packages appear and people are encouraged to start using it.&lt;/p&gt;

&lt;p&gt;I decided to contribute creating a package that perhaps will be useful to some people. &lt;/p&gt;

&lt;p&gt;The original react project is &lt;a href="https://github.com/amarofashion/react-credit-cards"&gt;this&lt;/a&gt;, a component to render a credit card. Very cool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And this was my experience&lt;/strong&gt;:&lt;/p&gt;




&lt;h3&gt;
  
  
  1.) Folder structure:
&lt;/h3&gt;

&lt;p&gt;I had no idea how to create an npm package for svelte. So dig a little. In the github profile of sveltejs i founded &lt;a href="https://github.com/sveltejs/component-template"&gt;this&lt;/a&gt;&lt;br&gt;
A template to create shareables components.&lt;/p&gt;
&lt;h3&gt;
  
  
  2.) Sandbox environment to test the svelte component
&lt;/h3&gt;

&lt;p&gt;My first idea was &lt;a href="https://storybook.js.org/docs/guides/guide-svelte"&gt;Storybook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The new packages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;"@babel/core"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^7.9.6"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"@storybook/addon-actions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^5.3.17"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"@storybook/addon-links"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^5.3.17"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"@storybook/addons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^5.3.17"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"@storybook/svelte"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^5.3.18"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"babel-loader"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^8.1.0"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And a config file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;stories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../src/*.stories.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../examples/*.stories.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;addons&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@storybook/addon-actions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@storybook/addon-links&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What scenarios should we try with Storybook?&lt;/p&gt;

&lt;p&gt;A file answered this question for me, &lt;a href="https://github.com/amarofashion/react-credit-cards/blob/master/test/index.spec.js"&gt;the unit tests&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/CharlyJazz/svelte-credit-card/blob/master/src/CreditCard.stories.js"&gt;So I transformed the test cases into a storybook&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;CreditCard&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Credit Card&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CreditCard&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AmericanExpress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Dankort&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Diners, Visa, Maestro, ETC...&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3.) CSS y JSX:
&lt;/h3&gt;

&lt;p&gt;This stage seemed complex. Since it involved the adaptation of CSS and React JSX to Svelte. I didn't know what bugs was going to find me with.&lt;/p&gt;

&lt;p&gt;Browsing the original react package repository i &lt;a href="https://github.com/amarofashion/react-credit-cards/blob/master/src/styles.scss"&gt;discovered this&lt;/a&gt; A good SCSS file with all styles. I didn't think twice and put it inside the &lt;code&gt;style&lt;/code&gt; tags in our new svelte component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--exWQAjnr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/12489333/82091151-3e8b4c80-96cd-11ea-9811-ff8bf665a318.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--exWQAjnr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/12489333/82091151-3e8b4c80-96cd-11ea-9811-ff8bf665a318.png" alt="Example of scss in svelte"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It worked. Now the JSX&lt;/p&gt;

&lt;p&gt;Copy and paste the JSX to Svelte and replace &lt;code&gt;className&lt;/code&gt; with &lt;code&gt;class&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yfP24Z2u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/12489333/82092305-667baf80-96cf-11ea-8562-1140fdf8670f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yfP24Z2u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/12489333/82092305-667baf80-96cf-11ea-8562-1140fdf8670f.png" alt="jsx to svelte"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;it worked again!&lt;/p&gt;

&lt;h2&gt;
  
  
  4.) Javascript, the challenge:
&lt;/h2&gt;

&lt;p&gt;The first step was to write the &lt;code&gt;script&lt;/code&gt; tags in the svelte component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="c1"&gt;// This will be insane&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First we had to create the props.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;focused&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;acceptedCards&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cvc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;expiry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;issuer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;locale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;VALID THRU&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;placeholders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YOUR NAME HERE&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;preview&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need use&lt;a href="https://www.npmjs.com/package/payment"&gt;payment&lt;/a&gt; as in the React project to manage credit cards and their validations. And we needed to implement a method in the constructor like in the &lt;a href="https://github.com/amarofashion/react-credit-cards/blob/master/src/index.js#L9"&gt;version de react&lt;/a&gt;. The closest thing is &lt;code&gt;onMount&lt;/code&gt; in Svelte.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;onMount&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Logic for credit cards&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It worked.&lt;/p&gt;

&lt;p&gt;Now we need derived data (Format credit number from the text props, format the CVC with the slash MM/YY). &lt;a href="https://github.com/amarofashion/react-credit-cards/blob/master/src/index.js#L71"&gt;As we can see the react component&lt;/a&gt; used &lt;code&gt;get&lt;/code&gt; to create classes methods that don't need be called like a function &lt;code&gt;call_me_i_am_a_function()&lt;/code&gt; and the behavior of this method is like a property. Very common in object oriented programming:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;preview&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;maxLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;preview&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;19&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;maxLength&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;nextNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-Za-z&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;| /g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So it seemed impossible to use something like that in Svelte. It is time to research.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://svelte.dev/tutorial/updating-arrays-and-objects"&gt;The weird dollar symbol&lt;/a&gt;. What?&lt;/p&gt;

&lt;p&gt;Lets try:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;expiryDerived&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;focused&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;expiry&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;expiry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;expiry&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;month&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// .... bla bla bla&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;
  &lt;span class="p"&gt;})();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it worked, wow. At this time I am not sure if what I am doing is a good practice. If any of you have any ideas please submit a pull request: star:&lt;/p&gt;

&lt;h2&gt;
  
  
  5.) A bug when compiling.
&lt;/h2&gt;

&lt;p&gt;It seems that payment uses commonjs and we don't have a plugin for this in our rollup configuration that gave us the svelte template.&lt;/p&gt;

&lt;p&gt;So I had to add the commonjs plugin for rollup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;commonjs&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@rollup/plugin-commonjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nl"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="nx"&gt;svelte&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="nx"&gt;commonjs&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// &amp;lt;-- Our new friend&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Easy, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  6.) Publish NPM Package
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Everything very easy and fun. There was not much stress. Svelte fulfilled all the requirements to create this component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enhacements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Refactor CSS to make customizable&lt;/li&gt;
&lt;li&gt;Delete the payment package because it is very old and there is a news alternatives to manage credit card validation&lt;/li&gt;
&lt;li&gt;Use &lt;a href="https://svelte.dev/tutorial/animate"&gt;Svelte animation&lt;/a&gt; and not &lt;code&gt;@keyframes&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add &lt;a href="https://dev.to/d_ir/introduction-4cep"&gt;unit test&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Contributions
&lt;/h2&gt;

&lt;p&gt;Send a pull requests to &lt;a href="https://github.com/CharlyJazz/svelte-credit-card"&gt;https://github.com/CharlyJazz/svelte-credit-card&lt;/a&gt;&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>react</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
