/
index.html
288 lines (231 loc) · 11.1 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
@hexagon/base64 - Documentation
</title>
<link href="https://www.braintreepayments.com/images/favicon-ccda0b14.png" rel="icon" type="image/png">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link id="google-font" href="https://fonts.googleapis.com/css?family=Roboto+Mono|Cutive+Mono|Roboto:300,400,700" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="styles/highlight-themes/current.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapsible.css">
<link type="text/css" rel="stylesheet" href="styles/style-switcher.css">
<link type="text/css" rel="stylesheet" href="styles/selectric.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<script src="https://embed.runkit.com"></script>
<style id="style-switcher-styles">
nav {
background: #282c34;
}
.hljs {
background: #1d2027;
}
.nav-container > ul > li.active a {
color: #dcdcdc;
}
.nav-container > ul > li.active a:hover {
color: #f78200;
}
.nav-container > ul > li.active ul {
border-color: #f78200;
}
h4.name {
color: #f78200;
}
.params > div > code, .params > div > em {
color: #f78200;
}
a, a:active {
color: #f78200;
}
.hljs-doctag, .hljs-keyword, .hljs-formula {
color: #f78200;
}
nav ul a:hover, nav ul a:active {
color: #f78200;
}
</style>
</head>
<body>
<header class="header-fixed">
<h1>
<a href="index.html" title="modernTemplate.title">
<img alt="@hexagon/base64" src="https://cdn.jsdelivr.net/gh/hexagon/base64@master/base64.png" />
@hexagon/base64
</a>
</h1>
<div class="center-header">
<ul>
</ul>
</div>
<div class="right-header">
<a href="https://github.com/hexagon/base64" title="View it on Github" style="">
<i class="fab fa-github-alt"></i>
</a>
<a href="https://www.npmjs.com/package/@hexagon/base64" title="View it on NPM" style="font-size: 19px">
<i class="fas fa-exclamation-triangle"></i>
</a>
</div>
</header>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<div id="menu-container" class="scrollbar-inner">
<div class="nav-container">
</div>
</div>
</nav>
<div id="main">
<section class="readme">
<article>
<p align="center">
<img src="https://cdn.jsdelivr.net/gh/hexagon/base64@main/base64.png" alt="@hexagon/base64" width="200" height="200"><br>
<br>Probably the only JavaScript base64 library you'll ever need.<br>
</p>
<h1>@hexagon/base64</h1>
<p>Encode, decode and validate base64 and base64url to string or arraybuffer, and back. Works in Node, Deno or browser.</p>
<p><a href="https://github.com/Hexagon/base64/actions/workflows/node.js.yml"><img src="https://github.com/Hexagon/base64/actions/workflows/node.js.yml/badge.svg" alt="Node.js CI"></a> <a href="https://github.com/Hexagon/base64/actions/workflows/deno.yml"><img src="https://github.com/Hexagon/base64/actions/workflows/deno.yml/badge.svg" alt="Deno CI"></a>
<a href="https://badge.fury.io/js/@hexagon%2Fbase64"><img src="https://badge.fury.io/js/@hexagon%2Fbase64.svg" alt="npm version"></a> <a href="https://www.npmjs.org/package/@hexagon/base64"><img src="https://img.shields.io/npm/dm/@hexagon/base64.svg" alt="NPM Downloads"></a> <a href="https://www.jsdelivr.com/package/npm/@hexagon/base64"><img src="https://data.jsdelivr.com/v1/package/npm/@hexagon/base64/badge?style=rounded" alt="jsdelivr"></a> <a href="https://www.codacy.com/gh/Hexagon/base64/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Hexagon/base64&utm_campaign=Badge_Grade"><img src="https://app.codacy.com/project/badge/Grade/4978bdbf495941c087ecb32b120f28ff" alt="Codacy Badge"></a>
<a href="https://github.com/Hexagon/base64/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License"></a></p>
<ul>
<li>Supports regular base64, as well as base64url</li>
<li>Convert to/from string or arraybuffer</li>
<li>Validate / identify base64 and base64url</li>
<li>Works in Node.js >=4.0 (both require and import).</li>
<li>Works in Deno >=1.16.</li>
<li>Works in browsers as standalone, UMD or ES-module.</li>
<li>Includes <a href="https://www.typescriptlang.org/">TypeScript</a> typings.</li>
</ul>
<h2>Installation</h2>
<h3>Node.js</h3>
<p><code>npm install @hexagon/base64 --save</code></p>
<p>JavaScript</p>
<pre class="prettyprint source lang-javascript"><code>// ESM Import ...
import base64 from "@hexagon/base64";
// ... or CommonJS Require
const base64 = require("@hexagon/base64");
</code></pre>
<p>TypeScript</p>
<p><em>Note that only default export is available in Node.js TypeScript, as the commonjs module is used internally.</em></p>
<pre class="prettyprint source lang-typescript"><code>import base64 from "@hexagon/base64";
// ...
</code></pre>
<h3>Deno</h3>
<p>JavaScript</p>
<pre class="prettyprint source lang-javascript"><code>import base64 from "https://cdn.jsdelivr.net/gh/hexagon/base64@1/src/base64.js";
// ...
</code></pre>
<p>TypeScript</p>
<pre class="prettyprint source lang-typescript"><code>import { base64 } from "https://cdn.jsdelivr.net/gh/hexagon/base64@1/src/base64.js";
// ...
</code></pre>
<h3>Browser</h3>
<h4>Manual</h4>
<ul>
<li>Download latest <a href="https://github.com/Hexagon/base64/archive/refs/heads/master.zip">zipball</a></li>
<li>Unpack</li>
<li>Grab <code>base64.min.js</code> (UMD and standalone) or <code>base64.min.mjs</code> (ES-module) from the <a href="/dist">dist/</a> folder</li>
</ul>
<h4>CDN</h4>
<p>To use as a <a href="https://github.com/umdjs/umd">UMD</a>-module (stand alone, <a href="https://requirejs.org/">RequireJS</a> etc.)</p>
<pre class="prettyprint source lang-html"><code><script src="https://cdn.jsdelivr.net/npm/@hexagon/base64@1/dist/base64.min.js"></script>
</code></pre>
<p>To use as a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules">ES-module</a></p>
<pre class="prettyprint source lang-html"><code><script type="module">
import base64 from "https://cdn.jsdelivr.net/npm/hexagon/base64@1/dist/base64.min.mjs";
// ... see usage section ...
</script>
</code></pre>
<h2>Documentation</h2>
<p>Full documentation available at <a href="https://hexagon.github.io/base64/">hexagon.github.io/base64</a>.</p>
<h3>Examples</h3>
<p>Assuming you have imported base64 as described under 'Installation'.</p>
<pre class="prettyprint source lang-javascript"><code>// Encode string as regular base64
const example1enc = base64.fromString("Hellö Wörld, how are you doing today?!");
console.log(example1enc);
// > SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==
// Decode string as regular base64
const example1dec = base64.toString("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==");
console.log(example1dec);
// > Hellö Wörld, how are you doing today?!
// Encode string as base64url (setting the second parameter to true gives base64url)
const example2enc = base64.fromString("Hellö Wörld, how are you doing today?!", true);
console.log(example2enc);
// > SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk_IQ
// Decode string as base64url (setting the second parameter to true takes base64url)
const example2dec = base64.toString("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk_IQ", true);
console.log(example2dec);
// > Hellö Wörld, how are you doing today?!
// Check if string is base64url (setting the second parameter to true validates base64url)
const example3valid = base64.validate("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk_IQ", true);
console.log(example3valid);
// > true
// Check if string is base64
const example4valid = base64.validate("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk_IQ");
console.log(example4valid);
// > false
// Check if string is base64
const example5valid = base64.validate("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==");
console.log(example5valid);
// > true
</code></pre>
<h3>Full API</h3>
<p>The library encodes and decodes base64/base64url to and from ArrayBuffers</p>
<ul>
<li>
<p><strong>fromArrayBuffer(buffer, urlMode)</strong> - Encodes <code>ArrayBuffer</code> into base64 or base64url if urlMode (optional) is true</p>
</li>
<li>
<p><strong>toArrayBuffer(str, urlMode)</strong> - Decodes base64url string (or base64url string if urlMode is true) to <code>ArrayBuffer</code></p>
</li>
<li>
<p><strong>fromString(str)</strong> - Encodes <code>String</code> into base64 string</p>
</li>
<li>
<p><strong>toString(str)</strong> - Decodes base64 string to <code>String</code></p>
</li>
<li>
<p><strong>validate(str, urlMode)</strong> - Returns true if <code>String</code> str is valid base64/base64 dependending on urlMode</p>
</li>
</ul>
<h2>Contributing</h2>
<p>See <a href="/CONTRIBUTING.md">Contribution Guide</a></p>
<h3>Contributors</h3>
<p>The underlying code is loosely based on <a href="https://github.com/niklasvh/base64-arraybuffer">github.com/niklasvh/base64-arraybuffer</a></p>
<h2>License</h2>
<p>MIT</p>
</article>
</section>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
<script src="scripts/scrollbar.js"></script>
<script src="scripts/collapsible.js"></script>
<script src="scripts/jquery.selectric.min.js"></script>
<script src="scripts/clipboard.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script>
$(function () {
$('#menu-container').scrollbar();
});
</script>
</body>
</html>