<?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: Dennis Zimmermann</title>
    <description>The latest articles on DEV Community by Dennis Zimmermann (@dennzimm).</description>
    <link>https://dev.to/dennzimm</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%2F174342%2Fa1363593-4d95-4e54-a131-97bc35e957e7.jpeg</url>
      <title>DEV Community: Dennis Zimmermann</title>
      <link>https://dev.to/dennzimm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dennzimm"/>
    <language>en</language>
    <item>
      <title>When redux-persist meets Expo FileSystem</title>
      <dc:creator>Dennis Zimmermann</dc:creator>
      <pubDate>Mon, 04 Mar 2024 18:47:04 +0000</pubDate>
      <link>https://dev.to/dennzimm/when-redux-persist-meets-expo-filesystem-4km</link>
      <guid>https://dev.to/dennzimm/when-redux-persist-meets-expo-filesystem-4km</guid>
      <description>&lt;p&gt;In the world of react(-native) development, where efficient state management is essential, &lt;a href="https://github.com/rt2zz/redux-persist"&gt;redux-persist&lt;/a&gt; has proven to be a reliable tool. Today, I introduce a practical companion specifically designed for react-native / expo apps - &lt;a href="https://github.com/dennzimm/redux-persist-expo-file-system-storage"&gt;redux-persist-expo-file-system-storage&lt;/a&gt;. Instead of a major overhaul, consider this as a seamless enhancement that optimizes state persistence in your applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, What Exactly is redux-persist?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/rt2zz/redux-persist"&gt;redux-persist&lt;/a&gt; is designed to handle state persistence in &lt;a href="https://redux.js.org/"&gt;redux&lt;/a&gt; applications. It integrates with redux to automatically save the application's state to a storage system (e.g., local storage, AsyncStorage) and then restores it upon subsequent app launches. This enables developers to maintain the state across sessions, enhancing user experience by preserving data and application state.&lt;/p&gt;

&lt;h3&gt;
  
  
  AsyncStorage Size Limitations on Android: What You Need to Know
&lt;/h3&gt;

&lt;p&gt;Dealing with storage limitations on Android, &lt;a href="https://react-native-async-storage.github.io/async-storage/docs/limits"&gt;particularly with AsyncStorage&lt;/a&gt;, can be challenging. When the storage reaches its maximum size, data may be deleted or stored information may fail to display, leading to severe consequences for established apps. In addition to AsyncStorage, Android's storage system imposes two main constraints: total storage size limits and per-entry size limits. It is essential to explore alternatives not only to overcome size restrictions but also to handle such scenarios more gracefully. Keep in mind that AsyncStorage for Android relies on SQLite as its storage backend, introducing its own set of size limitations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing &lt;strong&gt;redux-persist-expo-file-system-storage&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/dennzimm/redux-persist-expo-file-system-storage"&gt;redux-persist-expo-file-system-storage&lt;/a&gt; is a specialized storage engine within redux-persist, leverages &lt;a href="https://docs.expo.dev/versions/latest/sdk/filesystem/"&gt;expo-file-system&lt;/a&gt; to enhance state persistence.&lt;/p&gt;

&lt;p&gt;In a landscape with existing alternatives, &lt;strong&gt;redux-persist-expo-file-system-storage&lt;/strong&gt; distinguishes itself by focusing on flexibility, extensibility, and robust debugging capabilities specifically tailored for react-native / expo apps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Written in TypeScript:&lt;/strong&gt; Complete TypeScript support for improved type safety and development experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Extensibility:&lt;/strong&gt; Designed to be easily extended with options for customizing storage behavior through various callbacks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configurability:&lt;/strong&gt; Fine-tune the storage engine with a variety of options, making it adaptable to different project requirements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debug Mode:&lt;/strong&gt; Enable the debug mode for detailed logs during development, helping you troubleshoot and understand the library's actions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Custom Logging:&lt;/strong&gt; Utilize your own logger functions for debug and error messages, allowing seamless integration with your application's logging strategy.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Installation and Usage
&lt;/h3&gt;

