@algorithm.ts/base64 3.1.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +98 -147
- package/README.md +36 -44
- package/lib/cjs/index.cjs +16 -14
- package/lib/esm/index.mjs +16 -14
- package/lib/types/index.d.ts +3 -3
- package/package.json +4 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,312 +1,263 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
3
|
+
All notable changes to this project will be documented in this file. See
|
|
4
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
6
|
## [3.1.1](https://github.com/guanghechen/algorithm.ts/compare/@algorithm.ts/base64@3.1.0...@algorithm.ts/base64@3.1.1) (2023-06-10)
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
### Performance Improvements
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
- ⬆️ upgrade dependencies
|
|
11
|
+
([c555512](https://github.com/guanghechen/algorithm.ts/commit/c55551269eda0f98e75fca3fb862ce122b1a4889))
|
|
16
12
|
|
|
17
13
|
# 3.1.0 (2023-05-13)
|
|
18
14
|
|
|
19
|
-
|
|
20
15
|
### Performance Improvements
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
- ⬆️ upgrade dependencies
|
|
18
|
+
([1ebc2c1](https://github.com/guanghechen/algorithm.ts/commit/1ebc2c167dcc4024d9552aacf5838e1ffc73e58f))
|
|
25
19
|
|
|
26
20
|
# 3.0.0 (2023-04-02)
|
|
27
21
|
|
|
28
|
-
|
|
29
22
|
### Performance Improvements
|
|
30
23
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
- 🔧 add missing devDependencies
|
|
25
|
+
([69f6da4](https://github.com/guanghechen/algorithm.ts/commit/69f6da43cf1ecebac9f6bf8a7d8ffaced7f9de4c))
|
|
26
|
+
- 🔧 don't pack src/ folder into tarball file
|
|
27
|
+
([2dc61ad](https://github.com/guanghechen/algorithm.ts/commit/2dc61ad8c031cfc1ecf4f63c405d3e23eff1d9c9))
|
|
28
|
+
- 🔖 publish v3.0.0
|
|
29
|
+
([9bb1f35](https://github.com/guanghechen/algorithm.ts/commit/9bb1f3515444890907c8e811b989f17073f39591))
|
|
30
|
+
- ⬆️ upgrade devDependencies
|
|
31
|
+
([e88a181](https://github.com/guanghechen/algorithm.ts/commit/e88a181201ea675715be11d165b0c49c0f9224b8))
|
|
37
32
|
|
|
38
33
|
# 3.0.0-alpha.8 (2023-03-11)
|
|
39
34
|
|
|
40
|
-
|
|
41
35
|
### Performance Improvements
|
|
42
36
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
- 🔖 publish v3.0.0-alpha.8
|
|
38
|
+
([104385f](https://github.com/guanghechen/algorithm.ts/commit/104385f40c0be99b843e3342e85b618761047b69))
|
|
39
|
+
- 🔧 update package entry
|
|
40
|
+
([fd4445a](https://github.com/guanghechen/algorithm.ts/commit/fd4445a0197b21b1d6cc157c543c1f59116c2cc5))
|
|
41
|
+
- ⬆️ upgrade devDependencies
|
|
42
|
+
([4aac0d0](https://github.com/guanghechen/algorithm.ts/commit/4aac0d0267b4050689e95902d081302131417ec5))
|
|
48
43
|
|
|
49
44
|
# 3.0.0-alpha.7 (2023-01-09)
|
|
50
45
|
|
|
51
|
-
|
|
52
46
|
### Performance Improvements
|
|
53
47
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
- 🔖 publish v3.0.0-alpha.7
|
|
49
|
+
([336c4da](https://github.com/guanghechen/algorithm.ts/commit/336c4da3b92a49804c60d0a6dfb783b14712ce0a))
|
|
57
50
|
|
|
58
51
|
# 3.0.0-alpha.6 (2023-01-07)
|
|
59
52
|
|
|
60
|
-
|
|
61
53
|
### Performance Improvements
|
|
62
54
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
- 🔖 publish v3.0.0-alpha.6
|
|
56
|
+
([1758289](https://github.com/guanghechen/algorithm.ts/commit/1758289e40e4d8786800b21aeed3525a572e89fe))
|
|
57
|
+
- 🔧 set engine node>=16.0.0
|
|
58
|
+
([76e08d7](https://github.com/guanghechen/algorithm.ts/commit/76e08d7a410d437f83a84002c97892204c1fd5ca))
|
|
67
59
|
|
|
68
60
|
# 3.0.0-alpha.5 (2023-01-07)
|
|
69
61
|
|
|
70
|
-
|
|
71
62
|
### Performance Improvements
|
|
72
63
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
- 🔖 publish v3.0.0-alpha.5
|
|
65
|
+
([6c10d3c](https://github.com/guanghechen/algorithm.ts/commit/6c10d3c77bf342c7284a27e0fe07ce26fbdba05b))
|
|
66
|
+
- 🔧 set engine node>=16.15.1
|
|
67
|
+
([464c990](https://github.com/guanghechen/algorithm.ts/commit/464c99062aeec99258c1a1e475570b549f63addb))
|
|
77
68
|
|
|
78
69
|
# 3.0.0-alpha.4 (2023-01-07)
|
|
79
70
|
|
|
80
|
-
|
|
81
71
|
### Performance Improvements
|
|
82
72
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
- 🔖 publish v3.0.0-alpha.4
|
|
74
|
+
([969d685](https://github.com/guanghechen/algorithm.ts/commit/969d68502c3c35690ed7aee86dde2fe60cddddfc))
|
|
75
|
+
- 🔧 update npm entries
|
|
76
|
+
([950e3ec](https://github.com/guanghechen/algorithm.ts/commit/950e3ec1d0c9ec3a53de613b9048b3442697404d))
|
|
87
77
|
|
|
88
78
|
# 3.0.0-alpha.3 (2023-01-04)
|
|
89
79
|
|
|
90
|
-
|
|
91
80
|
### Performance Improvements
|
|
92
81
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
82
|
+
- 🔖 publish v3.0.0-alpha.3
|
|
83
|
+
([d50b472](https://github.com/guanghechen/algorithm.ts/commit/d50b4725bde1b43474f490a29672db5aa1482ae3))
|
|
84
|
+
- 🔧 support dual esm/commonjs packages
|
|
85
|
+
([0f91fbf](https://github.com/guanghechen/algorithm.ts/commit/0f91fbf7c22d7778175ee833afdcf05df5dd34ba))
|
|
97
86
|
|
|
98
87
|
# 3.0.0-alpha.2 (2023-01-02)
|
|
99
88
|
|
|
100
|
-
|
|
101
89
|
### Performance Improvements
|
|
102
90
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
- 🔖 publish v3.0.0-alpha.2
|
|
92
|
+
([3d718fb](https://github.com/guanghechen/algorithm.ts/commit/3d718fba94605e2fd60a3056b502e2e1376ca0ed))
|
|
93
|
+
- ⬆️ upgrade dependencies
|
|
94
|
+
([2672a11](https://github.com/guanghechen/algorithm.ts/commit/2672a119246358d4589ae36bcabd044d395b6136))
|
|
107
95
|
|
|
108
96
|
# 3.0.0-alpha.1 (2022-11-13)
|
|
109
97
|
|
|
110
|
-
|
|
111
98
|
### Performance Improvements
|
|
112
99
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
100
|
+
- 🔖 publish v3.0.0-alpha.1
|
|
101
|
+
([8f9a0d0](https://github.com/guanghechen/algorithm.ts/commit/8f9a0d0dfee15efc08c4165848123b118c13ce81))
|
|
116
102
|
|
|
117
103
|
# 3.0.0-alpha.0 (2022-09-12)
|
|
118
104
|
|
|
119
|
-
|
|
120
105
|
### Features
|
|
121
106
|
|
|
122
|
-
|
|
123
|
-
|
|
107
|
+
- ✨ refactor base64
|
|
108
|
+
([1059ed6](https://github.com/guanghechen/algorithm.ts/commit/1059ed64895529d0a5c37b6caa3e22ce854f9ef5))
|
|
124
109
|
|
|
125
110
|
### Performance Improvements
|
|
126
111
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
112
|
+
- 🔖 publish v3.0.0-alpha.0
|
|
113
|
+
([7562a90](https://github.com/guanghechen/algorithm.ts/commit/7562a908843d63b6b1bf92e7aa2104e7b294eaa0))
|
|
130
114
|
|
|
131
115
|
## 2.0.14 (2022-08-27)
|
|
132
116
|
|
|
133
|
-
|
|
134
117
|
### Performance Improvements
|
|
135
118
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
119
|
+
- 🔖 publish v2.0.14
|
|
120
|
+
([53a2462](https://github.com/guanghechen/algorithm.ts/commit/53a24624195c9f09422c9769c552f9066bc22c70))
|
|
121
|
+
- 🔧 update build configs
|
|
122
|
+
([266538b](https://github.com/guanghechen/algorithm.ts/commit/266538bb6736e85c2439b706f11865425b570563))
|
|
123
|
+
- 📝 update repo link
|
|
124
|
+
([f0210ca](https://github.com/guanghechen/algorithm.ts/commit/f0210ca93780ed4109c90d4d337604a6b998b01b))
|
|
141
125
|
|
|
142
126
|
## 2.0.13 (2022-06-26)
|
|
143
127
|
|
|
144
|
-
|
|
145
128
|
### Performance Improvements
|
|
146
129
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
130
|
+
- 🔖 publish v2.0.13
|
|
131
|
+
([ebd6447](https://github.com/guanghechen/algorithm.ts/commit/ebd6447586d9958adaff5218e91768eda82b5bec))
|
|
150
132
|
|
|
151
133
|
## 2.0.12 (2022-06-07)
|
|
152
134
|
|
|
153
|
-
|
|
154
135
|
### Performance Improvements
|
|
155
136
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
137
|
+
- 🔖 publish v2.0.12
|
|
138
|
+
([cfc415a](https://github.com/guanghechen/algorithm.ts/commit/cfc415a6e56d76dcf795421d92dd81ac2a39a5fc))
|
|
159
139
|
|
|
160
140
|
## 2.0.11 (2022-04-19)
|
|
161
141
|
|
|
162
|
-
|
|
163
142
|
### Performance Improvements
|
|
164
143
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
144
|
+
- 🔖 publish v2.0.11
|
|
145
|
+
([42feafd](https://github.com/guanghechen/algorithm.ts/commit/42feafd0303f51767aa7e498f6de84d9478c1dca))
|
|
168
146
|
|
|
169
147
|
## 2.0.10 (2022-04-12)
|
|
170
148
|
|
|
171
|
-
|
|
172
149
|
### Performance Improvements
|
|
173
150
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
151
|
+
- 🔖 publish v2.0.10
|
|
152
|
+
([65694a5](https://github.com/guanghechen/algorithm.ts/commit/65694a5108c220d1edff9be57a12bf8c8403e14d))
|
|
177
153
|
|
|
178
154
|
## 2.0.9 (2022-04-10)
|
|
179
155
|
|
|
180
|
-
|
|
181
156
|
### Performance Improvements
|
|
182
157
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
158
|
+
- 🔖 publish v2.0.9
|
|
159
|
+
([1bdac64](https://github.com/guanghechen/algorithm.ts/commit/1bdac6453d21e3cfeca2e65413e01aa720a34d38))
|
|
186
160
|
|
|
187
161
|
## 2.0.8 (2022-04-10)
|
|
188
162
|
|
|
189
|
-
|
|
190
163
|
### Performance Improvements
|
|
191
164
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
165
|
+
- 🔖 publish v2.0.8
|
|
166
|
+
([7d92191](https://github.com/guanghechen/algorithm.ts/commit/7d921919d03570e772a847763100eb1a58d10d2d))
|
|
195
167
|
|
|
196
168
|
## 2.0.8-alpha.0 (2022-04-05)
|
|
197
169
|
|
|
198
|
-
|
|
199
170
|
### Performance Improvements
|
|
200
171
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
172
|
+
- 🔖 publish v2.0.8-alpha.0
|
|
173
|
+
([24a301c](https://github.com/guanghechen/algorithm.ts/commit/24a301c145ad9f6c0e50494de39456c42bb02f29))
|
|
204
174
|
|
|
205
175
|
## 2.0.7 (2022-04-03)
|
|
206
176
|
|
|
207
|
-
|
|
208
177
|
### Performance Improvements
|
|
209
178
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
179
|
+
- 🔖 publish v2.0.7
|
|
180
|
+
([814bc48](https://github.com/guanghechen/algorithm.ts/commit/814bc48415c5bbea555e0807b8a862cf348df5c1))
|
|
213
181
|
|
|
214
182
|
## 2.0.7-alpha.1 (2022-04-03)
|
|
215
183
|
|
|
216
|
-
|
|
217
184
|
### Performance Improvements
|
|
218
185
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
186
|
+
- 🔖 publish v2.0.7-alpha.1
|
|
187
|
+
([fd487f4](https://github.com/guanghechen/algorithm.ts/commit/fd487f425bd3b8273a414ead8b697010fe1a3a83))
|
|
222
188
|
|
|
223
189
|
## 2.0.7-alpha.0 (2022-03-27)
|
|
224
190
|
|
|
225
|
-
|
|
226
191
|
### Performance Improvements
|
|
227
192
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
193
|
+
- 🔖 publish v2.0.7-alpha.0
|
|
194
|
+
([8a89b2b](https://github.com/guanghechen/algorithm.ts/commit/8a89b2b68855a8eee6b244188792bd294e56045f))
|
|
231
195
|
|
|
232
196
|
## 2.0.6 (2022-03-26)
|
|
233
197
|
|
|
234
|
-
|
|
235
198
|
### Performance Improvements
|
|
236
199
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
200
|
+
- 🔖 publish v2.0.6
|
|
201
|
+
([27a96ca](https://github.com/guanghechen/algorithm.ts/commit/27a96ca7e37b440880b5fd3be8bd1bd08939104e))
|
|
240
202
|
|
|
241
203
|
## 2.0.5 (2022-03-23)
|
|
242
204
|
|
|
243
|
-
|
|
244
205
|
### Performance Improvements
|
|
245
206
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
207
|
+
- 🔖 publish v2.0.5
|
|
208
|
+
([b6f49a9](https://github.com/guanghechen/algorithm.ts/commit/b6f49a92024b9062f89a47277f692069e3abd9ec))
|
|
249
209
|
|
|
250
210
|
## 2.0.4 (2022-03-20)
|
|
251
211
|
|
|
252
|
-
|
|
253
212
|
### Performance Improvements
|
|
254
213
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
214
|
+
- 🔖 publish v2.0.4
|
|
215
|
+
([1f37699](https://github.com/guanghechen/algorithm.ts/commit/1f37699b24bbf498fa820a44056c5f7b291308ee))
|
|
258
216
|
|
|
259
217
|
## 2.0.3 (2022-02-24)
|
|
260
218
|
|
|
261
|
-
|
|
262
219
|
### Performance Improvements
|
|
263
220
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
221
|
+
- 🔖 publish v2.0.3
|
|
222
|
+
([bfd7ee8](https://github.com/guanghechen/algorithm.ts/commit/bfd7ee8420771cc02f7ef53833ba17780192cc88))
|
|
267
223
|
|
|
268
224
|
## 2.0.2 (2022-02-24)
|
|
269
225
|
|
|
270
|
-
|
|
271
226
|
### Performance Improvements
|
|
272
227
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
228
|
+
- 🔖 publish v2.0.2
|
|
229
|
+
([386ea6e](https://github.com/guanghechen/algorithm.ts/commit/386ea6eef0154a42689f03c4943c526a1234db45))
|
|
276
230
|
|
|
277
231
|
## 2.0.1 (2022-02-22)
|
|
278
232
|
|
|
279
|
-
|
|
280
233
|
### Performance Improvements
|
|
281
234
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
235
|
+
- 🔖 publish v2.0.1
|
|
236
|
+
([cac97b1](https://github.com/guanghechen/algorithm.ts/commit/cac97b1cbdc95e0c0914b24ea4e4d25e40bb15c5))
|
|
237
|
+
- 📝 update package descriptions
|
|
238
|
+
([a2455ed](https://github.com/guanghechen/algorithm.ts/commit/a2455edb5dbf5e7662e85e04733b86b8d5e30a5b))
|
|
286
239
|
|
|
287
240
|
# 2.0.0 (2022-02-06)
|
|
288
241
|
|
|
289
|
-
|
|
290
242
|
### Performance Improvements
|
|
291
243
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
244
|
+
- 🔖 publish v2.0.0
|
|
245
|
+
([832e998](https://github.com/guanghechen/algorithm.ts/commit/832e998c72a5e2de64cdca52655e2f0456a17ba2))
|
|
295
246
|
|
|
296
247
|
# 2.0.0-alpha.0 (2022-02-05)
|
|
297
248
|
|
|
298
|
-
|
|
299
249
|
### Performance Improvements
|
|
300
250
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
251
|
+
- 🔖 publish v2.0.0-alpha.0
|
|
252
|
+
([f48a558](https://github.com/guanghechen/algorithm.ts/commit/f48a558ad6decd6c5eee4b9a999ac085c9e19a22))
|
|
304
253
|
|
|
305
254
|
## 1.0.24 (2022-01-22)
|
|
306
255
|
|
|
307
|
-
|
|
308
256
|
### Performance Improvements
|
|
309
257
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
258
|
+
- :sparkles: feat:implement '@algorithm.ts/base64'
|
|
259
|
+
([5aef00b](https://github.com/guanghechen/algorithm.ts/commit/5aef00b59f57e2a15dec110b5af2ab320373d85c))
|
|
260
|
+
- 🔖 publish v1.0.24
|
|
261
|
+
([be5ff5e](https://github.com/guanghechen/algorithm.ts/commit/be5ff5ef055a514bd2f9113b541e9f49ad6008b4))
|
|
262
|
+
- 📝 update READMEs
|
|
263
|
+
([89d28d1](https://github.com/guanghechen/algorithm.ts/commit/89d28d1bbf2b7db1f87dbfde8d079a82925a5847))
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<header>
|
|
2
2
|
<h1 align="center">
|
|
3
|
-
<a href="https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@
|
|
3
|
+
<a href="https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@4.0.0/packages/base64/#readme">@algorithm.ts/base64</a>
|
|
4
4
|
</h1>
|
|
5
5
|
<div align="center">
|
|
6
6
|
<a href="https://www.npmjs.com/package/@algorithm.ts/base64">
|
|
@@ -49,30 +49,26 @@
|
|
|
49
49
|
</header>
|
|
50
50
|
<br/>
|
|
51
51
|
|
|
52
|
-
|
|
53
52
|
A typescript implementation of the **base64** encoding. Unlike traditional implementations, this
|
|
54
53
|
project uses `Uint8Array` to represent byte streams.
|
|
55
54
|
|
|
56
|
-
|
|
57
55
|
## Install
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
- npm
|
|
60
58
|
|
|
61
59
|
```bash
|
|
62
60
|
npm install --save @algorithm.ts/base64
|
|
63
61
|
```
|
|
64
62
|
|
|
65
|
-
|
|
63
|
+
- yarn
|
|
66
64
|
|
|
67
65
|
```bash
|
|
68
66
|
yarn add @algorithm.ts/base64
|
|
69
67
|
```
|
|
70
68
|
|
|
71
|
-
|
|
72
69
|
## Usage
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
* `encode`: Encode a Uint8Array into base64 encoded string.
|
|
71
|
+
- `encode`: Encode a Uint8Array into base64 encoded string.
|
|
76
72
|
|
|
77
73
|
```typescript
|
|
78
74
|
// node env: import { TextEncoder } from 'util'
|
|
@@ -87,23 +83,23 @@ project uses `Uint8Array` to represent byte streams.
|
|
|
87
83
|
encode(getBytes('Hello, world!')) // => 'SGVsbG8sIHdvcmxkIQ=='
|
|
88
84
|
```
|
|
89
85
|
|
|
90
|
-
|
|
86
|
+
- `decode`: Decode a base64 encoded string to Uint8Array
|
|
91
87
|
|
|
92
88
|
```typescript
|
|
93
89
|
import { decode } from '@algorithm.ts/base64'
|
|
94
90
|
|
|
95
|
-
const data: Uint8Array = decode('SGVsbG8sIHdvcmxkIQ==')
|
|
91
|
+
const data: Uint8Array = decode('SGVsbG8sIHdvcmxkIQ==')
|
|
96
92
|
const textDecoder = new TextDecoder()
|
|
97
93
|
textDecoder.decode(data) // => 'Hello, world!'
|
|
98
94
|
```
|
|
99
95
|
|
|
100
|
-
|
|
96
|
+
- `validate`: Check if a string is base64 encoded.
|
|
101
97
|
|
|
102
98
|
```typescript
|
|
103
99
|
validate('SGVsbG8sIHdvcmxkIQ==') // => true
|
|
104
100
|
```
|
|
105
101
|
|
|
106
|
-
|
|
102
|
+
- Custom code map.
|
|
107
103
|
|
|
108
104
|
```typescript
|
|
109
105
|
// node env: import { TextEncoder } from 'util'
|
|
@@ -121,37 +117,33 @@ project uses `Uint8Array` to represent byte streams.
|
|
|
121
117
|
base64.encode(getBytes('Hello, world!')) // => RFUraF7rHGcublwjHP==
|
|
122
118
|
```
|
|
123
119
|
|
|
124
|
-
|
|
125
120
|
## Related
|
|
126
121
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
Index | Binary
|
|
130
|
-
|
|
131
|
-
0
|
|
132
|
-
1
|
|
133
|
-
2
|
|
134
|
-
3
|
|
135
|
-
4
|
|
136
|
-
5
|
|
137
|
-
6
|
|
138
|
-
7
|
|
139
|
-
8
|
|
140
|
-
9
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
[homepage]: https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@3.1.1/packages/base64#readme
|
|
122
|
+
- BASE64 Table
|
|
123
|
+
|
|
124
|
+
| Index | Binary | Char | Index | Binary | Char | Index | Binary | Char | Index | Binary | Char |
|
|
125
|
+
| :---: | :----: | :--: | :---: | :----: | :--: | :---: | :----: | :--: | :---: | :----: | :--- |
|
|
126
|
+
| 0 | 000000 | A | 16 | 010000 | Q | 32 | 100000 | g | 48 | 110000 | w |
|
|
127
|
+
| 1 | 000001 | B | 17 | 010001 | R | 33 | 100001 | h | 49 | 110001 | x |
|
|
128
|
+
| 2 | 000010 | C | 18 | 010010 | S | 34 | 100010 | i | 50 | 110010 | y |
|
|
129
|
+
| 3 | 000011 | D | 19 | 010011 | T | 35 | 100011 | j | 51 | 110011 | z |
|
|
130
|
+
| 4 | 000100 | E | 20 | 010100 | U | 36 | 100100 | k | 52 | 110100 | 0 |
|
|
131
|
+
| 5 | 000101 | F | 21 | 010101 | V | 37 | 100101 | l | 53 | 110101 | 1 |
|
|
132
|
+
| 6 | 000110 | G | 22 | 010110 | W | 38 | 100110 | m | 54 | 110110 | 2 |
|
|
133
|
+
| 7 | 000111 | H | 23 | 010111 | X | 39 | 100111 | n | 55 | 110111 | 3 |
|
|
134
|
+
| 8 | 001000 | I | 24 | 011000 | Y | 40 | 101000 | o | 56 | 111000 | 4 |
|
|
135
|
+
| 9 | 001001 | J | 25 | 011001 | Z | 41 | 101001 | p | 57 | 111001 | 5 |
|
|
136
|
+
| 10 | 001010 | K | 26 | 011010 | a | 42 | 101010 | q | 58 | 111010 | 6 |
|
|
137
|
+
| 11 | 001011 | L | 27 | 011011 | b | 43 | 101011 | r | 59 | 111011 | 7 |
|
|
138
|
+
| 12 | 001100 | M | 28 | 011100 | c | 44 | 101100 | s | 60 | 111100 | 8 |
|
|
139
|
+
| 13 | 001101 | N | 29 | 011101 | d | 45 | 101101 | t | 61 | 111101 | 9 |
|
|
140
|
+
| 14 | 001110 | O | 30 | 011110 | e | 46 | 101110 | u | 62 | 111110 | + |
|
|
141
|
+
| 15 | 001111 | P | 31 | 011111 | f | 47 | 101111 | v | 63 | 111111 | / |
|
|
142
|
+
|
|
143
|
+
- [Base64 | Wikipedia](https://en.wikipedia.org/wiki/Base64)
|
|
144
|
+
- [base-64 | github](https://github.com/mathiasbynens/base64)
|
|
145
|
+
- [`atob()` | MDN](https://developer.mozilla.org/en-US/docs/Web/API/atob)
|
|
146
|
+
- [`btoa()` | MDN](https://developer.mozilla.org/en-US/docs/Web/API/btoa)
|
|
147
|
+
|
|
148
|
+
[homepage]:
|
|
149
|
+
https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@4.0.0/packages/base64#readme
|
package/lib/cjs/index.cjs
CHANGED
|
@@ -2,23 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const SANITIZE_REGEX = /([*^$\\])/g;
|
|
6
|
+
const DEFAULT_CODES = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
7
|
+
const DEFAULT_CODE_PADDING = '=';
|
|
6
8
|
class Base64 {
|
|
7
9
|
CODE_LIST;
|
|
8
10
|
CODE_REFLECT;
|
|
9
11
|
CODE_PADDING;
|
|
10
12
|
VALIDATE_REGEX;
|
|
11
13
|
constructor(props = {}) {
|
|
12
|
-
const CODES = props.CODES?.length === 64
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.
|
|
14
|
+
const CODES = props.CODES?.length === 64 ? props.CODES : DEFAULT_CODES;
|
|
15
|
+
const CODE_PADDING = props.CODE_PADDING?.length === 1 ? props.CODE_PADDING : DEFAULT_CODE_PADDING;
|
|
16
|
+
const CODE_LIST = CODES.split('');
|
|
17
|
+
const CODE_REFLECT = { [CODE_PADDING]: 0 };
|
|
18
|
+
for (const [idx, v] of CODE_LIST.entries())
|
|
19
|
+
CODE_REFLECT[v] = idx;
|
|
20
|
+
const VALIDATE_REGEX = new RegExp(`^[${CODES.replace(SANITIZE_REGEX, '\\$1')}]+${CODE_PADDING.replace(SANITIZE_REGEX, '\\$1')}{0,2}$`);
|
|
21
|
+
this.CODE_LIST = CODE_LIST;
|
|
22
|
+
this.CODE_REFLECT = CODE_REFLECT;
|
|
21
23
|
this.CODE_PADDING = CODE_PADDING;
|
|
24
|
+
this.VALIDATE_REGEX = VALIDATE_REGEX;
|
|
22
25
|
}
|
|
23
26
|
encode(data) {
|
|
24
27
|
let result = '';
|
|
@@ -41,19 +44,17 @@ class Base64 {
|
|
|
41
44
|
return result;
|
|
42
45
|
}
|
|
43
46
|
decode(text) {
|
|
44
|
-
if (text.length <= 0 || !this.validate(text))
|
|
47
|
+
if (text.length <= 0 || !this.validate(text))
|
|
45
48
|
throw new TypeError('Invalid base64 string.');
|
|
46
|
-
}
|
|
47
49
|
let countOfPadding = 0;
|
|
48
50
|
const { CODE_PADDING } = this;
|
|
49
51
|
for (let i = text.length - 1; i >= 0 && text[i] === CODE_PADDING; --i)
|
|
50
52
|
countOfPadding += 1;
|
|
51
53
|
const _size = (text.length >> 2) * 3 - countOfPadding;
|
|
52
54
|
const result = new Uint8Array(_size);
|
|
53
|
-
const _end = ((text.length - countOfPadding) >> 2) << 2;
|
|
54
55
|
let i = 0;
|
|
55
56
|
let j = 0;
|
|
56
|
-
for (; i < _end; i += 4, j += 3) {
|
|
57
|
+
for (const _end = ((text.length - countOfPadding) >> 2) << 2; i < _end; i += 4, j += 3) {
|
|
57
58
|
const v = this._decodeUint(text, i);
|
|
58
59
|
result[j] = v >> 16;
|
|
59
60
|
result[j + 1] = (v >> 8) & 0xff;
|
|
@@ -108,3 +109,4 @@ exports.decode = decode;
|
|
|
108
109
|
exports.default = index;
|
|
109
110
|
exports.encode = encode;
|
|
110
111
|
exports.validate = validate;
|
|
112
|
+
//# sourceMappingURL=index.cjs.map
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
const
|
|
1
|
+
const SANITIZE_REGEX = /([*^$\\])/g;
|
|
2
|
+
const DEFAULT_CODES = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
3
|
+
const DEFAULT_CODE_PADDING = '=';
|
|
2
4
|
class Base64 {
|
|
3
5
|
CODE_LIST;
|
|
4
6
|
CODE_REFLECT;
|
|
5
7
|
CODE_PADDING;
|
|
6
8
|
VALIDATE_REGEX;
|
|
7
9
|
constructor(props = {}) {
|
|
8
|
-
const CODES = props.CODES?.length === 64
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.
|
|
10
|
+
const CODES = props.CODES?.length === 64 ? props.CODES : DEFAULT_CODES;
|
|
11
|
+
const CODE_PADDING = props.CODE_PADDING?.length === 1 ? props.CODE_PADDING : DEFAULT_CODE_PADDING;
|
|
12
|
+
const CODE_LIST = CODES.split('');
|
|
13
|
+
const CODE_REFLECT = { [CODE_PADDING]: 0 };
|
|
14
|
+
for (const [idx, v] of CODE_LIST.entries())
|
|
15
|
+
CODE_REFLECT[v] = idx;
|
|
16
|
+
const VALIDATE_REGEX = new RegExp(`^[${CODES.replace(SANITIZE_REGEX, '\\$1')}]+${CODE_PADDING.replace(SANITIZE_REGEX, '\\$1')}{0,2}$`);
|
|
17
|
+
this.CODE_LIST = CODE_LIST;
|
|
18
|
+
this.CODE_REFLECT = CODE_REFLECT;
|
|
17
19
|
this.CODE_PADDING = CODE_PADDING;
|
|
20
|
+
this.VALIDATE_REGEX = VALIDATE_REGEX;
|
|
18
21
|
}
|
|
19
22
|
encode(data) {
|
|
20
23
|
let result = '';
|
|
@@ -37,19 +40,17 @@ class Base64 {
|
|
|
37
40
|
return result;
|
|
38
41
|
}
|
|
39
42
|
decode(text) {
|
|
40
|
-
if (text.length <= 0 || !this.validate(text))
|
|
43
|
+
if (text.length <= 0 || !this.validate(text))
|
|
41
44
|
throw new TypeError('Invalid base64 string.');
|
|
42
|
-
}
|
|
43
45
|
let countOfPadding = 0;
|
|
44
46
|
const { CODE_PADDING } = this;
|
|
45
47
|
for (let i = text.length - 1; i >= 0 && text[i] === CODE_PADDING; --i)
|
|
46
48
|
countOfPadding += 1;
|
|
47
49
|
const _size = (text.length >> 2) * 3 - countOfPadding;
|
|
48
50
|
const result = new Uint8Array(_size);
|
|
49
|
-
const _end = ((text.length - countOfPadding) >> 2) << 2;
|
|
50
51
|
let i = 0;
|
|
51
52
|
let j = 0;
|
|
52
|
-
for (; i < _end; i += 4, j += 3) {
|
|
53
|
+
for (const _end = ((text.length - countOfPadding) >> 2) << 2; i < _end; i += 4, j += 3) {
|
|
53
54
|
const v = this._decodeUint(text, i);
|
|
54
55
|
result[j] = v >> 16;
|
|
55
56
|
result[j + 1] = (v >> 8) & 0xff;
|
|
@@ -100,3 +101,4 @@ const validate = base64.validate.bind(base64);
|
|
|
100
101
|
var index = { encode, decode, validate };
|
|
101
102
|
|
|
102
103
|
export { Base64, decode, index as default, encode, validate };
|
|
104
|
+
//# sourceMappingURL=index.mjs.map
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ interface IBase64Props {
|
|
|
2
2
|
/**
|
|
3
3
|
* @default 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
|
4
4
|
*/
|
|
5
|
-
CODES?: string;
|
|
5
|
+
readonly CODES?: string;
|
|
6
6
|
/**
|
|
7
7
|
* @default '=''
|
|
8
8
|
*/
|
|
9
|
-
CODE_PADDING?: string;
|
|
9
|
+
readonly CODE_PADDING?: string;
|
|
10
10
|
}
|
|
11
11
|
declare class Base64 {
|
|
12
12
|
protected readonly CODE_LIST: string[];
|
|
@@ -30,4 +30,4 @@ declare const _default: {
|
|
|
30
30
|
validate: (text: string) => boolean;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export { Base64, IBase64Props, decode, _default as default, encode, validate };
|
|
33
|
+
export { Base64, type IBase64Props, decode, _default as default, encode, validate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algorithm.ts/base64",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A Base64 encoding implementation.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "guanghechen",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@
|
|
11
|
+
"url": "https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@4.0.0-alpha.0",
|
|
12
12
|
"directory": "packages/base64"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@
|
|
14
|
+
"homepage": "https://github.com/guanghechen/algorithm.ts/tree/@algorithm.ts/base64@4.0.0-alpha.0/packages/base64#readme",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"algorithm",
|
|
17
17
|
"base64"
|
|
@@ -27,9 +27,6 @@
|
|
|
27
27
|
"main": "./lib/cjs/index.cjs",
|
|
28
28
|
"module": "./lib/esm/index.mjs",
|
|
29
29
|
"license": "MIT",
|
|
30
|
-
"engines": {
|
|
31
|
-
"node": ">= 16.0.0"
|
|
32
|
-
},
|
|
33
30
|
"files": [
|
|
34
31
|
"lib/",
|
|
35
32
|
"!lib/**/*.map",
|
|
@@ -38,16 +35,5 @@
|
|
|
38
35
|
"LICENSE",
|
|
39
36
|
"README.md"
|
|
40
37
|
],
|
|
41
|
-
"
|
|
42
|
-
"build": "rimraf lib/ && cross-env NODE_ENV=production rollup -c ../../rollup.config.mjs",
|
|
43
|
-
"prepublishOnly": "yarn build",
|
|
44
|
-
"test": "cross-env TS_NODE_FILES=true NODE_OPTIONS=--experimental-vm-modules jest --config ../../jest.config.mjs --rootDir ."
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"cross-env": "^7.0.3",
|
|
48
|
-
"jest": "^29.5.0",
|
|
49
|
-
"rimraf": "^5.0.1",
|
|
50
|
-
"rollup": "^3.24.1"
|
|
51
|
-
},
|
|
52
|
-
"gitHead": "a47ef12836f8878f7fdf49e1930d0dd6b3a349bc"
|
|
38
|
+
"gitHead": "6a88f4a7ccb2ea5416185b562482255d752c4528"
|
|
53
39
|
}
|