<?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: ThornDuke</title>
    <description>The latest articles on DEV Community by ThornDuke (@thornduke).</description>
    <link>https://dev.to/thornduke</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%2F3051994%2Fc537fdce-d4c0-4b5c-a75a-46f18b324610.png</url>
      <title>DEV Community: ThornDuke</title>
      <link>https://dev.to/thornduke</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thornduke"/>
    <language>en</language>
    <item>
      <title>kinoid</title>
      <dc:creator>ThornDuke</dc:creator>
      <pubDate>Tue, 22 Apr 2025 09:38:06 +0000</pubDate>
      <link>https://dev.to/thornduke/kinoid-ap7</link>
      <guid>https://dev.to/thornduke/kinoid-ap7</guid>
      <description></description>
      <category>watercooler</category>
    </item>
    <item>
      <title>Generate Unique, Sortable, and Decodable IDs for Node.js and Browsers. How to use Kinoid</title>
      <dc:creator>ThornDuke</dc:creator>
      <pubDate>Tue, 22 Apr 2025 08:08:23 +0000</pubDate>
      <link>https://dev.to/thornduke/generate-unique-sortable-and-decodable-ids-for-nodejs-and-browsers-how-to-use-kinoid-jd</link>
      <guid>https://dev.to/thornduke/generate-unique-sortable-and-decodable-ids-for-nodejs-and-browsers-how-to-use-kinoid-jd</guid>
      <description>&lt;p&gt;Kinoid is an ultra-lightweight JavaScript library engineered for the generation of unique, URL-friendly, and temporally sortable identifiers. Designed for compatibility across Node.js and browser environments, it leverages a timestamp-based approach to produce compact IDs encoded in base36.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why Choose Kinoid?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Kinoid is a robust and efficient solution for unique ID generation. Several key attributes warrant its consideration.&lt;/p&gt;

&lt;p&gt;Firstly, &lt;strong&gt;guaranteed uniqueness&lt;/strong&gt; is a fundamental characteristic; each generated ID is distinct, even under conditions of high-frequency generation within the same millisecond or across distributed systems.&lt;/p&gt;

&lt;p&gt;Secondly, the inherent &lt;strong&gt;time-sortability&lt;/strong&gt; of the IDs, based on their creation timestamp, renders them suitable for time-sensitive operations and chronological ordering.&lt;/p&gt;

&lt;p&gt;Furthermore, &lt;strong&gt;decodability&lt;/strong&gt; is a significant feature, allowing for the extraction of embedded information such as the precise generation timestamp, process identifier, and the singularity factor directly from the ID string.&lt;/p&gt;

&lt;p&gt;The library exhibits &lt;strong&gt;cross-platform compatibility&lt;/strong&gt;, ensuring seamless operation within both Node.js server-side applications and client-side browser contexts.&lt;/p&gt;

&lt;p&gt;Finally, Kinoid's design emphasizes efficiency, being &lt;strong&gt;lightweight and fast&lt;/strong&gt; with no external dependencies, thereby facilitating rapid integration and minimizing performance overhead.&lt;/p&gt;

&lt;p&gt;Irrespective of whether the development context involves backend services, frontend applications, or hybrid architectures, Kinoid offers a concise yet potent mechanism for managing unique dentifiers.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;How Does Kinoid Work?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Kinoid generates unique IDs by combining three key components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Timestamp&lt;/strong&gt;: Each ID includes the number of milliseconds that have passed since a specific date. This ensures that IDs are naturally sortable by the time they were created.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Process ID&lt;/strong&gt;: To make IDs unique across different processes, Kinoid includes the process ID (PID) of the environment where the ID is generated. This is particularly useful in multi-process or distributed systems.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Singularity Factor&lt;/strong&gt;: Even if multiple IDs are generated within the same millisecond, Kinoid uses a sequential number (the singularity factor) to ensure that each ID remains unique.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once these components are combined, Kinoid encodes the ID in &lt;strong&gt;base36&lt;/strong&gt; format. This encoding makes the IDs compact, URL-friendly, and easy to read.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Why Base36?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Base36 encoding uses numbers (0-9) and lowercase letters (a-z), making the IDs shorter and more human-readable compared to other formats like hexadecimal. It’s also ideal for use in URLs, as it avoids special characters that might need encoding.&lt;/p&gt;