&lt;p&gt;Choose your preferred package manager and add &lt;strong&gt;redux-persist-expo-file-system-storage&lt;/strong&gt; to your project, e.g.:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add redux-persist-expo-file-system-storage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installation, you're ready to integrate the storage engine into your setup for seamless state persistence 🥳.&lt;/p&gt;

&lt;p&gt;Here's a simple example demonstrating how to integrate &lt;strong&gt;redux-persist-expo-file-system-storage&lt;/strong&gt; into your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;FileSystem&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;expo-file-system&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createExpoFileSystemStorage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;StorageOptions&lt;/span&gt; &lt;span class="p"&gt;}&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;redux-persist-expo-file-system-storage&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;PersistConfig&lt;/span&gt; &lt;span class="p"&gt;}&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;redux-persist&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;rootReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;RootState&lt;/span&gt; &lt;span class="p"&gt;}&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;./store.config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// either without custom options &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;expoFileSystemStorage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createExpoFileSystemStorage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// or with custom options&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;expoFileSystemStorage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createExpoFileSystemStorage&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;storagePath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;FileSystem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentDirectory&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;customPersistStorageData/`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;encoding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FileSystem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;EncodingType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BASE64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;customDebugFunction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;customErrorFunction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;beforeInit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;customBeforeInitFunction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;afterInit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;customAfterInitFunction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}),&lt;/span&gt;

&lt;span class="c1"&gt;// configuration for redux-ersist&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;persistConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PersistConfig&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;RootState&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// Use the expoFileSystemStorage as the storage engine&lt;/span&gt;
  &lt;span class="na"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;expoFileSystemStorage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// ... Add other persist config options if needed&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;persistedReducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;persistReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;persistConfig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rootReducer&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;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;configureStore&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;persistedReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// ... Add other config options if needed&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For detailed instructions on installing and utilizing &lt;strong&gt;redux-persist-expo-file-system-storage&lt;/strong&gt;, check out the &lt;a href="https://github.com/dennzimm/redux-persist-expo-file-system-storage/blob/main/README.md#usage"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;In Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you're looking to improve state persistence in your react-native / expo applications, &lt;a href="https://github.com/dennzimm/redux-persist-expo-file-system-storage"&gt;redux-persist-expo-file-system-storage&lt;/a&gt; is a great tool to consider. With a variety of features to enhance state management, it's definitely worth exploring. &lt;/p&gt;

&lt;p&gt;Have you found &lt;strong&gt;redux-persist-expo-file-system-storage&lt;/strong&gt; to be helpful in your development journey? If so, why not spread the love on &lt;a href="https://github.com/dennzimm/redux-persist-expo-file-system-storage"&gt;GitHub&lt;/a&gt;? ⭐️&lt;/p&gt;

</description>
      <category>expo</category>
      <category>reactnative</category>
      <category>redux</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How to replace Environment Variables in a .npmrc File</title>
      <dc:creator>Dennis Zimmermann</dc:creator>
      <pubDate>Fri, 16 Feb 2024 11:14:20 +0000</pubDate>
      <link>https://dev.to/dennzimm/how-to-replace-environment-variables-in-a-npmrc-file-jpg</link>
      <guid>https://dev.to/dennzimm/how-to-replace-environment-variables-in-a-npmrc-file-jpg</guid>
      <description>&lt;p&gt;Managing npm registry configurations and authentication tokens can be a tricky task, especially when working collaboratively on multiple projects and environments. To simplify this process, I've created a package called &lt;a href="https://www.npmjs.com/package/npmrc-replace-env"&gt;npmrc-replace-env&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;So, picture this – we're deep into a project, and suddenly, we need this secret &lt;code&gt;_authToken&lt;/code&gt; in our &lt;code&gt;.npmrc&lt;/code&gt; file to access some essential packages (e.g. &lt;code&gt;@fortawesome&lt;/code&gt; pro version 😉). Cool, but how do we share this without risking our repo's security or making everyone's life complicated?&lt;/p&gt;

&lt;p&gt;That's the snag I hit, and it got me thinking. I needed a way to smoothly pass around this &lt;code&gt;_authToken&lt;/code&gt;, making sure everyone gets what they need without committing it to our codebase.&lt;/p&gt;

