-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
237 lines (224 loc) · 8.32 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="color-scheme" content="light dark" />
<link rel="stylesheet" href="css/pico.indigo.min.css" />
<style>
body > header {
box-shadow: lightgrey 0 2px 3px;
background: rgba(238, 238, 238, 0.9);
width: 100%;
position: fixed;
padding: 0;
}
main {
border-top: transparent solid 120px;
}
a#dxid {
text-decoration: none;
}
</style>
<title>Understanding DXID Identifiers</title>
</head>
<body>
<header class="is-fixed-above-lg is-fixed">
<div class="container">
<nav>
<ul>
<li><h1>🆔</h1></li>
</ul>
<ul>
<li>
<a href="https://github.com/tttp/dxid">
<svg
height="32"
aria-hidden="true"
viewBox="0 0 24 24"
version="1.1"
width="32"
data-view-component="true"
>
<path
d="M12.5.75C6.146.75 1 5.896 1 12.25c0 5.089 3.292 9.387 7.863 10.91.575.101.79-.244.79-.546 0-.273-.014-1.178-.014-2.142-2.889.532-3.636-.704-3.866-1.35-.13-.331-.69-1.352-1.18-1.625-.402-.216-.977-.748-.014-.762.906-.014 1.553.834 1.769 1.179 1.035 1.74 2.688 1.25 3.349.948.1-.747.402-1.25.733-1.538-2.559-.287-5.232-1.279-5.232-5.678 0-1.25.445-2.285 1.178-3.09-.115-.288-.517-1.467.115-3.048 0 0 .963-.302 3.163 1.179.92-.259 1.897-.388 2.875-.388.977 0 1.955.13 2.875.388 2.2-1.495 3.162-1.179 3.162-1.179.633 1.581.23 2.76.115 3.048.733.805 1.179 1.825 1.179 3.09 0 4.413-2.688 5.39-5.247 5.678.417.36.776 1.05.776 2.128 0 1.538-.014 2.774-.014 3.162 0 .302.216.662.79.547C20.709 21.637 24 17.324 24 12.25 24 5.896 18.854.75 12.5.75Z"
></path>
</svg>
</a>
</li>
<li><a href="https://fixthestatusquo.org">made with ♥️</a></li>
</ul>
</nav>
</div>
</header>
<main class="container">
<p>
dxid is an easier way to identify all the things stored in your
application. <br />
Instead of using numbers like Action <b id="id">#13672</b>, you'll
use shorter codes like Action <b><a id="dxid" href="#prpl">prpl</a></b>
</p>
<article>
<header id="converter">Convert from and to dxid</header>
<form>
<fieldset class="grid">
<div class="row">
<label>
#id
<input type="number" name="id" placeholder="13672" min="0" />
</label>
</div>
<div class="row">
<label>
dxid
<input name="dxid" placeholder="prpl" />
</label>
</div>
</fieldset>
<small>fill either the id or dxid</small>
</form>
</article>
<section>
<h2>Key Advantages for your users</h2>
<ul>
<li>Shorter, clearer references in communications</li>
<li>Fewer mistakes when sharing IDs</li>
<li>No confusion between IDs and metrics/counts</li>
<li>Cleaner and shorter URLs when they contains an ID</li>
</ul>
</section>
<section>
<h3 id="benefits-of-dxid">Benefits of DXID</h3>
<ol>
<li>
<p><strong>Shorter and Clearer</strong></p>
<ul>
<li>Easier to read, write, and remember</li>
<li>Less prone to copy/paste errors</li>
<li>
Built-in
<em
data-tooltip="the first digit is a checksum, like for credit cards or IBANs"
>error detection</em
>
to catch typos
</li>
</ul>
</li>
<li>
<p><strong>Better Communication</strong></p>
<ul>
<li>
Instead of: "There's a problem with Widget
#234657" (easy to mistype)
</li>
<li>
You'll say: "There's a problem with Widget
<a href="#lkhhc">lkhhc</a>" (shorter and catches typos)
</li>
<li>
If there is a mistake and you forget a char, it will correctly
identify lkhh or lkhc as typos
</li>
</ul>
</li>
<li>
<p><strong>Human and URL-Friendly</strong></p>
<ul>
<li>
you can put the uxid in a link without having to worry about
encoding
</li>
<li>
all the easy to confuse chars (1 vs. l, 0 vs. O) aren't used
</li>
<li>
there aren't
<em data-tooltip="well, there is y">voyels</em> either, so no
risk that an diid looks
<em
data-tooltip="we checked, no offensive words in 48 languages"
>like a word</em
>
</li>
</ul>
</li>
<li>
<p><strong>Minimal tech change</strong></p>
<ul>
<li>
in your database and backend, you keep using the ids as always
</li>
<li>you just convert them to dxid when displaying them</li>
<li>you just convert them to id when the users submit them</li>
<li>simple to check from the cli<code>$npx dxid lkhhc</code></li>
<li>923 <b>bytes</b> zipped and compressed</li>
<li>no dependency, lots of tests</li>
</ul>
</li>
</ol>
</section>
</main>
<script type="module">
import dxid from "./src/dxid.js";
const dxidField = document.querySelector('input[name="dxid"]');
const idField = document.querySelector('input[name="id"]');
function handleHash() {
const hash = window.location.hash;
if (hash) {
const _dxid = hash.substring(1); // Remove the # character
if (dxidField.value === _dxid || !dxid.parse(_dxid,false)) return;
dxidField.value = _dxid;
dxidField.dispatchEvent(new Event("input", { bubbles: true }));
}
}
handleHash();
window.addEventListener("hashchange", handleHash);
dxidField.addEventListener("input", (e) => {
const value = e.target.value.trim();
try {
idField.value = dxid.parse(value);
dxidField.ariaInvalid = "false";
document.location.hash = value;
} catch (e) {
console.log(e.toString());
idField.value = "";
dxidField.ariaInvalid = "true";
}
});
idField.addEventListener("input", (e) => {
const id = e.target.value.trim();
dxidField.value = id ? dxid.stringify(+id) : "";
document.location.hash = dxidField.value;
dxidField.ariaInvalid = "false";
});
idField.addEventListener("focus", () => {
idField.placeholder = "";
dxidField.placeholder = "";
});
dxidField.addEventListener("focus", () => {
idField.placeholder = "";
dxidField.placeholder = "";
});
const example = (digitLength) => {
const min = Math.pow(10, digitLength - 1);
const max = Math.pow(10, digitLength) - 1;
const randomValue = Math.floor(Math.random() * (max - min + 1)) + min;
const randomdxid = dxid.stringify(randomValue); // stringify takes an id and returns a dxid
//const randomValue = dxid.parse(randomdxid,false); // parse takes a dxid and returns an id
document.getElementById("id").textContent = "#" + randomValue;
document.getElementById("dxid").textContent = randomdxid;
document.getElementById("dxid").href = "#" + randomdxid;
if (idField.placeholder != "") {
dxidField.placeholder = randomdxid;
idField.placeholder = randomValue;
}
};
example(5);
setInterval(() => {
const digitLength = Math.floor(Math.random() * 10) + 3;
example(digitLength);
}, 5000);
</script>
</body>
</html>