&lt;p&gt;By combining these elements, Kinoid ensures that every ID is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unique&lt;/strong&gt;: No two IDs are the same, even if generated in the same millisecond.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sortable&lt;/strong&gt;: IDs can be sorted chronologically based on their creation time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decodable&lt;/strong&gt;: You can extract meaningful information, such as the timestamp, process ID, and singularity factor, directly from the ID.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach makes Kinoid a reliable and efficient solution for generating unique identifiers in a wide range of applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Installation&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# with npm&lt;/span&gt;
npm &lt;span class="nb"&gt;install &lt;/span&gt;kinoid

&lt;span class="c"&gt;# with yarn&lt;/span&gt;
yarn add kinoid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Practical Examples&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Generate a New ID&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;newId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;kinoid&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;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;newId&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// cohb4z87mvoyf1zjy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;2. Decode an ID&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;decodeId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;kinoid&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;decoded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;decodeId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cohb4z87mvoyf1zjy&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// {&lt;/span&gt;
&lt;span class="c1"&gt;//   id: 'cohb4z87mvoyf1zjy',&lt;/span&gt;
&lt;span class="c1"&gt;//   date: 2024-11-19T16:52:19.962Z,&lt;/span&gt;
&lt;span class="c1"&gt;//   singularity: 1144,&lt;/span&gt;
&lt;span class="c1"&gt;//   pid: 5438&lt;/span&gt;
&lt;span class="c1"&gt;// }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;3. Validate an ID&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;decodeId()&lt;/code&gt; function returns an object with an error message if it receives an invalid ID as input. It can therefore also be used for ID validation.&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;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;decodeId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;kinoid&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;invalidId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;c1vz87moyfzjyoHB4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;decodeId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;invalidId&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Output:&lt;/span&gt;
&lt;span class="c1"&gt;// {&lt;/span&gt;
&lt;span class="c1"&gt;//   id: 'c1vz87moyfzjyoHB4',&lt;/span&gt;
&lt;span class="c1"&gt;//   error: 'the string c1vz87moyfzjyoHB4 is not a valid ID'&lt;/span&gt;
&lt;span class="c1"&gt;// }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is very easy to use &lt;code&gt;decodeId()&lt;/code&gt; to build a boolean validator&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;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;decodeId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;kinoid&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)();&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isValidId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasOwn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;decodeId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&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;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;invalidId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;c1vz87moyfzjyoHB4&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;validated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;isValidId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;invalidId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, the &lt;code&gt;README&lt;/code&gt; file in the GitHub repository or on the &lt;code&gt;NPM&lt;/code&gt; page contains detailed examples of how to use Kinoid in all Node.js scenarios or in browser applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Comparison with Other Libraries&lt;/strong&gt;
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;Uniqueness&lt;/th&gt;
&lt;th&gt;Sortable&lt;/th&gt;
&lt;th&gt;Decodable&lt;/th&gt;
&lt;th&gt;Size (kB)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Kinoid&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;~1.6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;uuid&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;~10.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;nanoid&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;~0.8&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Data collected from &lt;a href="https://bundlephobia.com" rel="noopener noreferrer"&gt;bundlephobia&lt;/a&gt; and &lt;a href="https://npmjs.com" rel="noopener noreferrer"&gt;npmjs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Some versions of &lt;code&gt;uuid&lt;/code&gt; produce a sortable ID.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;When to Use Kinoid?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Kinoid proves particularly beneficial in scenarios requiring the generation of unique identifiers.&lt;/p&gt;

&lt;p&gt;A primary application lies in the creation of IDs for database records. The time-sortable nature of Kinoid-generated IDs can offer advantages in indexing and querying time-based data.&lt;/p&gt;

&lt;p&gt;Furthermore, Kinoid is well-suited for generating unique and URL-friendly identifiers for resources within web applications. Its base36 encoding ensures compact and easily shareable URLs.&lt;/p&gt;

&lt;p&gt;Another compelling use case involves the creation of unique identifiers for sessions or users, where the embedded timestamp can be valuable for tracking session activity or user creation times.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Kinoid is a simple and powerful solution for generating unique and sortable IDs. Try it today and see how easy it is to integrate into your projects!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Call to Action&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/ThornDuke/kinoid" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/kinoid" rel="noopener noreferrer"&gt;npm Page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codesandbox.io/p/sandbox/pdj5qy" rel="noopener noreferrer"&gt;Demo on CodeSandbox&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>backend</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