&lt;p&gt;The goal? To make life easier for all of us – no headaches, no communication chaos, and definitely no disruptions to our coding vibe. I wanted something straightforward that could handle this kind of situation in other projects too.&lt;/p&gt;

&lt;p&gt;And voila, &lt;strong&gt;npmrc-replace-env&lt;/strong&gt; was born!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;npmrc-replace-env&lt;/strong&gt; is a utility designed to dynamically generate &lt;code&gt;.npmrc&lt;/code&gt; files based on configuration and environment variables.&lt;/p&gt;

&lt;p&gt;By having a committed &lt;code&gt;.npmrc.config&lt;/code&gt; file as a template, you're basically giving your team a shortcut. They only need to worry about updating their &lt;code&gt;.env&lt;/code&gt; file with their environment variables, and bam, they're good to go. No more wrestling with the entire &lt;code&gt;.npmrc&lt;/code&gt; file, no more back-and-forth to keep everyone on the same page 🎉.&lt;/p&gt;

&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;p&gt;This package follows a simple yet powerful approach. The magic begins with the &lt;code&gt;.npmrc.config&lt;/code&gt; file in your project's root. This file outlines the configuration for your &lt;code&gt;.npmrc&lt;/code&gt; file, with placeholders serving as markers for environment variables to be injected. &lt;/p&gt;

&lt;p&gt;Example &lt;code&gt;.npmrc.config&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .npmrc.config

# Custom registry for @myorg packages
@myorg:registry=https://somewhere-else.com/myorg
//somewhere-else.com/myorg/:_authToken=NPMRC_MYTOKEN1

# Custom registry for @another packages
@another:registry=https://somewhere-else.com/another
//somewhere-else.com/another/:_authToken=NPMRC_MYTOKEN2

# Custom registry for @fortawesome packages
@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=NPMRC_FA_AUTH_TOKEN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;.npmrc.config&lt;/code&gt; file defines custom registries. The authentication tokens are provided as environment variables (&lt;code&gt;NPMRC_MYTOKEN1&lt;/code&gt;, &lt;code&gt;NPMRC_MYTOKEN2&lt;/code&gt;, and &lt;code&gt;NPMRC_FA_AUTH_TOKEN&lt;/code&gt;), which will be replaced during the generation process.&lt;/p&gt;

&lt;p&gt;It's important to add &lt;code&gt;.npmrc&lt;/code&gt; to your &lt;code&gt;.gitignore&lt;/code&gt; file to prevent accidentally committing sensitive information, such as authentication tokens. &lt;/p&gt;

&lt;p&gt;Next, define your environment variables in the &lt;code&gt;.env&lt;/code&gt; file, each prefixed with &lt;code&gt;NPMRC_&lt;/code&gt;. Each placeholder in the &lt;code&gt;.npmrc.config&lt;/code&gt; file corresponds to an environment variable defined here.&lt;/p&gt;

&lt;p&gt;Example &lt;code&gt;.env&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NPMRC_MYTOKEN1=your_myorg_token_value
NPMRC_MYTOKEN2=your_another_token_value
NPMRC_FA_AUTH_TOKEN=your_fontawesome_token_value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With everything set up, execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx npmrc-replace-env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep in mind: This will override any existing &lt;code&gt;.npmrc&lt;/code&gt; files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Explore npmrc-replace-env
&lt;/h2&gt;

&lt;p&gt;If &lt;strong&gt;npmrc-replace-env&lt;/strong&gt; has made your development life easier, consider showing some love on &lt;a href="https://github.com/dennzimm/npmrc-replace-env"&gt;GitHub&lt;/a&gt; ⭐️.&lt;/p&gt;

&lt;p&gt;Discover more about &lt;strong&gt;npmrc-replace-env&lt;/strong&gt; by checking out the &lt;a href="https://www.npmjs.com/package/npmrc-replace-env"&gt;npm package&lt;/a&gt;. Dive into the &lt;a href="https://github.com/dennzimm/npmrc-replace-env"&gt;GitHub repository&lt;/a&gt; for detailed documentation, updates, and opportunities to contribute.&lt;/p&gt;

&lt;p&gt;Happy coding! 👨‍💻&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>npm</category>
      <category>opensource</category>
      <category>npmrc</category>
    </item>
  </channel>
</rss>
